Skip to content

Commit daba1b4

Browse files
authored
Merge pull request #34 from didww/typos
fixed typos
2 parents 354109b + a347bad commit daba1b4

File tree

2 files changed

+69
-59
lines changed

2 files changed

+69
-59
lines changed

README.md

Lines changed: 68 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,57 @@
1-
## Activeresource-response
2-
This gem adds possibility to access http response (Net::HTTPResponse) object from result (single object or collection) of activeresource call (methods : find, all, first, last, get )
1+
## ActiveResource-Response
2+
This gem adds the ability to access the HTTP response (`Net::HTTPResponse`) object from the result (either a single object or a collection) of an ActiveResource call (methods: `find`, `all`, `first`, `last`, `get`).
33

4-
#### Why It can be used?
5-
Such functionallity can be used for easily implementing pagination in a REST API so that an ActiveResource client can navigate paginated results.
4+
#### Why Can It Be Used?
5+
This functionality can be used to easily implement pagination in a REST API, so that an ActiveResource client can navigate paginated results.
66

7-
#### How to use?
8-
Add dependency to your Gemfile
7+
#### How to Use?
8+
Add the dependency to your `Gemfile`:
99

1010
```ruby
1111
gem "activeresource-response"
1212
```
1313

14-
Just open your ActiveResource class and add
14+
Open your ActiveResource class and add:
1515

1616
```ruby
1717
add_response_method :your_method_name
1818
```
1919

20-
You can add method to ActiveResource::Base to use it in all subclasses
20+
You can add the method to `ActiveResource::Base` to use it in all subclasses:
2121

2222
```ruby
2323
class ActiveResource::Base
2424
add_response_method :my_response
2525
end
2626
```
2727

28-
You can remove method from ActiveResource subclass
28+
You can remove the method from an ActiveResource subclass:
2929

3030
```ruby
3131
class Order < ActiveResource::Base
3232
remove_response_method
3333
end
3434
```
3535

36-
## Full example of usage with kaminari gem
36+
## Full Example of Usage with the Kaminari Gem
3737

38-
ActiveResource Class
38+
ActiveResource Class:
3939

4040
```ruby
4141
class Order < ActiveResource::Base
4242
self.format = :json
4343
self.site = 'http://0.0.0.0:3000/'
4444
self.element_name = "order"
45-
add_response_method :http_response # our new method for returned objects
45+
add_response_method :http_response # Our new method for returned objects
4646
end
4747
```
4848

