restful_resource 0.8.8 → 0.8.9
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 91803ab9a7afb00f09ddc7272c06e3330f3418fd
|
4
|
+
data.tar.gz: 8ed0b0c0a0b914b940cdb35cc3c486107909e0b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aada22cf8f429ea81558f25f73b8e9bc4420929e1156e21f57a4d01fa1af45c47a528e25a76eb774c96a708e31da85459c738067ca3ef5e7d5af3b41570f2a8f
|
7
|
+
data.tar.gz: 797b5200c5f2a7d9ece83ddb0aadccffe8b13414b5eebeaf5d5401f564467cc0bf0fd681be34e6623443f22ef8600aa5c174f9e9fe6d8498764331f869af3cff
|
@@ -3,11 +3,11 @@ module RestfulResource
|
|
3
3
|
extend RestfulResource::Associations
|
4
4
|
|
5
5
|
def self.http=(http)
|
6
|
-
|
6
|
+
@http = http
|
7
7
|
end
|
8
8
|
|
9
9
|
def self.http
|
10
|
-
|
10
|
+
@http ||= RestfulResource::HttpClient.new(authorization: superclass.base_authorization)
|
11
11
|
end
|
12
12
|
|
13
13
|
def self.http_authorization(user, password)
|
@@ -23,24 +23,24 @@ module RestfulResource
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def self.find(id, params={})
|
26
|
-
response = http.get(member_url(id, params))
|
26
|
+
response = superclass.http.get(member_url(id, params))
|
27
27
|
self.new(parse_json(response.body))
|
28
28
|
end
|
29
29
|
|
30
30
|
def self.where(params={})
|
31
|
-
response = http.get(collection_url(params))
|
31
|
+
response = superclass.http.get(collection_url(params))
|
32
32
|
self.paginate_response(response)
|
33
33
|
end
|
34
34
|
|
35
35
|
def self.get(params={})
|
36
|
-
response = http.get(collection_url(params))
|
36
|
+
response = superclass.http.get(collection_url(params))
|
37
37
|
RestfulResource::OpenObject.new(parse_json(response.body))
|
38
38
|
end
|
39
39
|
|
40
40
|
def self.put(id, data: {}, **params)
|
41
41
|
url = member_url(id, params)
|
42
42
|
|
43
|
-
response = http.put(url, data: data)
|
43
|
+
response = superclass.http.put(url, data: data)
|
44
44
|
self.new(parse_json(response.body))
|
45
45
|
end
|
46
46
|
|
@@ -64,6 +64,8 @@ module RestfulResource
|
|
64
64
|
|
65
65
|
protected
|
66
66
|
def self.base_url
|
67
|
+
raise BaseUrlMissing.new if @base_url.nil?
|
68
|
+
|
67
69
|
@base_url
|
68
70
|
end
|
69
71
|
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
|
3
|
+
describe "http client" do
|
4
|
+
before :each do
|
5
|
+
class FirstClient < RestfulResource::Base
|
6
|
+
end
|
7
|
+
|
8
|
+
class SecondClient < RestfulResource::Base
|
9
|
+
end
|
10
|
+
|
11
|
+
class FirstTest < FirstClient
|
12
|
+
resource_path 'test'
|
13
|
+
end
|
14
|
+
|
15
|
+
class SecondTest < SecondClient
|
16
|
+
resource_path 'test'
|
17
|
+
end
|
18
|
+
|
19
|
+
FirstClient.http = nil
|
20
|
+
FirstClient.base_url = 'http://api.carwow.co.uk/api/first'
|
21
|
+
SecondClient.http = nil
|
22
|
+
SecondClient.base_url = 'http://api.carwow.co.uk/api/second'
|
23
|
+
SecondClient.http_authorization('test_user', 'test_pass')
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should use two different http instances" do
|
27
|
+
expect(FirstTest.http).not_to equal(SecondTest.http)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should have http auth on SecondClient when initialised first' do
|
31
|
+
SecondTest.http
|
32
|
+
FirstTest.http
|
33
|
+
|
34
|
+
authorization = SecondTest.http.instance_variable_get :@authorization
|
35
|
+
expect(authorization).to be_truthy
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should have http auth on SecondTest when initialised second' do
|
39
|
+
FirstTest.http
|
40
|
+
SecondTest.http
|
41
|
+
|
42
|
+
authorization = SecondTest.http.instance_variable_get :@authorization
|
43
|
+
expect(authorization).to be_truthy
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
@@ -78,7 +78,10 @@ describe RestfulResource::Base do
|
|
78
78
|
describe "#base_url" do
|
79
79
|
it "should be different for each subclass of Base" do
|
80
80
|
BaseA.base_url = "http://a.carwow.co.uk"
|
81
|
+
BaseA.http = @mock_http
|
82
|
+
|
81
83
|
BaseB.base_url = "http://b.carwow.co.uk"
|
84
|
+
BaseB.http = @mock_http
|
82
85
|
|
83
86
|
expect_get('http://a.carwow.co.uk/testa/1', RestfulResource::Response.new())
|
84
87
|
expect_get('http://b.carwow.co.uk/testb/2', RestfulResource::Response.new())
|
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.9
|
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-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -137,6 +137,7 @@ files:
|
|
137
137
|
- restful_resource.gemspec
|
138
138
|
- spec/fixtures.rb
|
139
139
|
- spec/restful_resource/associations_spec.rb
|
140
|
+
- spec/restful_resource/base_authorization_spec.rb
|
140
141
|
- spec/restful_resource/base_spec.rb
|
141
142
|
- spec/restful_resource/http_client_spec.rb
|
142
143
|
- spec/restful_resource/old_base_spec.rb
|
@@ -172,6 +173,7 @@ summary: A simple activerecord inspired rest resource base class implemented usi
|
|
172
173
|
test_files:
|
173
174
|
- spec/fixtures.rb
|
174
175
|
- spec/restful_resource/associations_spec.rb
|
176
|
+
- spec/restful_resource/base_authorization_spec.rb
|
175
177
|
- spec/restful_resource/base_spec.rb
|
176
178
|
- spec/restful_resource/http_client_spec.rb
|
177
179
|
- spec/restful_resource/old_base_spec.rb
|