shutl_resource 1.4.2 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/lib/shutl/resource/rest.rb +10 -9
- data/lib/shutl/resource/rest_class_methods.rb +0 -8
- data/lib/shutl/resource/version.rb +1 -1
- data/spec/dynamic_resource_spec.rb +3 -4
- data/spec/request_headers_spec.rb +26 -0
- data/spec/rest_resource_spec.rb +5 -5
- metadata +5 -31
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NmRlNDY2N2JlODI4YmZhYzdmZWJkOGVjOGFhOWFkMTQ1NGZlYmIxZg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
Yzg2NTQ4YjZmNzg3MTI4MTNmYmVhYjQ0MTQxYTU4MjVlZDNjYWUxMA==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ODlhY2MyYWE2ZjM1YTNkNjYyYjA0NzFjZTBkZjU2MmMzZDAyMzA1OWI1MTQ1
|
10
|
+
ZThmZDdmOWJkZjg5ZGQ1Nzk3YWZlYjljMzViNTkyMmY3MDkzMThhZTIyYTJk
|
11
|
+
Y2E3Mjc0Y2RkMWMyNDVlN2I0ZTg0YTNkMDdhMzBmZmE4NjU4NjA=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ODJlMzU5ZTM5MzRhZjkxODBlMmVlMjdlMWFhZWFjZDBkOWE0YTEzNzRjN2Qw
|
14
|
+
ZmFmZDJjNTRiYTNjNDZhNDRjZWNmYWMzMjlkMTkxMTFlZjc1OTY2MDJiODg4
|
15
|
+
MWFjY2I5ZWIyNjRmOWZjZDM5ZjI1N2VkMjE3ODBlYmM4NjQwMjU=
|
data/lib/shutl/resource/rest.rb
CHANGED
@@ -33,7 +33,12 @@ module Shutl::Resource
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def update_attributes(attrs)
|
36
|
-
attrs.each
|
36
|
+
attrs.each do |a, v|
|
37
|
+
unless String(a) == 'id' && attributes.include?('id')
|
38
|
+
a = 'id' if String(a) == 'new_id'
|
39
|
+
attributes.update String(a) => v
|
40
|
+
end
|
41
|
+
end
|
37
42
|
end
|
38
43
|
|
39
44
|
def update!(attrs, headers = {})
|
@@ -51,14 +56,12 @@ module Shutl::Resource
|
|
51
56
|
end
|
52
57
|
|
53
58
|
def method_missing(method, *args, &block)
|
54
|
-
|
55
|
-
|
56
|
-
end
|
57
|
-
super
|
59
|
+
return attributes[String(args.first)] if method.to_s == '[]'
|
60
|
+
attributes.fetch(String(method)) { super }
|
58
61
|
end
|
59
62
|
|
60
63
|
def respond_to? method
|
61
|
-
|
64
|
+
attributes.has_key?(method) ? true : super
|
62
65
|
end
|
63
66
|
|
64
67
|
|
@@ -79,9 +82,7 @@ module Shutl::Resource
|
|
79
82
|
end
|
80
83
|
|
81
84
|
def attributes
|
82
|
-
|
83
|
-
h.merge( { var.to_s.gsub('@','').to_sym => instance_variable_get(var)})
|
84
|
-
end
|
85
|
+
@attributes ||= {}
|
85
86
|
end
|
86
87
|
|
87
88
|
protected
|
@@ -31,7 +31,6 @@ module Shutl::Resource
|
|
31
31
|
else
|
32
32
|
url = member_url args.dup, params
|
33
33
|
end
|
34
|
-
|
35
34
|
response = connection.get(url) do |req|
|
36
35
|
req.headers = generate_request_header(header_options(params))
|
37
36
|
end
|
@@ -247,13 +246,6 @@ module Shutl::Resource
|
|
247
246
|
header_key.split(%r{\_|\-}).map {|e| e.capitalize }.join("-")
|
248
247
|
end
|
249
248
|
|
250
|
-
def headers_with_auth options = {}
|
251
|
-
headers.tap do |h|
|
252
|
-
h['Authorization'] = "Bearer #{options[:auth]}" if options[:auth]
|
253
|
-
h['From'] = "#{options[:from]}" if options[:from]
|
254
|
-
end
|
255
|
-
end
|
256
|
-
|
257
249
|
def perform_action instance, verb, body, headers, failure_message
|
258
250
|
attributes = instance.is_a?(Hash) ? instance : instance.attributes
|
259
251
|
attributes.delete "response" #used in debugging requests/responses
|
@@ -15,8 +15,8 @@ describe Shutl::Resource::Rest do
|
|
15
15
|
|
16
16
|
describe '#initalize' do
|
17
17
|
it 'should assign the instance variable value for the entries in the hash' do
|
18
|
-
resource.
|
19
|
-
resource.
|
18
|
+
resource.attributes['a'].should == 'a'
|
19
|
+
resource.attributes['b'].should == 'b'
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'should create a attribute reader' do
|
@@ -55,8 +55,7 @@ describe Shutl::Resource::Rest do
|
|
55
55
|
it 'should replace the attributes' do
|
56
56
|
resource.update_attributes(a: 'c')
|
57
57
|
|
58
|
-
resource
|
59
|
-
|
58
|
+
resource['a'].should == 'c'
|
60
59
|
end
|
61
60
|
end
|
62
61
|
end
|
@@ -31,6 +31,32 @@ describe Shutl::Resource::Rest do
|
|
31
31
|
}
|
32
32
|
}
|
33
33
|
|
34
|
+
describe 'prepends Bearer if auth is passed in for authorization' do
|
35
|
+
let(:resource) { TestSingularResource.new }
|
36
|
+
let(:expected_headers) {
|
37
|
+
{
|
38
|
+
'Accept' => 'application/json',
|
39
|
+
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
40
|
+
'Authorization' => 'Bearer some_auth',
|
41
|
+
'Content-Type' => 'application/json',
|
42
|
+
'User-Agent' => "Shutl Resource Gem v#{Shutl::Resource::VERSION}",
|
43
|
+
}
|
44
|
+
}
|
45
|
+
before do
|
46
|
+
@request = stub_request(:get, 'http://host/test_singular_resource')
|
47
|
+
.with(expected_headers)
|
48
|
+
.to_return(:status => 200,
|
49
|
+
:body => '{"test_singular_resource": { "a": "a", "b": 2 }}',
|
50
|
+
:headers => response_headers)
|
51
|
+
end
|
52
|
+
it 'queries the endpoint' do
|
53
|
+
TestSingularResource.find(auth: "some_auth")
|
54
|
+
@request.should have_been_requested
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
|
34
60
|
describe '#find' do
|
35
61
|
context "with a singular resource" do
|
36
62
|
let(:resource) { TestSingularResource.new }
|
data/spec/rest_resource_spec.rb
CHANGED
@@ -114,8 +114,8 @@ describe Shutl::Resource::Rest do
|
|
114
114
|
it 'should assign the attributes based on the json returned' do
|
115
115
|
resource = TestRest.find('a', auth: "some auth")
|
116
116
|
|
117
|
-
resource.
|
118
|
-
resource.
|
117
|
+
resource.attributes['a'].should == 'a'
|
118
|
+
resource.attributes['b'].should == 2
|
119
119
|
end
|
120
120
|
|
121
121
|
context "299" do
|
@@ -182,7 +182,7 @@ describe Shutl::Resource::Rest do
|
|
182
182
|
it 'should add a id based on the resource id' do
|
183
183
|
resource = TestRest.find('a')
|
184
184
|
|
185
|
-
resource.
|
185
|
+
resource.attributes['id'].should == 'a'
|
186
186
|
end
|
187
187
|
end
|
188
188
|
|
@@ -241,8 +241,8 @@ describe Shutl::Resource::Rest do
|
|
241
241
|
it 'should assign the attributes based on the json returned' do
|
242
242
|
resource = TestRest.all
|
243
243
|
|
244
|
-
resource.first.
|
245
|
-
resource.first.
|
244
|
+
resource.first.attributes['a'].should == 'a'
|
245
|
+
resource.first.attributes['b'].should == 2
|
246
246
|
end
|
247
247
|
|
248
248
|
it 'should provide accessor to pagination' do
|
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shutl_resource
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
5
|
-
prerelease:
|
4
|
+
version: 1.5.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- David Rouchy
|
@@ -12,12 +11,11 @@ authors:
|
|
12
11
|
autorequire:
|
13
12
|
bindir: bin
|
14
13
|
cert_chain: []
|
15
|
-
date: 2013-11-
|
14
|
+
date: 2013-11-13 00:00:00.000000000 Z
|
16
15
|
dependencies:
|
17
16
|
- !ruby/object:Gem::Dependency
|
18
17
|
name: shutl_auth
|
19
18
|
requirement: !ruby/object:Gem::Requirement
|
20
|
-
none: false
|
21
19
|
requirements:
|
22
20
|
- - ~>
|
23
21
|
- !ruby/object:Gem::Version
|
@@ -25,7 +23,6 @@ dependencies:
|
|
25
23
|
type: :runtime
|
26
24
|
prerelease: false
|
27
25
|
version_requirements: !ruby/object:Gem::Requirement
|
28
|
-
none: false
|
29
26
|
requirements:
|
30
27
|
- - ~>
|
31
28
|
- !ruby/object:Gem::Version
|
@@ -33,7 +30,6 @@ dependencies:
|
|
33
30
|
- !ruby/object:Gem::Dependency
|
34
31
|
name: activemodel
|
35
32
|
requirement: !ruby/object:Gem::Requirement
|
36
|
-
none: false
|
37
33
|
requirements:
|
38
34
|
- - ! '>='
|
39
35
|
- !ruby/object:Gem::Version
|
@@ -41,7 +37,6 @@ dependencies:
|
|
41
37
|
type: :runtime
|
42
38
|
prerelease: false
|
43
39
|
version_requirements: !ruby/object:Gem::Requirement
|
44
|
-
none: false
|
45
40
|
requirements:
|
46
41
|
- - ! '>='
|
47
42
|
- !ruby/object:Gem::Version
|
@@ -49,7 +44,6 @@ dependencies:
|
|
49
44
|
- !ruby/object:Gem::Dependency
|
50
45
|
name: faraday
|
51
46
|
requirement: !ruby/object:Gem::Requirement
|
52
|
-
none: false
|
53
47
|
requirements:
|
54
48
|
- - ! '>='
|
55
49
|
- !ruby/object:Gem::Version
|
@@ -57,7 +51,6 @@ dependencies:
|
|
57
51
|
type: :runtime
|
58
52
|
prerelease: false
|
59
53
|
version_requirements: !ruby/object:Gem::Requirement
|
60
|
-
none: false
|
61
54
|
requirements:
|
62
55
|
- - ! '>='
|
63
56
|
- !ruby/object:Gem::Version
|
@@ -65,7 +58,6 @@ dependencies:
|
|
65
58
|
- !ruby/object:Gem::Dependency
|
66
59
|
name: faraday_middleware
|
67
60
|
requirement: !ruby/object:Gem::Requirement
|
68
|
-
none: false
|
69
61
|
requirements:
|
70
62
|
- - ! '>='
|
71
63
|
- !ruby/object:Gem::Version
|
@@ -73,7 +65,6 @@ dependencies:
|
|
73
65
|
type: :runtime
|
74
66
|
prerelease: false
|
75
67
|
version_requirements: !ruby/object:Gem::Requirement
|
76
|
-
none: false
|
77
68
|
requirements:
|
78
69
|
- - ! '>='
|
79
70
|
- !ruby/object:Gem::Version
|
@@ -81,7 +72,6 @@ dependencies:
|
|
81
72
|
- !ruby/object:Gem::Dependency
|
82
73
|
name: faraday-conductivity
|
83
74
|
requirement: !ruby/object:Gem::Requirement
|
84
|
-
none: false
|
85
75
|
requirements:
|
86
76
|
- - ! '>='
|
87
77
|
- !ruby/object:Gem::Version
|
@@ -89,7 +79,6 @@ dependencies:
|
|
89
79
|
type: :runtime
|
90
80
|
prerelease: false
|
91
81
|
version_requirements: !ruby/object:Gem::Requirement
|
92
|
-
none: false
|
93
82
|
requirements:
|
94
83
|
- - ! '>='
|
95
84
|
- !ruby/object:Gem::Version
|
@@ -97,7 +86,6 @@ dependencies:
|
|
97
86
|
- !ruby/object:Gem::Dependency
|
98
87
|
name: rake
|
99
88
|
requirement: !ruby/object:Gem::Requirement
|
100
|
-
none: false
|
101
89
|
requirements:
|
102
90
|
- - ! '>='
|
103
91
|
- !ruby/object:Gem::Version
|
@@ -105,7 +93,6 @@ dependencies:
|
|
105
93
|
type: :development
|
106
94
|
prerelease: false
|
107
95
|
version_requirements: !ruby/object:Gem::Requirement
|
108
|
-
none: false
|
109
96
|
requirements:
|
110
97
|
- - ! '>='
|
111
98
|
- !ruby/object:Gem::Version
|
@@ -113,7 +100,6 @@ dependencies:
|
|
113
100
|
- !ruby/object:Gem::Dependency
|
114
101
|
name: rspec
|
115
102
|
requirement: !ruby/object:Gem::Requirement
|
116
|
-
none: false
|
117
103
|
requirements:
|
118
104
|
- - ~>
|
119
105
|
- !ruby/object:Gem::Version
|
@@ -121,7 +107,6 @@ dependencies:
|
|
121
107
|
type: :development
|
122
108
|
prerelease: false
|
123
109
|
version_requirements: !ruby/object:Gem::Requirement
|
124
|
-
none: false
|
125
110
|
requirements:
|
126
111
|
- - ~>
|
127
112
|
- !ruby/object:Gem::Version
|
@@ -129,7 +114,6 @@ dependencies:
|
|
129
114
|
- !ruby/object:Gem::Dependency
|
130
115
|
name: debugger
|
131
116
|
requirement: !ruby/object:Gem::Requirement
|
132
|
-
none: false
|
133
117
|
requirements:
|
134
118
|
- - ! '>='
|
135
119
|
- !ruby/object:Gem::Version
|
@@ -137,7 +121,6 @@ dependencies:
|
|
137
121
|
type: :development
|
138
122
|
prerelease: false
|
139
123
|
version_requirements: !ruby/object:Gem::Requirement
|
140
|
-
none: false
|
141
124
|
requirements:
|
142
125
|
- - ! '>='
|
143
126
|
- !ruby/object:Gem::Version
|
@@ -145,7 +128,6 @@ dependencies:
|
|
145
128
|
- !ruby/object:Gem::Dependency
|
146
129
|
name: webmock
|
147
130
|
requirement: !ruby/object:Gem::Requirement
|
148
|
-
none: false
|
149
131
|
requirements:
|
150
132
|
- - ~>
|
151
133
|
- !ruby/object:Gem::Version
|
@@ -153,7 +135,6 @@ dependencies:
|
|
153
135
|
type: :development
|
154
136
|
prerelease: false
|
155
137
|
version_requirements: !ruby/object:Gem::Requirement
|
156
|
-
none: false
|
157
138
|
requirements:
|
158
139
|
- - ~>
|
159
140
|
- !ruby/object:Gem::Version
|
@@ -203,33 +184,26 @@ files:
|
|
203
184
|
- spec/support/test_singular_resource.rb
|
204
185
|
homepage: ''
|
205
186
|
licenses: []
|
187
|
+
metadata: {}
|
206
188
|
post_install_message:
|
207
189
|
rdoc_options: []
|
208
190
|
require_paths:
|
209
191
|
- lib
|
210
192
|
required_ruby_version: !ruby/object:Gem::Requirement
|
211
|
-
none: false
|
212
193
|
requirements:
|
213
194
|
- - ! '>='
|
214
195
|
- !ruby/object:Gem::Version
|
215
196
|
version: '0'
|
216
|
-
segments:
|
217
|
-
- 0
|
218
|
-
hash: -3229729289856773227
|
219
197
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
220
|
-
none: false
|
221
198
|
requirements:
|
222
199
|
- - ! '>='
|
223
200
|
- !ruby/object:Gem::Version
|
224
201
|
version: '0'
|
225
|
-
segments:
|
226
|
-
- 0
|
227
|
-
hash: -3229729289856773227
|
228
202
|
requirements: []
|
229
203
|
rubyforge_project:
|
230
|
-
rubygems_version: 1.
|
204
|
+
rubygems_version: 2.1.10
|
231
205
|
signing_key:
|
232
|
-
specification_version:
|
206
|
+
specification_version: 4
|
233
207
|
summary: Manage Shutl Rest resource. Parse/Serialize JSON
|
234
208
|
test_files:
|
235
209
|
- spec/configuration_spec.rb
|