Dear All,

I'm trying to build a ruby library to communicate with a REST API. I'm
thinking to make it as an abstraction so it can be modular.
for example

the API is structure as RESTful web service which is Rails like

/devices -> list all device
/devices/12 -> show specific device
/documents
/documents/14

etc.

The problem that I'm facing it structuring the library with module and
class. I wanted to make something like

client = MyLibrary.new user: 'user', password: 'password'

array_of_devices = client.devices.all -> GET /device
devies = client.device.create -> POST /device
device = client.device.get(1) -> GET /device/1

document = client.document.new(device)
document.save

and maybe in the future
document.device -> will return the device where the document belongs to

etc.

first of all is storing the config (user and password) because all of the
api needed this. My question is how to I structure it.

client.devices will return module or class ?
and how to share config variable with the other class or module within the
library.

If you have like a resource, book or maybe a project that go into the
detail of designin API library especially with REST that would help me a
lot and appreciate it.

Thank you very much

Ahmy Yulrizka

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • Colin Law at Jun 11, 2012 at 8:51 am

    On 11 June 2012 09:14, Ahmy Yulrizka wrote:
    Dear All,

    I'm trying to build a ruby library to communicate with a REST API. I'm
    thinking to make it as an abstraction so it can be modular.
    for example

    the API is structure as RESTful web service which is Rails like

    /devices -> list all device
    /devices/12 -> show specific device
    /documents
    /documents/14

    etc.

    The problem that I'm facing it structuring the library with module and
    class. I wanted to make something like

    client = MyLibrary.new user: 'user', password: 'password'

    array_of_devices = client.devices.all -> GET /device
    devies = client.device.create -> POST /device
    device = client.device.get(1) -> GET /device/1

    document = client.document.new(device)
    document.save

    and maybe in the future
    document.device -> will return the device where the document belongs to

    etc.

    first of all is storing the config (user and password) because all of the
    api needed this. My question is how to I structure it.
    I am not sure I fully understand the problem as the answer seems
    obvious, but if I do understand then the config would be stored as
    attributes of the MyLibrary object, so would be available as
    client.user or self.user, for example, when inside the class.
    client.devices will return module or class ?
    and how to share config variable with the other class or module within the
    library.
    Presumably client.device would be Device object, whatever that is,
    though again I am not sure I understand the question fully.

    Have you looked at ActiveResource? I have not used it myself but I
    think it may already do what you are trying to achieve.

    Colin

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Ahmy Yulrizka at Jun 11, 2012 at 11:37 am
    Sorry i think there is lack of consistency in my previous message.
    it should be

    client = MyLibrary.new user: 'user', password: 'password'

    array_of_devices = client.devices.all -> GET /device
    devies = client.devices.create -> POST /device
    device = client.devices.get(1) -> GET /device/1

    i understand that user and password would be attribute on client object.
    but for example,

    client.devices -> would this return a new class or its just a
    MyClient::Device module that have included in the client.
    client.devices.all -> where is the function 'all' implemented ?
    device = client.devices.find(1) -> this will return a new object of class
    Device right.

    then when i do device.save()
    'save' method on object device will have to send a request (POST or PUT).
    then the class should know the user and password which is stored in the
    client object. should I pass the user and password variable to the device
    object or there is a better way ?

    Thank you Collin, I will look at the ActiveResource implementation

    Kind Regards,
    Ahmy Yulrizka

    On Mon, Jun 11, 2012 at 10:50 AM, Colin Law wrote:
    On 11 June 2012 09:14, Ahmy Yulrizka wrote:
    Dear All,

    I'm trying to build a ruby library to communicate with a REST API. I'm
    thinking to make it as an abstraction so it can be modular.
    for example

    the API is structure as RESTful web service which is Rails like

    /devices -> list all device
    /devices/12 -> show specific device
    /documents
    /documents/14

    etc.

    The problem that I'm facing it structuring the library with module and
    class. I wanted to make something like

    client = MyLibrary.new user: 'user', password: 'password'

    array_of_devices = client.devices.all -> GET /device
    devies = client.device.create -> POST /device
    device = client.device.get(1) -> GET /device/1

    document = client.document.new(device)
    document.save

    and maybe in the future
    document.device -> will return the device where the document belongs to

    etc.

    first of all is storing the config (user and password) because all of the
    api needed this. My question is how to I structure it.
    I am not sure I fully understand the problem as the answer seems
    obvious, but if I do understand then the config would be stored as
    attributes of the MyLibrary object, so would be available as
    client.user or self.user, for example, when inside the class.
    client.devices will return module or class ?
    and how to share config variable with the other class or module within the
    library.
    Presumably client.device would be Device object, whatever that is,
    though again I am not sure I understand the question fully.

    Have you looked at ActiveResource? I have not used it myself but I
    think it may already do what you are trying to achieve.

    Colin

    --
    You received this message because you are subscribed to the Google Groups
    "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to
    rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at
    http://groups.google.com/group/rubyonrails-talk?hl=en.
    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Garcia Souza at Jun 12, 2012 at 1:07 pm
    Dear Ahmy Yulrizka,

    I think what you are searching for is a REST Client API for Ruby that have
    integration with ActiveResource.

    Hope this help you :)

    2012/6/11 Ahmy Yulrizka <ahmy135@gmail.com>
    Sorry i think there is lack of consistency in my previous message.
    it should be

    client = MyLibrary.new user: 'user', password: 'password'

    array_of_devices = client.devices.all -> GET /device
    devies = client.devices.create -> POST /device
    device = client.devices.get(1) -> GET /device/1

    i understand that user and password would be attribute on client object.
    but for example,

    client.devices -> would this return a new class or its just a
    MyClient::Device module that have included in the client.
    client.devices.all -> where is the function 'all' implemented ?
    device = client.devices.find(1) -> this will return a new object of class
    Device right.

    then when i do device.save()
    'save' method on object device will have to send a request (POST or PUT).
    then the class should know the user and password which is stored in the
    client object. should I pass the user and password variable to the device
    object or there is a better way ?

    Thank you Collin, I will look at the ActiveResource implementation

    Kind Regards,
    Ahmy Yulrizka


    On Mon, Jun 11, 2012 at 10:50 AM, Colin Law wrote:
    On 11 June 2012 09:14, Ahmy Yulrizka wrote:
    Dear All,

    I'm trying to build a ruby library to communicate with a REST API. I'm
    thinking to make it as an abstraction so it can be modular.
    for example

    the API is structure as RESTful web service which is Rails like

    /devices -> list all device
    /devices/12 -> show specific device
    /documents
    /documents/14

    etc.

    The problem that I'm facing it structuring the library with module and
    class. I wanted to make something like

    client = MyLibrary.new user: 'user', password: 'password'

    array_of_devices = client.devices.all -> GET /device
    devies = client.device.create -> POST /device
    device = client.device.get(1) -> GET /device/1

    document = client.document.new(device)
    document.save

    and maybe in the future
    document.device -> will return the device where the document belongs to

    etc.

    first of all is storing the config (user and password) because all of the
    api needed this. My question is how to I structure it.
    I am not sure I fully understand the problem as the answer seems
    obvious, but if I do understand then the config would be stored as
    attributes of the MyLibrary object, so would be available as
    client.user or self.user, for example, when inside the class.
    client.devices will return module or class ?
    and how to share config variable with the other class or module within the
    library.
    Presumably client.device would be Device object, whatever that is,
    though again I am not sure I understand the question fully.

    Have you looked at ActiveResource? I have not used it myself but I
    think it may already do what you are trying to achieve.

    Colin

    --
    You received this message because you are subscribed to the Google Groups
    "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to
    rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at
    http://groups.google.com/group/rubyonrails-talk?hl=en.
    --
    You received this message because you are subscribed to the Google Groups
    "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to
    rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at
    http://groups.google.com/group/rubyonrails-talk?hl=en.


    --
    *Garcia Souza.*

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedJun 11, '12 at 8:15a
activeJun 12, '12 at 1:07p
posts4
users3
websiterubyonrails.org
irc#RubyOnRails

People

Translate

site design / logo © 2021 Grokbase