europeana-api 0.5.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -0
  3. data/.travis.yml +4 -2
  4. data/Gemfile +1 -8
  5. data/README.md +103 -21
  6. data/Rakefile +2 -1
  7. data/bin/console +21 -0
  8. data/europeana-api.gemspec +12 -1
  9. data/lib/europeana/api.rb +44 -68
  10. data/lib/europeana/api/annotation.rb +20 -0
  11. data/lib/europeana/api/client.rb +51 -0
  12. data/lib/europeana/api/entity.rb +16 -0
  13. data/lib/europeana/api/errors.rb +25 -41
  14. data/lib/europeana/api/faraday_middleware.rb +26 -0
  15. data/lib/europeana/api/faraday_middleware/request/authenticated_request.rb +25 -0
  16. data/lib/europeana/api/faraday_middleware/request/parameter_repetition.rb +25 -0
  17. data/lib/europeana/api/faraday_middleware/response/handle_text.rb +19 -0
  18. data/lib/europeana/api/faraday_middleware/response/parse_json_to_various.rb +52 -0
  19. data/lib/europeana/api/logger.rb +10 -0
  20. data/lib/europeana/api/queue.rb +47 -0
  21. data/lib/europeana/api/record.rb +29 -83
  22. data/lib/europeana/api/request.rb +77 -38
  23. data/lib/europeana/api/resource.rb +30 -0
  24. data/lib/europeana/api/response.rb +47 -0
  25. data/lib/europeana/api/version.rb +2 -1
  26. data/spec/europeana/api/annotation_spec.rb +77 -0
  27. data/spec/europeana/api/client_spec.rb +46 -0
  28. data/spec/europeana/api/entity_spec.rb +6 -0
  29. data/spec/europeana/api/faraday_middleware/request/authenticated_request_spec.rb +22 -0
  30. data/spec/europeana/api/queue_spec.rb +4 -0
  31. data/spec/europeana/api/record_spec.rb +54 -104
  32. data/spec/europeana/api/request_spec.rb +3 -0
  33. data/spec/europeana/api/resource_spec.rb +47 -0
  34. data/spec/europeana/api/response_spec.rb +10 -0
  35. data/spec/europeana/api_spec.rb +34 -84
  36. data/spec/spec_helper.rb +8 -0
  37. data/spec/support/shared_examples/resource_endpoint.rb +11 -0
  38. metadata +158 -34
  39. data/lib/europeana/api/record/hierarchy.rb +0 -48
  40. data/lib/europeana/api/record/hierarchy/ancestor_self_siblings.rb +0 -12
  41. data/lib/europeana/api/record/hierarchy/base.rb +0 -30
  42. data/lib/europeana/api/record/hierarchy/children.rb +0 -12
  43. data/lib/europeana/api/record/hierarchy/following_siblings.rb +0 -12
  44. data/lib/europeana/api/record/hierarchy/parent.rb +0 -12
  45. data/lib/europeana/api/record/hierarchy/preceding_siblings.rb +0 -15
  46. data/lib/europeana/api/record/hierarchy/self.rb +0 -12
  47. data/lib/europeana/api/requestable.rb +0 -118
  48. data/lib/europeana/api/search.rb +0 -64
  49. data/lib/europeana/api/search/fields.rb +0 -112
  50. data/spec/europeana/api/errors_spec.rb +0 -23
  51. data/spec/europeana/api/record/hierarchy_spec.rb +0 -15
  52. data/spec/europeana/api/search_spec.rb +0 -97
  53. data/spec/support/shared_examples/api_request.rb +0 -65
  54. data/spec/support/shared_examples/record_request.rb +0 -26
  55. data/spec/support/shared_examples/search_request.rb +0 -42
  56. data/spec/support/webmock.rb +0 -14
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+ RSpec.describe Europeana::API::Request do
3
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+ RSpec.describe Europeana::API::Resource do
3
+ let(:resource_class) do
4
+ Class.new do
5
+ include Europeana::API::Resource
6
+ end
7
+ end
8
+
9
+ it 'adds #has_api_endpoint class method' do
10
+ expect(resource_class).to respond_to(:has_api_endpoint)
11
+ end
12
+
13
+ it 'adds #api_request_for_endpoint class method' do
14
+ expect(resource_class).to respond_to(:api_request_for_endpoint)
15
+ end
16
+
17
+ it 'adds @api_endpoints class attribute accessor' do
18
+ expect(resource_class).to respond_to(:api_endpoints)
19
+ end
20
+
21
+ describe '#has_api_endpoint' do
22
+ it 'registers API endpoint method on class' do
23
+ resource_class.has_api_endpoint(:fish, path: '/go/fish')
24
+ expect(resource_class.api_endpoints).to have_key(:fish)
25
+ expect(resource_class.api_endpoints[:fish]).to eq(path: '/go/fish')
26
+ expect(resource_class).to respond_to(:fish)
27
+ end
28
+
29
+ it 'provides a means to make a request to the API' do
30
+ resource_class.has_api_endpoint(:fish, path: '/go/fish')
31
+ stub_request(:get, %r{://www.europeana.eu/api/go/fish}).
32
+ to_return(status: 200, body: '{"catch":[]}', headers: { 'Content-Type' => 'application/json' })
33
+ resource_class.fish(with: 'rod', 'without' => 'net')
34
+ expect(a_request(:get, %r{www.europeana.eu/api/go/fish})).to have_been_made.once
35
+ end
36
+ end
37
+
38
+ describe '#api_request_for_endpoint' do
39
+ it 'builds a request for the endpoint' do
40
+ resource_class.has_api_endpoint(:fish, path: '/go/fish')
41
+ request = resource_class.api_request_for_endpoint(:fish, with: 'rod')
42
+ expect(request).to be_a(Europeana::API::Request)
43
+ expect(request.params).to eq(with: 'rod')
44
+ expect(request.endpoint).to eq(resource_class.api_endpoints[:fish])
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+ RSpec.describe Europeana::API::Response do
3
+ it 'handles blank responses' do
4
+ request = instance_double('Europeana::API::Request', endpoint: {})
5
+ faraday_response = instance_double('Faraday::Response', status: 204, body: '')
6
+ response = described_class.new(request, faraday_response)
7
+ expect { response.validate! }.not_to raise_error
8
+ expect(response.body).to eq('')
9
+ end
10
+ end
@@ -1,97 +1,47 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
+ describe Europeana::API do
3
+ let(:api_key) { 'xyz' }
2
4
 
3
- module Europeana
4
- describe API do
5
- let(:api_key) { 'xyz' }
6
- let(:record_id) { '/abc/1234' }
7
- let(:params) { { callback: 'doSomething();' } }
8
-
9
- before(:each) do
10
- described_class.defaults!
11
- end
12
-
13
- describe '.url' do
14
- it 'defaults to the live API URL' do
15
- expect(subject.url).to eq('https://www.europeana.eu/api/v2')
16
- end
17
- end
18
-
19
- describe '.url=' do
20
- let(:url) { 'http://www.example.com/v2' }
21
- it 'accepts override of the API URL' do
22
- described_class.url = url
23
- expect(described_class.instance_variable_get(:@url)).to eq(url)
24
- end
25
- end
26
-
27
- describe ".api_key=" do
28
- it "sets the API key" do
29
- described_class.api_key = api_key
30
- expect(described_class.instance_variable_get(:@api_key)).to eq(api_key)
31
- end
32
- end
33
-
34
- describe ".api_key" do
35
- it "gets the API key" do
36
- described_class.instance_variable_set(:@api_key, api_key)
37
- expect(described_class.api_key).to eq(api_key)
38
- end
39
- end
40
-
41
- describe ".max_retries" do
42
- it "defaults to 5" do
43
- expect(described_class.max_retries).to eq(5)
44
- end
5
+ describe '.url' do
6
+ it 'defaults to the production API URL' do
7
+ expect(described_class.url).to eq('https://www.europeana.eu/api')
45
8
  end
9
+ end
46
10
 
47
- describe ".max_retries=" do
48
- it "sets the maximum number of retries" do
49
- described_class.max_retries = 2
50
- expect(described_class.max_retries).to eq(2)
51
- end
11
+ describe '.url=' do
12
+ let(:url) { 'http://www.example.com/api' }
13
+ it 'accepts override of the API URL' do
14
+ described_class.url = url
15
+ expect(described_class.instance_variable_get(:@url)).to eq(url)
52
16
  end
17
+ end
53
18
 
54
- describe ".retry_delay" do
55
- it "defaults to 10" do
56
- expect(described_class.retry_delay).to eq(10)
57
- end
19
+ describe '.key=' do
20
+ it 'sets the API key' do
21
+ described_class.key = api_key
22
+ expect(described_class.instance_variable_get(:@key)).to eq(api_key)
58
23
  end
24
+ end
59
25
 
60
- describe ".retry_delay=" do
61
- it "sets the retry delay" do
62
- described_class.retry_delay = 3
63
- expect(described_class.retry_delay).to eq(3)
64
- end
26
+ describe '.key' do
27
+ it 'gets the API key' do
28
+ described_class.instance_variable_set(:@key, api_key)
29
+ expect(described_class.key).to eq(api_key)
65
30
  end
31
+ end
66
32
 
67
- describe ".defaults!" do
68
- it "sets the API URL to its default" do
69
- described_class.url = 'http://www.example.com/v2'
70
- expect { described_class.defaults! }.
71
- to change { described_class.url }.
72
- from('http://www.example.com/v2').
73
- to('https://www.europeana.eu/api/v2')
74
- end
75
-
76
- it "sets retry delay to its default" do
77
- described_class.retry_delay = 3
78
- expect { described_class.defaults! }.to change { described_class.retry_delay }.from(3).to(10)
79
- end
80
-
81
- it "sets max retries to its default" do
82
- described_class.max_retries = 3
83
- expect { described_class.defaults! }.to change { described_class.max_retries }.from(3).to(5)
84
- end
85
- end
33
+ describe '.record' do
34
+ subject { described_class.record }
35
+ it { is_expected.to eq(Europeana::API::Record) }
36
+ end
86
37
 
87
- describe ".search" do
88
- subject { described_class.search(params) }
89
- it_behaves_like "search request"
90
- end
38
+ describe '.annotation' do
39
+ subject { described_class.annotation }
40
+ it { is_expected.to eq(Europeana::API::Annotation) }
41
+ end
91
42
 
92
- describe ".record" do
93
- subject { described_class.record(record_id, params) }
94
- it_behaves_like "record request"
95
- end
43
+ describe '.entity' do
44
+ subject { described_class.entity }
45
+ it { is_expected.to eq(Europeana::API::Entity) }
96
46
  end
97
47
  end
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
1
2
  require 'coveralls'
2
3
  require 'europeana/api'
4
+ require 'shoulda/matchers'
3
5
  require 'webmock/rspec'
4
6
 
5
7
  Dir['./spec/support/**/*.rb'].each { |f| require f }
@@ -13,3 +15,9 @@ RSpec.configure do |config|
13
15
  c.syntax = :expect
14
16
  end
15
17
  end
18
+
19
+ Shoulda::Matchers.configure do |config|
20
+ config.integrate do |with|
21
+ with.test_framework :rspec
22
+ end
23
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+ RSpec.shared_examples 'a resource with API endpoint' do |endpoint, method|
3
+ subject { described_class }
4
+
5
+ it { is_expected.to respond_to(endpoint) }
6
+
7
+ it "has #{endpoint} endpoint registered" do
8
+ expect(subject.api_endpoints).to have_key(endpoint)
9
+ expect(subject.api_endpoints[endpoint][:method]).to eq(method)
10
+ end
11
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: europeana-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Doe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-27 00:00:00.000000000 Z
11
+ date: 2017-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,20 +16,54 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '3.0'
19
+ version: '4.2'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '5'
22
+ version: '6.0'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: '3.0'
29
+ version: '4.2'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '6.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: faraday
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '0.9'
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: 0.12.2
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '0.9'
30
50
  - - "<"
31
51
  - !ruby/object:Gem::Version
32
- version: '5'
52
+ version: 0.12.2
53
+ - !ruby/object:Gem::Dependency
54
+ name: faraday_middleware
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ type: :runtime
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
33
67
  - !ruby/object:Gem::Dependency
34
68
  name: multi_json
35
69
  requirement: !ruby/object:Gem::Requirement
@@ -44,6 +78,34 @@ dependencies:
44
78
  - - "~>"
45
79
  - !ruby/object:Gem::Version
46
80
  version: '1.0'
81
+ - !ruby/object:Gem::Dependency
82
+ name: rack
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">"
86
+ - !ruby/object:Gem::Version
87
+ version: 1.6.2
88
+ type: :runtime
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">"
93
+ - !ruby/object:Gem::Version
94
+ version: 1.6.2
95
+ - !ruby/object:Gem::Dependency
96
+ name: typhoeus
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - "~>"
100
+ - !ruby/object:Gem::Version
101
+ version: '1.1'
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - "~>"
107
+ - !ruby/object:Gem::Version
108
+ version: '1.1'
47
109
  - !ruby/object:Gem::Dependency
48
110
  name: bundler
49
111
  requirement: !ruby/object:Gem::Requirement
@@ -58,6 +120,34 @@ dependencies:
58
120
  - - "~>"
59
121
  - !ruby/object:Gem::Version
60
122
  version: '1.3'
123
+ - !ruby/object:Gem::Dependency
124
+ name: coveralls
125
+ requirement: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ type: :development
131
+ prerelease: false
132
+ version_requirements: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ - !ruby/object:Gem::Dependency
138
+ name: dotenv
139
+ requirement: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ type: :development
145
+ prerelease: false
146
+ version_requirements: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
61
151
  - !ruby/object:Gem::Dependency
62
152
  name: rake
63
153
  requirement: !ruby/object:Gem::Requirement
@@ -86,6 +176,34 @@ dependencies:
86
176
  - - "~>"
87
177
  - !ruby/object:Gem::Version
88
178
  version: '3.0'
179
+ - !ruby/object:Gem::Dependency
180
+ name: rubocop
181
+ requirement: !ruby/object:Gem::Requirement
182
+ requirements:
183
+ - - '='
184
+ - !ruby/object:Gem::Version
185
+ version: 0.39.0
186
+ type: :development
187
+ prerelease: false
188
+ version_requirements: !ruby/object:Gem::Requirement
189
+ requirements:
190
+ - - '='
191
+ - !ruby/object:Gem::Version
192
+ version: 0.39.0
193
+ - !ruby/object:Gem::Dependency
194
+ name: shoulda-matchers
195
+ requirement: !ruby/object:Gem::Requirement
196
+ requirements:
197
+ - - "~>"
198
+ - !ruby/object:Gem::Version
199
+ version: '3.1'
200
+ type: :development
201
+ prerelease: false
202
+ version_requirements: !ruby/object:Gem::Requirement
203
+ requirements:
204
+ - - "~>"
205
+ - !ruby/object:Gem::Version
206
+ version: '3.1'
89
207
  - !ruby/object:Gem::Dependency
90
208
  name: webmock
91
209
  requirement: !ruby/object:Gem::Requirement
@@ -103,7 +221,8 @@ dependencies:
103
221
  description: Search and retrieve records from the Europeana REST API
104
222
  email:
105
223
  - richard.doe@rwdit.net
106
- executables: []
224
+ executables:
225
+ - console
107
226
  extensions: []
108
227
  extra_rdoc_files: []
109
228
  files:
@@ -117,33 +236,37 @@ files:
117
236
  - LICENSE.md
118
237
  - README.md
119
238
  - Rakefile
239
+ - bin/console
120
240
  - europeana-api.gemspec
121
241
  - lib/europeana/api.rb
242
+ - lib/europeana/api/annotation.rb
243
+ - lib/europeana/api/client.rb
244
+ - lib/europeana/api/entity.rb
122
245
  - lib/europeana/api/errors.rb
246
+ - lib/europeana/api/faraday_middleware.rb
247
+ - lib/europeana/api/faraday_middleware/request/authenticated_request.rb
248
+ - lib/europeana/api/faraday_middleware/request/parameter_repetition.rb
249
+ - lib/europeana/api/faraday_middleware/response/handle_text.rb
250
+ - lib/europeana/api/faraday_middleware/response/parse_json_to_various.rb
251
+ - lib/europeana/api/logger.rb
252
+ - lib/europeana/api/queue.rb
123
253
  - lib/europeana/api/record.rb
124
- - lib/europeana/api/record/hierarchy.rb
125
- - lib/europeana/api/record/hierarchy/ancestor_self_siblings.rb
126
- - lib/europeana/api/record/hierarchy/base.rb
127
- - lib/europeana/api/record/hierarchy/children.rb
128
- - lib/europeana/api/record/hierarchy/following_siblings.rb
129
- - lib/europeana/api/record/hierarchy/parent.rb
130
- - lib/europeana/api/record/hierarchy/preceding_siblings.rb
131
- - lib/europeana/api/record/hierarchy/self.rb
132
254
  - lib/europeana/api/request.rb
133
- - lib/europeana/api/requestable.rb
134
- - lib/europeana/api/search.rb
135
- - lib/europeana/api/search/fields.rb
255
+ - lib/europeana/api/resource.rb
256
+ - lib/europeana/api/response.rb
136
257
  - lib/europeana/api/version.rb
137
- - spec/europeana/api/errors_spec.rb
138
- - spec/europeana/api/record/hierarchy_spec.rb
258
+ - spec/europeana/api/annotation_spec.rb
259
+ - spec/europeana/api/client_spec.rb
260
+ - spec/europeana/api/entity_spec.rb
261
+ - spec/europeana/api/faraday_middleware/request/authenticated_request_spec.rb
262
+ - spec/europeana/api/queue_spec.rb
139
263
  - spec/europeana/api/record_spec.rb
140
- - spec/europeana/api/search_spec.rb
264
+ - spec/europeana/api/request_spec.rb
265
+ - spec/europeana/api/resource_spec.rb
266
+ - spec/europeana/api/response_spec.rb
141
267
  - spec/europeana/api_spec.rb
142
268
  - spec/spec_helper.rb
143
- - spec/support/shared_examples/api_request.rb
144
- - spec/support/shared_examples/record_request.rb
145
- - spec/support/shared_examples/search_request.rb
146
- - spec/support/webmock.rb
269
+ - spec/support/shared_examples/resource_endpoint.rb
147
270
  homepage: https://github.com/europeana/europeana-api-client-ruby
148
271
  licenses:
149
272
  - EUPL V.1.1
@@ -164,19 +287,20 @@ required_rubygems_version: !ruby/object:Gem::Requirement
164
287
  version: '0'
165
288
  requirements: []
166
289
  rubyforge_project:
167
- rubygems_version: 2.5.1
290
+ rubygems_version: 2.6.12
168
291
  signing_key:
169
292
  specification_version: 4
170
293
  summary: Ruby client library for the Europeana API
171
294
  test_files:
172
- - spec/europeana/api/errors_spec.rb
173
- - spec/europeana/api/record/hierarchy_spec.rb
295
+ - spec/europeana/api/annotation_spec.rb
296
+ - spec/europeana/api/client_spec.rb
297
+ - spec/europeana/api/entity_spec.rb
298
+ - spec/europeana/api/faraday_middleware/request/authenticated_request_spec.rb
299
+ - spec/europeana/api/queue_spec.rb
174
300
  - spec/europeana/api/record_spec.rb
175
- - spec/europeana/api/search_spec.rb
301
+ - spec/europeana/api/request_spec.rb
302
+ - spec/europeana/api/resource_spec.rb
303
+ - spec/europeana/api/response_spec.rb
176
304
  - spec/europeana/api_spec.rb
177
305
  - spec/spec_helper.rb
178
- - spec/support/shared_examples/api_request.rb
179
- - spec/support/shared_examples/record_request.rb
180
- - spec/support/shared_examples/search_request.rb
181
- - spec/support/webmock.rb
182
- has_rdoc:
306
+ - spec/support/shared_examples/resource_endpoint.rb