restful_resource 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9f17e8f89884d658d625011c557a6f9f0c6c571c
4
- data.tar.gz: afc30ece06fb8a423b3eb7ba0f785b7ae9e153b3
3
+ metadata.gz: c8e1e4d94c7b281da63d40df207eccf513c8be52
4
+ data.tar.gz: 5b3631c56fc97945ac8387cdc68992c6b811f405
5
5
  SHA512:
6
- metadata.gz: c71670a30ec98b98447f0ac17a6785eab1dad1c98a164379319d48f7495e7a3c939aa49e7ff4c5886d293c0024a62072c2c426a38134c47152c26d537cc28035
7
- data.tar.gz: 9e9acc3e3004004fbceb68691b0807428d689979554ba67d0869d2d988f44fd15313b267f154d0c7623ca3f9325974216cca974b82100ff4b9227de3bba88e10
6
+ metadata.gz: 112296a67c1befbdf82f0d2fce70b6e7b96490e2f3a406f326ec164c15bc907c0287da7a371d8922f334e728816ee2f9a824503c80be1e6a362bb979bd0e1932
7
+ data.tar.gz: 8bfa1a701d6e1a1ef08fbb3b6b6cd123cc7bc47e574e13267725cfd9131bdf080b516f4afd83cac113e0a422ec0399db8c1445401f8fd813edc22dd3622e0813
@@ -76,6 +76,12 @@ module RestfulResource
76
76
  self.new(ActiveSupport::JSON.decode(response))
77
77
  end
78
78
 
79
+ def self.get_one(url_params={})
80
+ resource = create_new_resource(url_params)
81
+ response = resource.get
82
+ self.new(ActiveSupport::JSON.decode(response))
83
+ end
84
+
79
85
  def self.update_attributes(id, attributes)
80
86
  begin
81
87
  result = parse(RestClient.put("#{url}/#{id}", attributes))
@@ -102,8 +108,8 @@ module RestfulResource
102
108
  end
103
109
 
104
110
  def self.all(params = {})
105
- url, other_params = processed_url_and_params(params)
106
- response = RestClient.get("#{url}", params: other_params)
111
+ resource = create_new_resource(params)
112
+ response = resource.get
107
113
  paginate_response(response)
108
114
  end
109
115
 
@@ -155,5 +161,12 @@ module RestfulResource
155
161
  array = ActiveSupport::JSON.decode(response).map { |attributes| self.new(attributes) }
156
162
  PaginatedArray.new(array, previous_page_url: prev_url, next_page_url: next_url)
157
163
  end
164
+
165
+ def self.create_new_resource(params={})
166
+ url, other_params = processed_url_and_params(params)
167
+ url += "?#{other_params.to_query}" if not other_params.empty?
168
+ resource = RestClient::Resource.new("#{url}")
169
+ end
170
+
158
171
  end
159
172
  end
@@ -1,3 +1,3 @@
1
1
  module RestfulResource
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
@@ -54,7 +54,7 @@ describe RestfulResource::Base do
54
54
  context "#all" do
55
55
  it "should provide a paginated result if response contains rest pagination headers" do
56
56
  response = response_with_page_information()
57
- stub_get('http://api.carwow.co.uk/teams', response)
57
+ stub_new_resource('http://api.carwow.co.uk/teams', response)
58
58
 
59
59
  teams = Team.all
60
60
 
@@ -73,8 +73,7 @@ describe RestfulResource::Base do
73
73
  end
74
74
 
75
75
  it "should use some params for the url and other for the query string" do
76
- stub_get('http://api.carwow.co.uk/teams/15/players', response_with_page_information,
77
- {name_like: 'Ars'})
76
+ stub_new_resource('http://api.carwow.co.uk/teams/15/players?name_like=Ars', response_with_page_information)
78
77
 
79
78
  players = Player.all(team_id: 15, name_like: 'Ars')
80
79
  end
@@ -86,6 +85,11 @@ describe RestfulResource::Base do
86
85
  end
87
86
 
88
87
  private
88
+ def stub_new_resource(url, fake_response)
89
+ resource = instance_double('RestClient::Resource', get: fake_response)
90
+ allow(RestClient::Resource).to receive(:new).with(url).and_return resource
91
+ end
92
+
89
93
  def stub_get(url, fake_response, params = {})
90
94
  expect(RestClient).to receive(:get).
91
95
  with(url, params: params).
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restful_resource
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Santoro
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-07 00:00:00.000000000 Z
11
+ date: 2014-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler