restful_resource 0.8.13 → 0.8.14
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b8e326237bb1c642d55959bf1be9928b5ac0876
|
4
|
+
data.tar.gz: d02d72af334a19c74a626ea4765dd589ea0650e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cdb3fbef36a797c3dce90f3deef8f3fcc81074b6072d98ae5bc1c778e250b1c8572896ac592e6fe501d0b850cf180dd1aecd3d60bae1896ed5a707451fb09581
|
7
|
+
data.tar.gz: f3684e6c315892bda85f7c40d62f6ef4eda008eae39e82a7122427a6b2e02bafa10063331129a2de6968fcd974c6b8ee993dd09421472950930888da85e67972
|
@@ -40,6 +40,13 @@ module RestfulResource
|
|
40
40
|
self.new(parse_json(response.body))
|
41
41
|
end
|
42
42
|
|
43
|
+
def self.post(data: {}, **params)
|
44
|
+
url = collection_url(params)
|
45
|
+
|
46
|
+
response = http.post(url, data: data)
|
47
|
+
self.new(parse_json(response.body))
|
48
|
+
end
|
49
|
+
|
43
50
|
def self.all
|
44
51
|
self.where
|
45
52
|
end
|
@@ -25,5 +25,14 @@ module RestfulResource
|
|
25
25
|
end
|
26
26
|
Response.new(body: response.body, headers: response.headers, status: response.code)
|
27
27
|
end
|
28
|
+
|
29
|
+
def post(url, data: {})
|
30
|
+
begin
|
31
|
+
response = RestClient.post(url, data, :accept => :json, authorization: @authorization)
|
32
|
+
rescue RestClient::UnprocessableEntity => e
|
33
|
+
raise HttpClient::UnprocessableEntity.new(e.response)
|
34
|
+
end
|
35
|
+
Response.new(body: response.body, headers: response.headers, status: response.code)
|
36
|
+
end
|
28
37
|
end
|
29
38
|
end
|
@@ -130,7 +130,7 @@ describe RestfulResource::Base do
|
|
130
130
|
expect(object.name).to eq 'Audi'
|
131
131
|
end
|
132
132
|
|
133
|
-
it 'should put no data with params passed' do
|
133
|
+
it 'should put no data with no params passed' do
|
134
134
|
expected_response = RestfulResource::Response.new(body: {name: 'Audi'}.to_json, status: 200)
|
135
135
|
expect_put('http://api.carwow.co.uk/makes/1?make_slug=Volkswagen', expected_response)
|
136
136
|
|
@@ -139,7 +139,7 @@ describe RestfulResource::Base do
|
|
139
139
|
expect(object.name).to eq 'Audi'
|
140
140
|
end
|
141
141
|
|
142
|
-
it 'should put data with
|
142
|
+
it 'should put data with params passed' do
|
143
143
|
data = {make_slug: 'Audi'}
|
144
144
|
|
145
145
|
expected_response = RestfulResource::Response.new(body: {name: 'Audi'}.to_json, status: 200)
|
@@ -162,6 +162,20 @@ describe RestfulResource::Base do
|
|
162
162
|
end
|
163
163
|
end
|
164
164
|
|
165
|
+
describe "#post" do
|
166
|
+
it "should post parameters to the collection url" do
|
167
|
+
data = {slug: 'audi-make', name: 'Audi', num_of_cars: 3}
|
168
|
+
|
169
|
+
expected_response = RestfulResource::Response.new(body: data.to_json, status: 200)
|
170
|
+
expect_post('http://api.carwow.co.uk/makes', expected_response, data: data)
|
171
|
+
|
172
|
+
object = Make.post(data: data)
|
173
|
+
|
174
|
+
expect(object.name).to eq 'Audi'
|
175
|
+
expect(object.num_of_cars).to eq 3
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
165
179
|
describe ".as_json" do
|
166
180
|
before :each do
|
167
181
|
expected_response = RestfulResource::Response.new(body: [{name: 'Audi', slug: 'Audi-Slug'}, {name: 'Fiat', slug: 'Fiat-Slug'}].to_json)
|
@@ -16,6 +16,12 @@ describe RestfulResource::HttpClient do
|
|
16
16
|
expect(response.status).to eq 200
|
17
17
|
end
|
18
18
|
|
19
|
+
it 'should execute post' do
|
20
|
+
response = @http_client.post('http://httpbin.org/post', data: { name: 'Alfred' })
|
21
|
+
expect(response.body).to include "name\": \"Alfred"
|
22
|
+
expect(response.status).to eq 200
|
23
|
+
end
|
24
|
+
|
19
25
|
it 'should raise error 422' do
|
20
26
|
expect { @http_client.put('http://httpbin.org/status/422', data: { name: 'Mad cow' }) }.to raise_error(RestfulResource::HttpClient::UnprocessableEntity)
|
21
27
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -16,6 +16,10 @@ def expect_put(url, response, data: {})
|
|
16
16
|
expect(@mock_http).to receive(:put).with(url, data: data).and_return(response)
|
17
17
|
end
|
18
18
|
|
19
|
+
def expect_post(url, response, data: {})
|
20
|
+
expect(@mock_http).to receive(:post).with(url, data: data).and_return(response)
|
21
|
+
end
|
22
|
+
|
19
23
|
def expect_put_with_unprocessable_entity(url, response, data: {})
|
20
24
|
rest_client_response = OpenStruct.new({body: response.body, headers: response.headers, code: response.status})
|
21
25
|
exception = RestfulResource::HttpClient::UnprocessableEntity.new(rest_client_response)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: restful_resource
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Santoro
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-10-
|
12
|
+
date: 2014-10-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|