49-
```ruby
50-
Server Side
49+
Server Side:
5150

51+
```ruby
5252
class OrdersController < ApplicationController
5353
def index
54-
@orders = Order.page(params[:page]).per(params[:per_page] || 10) #default 10 per page
54+
@orders = Order.page(params[:page]).per(params[:per_page] || 10) # default 10 per page
5555
response.headers["X-total"] = @orders.total_count.to_s
5656
response.headers["X-offset"] = @orders.offset_value.to_s
5757
response.headers["X-limit"] = @orders.limit_value.to_s
@@ -60,13 +60,13 @@ class OrdersController < ApplicationController
6060
end
6161
```
6262

63-
Client Side
63+
Client Side:
6464

6565
```ruby
6666
class OrdersController < ApplicationController
6767
def index
6868
orders = Order.all(params: params)
69-
@orders = Kaminari::PaginatableArray.new(orders,{
69+
@orders = Kaminari::PaginatableArray.new(orders, {
7070
limit: orders.http_response['X-limit'].to_i,
7171
offset: orders.http_response['X-offset'].to_i,
7272
total_count: orders.http_response['X-total'].to_i
@@ -75,92 +75,102 @@ class OrdersController < ApplicationController
7575
end
7676
```
7777

78-
### will_paginate compatibility
79-
will_paginate has a little different API, so to populate headers
78+
### Will_paginate Compatibility
79+
`will_paginate` has a slightly different API, so to populate the headers:
8080

8181
```ruby
8282
response.headers["X-total"] = @orders.total_entries.to_s
8383
response.headers["X-offset"] = @orders.offset.to_s
8484
response.headers["X-limit"] = @orders.per_page.to_s
85-
```
85+
```
8686

87-
On the API client side you might also use will_paginate, in that case you can just require will_paginate/array (in initializer for example)
88-
```ruby
89-
orders = Order.all(params: params)
90-
@orders = WillPaginate::Collection.create(params[:page] || 1, params[:per_page] || 10, orders.http_response['X-total'].to_i) do |pager|
87+
On the API client side, you might also use `will_paginate`. In that case, you can just require `will_paginate/array` (e.g., in an initializer):
88+
89+
```ruby
90+
orders = Order.all(params: params)
91+
@orders = WillPaginate::Collection.create(params[:page] || 1, params[:per_page] || 10, orders.http_response['X-total'].to_i) do |pager|
9192
pager.replace orders
9293
end
9394
```
9495

95-
### Every time when http connection invoked ActiveResource connection object stores http response. You can access it with http_response method.
96-
Example
96+
### Every Time an HTTP Connection is Invoked
97+
The ActiveResource connection object stores the HTTP response. You can access it with the `http_response` method.
98+
99+
Example:
100+
97101
```ruby
98102
class Order < ActiveResource::Base
99103
self.site = 'http://0.0.0.0:3000/'
100104
self.element_name = "order"
101-
add_response_method :my_response # our new method
105+
add_response_method :my_response # Our new method
102106
end
103107

104108
orders = Order.all
105109
first_order = Order.find(1)
106-
#see Net::HTTPResponse#[] method
110+
# See Net::HTTPResponse#[] method
107111
orders.my_response['content-length']
108112
# => "3831"
109113
first_order.my_response['content-length']
110-
#=> "260"
111-
#connection also always has last http response object , to access it use http_response method
114+
# => "260"
115+
# Connection also always has the last HTTP response object. To access it, use the http_response method:
112116
Order.connection.http_response.to_hash
113117
# => {"content-type"=>["application/json; charset=utf-8"], "x-ua-compatible"=>["IE=Edge"], "etag"=>["\"573cabd02b2f1f90405f7f4f77995fab\""], "cache-control"=>["max-age=0, private, must-revalidate"], "x-request-id"=>["2911c13a0c781044c474450ed789613d"], "x-runtime"=>["0.071018"], "content-length"=>["260"], "server"=>["WEBrick/1.3.1 (Ruby/1.9.2/2011-02-18)"], "date"=>["Sun, 19 Feb 2012 10:21:29 GMT"], "connection"=>["close"]}
114-
```
115-
116-
### Custom get method
117-
You can access response from result of custom get method
118-
Example
118+
```
119+
120+
### Custom `get` Method
121+
You can access the response from the result of a custom `get` method.
122+
123+
Example:
124+
119125
```ruby
120126
class Country < ActiveResource::Base
121127
self.site = 'http://0.0.0.0:3000/'
122-
add_response_method :http # our new method
128+
add_response_method :http # Our new method
123129
end
130+
124131
cities = Country.find(1).get(:cities)
125-
cities.http #method from Country class is available
126-
```
132+
cities.http # Method from the Country class is available
133+
```
134+
135+
### Headers and Cookies Methods
136+
You can get cookies and headers from the response.
137+
138+
Example:
127139

128-
### Headers and cookies methods
129-
You can get cookies and headers from response
130-
Example
131140
```ruby
132141
class Country < ActiveResource::Base
133142
self.site = 'http://0.0.0.0:3000/'
134-
add_response_method :my_response # our new method
143+
add_response_method :my_response # Our new method
135144
end
145+
136146
countries = Country.all
137147
countries.my_response.headers
138148

139-
# collection with symbolized keys => {:content_type=>["application/json; charset=utf-8"], :x_ua_compatible=>["IE=Edge"], ..., :set_cookie=>["bar=foo; path=/", "foo=bar; path=/"]}
149+
# Collection with symbolized keys:
150+
# {:content_type=>["application/json; charset=utf-8"], :x_ua_compatible=>["IE=Edge"], ..., :set_cookie=>["bar=foo; path=/", "foo=bar; path=/"]}
140151

141152
countries.my_response.cookies
142-
# => {"bar"=>"foo", "foo"=>"bar"}
143-
```
144-
145-
### Note About Http response
146-
http response is object of ```Net::HTTPOK```, ```Net::HTTPClientError``` or one of other subclasses
147-
of Net::HTTPResponse class. For more information see documentation http://www.ruby-doc.org/stdlib-1.9.3/libdoc/net/http/rdoc/Net/HTTPResponse.html
153+
# => {"bar"=>"foo", "foo"=>"bar"}
154+
```
155+
156+
### Note About HTTP Response
157+
The HTTP response is an object of `Net::HTTPOK`, `Net::HTTPClientError`, or one of the other subclasses of the `Net::HTTPResponse` class. For more information, see the documentation: [Net::HTTPResponse](http://www.ruby-doc.org/stdlib-1.9.3/libdoc/net/http/rdoc/Net/HTTPResponse.html).
148158

149159
### Testing with ActiveResource::HttpMock
150-
Add this line to your test to patch http_mock
160+
Add this line to your test to patch `http_mock`:
151161

152162
```ruby
153-
require "active_resource_response/http_mock"
163+
require "active_resource_response/http_mock"
154164
```
155165

156166
### Contributing
157-
Fork it
158-
Create your feature branch (git checkout -b my-new-feature)
159-
Commit your changes (git commit -am 'Add some feature')
160-
Push to the branch (git push origin my-new-feature)
161-
Create new Pull Request
167+
1. Fork it
168+
2. Create your feature branch (`git checkout -b my-new-feature`)
169+
3. Commit your changes (`git commit -am 'Add some feature'`)
170+
4. Push to the branch (`git push origin my-new-feature`)
171+
5. Create a new Pull Request
162172

163-
164-
#### Please, feel free to contact me if you have any questions
173+
#### Please feel free to contact me if you have any questions:
165174
fedoronchuk(at)gmail.com
166175

176+

activeresource-response.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
88
s.version = ActiveResourceResponse::Version::VERSION
99
s.authors = ["Igor Fedoronchuk"]
1010
s.email = ["[email protected]"]
11-
s.homepage = "http://fivell.github.com/activeresource-response/"
11+
s.homepage = "https://github.com/didww/activeresource-response"
1212
s.summary = %q{activeresource extension}
1313
s.description = %q{This gem adds possibility to access http response object from result of ActiveResource::Base find method }
1414
s.license = 'MIT'

0 commit comments

Comments
 (0)