reviewed 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/lib/reviewed/article.rb +10 -8
  2. data/lib/reviewed/attachment.rb +4 -0
  3. data/lib/reviewed/base.rb +25 -40
  4. data/lib/reviewed/client.rb +56 -0
  5. data/lib/reviewed/collection.rb +16 -19
  6. data/lib/reviewed/configurable.rb +26 -0
  7. data/lib/reviewed/embeddable.rb +74 -0
  8. data/lib/reviewed/page.rb +4 -0
  9. data/lib/reviewed/product.rb +6 -2
  10. data/lib/reviewed/utils.rb +25 -0
  11. data/lib/reviewed/version.rb +1 -1
  12. data/lib/reviewed.rb +20 -33
  13. data/reviewed.gemspec +2 -1
  14. data/spec/article_spec.rb +65 -39
  15. data/spec/base_spec.rb +39 -74
  16. data/spec/client_spec.rb +95 -0
  17. data/spec/collection_spec.rb +5 -6
  18. data/spec/configurable_spec.rb +44 -0
  19. data/spec/embeddable_spec.rb +176 -0
  20. data/spec/fixtures/vcr/article/attachments.yml +464 -457
  21. data/spec/fixtures/vcr/article/find_page.yml +115 -111
  22. data/spec/fixtures/vcr/article/products.yml +464 -457
  23. data/spec/fixtures/vcr/base/article/find.yml +7618 -0
  24. data/spec/fixtures/vcr/base/where_collection.yml +600 -7626
  25. data/spec/fixtures/vcr/collection/products.yml +501 -498
  26. data/spec/fixtures/vcr/product/attachments.yml +94 -68
  27. data/spec/fixtures/vcr/utils/collection.yml +346 -0
  28. data/spec/fixtures/vcr/utils/object.yml +7618 -0
  29. data/spec/fixtures/vcr/utils.yml +7961 -0
  30. data/spec/product_spec.rb +31 -17
  31. data/spec/reviewed_spec.rb +19 -0
  32. data/spec/utils_spec.rb +40 -0
  33. metadata +45 -22
  34. data/lib/reviewed/request.rb +0 -23
  35. data/lib/reviewed/response.rb +0 -12
  36. data/lib/reviewed/util.rb +0 -16
  37. data/spec/fixtures/vcr/base/find_error_key.yml +0 -172
  38. data/spec/fixtures/vcr/base/find_ok.yml +0 -1155
  39. data/spec/fixtures/vcr/request/authors.yml +0 -133
  40. data/spec/fixtures/vcr/response/authors.yml +0 -133
  41. data/spec/request_spec.rb +0 -15
  42. data/spec/response_spec.rb +0 -26
  43. data/spec/util_spec.rb +0 -33
data/spec/product_spec.rb CHANGED
@@ -1,28 +1,42 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Reviewed::Product do
4
- describe 'attachments' do
5
- use_vcr_cassette 'product/attachments'
6
4
 
7
- before(:each) do
8
- @product = Reviewed::Product.find('minden-master-ii')
9
- end
5
+ describe 'associations' do
10
6
 
11
- it 'returns all attachments' do
12
- @product.attachments.length.should == 1
13
- end
7
+ describe 'attachments' do
8
+ use_vcr_cassette 'product/attachments'
14
9
 
15
- it 'finds attachments by tag' do
16
- attachments = @product.attachments('vanity')
17
- attachments.length.should == 1
18
- attachments.each do |attachment|
19
- attachment.tags.join(',').should match(/vanity/i)
10
+ before(:each) do
11
+ @product = Reviewed::Product.find('minden-master-ii')
12
+ end
13
+
14
+ it 'has_many :attachments' do
15
+ Reviewed::Product._embedded_many.should include({"attachments"=>Reviewed::Attachment})
16
+ end
17
+
18
+ it 'returns attachments of the correct class' do
19
+ @product.attachments.each do |attachment|
20
+ attachment.should be_an_instance_of(Reviewed::Attachment)
21
+ end
22
+ end
23
+
24
+ it 'returns all attachments' do
25
+ @product.attachments.length.should == 1
20
26
  end
21
- end
22
27
 
23
- it 'does not have any matching attachments' do
24
- attachments = @product.attachments('doesnotcompute')
25
- attachments.length.should == 0
28
+ it 'finds attachments by tag' do
29
+ attachments = @product.attachments('vanity')
30
+ attachments.length.should == 1
31
+ attachments.each do |attachment|
32
+ attachment.tags.join(',').should match(/vanity/i)
33
+ end
34
+ end
35
+
36
+ it 'does not have any matching attachments' do
37
+ attachments = @product.attachments('doesnotcompute')
38
+ attachments.length.should == 0
39
+ end
26
40
  end
