activeresource-response 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc ADDED
@@ -0,0 +1,50 @@
1
+ = Activeresource-response
2
+
3
+ This gem adds possibility to access http response object from result of activeresource call (see ActiveResource::Base#find)
4
+
5
+ == Why It can be used?
6
+ Such functionallity can be used for easily implementing pagination in a REST API so that an ActiveResource client can navigate paginated results.
7
+
8
+ == How to use?
9
+ Just open your ActiveResource class and add
10
+
11
+ add_response_method :your_method_name
12
+
13
+ == Full example of usage with kaminari gem
14
+
15
+ Rest Client
16
+
17
+ class Order < ActiveResource::Base
18
+ self.format = :json
19
+ self.site = 'http://0.0.0.0:3000/'
20
+ self.element_name = "order"
21
+ add_response_method :http_response # our new method
22
+ end
23
+
24
+ Server Side
25
+
26
+ class OrdersController < ApplicationController
27
+ def index
28
+ @orders = Order.page(params[:page]).per(params[:per_page])
29
+ response.headers["X-total"] = @orders.total_count.to_s
30
+ response.headers["X-offset"] = @orders.offset_value.to_s
31
+ response.headers["X-limit"] = @orders.limit_value.to_s
32
+ respond_with(@orders)
33
+ end
34
+ end
35
+
36
+ Client Side
37
+
38
+ class OrdersController < ApplicationController
39
+ def index
40
+ orders = Order.all(:params=>params)
41
+ @orders = Kaminari::PaginatableArray.new(
42
+ orders,{
43
+ :limit => orders.http_response['X-limit'].to_i,
44
+ :offset =>orders.http_response['X-offset'].to_i,
45
+ :total_count => orders.http_response['X-total'].to_i
46
+ })
47
+ end
48
+ end
49
+
50
+
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
9
9
  s.email = ["fedoronchuk@gmail.com"]
10
10
  s.homepage = "https://github.com/Fivell/activeresource-response"
11
11
  s.summary = %q{activeresoure extension}
12
- s.description = %q{create method for ActiveResource::Base object to access to response }
12
+ s.description = %q{adding possibility to access http response object from result of activeresource call }
13
13
 
14
14
 
15
15
  s.add_dependency('activeresource', '>= 3.1')
@@ -1,3 +1,3 @@
1
1
  module ActiveresourceResponse
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: activeresource-response
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.2
5
+ version: 0.0.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Igor Fedoronchuk
@@ -23,7 +23,7 @@ dependencies:
23
23
  version: "3.1"
24
24
  type: :runtime
25
25
  version_requirements: *id001
26
- description: "create method for ActiveResource::Base object to access to response "
26
+ description: "adding possibility to access http response object from result of activeresource call "
27
27
  email:
28
28
  - fedoronchuk@gmail.com
29
29
  executables: []
@@ -35,7 +35,7 @@ extra_rdoc_files: []
35
35
  files:
36
36
  - .gitignore
37
37
  - Gemfile
38
- - README
38
+ - README.rdoc
39
39
  - Rakefile
40
40
  - activeresource-response.gemspec
41
41
  - lib/activeresource-response.rb
data/README DELETED
@@ -1 +0,0 @@
1
- Read Me!!