restful_resource 0.0.9 → 0.0.10
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.
- checksums.yaml +4 -4
- data/lib/restful_resource/base.rb +15 -2
- data/lib/restful_resource/version.rb +1 -1
- data/spec/restful_resource/base_spec.rb +7 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8e1e4d94c7b281da63d40df207eccf513c8be52
|
4
|
+
data.tar.gz: 5b3631c56fc97945ac8387cdc68992c6b811f405
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
106
|
-
response =
|
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
|
@@ -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
|
-
|
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
|
-
|
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.
|
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-
|
11
|
+
date: 2014-09-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|