27
41
  end
28
42
  end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper.rb'
2
+
3
+ describe Reviewed do
4
+
5
+ describe '.client' do
6
+
7
+ it 'returns a Reviewed::Client' do
8
+ Reviewed.client.should be_an_instance_of(Reviewed::Client)
9
+ end
10
+ end
11
+
12
+ describe '.method_missing' do
13
+
14
+ it 'delegates to the client' do
15
+ Reviewed::Client.any_instance.should_receive(:api_key)
16
+ Reviewed.api_key
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper.rb'
2
+
3
+ describe Reviewed::Utils do
4
+
5
+ class MockUtils < Reviewed::Base; end
6
+
7
+ describe 'object_from_response' do
8
+ use_vcr_cassette "utils/object"
9
+
10
+ let(:article_id) { '509d166d60de7db97c05ce71' }
11
+
12
+ it 'returns an object of the correct class' do
13
+ response = MockUtils.object_from_response(:get, "articles/#{article_id}")
14
+ response.should be_an_instance_of(MockUtils)
15
+ end
16
+ end
17
+
18
+ describe 'collection_from_response' do
19
+ use_vcr_cassette "utils/collection"
20
+
21
+ it 'returns a collection object' do
22
+ collection = MockUtils.collection_from_response(:get, "articles")
23
+ collection.should be_an_instance_of(Reviewed::Collection)
24
+ end
25
+
26
+ it 'returns objects of the correct class' do
27
+ collection = MockUtils.collection_from_response(:get, "articles")
28
+ collection.items.each do |obj|
29
+ obj.should be_an_instance_of(MockUtils)
30
+ end
31
+ end
32
+ end
33
+
34
+ describe 'from_response' do
35
+
36
+ it 'returns a new object from a response' do
37
+ MockUtils.from_response({}).should be_an_instance_of(MockUtils)
38
+ end
39
+ end
40
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reviewed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-11-20 00:00:00.000000000 Z
13
+ date: 2012-11-23 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -45,13 +45,13 @@ dependencies:
45
45
  - !ruby/object:Gem::Version
46
46
  version: '3.0'
47
47
  - !ruby/object:Gem::Dependency
48
- name: rest-client
48
+ name: faraday
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
53
53
  - !ruby/object:Gem::Version
54
- version: '1.6'
54
+ version: 0.8.4
55
55
  type: :runtime
56
56
  prerelease: false
57
57
  version_requirements: !ruby/object:Gem::Requirement
@@ -59,7 +59,23 @@ dependencies:
59
59
  requirements:
60
60
  - - ! '>='
61
61
  - !ruby/object:Gem::Version
62
- version: '1.6'
62
+ version: 0.8.4
63
+ - !ruby/object:Gem::Dependency
64
+ name: faraday_middleware
65
+ requirement: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: 0.9.0
71
+ type: :runtime
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: 0.9.0
63
79
  - !ruby/object:Gem::Dependency
64
80
  name: hashie
65
81
  requirement: !ruby/object:Gem::Requirement
@@ -172,14 +188,17 @@ files:
172
188
  - Rakefile
173
189
  - lib/reviewed.rb
174
190
  - lib/reviewed/article.rb
191
+ - lib/reviewed/attachment.rb
175
192
  - lib/reviewed/author.rb
176
193
  - lib/reviewed/base.rb
177
194
  - lib/reviewed/brand.rb
195
+ - lib/reviewed/client.rb
178
196
  - lib/reviewed/collection.rb
197
+ - lib/reviewed/configurable.rb
198
+ - lib/reviewed/embeddable.rb
199
+ - lib/reviewed/page.rb
179
200
  - lib/reviewed/product.rb
180
- - lib/reviewed/request.rb
181
- - lib/reviewed/response.rb
182
- - lib/reviewed/util.rb
201
+ - lib/reviewed/utils.rb
183
202
  - lib/reviewed/version.rb
184
203
  - lib/reviewed/website.rb
185
204
  - reviewed.gemspec
@@ -187,23 +206,25 @@ files:
187
206
  - spec/author_spec.rb
188
207
  - spec/base_spec.rb
189
208
  - spec/brand_spec.rb
209
+ - spec/client_spec.rb
190
210
  - spec/collection_spec.rb
