You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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`).
3
3
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.
6
6
7
-
#### How to use?
8
-
Add dependency to your Gemfile
7
+
#### How to Use?
8
+
Add the dependency to your `Gemfile`:
9
9
10
10
```ruby
11
11
gem "activeresource-response"
12
12
```
13
13
14
-
Just open your ActiveResource class and add
14
+
Open your ActiveResource class and add:
15
15
16
16
```ruby
17
17
add_response_method :your_method_name
18
18
```
19
19
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:
21
21
22
22
```ruby
23
23
classActiveResource::Base
24
24
add_response_method :my_response
25
25
end
26
26
```
27
27
28
-
You can remove method from ActiveResource subclass
28
+
You can remove the method from an ActiveResource subclass:
29
29
30
30
```ruby
31
31
classOrder < ActiveResource::Base
32
32
remove_response_method
33
33
end
34
34
```
35
35
36
-
## Full example of usage with kaminari gem
36
+
## Full Example of Usage with the Kaminari Gem
37
37
38
-
ActiveResource Class
38
+
ActiveResource Class:
39
39
40
40
```ruby
41
41
classOrder < ActiveResource::Base
42
42
self.format=:json
43
43
self.site ='http://0.0.0.0:3000/'
44
44
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
46
46
end
47
47
```
48
48
49
-
```ruby
50
-
ServerSide
49
+
Server Side:
51
50
51
+
```ruby
52
52
classOrdersController < ApplicationController
53
53
defindex
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
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).
148
158
149
159
### 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`:
151
161
152
162
```ruby
153
-
require"active_resource_response/http_mock"
163
+
require"active_resource_response/http_mock"
154
164
```
155
165
156
166
### 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
162
172
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:
0 commit comments