Permalink
Browse files

lets use a real example

  • Loading branch information...
1 parent b3b4069 commit 6242b5eebd7e675f06ec3322fcf45aaa07a92fac @clayallsopp committed May 8, 2012
Showing with 3 additions and 4 deletions.
  1. +3 −4 README.md
View
7 README.md
@@ -106,22 +106,21 @@ end
## How?
-RemoteModel is designed for JSON apis which return structures with "nice" properties.
+RemoteModel is designed for JSON APIs which return structures with "nice" properties.
When you make a request with a RemoteModel (self.get/put/post/delete), the result is always parsed as JSON. The ActiveRecord-esque methods take this JSON and create objects out of it. It's clever and creates the proper associations (belongs_to/has_one/has_many) within the objects, as defined in the models.
#### FormatableString
-The AR methods also use the member/collection defined URLs to make requests. These URLs are a string which you can use :symbols to input dynamic values. These strings can be formatted using a hash and/or taking an object (it will look to see if the object responds to these symbols and call the method if applicable):
+The AR methods also use the member/collection defined URLs to make requests. These URLs are a string which you can use :symbols to input dynamic values. These strings can be formatted using a hash and/or using an object (it will look to see if the object responds to these symbols and call the method if applicable):
```ruby
>> s = RemoteModule::FormatableString.new("url/:param")
=> "url/:param"
>> s.format({param: 6})
=> "url/6"
->> obj = SomeObjectThatRespondsToParam.new
+>> obj = Struct.new("Paramer", :param).new(param: 100)
=> ...
->> obj.param = 10
>> s.format({}, obj)
=> "url/100"
```

0 comments on commit 6242b5e

Please sign in to comment.