211
+ - spec/configurable_spec.rb
212
+ - spec/embeddable_spec.rb
191
213
  - spec/fixtures/vcr/article/attachments.yml
192
214
  - spec/fixtures/vcr/article/find_page.yml
193
215
  - spec/fixtures/vcr/article/products.yml
194
- - spec/fixtures/vcr/base/find_error_key.yml
195
- - spec/fixtures/vcr/base/find_ok.yml
216
+ - spec/fixtures/vcr/base/article/find.yml
196
217
  - spec/fixtures/vcr/base/where_collection.yml
197
218
  - spec/fixtures/vcr/collection/products.yml
198
219
  - spec/fixtures/vcr/product/attachments.yml
199
- - spec/fixtures/vcr/request/authors.yml
200
- - spec/fixtures/vcr/response/authors.yml
220
+ - spec/fixtures/vcr/utils.yml
221
+ - spec/fixtures/vcr/utils/collection.yml
222
+ - spec/fixtures/vcr/utils/object.yml
201
223
  - spec/product_spec.rb
202
- - spec/request_spec.rb
203
- - spec/response_spec.rb
224
+ - spec/reviewed_spec.rb
204
225
  - spec/spec_helper.rb
205
226
  - spec/support/.gitkeep
206
- - spec/util_spec.rb
227
+ - spec/utils_spec.rb
207
228
  - spec/website_spec.rb
208
229
  homepage: ''
209
230
  licenses: []
@@ -234,21 +255,23 @@ test_files:
234
255
  - spec/author_spec.rb
235
256
  - spec/base_spec.rb
236
257
  - spec/brand_spec.rb
258
+ - spec/client_spec.rb
237
259
  - spec/collection_spec.rb
260
+ - spec/configurable_spec.rb
261
+ - spec/embeddable_spec.rb
238
262
  - spec/fixtures/vcr/article/attachments.yml
239
263
  - spec/fixtures/vcr/article/find_page.yml
240
264
  - spec/fixtures/vcr/article/products.yml
241
- - spec/fixtures/vcr/base/find_error_key.yml
242
- - spec/fixtures/vcr/base/find_ok.yml
265
+ - spec/fixtures/vcr/base/article/find.yml
243
266
  - spec/fixtures/vcr/base/where_collection.yml
244
267
  - spec/fixtures/vcr/collection/products.yml
245
268
  - spec/fixtures/vcr/product/attachments.yml
246
- - spec/fixtures/vcr/request/authors.yml
247
- - spec/fixtures/vcr/response/authors.yml
269
+ - spec/fixtures/vcr/utils.yml
270
+ - spec/fixtures/vcr/utils/collection.yml
271
+ - spec/fixtures/vcr/utils/object.yml
248
272
  - spec/product_spec.rb
249
- - spec/request_spec.rb
250
- - spec/response_spec.rb
273
+ - spec/reviewed_spec.rb
251
274
  - spec/spec_helper.rb
252
275
  - spec/support/.gitkeep
253
- - spec/util_spec.rb
276
+ - spec/utils_spec.rb
254
277
  - spec/website_spec.rb
