restful_resource 0.8.3 → 0.8.4

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: 341d21eb0a3a7d38425a4e2f42d028786a6f084c
4
- data.tar.gz: b91f20b5b741568b27291064c81a472a9e6a463f
3
+ metadata.gz: 319cf30c394b3307a02af91d62a46c977bda5e11
4
+ data.tar.gz: 339399b6d0252f5d75e94f186e72a07861ac056e
5
5
  SHA512:
6
- metadata.gz: 34a344643e859283d0ccb94ec70d1ac7329a397c8ee41826f9266f7b598ebdc99f56116a6b56de2d078f94367bec5e789d6cfda9412096c7bced4161d64975da
7
- data.tar.gz: 42f746eee9222cdf0d8ecf3734be9ab0d302353ffb278eeae5f21754535f332b18f203be73a8a6b44b0e4c2cb7a91940b4bebd6d4a5b7d8ad2277ceb0901b1c5
6
+ metadata.gz: 5282ec61b93e156b93572303b4f191a168c6893ef27525ce0413e7ca148a6199372fe05743db0ef941c8742a503d9b60864de8b718e4a7e61d2e8800816a0a11
7
+ data.tar.gz: 8118ff5f9df822f0af8b10ec900259914889d1c6f18142d2826828236fab5757af2468ba8d6b118235c76a0c3bf0a481085aa46e406678f688b75f4a80e70f63
@@ -37,6 +37,10 @@ module RestfulResource
37
37
  RestfulResource::OpenObject.new(parse_json(response.body))
38
38
  end
39
39
 
40
+ def self.put(params={}, data: {})
41
+ http.put(collection_url(params), data)
42
+ end
43
+
40
44
  def self.all
41
45
  self.where
42
46
  end
@@ -8,5 +8,10 @@ module RestfulResource
8
8
  response = RestClient.get(url, :accept => :json, authorization: @authorization)
9
9
  Response.new(body: response.body, headers: response.headers, status: response.code)
10
10
  end
11
+
12
+ def put(url, data: {})
13
+ response = RestClient.put(url, data, :accept => :json, authorization: @authorization)
14
+ Response.new(body: response.body, headers: response.headers, status: response.code)
15
+ end
11
16
  end
12
17
  end
@@ -1,3 +1,3 @@
1
1
  module RestfulResource
2
- VERSION = "0.8.3"
2
+ VERSION = "0.8.4"
3
3
  end
@@ -107,7 +107,7 @@ describe RestfulResource::Base do
107
107
  end
108
108
  end
109
109
 
110
- describe "#get" do
110
+ describe "#get" do
111
111
  it "should return an open_object" do
112
112
  expected_response = RestfulResource::Response.new(body: {average_score: 4.3}.to_json)
113
113
  expect_get('http://api.carwow.co.uk/makes/average_score?make_slug%5B%5D=Volkswagen&make_slug%5B%5D=Audi', expected_response)
@@ -119,6 +119,17 @@ describe RestfulResource::Base do
119
119
  end
120
120
  end
121
121
 
122
+ describe "#put" do
123
+ it 'should put data properly' do
124
+ expected_response = RestfulResource::Response.new(body: nil, status: 200)
125
+ expect_put('http://api.carwow.co.uk/makes?make_slug=Volkswagen', expected_response)
126
+
127
+ Make.put(make_slug: 'Volkswagen')
128
+
129
+ expect(expected_response.status).to eq 200
130
+ end
131
+ end
132
+
122
133
  describe ".as_json" do
123
134
  before :each do
124
135
  expected_response = RestfulResource::Response.new(body: [{name: 'Audi', slug: 'Audi-Slug'}, {name: 'Fiat', slug: 'Fiat-Slug'}].to_json)
@@ -1,13 +1,29 @@
1
1
  require_relative '../spec_helper'
2
2
 
3
3
  describe RestfulResource::HttpClient do
4
+ describe 'Basic HTTP' do
5
+ before :each do
6
+ @http_client = RestfulResource::HttpClient.new
7
+ end
8
+
9
+ it 'should execute get' do
10
+ response = @http_client.get('http://httpbin.org/get')
11
+ expect(response.status).to eq 200
12
+ end
13
+
14
+ it 'should execute put' do
15
+ response = @http_client.put('http://httpbin.org/put', data: { name: 'Alfred' })
16
+ expect(response.status).to eq 200
17
+ end
18
+ end
19
+
4
20
  describe 'Authentication' do
5
21
  before :each do
6
22
  auth = RestfulResource::Authorization.http_authorization('user', 'passwd')
7
23
  @http_client = RestfulResource::HttpClient.new(authorization: auth)
8
24
  end
9
25
 
10
- it 'should get authenticated get' do
26
+ it 'should execute authenticated get' do
11
27
  response = @http_client.get('http://httpbin.org/basic-auth/user/passwd')
12
28
  expect(response.status).to eq 200
13
29
  end
data/spec/spec_helper.rb CHANGED
@@ -11,3 +11,7 @@ end
11
11
  def expect_get(url, response)
12
12
  expect(@mock_http).to receive(:get).with(url).and_return(response)
13
13
  end
14
+
15
+ def expect_put(url, response, data: {})
16
+ expect(@mock_http).to receive(:put).with(url, data).and_return(response)
17
+ end
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.3
4
+ version: 0.8.4
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-23 00:00:00.000000000 Z
12
+ date: 2014-10-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler