Skip to content

Commit 25b41a3

Browse files
authored
Merge pull request #373 from obahareth/set-readme-snippets-language
Set Language on Code Snippets in README.md
2 parents 36d2e9d + 0195630 commit 25b41a3

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

README.md

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Source code can be downloaded on GitHub
3939
Putting Active Resource to use is very similar to Active Record. It's as simple as creating a model class
4040
that inherits from ActiveResource::Base and providing a <tt>site</tt> class variable to it:
4141

42-
```
42+
```rb
4343
class Person < ActiveResource::Base
4444
self.site = "http://api.people.com:3000"
4545
end
@@ -48,7 +48,7 @@ end
4848
Now the Person class is REST enabled and can invoke REST services very similarly to how Active Record invokes
4949
life cycle methods that operate against a persistent store.
5050

51-
```
51+
```rb
5252
# Find a person with id = 1
5353
tyler = Person.find(1)
5454
Person.exists?(1) # => true
@@ -60,13 +60,14 @@ records. But rather than dealing directly with a database record, you're dealin
6060
Connection settings (`site`, `headers`, `user`, `password`, `bearer_token`, `proxy`) and the connections themselves are store in
6161
thread-local variables to make them thread-safe, so you can also set these dynamically, even in a multi-threaded environment, for instance:
6262

63-
ActiveResource::Base.site = api_site_for(request)
64-
63+
```rb
64+
ActiveResource::Base.site = api_site_for(request)
65+
```
6566
### Authentication
6667

6768
Active Resource supports the token based authentication provided by Rails through the <tt>ActionController::HttpAuthentication::Token</tt> class using custom headers.
6869

69-
```
70+
```rb
7071
class Person < ActiveResource::Base
7172
self.headers['Authorization'] = 'Token token="abcd"'
7273
end
@@ -81,7 +82,7 @@ ActiveResource::Base.headers['Authorization'] = current_session_api_token
8182
ActiveResource supports 2 options for HTTP authentication today.
8283

8384
1. Basic
84-
```
85+
```rb
8586
class Person < ActiveResource::Base
8687
self.user = '[email protected]'
8788
self.password = '123'
@@ -90,7 +91,7 @@ end
9091
```
9192

9293
2. Bearer Token
93-
```
94+
```rb
9495
class Person < ActiveResource::Base
9596
self.auth_type = :bearer
9697
self.bearer_token = 'my-token123'
@@ -117,7 +118,7 @@ for more general information on REST web services, see the article here[http://e
117118
Find requests use the GET method and expect the JSON form of whatever resource/resources is/are being requested. So,
118119
for a request for a single element, the JSON of that item is expected in response:
119120

120-
```
121+
```rb
121122
# Expects a response of
122123
#
123124
# {"id":1,"first":"Tyler","last":"Durden"}
@@ -130,14 +131,14 @@ tyler = Person.find(1)
130131
The JSON document that is received is used to build a new object of type Person, with each
131132
JSON element becoming an attribute on the object.
132133

133-
```
134+
```rb
134135
tyler.is_a? Person # => true
135136
tyler.last # => 'Durden'
136137
```
137138

138139
Any complex element (one that contains other elements) becomes its own object:
139140

140-
```
141+
```rb
141142
# With this response:
142143
# {"id":1,"first":"Tyler","address":{"street":"Paper St.","state":"CA"}}
143144
#
@@ -150,7 +151,7 @@ tyler.address.street # => 'Paper St.'
150151

151152
Collections can also be requested in a similar fashion
152153

153-
```
154+
```rb
154155
# Expects a response of
155156
#
156157
# [
@@ -172,7 +173,7 @@ a 'Location' header in the response with the RESTful URL location of the newly c
172173
id of the newly created resource is parsed out of the Location response header and automatically set
173174
as the id of the ARes object.
174175

175-
```
176+
```rb
176177
# {"first":"Tyler","last":"Durden"}
177178
#
178179
# is submitted as the body on
@@ -200,7 +201,7 @@ tyler.id # => 2
200201
with the exception that no response headers are needed -- just an empty response when the update on the
201202
server side was successful.
202203

203-
```
204+
```rb
204205
# {"first":"Tyler"}
205206
#
206207
# is submitted as the body on
@@ -223,7 +224,7 @@ tyler.save # => true
223224

224225
Destruction of a resource can be invoked as a class and instance method of the resource.
225226

226-
```
227+
```rb
227228
# A request is made to
228229
#
229230
# DELETE http://api.people.com:3000/people/1.json
@@ -244,7 +245,7 @@ Relationships between resources can be declared using the standard association s
244245
that should be familiar to anyone who uses activerecord. For example, using the
245246
class definition below:
246247

247-
```
248+
```rb
248249
class Post < ActiveResource::Base
249250
self.site = "http://blog.io"
250251
has_many :comments
@@ -261,7 +262,7 @@ second network request. Given the resource above, if the response includes comme
261262
in the response, they will be automatically loaded into the activeresource object.
262263
The server-side model can be adjusted as follows to include comments in the response.
263264

264-
```
265+
```rb
265266
class Post < ActiveRecord::Base
266267
has_many :comments
267268

@@ -276,7 +277,7 @@ end
276277
Active Resource instruments the event `request.active_resource` when doing a request
277278
to the remote service. You can subscribe to it by doing:
278279

279-
```
280+
```rb
280281
ActiveSupport::Notifications.subscribe('request.active_resource') do |name, start, finish, id, payload|
281282
```
282283

0 commit comments

Comments
 (0)