@@ -1,23 +0,0 @@
1
- module Reviewed
2
- class Request
3
-
4
- class << self
5
-
6
- def get(url)
7
- url = url =~ /http/ ? url : build_url(url)
8
-
9
- begin
10
- raw_response = RestClient.get(url, Util.build_request_headers)
11
- Reviewed::Response.new(raw_response)
12
- rescue RestClient::Exception => e
13
- raise ResourceError.new(e.message)
14
- end
15
- end
16
-
17
- def build_url(url)
18
- url = [Reviewed.base_uri, API_VERSION, url].compact.join("/")
19
- end
20
- end
21
- end
22
- end
23
-
@@ -1,12 +0,0 @@
1
- module Reviewed
2
- class Response
3
-
4
- attr_accessor :raw
5
- attr_accessor :json
6
-
7
- def initialize(raw_response)
8
- @raw = raw_response
9
- @json = JSON.parse(raw_response)
10
- end
11
- end
12
- end
data/lib/reviewed/util.rb DELETED
@@ -1,16 +0,0 @@
1
- module Reviewed
2
- class Util
3
- def self.build_request_headers(headers={})
4
- headers['X-Reviewed-Authorization'] ||= Reviewed.api_key
5
- headers['accept'] ||= 'json'
6
- headers.stringify_keys!
7
- end
8
-
9
- def self.build_query_string(hash={})
10
- hash.keys.inject('') do |query_string, key|
11
- query_string << '&' unless key == hash.keys.first
12
- query_string << "#{URI.encode(key.to_s)}=#{URI.encode(hash[key].to_s)}"
13
- end
14
- end
15
- end
16
- end
@@ -1,172 +0,0 @@
1
- ---
2
- http_interactions:
3
- - request:
4
- method: get
5
- uri: https://the-guide-staging.herokuapp.com/api/v1/articles/50241b9c5da4ac8d38000001
6
- body:
7
- encoding: US-ASCII
8
- string: ''
9
- headers:
10
- Accept:
11
- - application/json
12
- Accept-Encoding:
13
- - gzip, deflate
14
- X-Reviewed-Authorization:
15
- - xxxxxxxxxxxxxxxx
16
- User-Agent:
17
- - Ruby
18
- response:
19
- status:
20
- code: 401
21
- message: !binary |-
22
- VW5hdXRob3JpemVk
23
- headers:
24
- !binary "QWNjZXNzLUNvbnRyb2wtQWxsb3ctQ3JlZGVudGlhbHM=":
25
- - !binary |-
26
- dHJ1ZQ==
27
- !binary "QWNjZXNzLUNvbnRyb2wtQWxsb3ctSGVhZGVycw==":
28
- - !binary |-
29
- eC1wYWdpbmF0aW9uLCB4LXJlcXVlc3RlZC13aXRoLCB4LXJlcXVlc3RlZC1i
30
- eSwgeC1yZXZpZXdlZC1hdXRob3JpemF0aW9uLCBDb250ZW50LVR5cGU=
31
- !binary "QWNjZXNzLUNvbnRyb2wtQWxsb3ctTWV0aG9kcw==":
32
- - !binary |-
33
- T1BUSU9OUywgR0VULCBQT1NULCBQVVQsIERFTEVURQ==
34
- !binary "QWNjZXNzLUNvbnRyb2wtQWxsb3ctT3JpZ2lu":
35
- - !binary |-
36
- Kg==
37
- !binary "QWNjZXNzLUNvbnRyb2wtTWF4LUFnZQ==":
38
- - !binary |-
39
- MTAwMA==
40
- !binary "Q2FjaGUtQ29udHJvbA==":
41
- - !binary |-
42
- bm8tY2FjaGUsIG5vLXN0b3Jl
43
- !binary "Q29udGVudC1FbmNvZGluZw==":
44
- - !binary |-
45
- Z3ppcA==
46
- !binary "Q29udGVudC1UeXBl":
47
- - !binary |-
48
- YXBwbGljYXRpb24vanNvbjsgY2hhcnNldD11dGYtOA==
49
- !binary "RGF0ZQ==":
50
- - !binary |-
51
- VHVlLCAwNiBOb3YgMjAxMiAyMTowMDowMSBHTVQ=
52
- !binary "U2VydmVy":
53
- - !binary |-
54
- dGhpbiAxLjUuMCBjb2RlbmFtZSBLbmlmZQ==
55
- !binary "U3RyaWN0LVRyYW5zcG9ydC1TZWN1cml0eQ==":
56
- - !binary |-
57
- bWF4LWFnZT0zMTUzNjAwMA==
58
- !binary "VmFyeQ==":
59
- - !binary |-
60
- QWNjZXB0LUVuY29kaW5n
61
- !binary "WC1SYWNrLUNhY2hl":
62
- - !binary |-
63
- bWlzcw==
64
- !binary "WC1SZXF1ZXN0LUlk":
65
- - !binary |-
66
- MWFkYWUxMWU5MmRmZTA5OThmODYxYmU3OTYwMGUwNTQ=
67
- !binary "WC1SdW50aW1l":
68
- - !binary |-
69
- MC4wMjM5NjM=
70
- !binary "WC1VYS1Db21wYXRpYmxl":
71
- - !binary |-
72
- SUU9RWRnZSxjaHJvbWU9MQ==
73
- !binary "VHJhbnNmZXItRW5jb2Rpbmc=":
74
- - !binary |-
75
- Y2h1bmtlZA==
76
- !binary "Q29ubmVjdGlvbg==":
77
- - !binary |-
78
- a2VlcC1hbGl2ZQ==
79
- body:
80
- encoding: ASCII-8BIT
81
- string: !binary |-
82
- H4sIAFF6mVAAA6pWyk0tLk5MT1WyUnIsyFTwTq1UyMsvUUjLL81LUaoFAAAA
83
- //8DABnVGWAfAAAA
84
- http_version:
85
- recorded_at: Tue, 06 Nov 2012 20:59:58 GMT
86
- - request:
87
- method: get
88
- uri: https://the-guide-staging.herokuapp.com/api/v1/articles/notfound
89
- body:
90
- encoding: US-ASCII
91
- string: ''
92
- headers:
93
- Accept:
94
- - application/json
95
- Accept-Encoding:
96
- - gzip, deflate
97
- X-Reviewed-Authorization:
98
- - '1234567890'
99
- User-Agent:
100
- - Ruby
101
- response:
102
- status:
103
- code: 404
104
- message: !binary |-
105
- Tm90IEZvdW5k
106
- headers:
107
- !binary "QWNjZXNzLUNvbnRyb2wtQWxsb3ctQ3JlZGVudGlhbHM=":
108
- - !binary |-
109
- dHJ1ZQ==
110
- !binary "QWNjZXNzLUNvbnRyb2wtQWxsb3ctSGVhZGVycw==":
111
- - !binary |-
112
- eC1wYWdpbmF0aW9uLCB4LXJlcXVlc3RlZC13aXRoLCB4LXJlcXVlc3RlZC1i
113
- eSwgeC1yZXZpZXdlZC1hdXRob3JpemF0aW9uLCBDb250ZW50LVR5cGU=
114
- !binary "QWNjZXNzLUNvbnRyb2wtQWxsb3ctTWV0aG9kcw==":
115
- - !binary |-
116
- T1BUSU9OUywgR0VULCBQT1NULCBQVVQsIERFTEVURQ==
117
- !binary "QWNjZXNzLUNvbnRyb2wtQWxsb3ctT3JpZ2lu":
118
- - !binary |-
119
- Kg==
120
- !binary "QWNjZXNzLUNvbnRyb2wtTWF4LUFnZQ==":
121
- - !binary |-
122
- MTAwMA==
123
- !binary "Q2FjaGUtQ29udHJvbA==":
124
- - !binary |-
125
- bm8tY2FjaGUsIG5vLXN0b3Jl
126
- !binary "Q29udGVudC1FbmNvZGluZw==":
127
- - !binary |-
128
- Z3ppcA==
129
- !binary "Q29udGVudC1UeXBl":
130
- - !binary |-
131
- YXBwbGljYXRpb24vanNvbjsgY2hhcnNldD11dGYtOA==
132
- !binary "RGF0ZQ==":
133
- - !binary |-
134
- VHVlLCAwNiBOb3YgMjAxMiAyMTowMDowMiBHTVQ=
135
- !binary "U2VydmVy":
136
- - !binary |-
137
- dGhpbiAxLjUuMCBjb2RlbmFtZSBLbmlmZQ==
138
- !binary "U3RyaWN0LVRyYW5zcG9ydC1TZWN1cml0eQ==":
139
- - !binary |-
140
- bWF4LWFnZT0zMTUzNjAwMA==
141
- !binary "VmFyeQ==":
142
- - !binary |-
143
- QWNjZXB0LUVuY29kaW5n
144
- !binary "WC1SYWNrLUNhY2hl":
145
- - !binary |-
146
- bWlzcw==
147
- !binary "WC1SYXRlLUxpbWl0":
148
- - !binary |-
149
- OTg5NjM=
150
- !binary "WC1SZXF1ZXN0LUlk":
151
- - !binary |-
152
- NDVlNjlmMDQ1MzUwZDJjMjAxZjE3Y2I5YjZmMzNiYzk=
153
- !binary "WC1SdW50aW1l":
154
- - !binary |-
155
- MC4yMjYzOTU=
156
- !binary "WC1VYS1Db21wYXRpYmxl":
157
- - !binary |-
158
- SUU9RWRnZSxjaHJvbWU9MQ==
159
- !binary "VHJhbnNmZXItRW5jb2Rpbmc=":
160
- - !binary |-
161
- Y2h1bmtlZA==
162
- !binary "Q29ubmVjdGlvbg==":
163
- - !binary |-
164
- a2VlcC1hbGl2ZQ==
165
- body:
166
- encoding: ASCII-8BIT
167
- string: !binary |-
168
- H4sIAFJ6mVAAA6pWyk0tLk5MT1WyUgpKTc4vSlHwyy9RcMsvzUtRqgUAAAD/
169
- /wMAZek3sh4AAAA=
170
- http_version:
171
- recorded_at: Tue, 06 Nov 2012 20:59:58 GMT
172
- recorded_with: VCR 2.2.5