shutl_resource 0.10.3 → 0.10.4
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.
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
module Shutl::Resource
|
|
2
2
|
module RestClassMethods
|
|
3
3
|
def find(args = {}, params = {})
|
|
4
|
+
params = args if @singular_resource
|
|
5
|
+
auth_options = { auth: params.delete(:auth), from: params.delete(:from) }
|
|
6
|
+
|
|
4
7
|
if @singular_resource
|
|
5
|
-
params = args
|
|
6
8
|
url = singular_member_url params
|
|
7
9
|
elsif !args.kind_of?(Hash)
|
|
8
10
|
id = args
|
|
@@ -12,10 +14,9 @@ module Shutl::Resource
|
|
|
12
14
|
url = member_url args.dup, params
|
|
13
15
|
end
|
|
14
16
|
|
|
15
|
-
auth_options = { auth: params.delete(:auth), from: params.delete(:from) }
|
|
16
17
|
response = get url, headers_with_auth(auth_options)
|
|
17
18
|
|
|
18
|
-
check_fail response, "Failed to find #{name}
|
|
19
|
+
check_fail response, "Failed to find #{name}! args: #{args}, params: #{params}"
|
|
19
20
|
|
|
20
21
|
parsed = response.parsed_response
|
|
21
22
|
|
data/spec/rest_resource_spec.rb
CHANGED
|
@@ -50,28 +50,32 @@ describe Shutl::Resource::Rest do
|
|
|
50
50
|
end
|
|
51
51
|
|
|
52
52
|
context 'with no arguments' do
|
|
53
|
+
let(:headers_with_auth) do
|
|
54
|
+
headers.merge("Authorization" => "Bearer some auth")
|
|
55
|
+
end
|
|
56
|
+
|
|
53
57
|
before do
|
|
54
58
|
@request = stub_request(:get, 'http://host/test_rests/a').
|
|
55
59
|
to_return(:status => 200,
|
|
56
60
|
:body => '{"test_rest": { "a": "a", "b": 2 }}',
|
|
57
|
-
:headers =>
|
|
61
|
+
:headers => headers_with_auth)
|
|
58
62
|
end
|
|
59
63
|
|
|
60
64
|
it 'should query the endpoint' do
|
|
61
|
-
TestRest.find('a')
|
|
65
|
+
TestRest.find('a', auth: "some auth")
|
|
62
66
|
|
|
63
67
|
@request.should have_been_requested
|
|
64
68
|
end
|
|
65
69
|
|
|
66
70
|
it 'should parse the result of the body to create an object' do
|
|
67
|
-
resource = TestRest.find('a')
|
|
71
|
+
resource = TestRest.find('a', auth: "some auth")
|
|
68
72
|
|
|
69
73
|
resource.should_not be_nil
|
|
70
74
|
resource.should be_kind_of TestRest
|
|
71
75
|
end
|
|
72
76
|
|
|
73
77
|
it 'should assign the attributes based on the json returned' do
|
|
74
|
-
resource = TestRest.find('a')
|
|
78
|
+
resource = TestRest.find('a', auth: "some auth")
|
|
75
79
|
|
|
76
80
|
resource.instance_variable_get('@a').should == 'a'
|
|
77
81
|
resource.instance_variable_get('@b').should == 2
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: shutl_resource
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.10.
|
|
4
|
+
version: 0.10.4
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -173,7 +173,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
173
173
|
version: '0'
|
|
174
174
|
segments:
|
|
175
175
|
- 0
|
|
176
|
-
hash:
|
|
176
|
+
hash: -2937045685155006965
|
|
177
177
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
178
178
|
none: false
|
|
179
179
|
requirements:
|
|
@@ -182,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
182
182
|
version: '0'
|
|
183
183
|
segments:
|
|
184
184
|
- 0
|
|
185
|
-
hash:
|
|
185
|
+
hash: -2937045685155006965
|
|
186
186
|
requirements: []
|
|
187
187
|
rubyforge_project:
|
|
188
188
|
rubygems_version: 1.8.23
|