Using a JSON service as a Rails model

Viewed 2280

How can I use a JSON service as a model for a Rails 3.2 application?

I would like to link model methods to JSON requests, e.g.

  • MyModel.create to generate a JSON request to create a new record
  • MyModel.find to generate a JSON request to retrieve a record and decode the JSON response into a model object

What is the preferred way to build this type of functionality? One option that I am looking at is to create a custom DataMapper adapter.

Thanks.

Update:
Note that I can't use ActiveResource because this requires the JSON service to respond in a certain way, which it doesn't in this instance.

5 Answers
Related