europeana-api 0.3.2 → 0.3.3
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.
- checksums.yaml +4 -4
- data/.hound.yml +10 -0
- data/.rspec +3 -0
- data/.rubocop.yml +1 -0
- data/.ruby-style.yml +1054 -0
- data/.travis.yml +6 -0
- data/LICENSE.md +119 -0
- data/README.md +6 -0
- data/Rakefile +3 -0
- data/europeana-api.gemspec +1 -1
- data/lib/europeana/api.rb +13 -5
- data/lib/europeana/api/errors.rb +1 -1
- data/lib/europeana/api/record.rb +4 -4
- data/lib/europeana/api/request.rb +16 -16
- data/lib/europeana/api/search.rb +5 -3
- data/lib/europeana/api/version.rb +1 -1
- data/spec/europeana/api/errors_spec.rb +23 -0
- data/spec/europeana/api/record_spec.rb +133 -0
- data/spec/europeana/api/search_spec.rb +89 -0
- data/spec/europeana/api_spec.rb +97 -0
- data/spec/spec_helper.rb +1 -1
- data/spec/support/shared_examples/api_request.rb +24 -15
- data/spec/support/shared_examples/record_request.rb +16 -17
- data/spec/support/shared_examples/search_request.rb +20 -19
- metadata +18 -13
- data/LICENSE.pdf +0 -0
- data/spec/europeana/errors_spec.rb +0 -13
- data/spec/europeana/record_spec.rb +0 -132
- data/spec/europeana/search_spec.rb +0 -92
- data/spec/europeana_spec.rb +0 -81
data/LICENSE.pdf
DELETED
Binary file
|
@@ -1,13 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module Europeana
|
4
|
-
describe "Errors" do
|
5
|
-
describe "MissingAPIKeyError" do
|
6
|
-
subject { Europeana::Errors::MissingAPIKeyError.new }
|
7
|
-
|
8
|
-
it "has an informative message" do
|
9
|
-
expect(subject.message).to match("Missing API key.")
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
@@ -1,132 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module Europeana
|
4
|
-
describe Record do
|
5
|
-
before(:each) do
|
6
|
-
@api_key = "xyz"
|
7
|
-
Europeana.api_key = @api_key
|
8
|
-
@record_id = "/abc/1234"
|
9
|
-
@params = { :callback => "doSomething();" }
|
10
|
-
end
|
11
|
-
|
12
|
-
describe "#new" do
|
13
|
-
context "without record ID" do
|
14
|
-
it "raises error" do
|
15
|
-
expect { subject }.to raise_error(ArgumentError)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
context "with record ID" do
|
20
|
-
context "without params" do
|
21
|
-
subject { Europeana::Record.new(@record_id) }
|
22
|
-
|
23
|
-
it "should not raise error" do
|
24
|
-
expect { subject }.to_not raise_error
|
25
|
-
end
|
26
|
-
|
27
|
-
it "sets id attribute" do
|
28
|
-
expect(subject.instance_variable_get(:@id)).to eq(@record_id)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
context "with params" do
|
33
|
-
subject { Europeana::Record.new(@record_id, @params) }
|
34
|
-
|
35
|
-
it "should not raise error" do
|
36
|
-
expect { subject }.to_not raise_error
|
37
|
-
end
|
38
|
-
|
39
|
-
it "sets params attribute" do
|
40
|
-
expect(subject.instance_variable_get(:@params)).to eq(@params)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
describe "#id" do
|
47
|
-
subject { Europeana::Record.new(@record_id) }
|
48
|
-
it "gets id attribute" do
|
49
|
-
expect(subject.id).to eq(subject.instance_variable_get(:@id))
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
describe "#id=" do
|
54
|
-
subject { Europeana::Record.new(@record_id) }
|
55
|
-
|
56
|
-
context "with valid ID" do
|
57
|
-
it "sets id attribute" do
|
58
|
-
subject.id = "/xyz/5678"
|
59
|
-
expect(subject.instance_variable_get(:@id)).to eq("/xyz/5678")
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
context "invalid ID" do
|
64
|
-
it "raises error" do
|
65
|
-
expect { subject.id = "invalid" }.to raise_error("Invalid Europeana record ID.")
|
66
|
-
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
end
|
71
|
-
|
72
|
-
describe "#params" do
|
73
|
-
subject { Europeana::Record.new(@record_id, @params) }
|
74
|
-
it "gets params attribute" do
|
75
|
-
expect(subject.params).to eq(subject.instance_variable_get(:@params))
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
describe "#params=" do
|
80
|
-
subject { Europeana::Record.new(@record_id, {}) }
|
81
|
-
|
82
|
-
context "valid params" do
|
83
|
-
it "sets params attribute" do
|
84
|
-
subject.params = @params
|
85
|
-
expect(subject.instance_variable_get(:@params)).to eq(@params)
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
it "validates param names" do
|
90
|
-
expect { subject.params = { :invalid => "parameter" } }.to raise_error(/Unknown key: :?invalid/)
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
describe "#params_with_authentication" do
|
95
|
-
subject { Europeana::Record.new(@record_id, @params) }
|
96
|
-
|
97
|
-
context "with API key" do
|
98
|
-
it "adds API key to params" do
|
99
|
-
expect(subject.params_with_authentication).to eq(@params.merge(:wskey => @api_key))
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
context "without API key" do
|
104
|
-
it "raises an error" do
|
105
|
-
Europeana.api_key = nil
|
106
|
-
expect { subject.params_with_authentication }.to raise_error(Europeana::Errors::MissingAPIKeyError)
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
describe "#request_uri" do
|
112
|
-
subject { Europeana::Record.new(@record_id, @params) }
|
113
|
-
|
114
|
-
it "returns a URI" do
|
115
|
-
expect(subject.request_uri).to be_a(URI)
|
116
|
-
end
|
117
|
-
|
118
|
-
it "includes the record ID" do
|
119
|
-
expect(subject.request_uri.to_s).to include(@record_id)
|
120
|
-
end
|
121
|
-
|
122
|
-
it "includes the query params" do
|
123
|
-
expect(subject.request_uri.to_s).to include(@params.to_query)
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
describe "#get" do
|
128
|
-
subject { Europeana::Record.new(@record_id, @params).get }
|
129
|
-
it_behaves_like "record request"
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
@@ -1,92 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module Europeana
|
4
|
-
describe Search do
|
5
|
-
before(:all) do
|
6
|
-
@params = { :query => "test", :profile => "standard", :qf => "where:London", :rows => 100, :start => 1, :callback => "" }
|
7
|
-
@api_key = "xyz"
|
8
|
-
end
|
9
|
-
|
10
|
-
before(:each) do
|
11
|
-
Europeana.api_key = @api_key
|
12
|
-
end
|
13
|
-
|
14
|
-
describe "#new" do
|
15
|
-
context "with no API request params" do
|
16
|
-
subject { lambda { Europeana::Search.new } }
|
17
|
-
it { should_not raise_error }
|
18
|
-
end
|
19
|
-
|
20
|
-
context "with API request params" do
|
21
|
-
subject { Europeana::Search.new(@params) }
|
22
|
-
it "should not raise error" do
|
23
|
-
expect { subject }.not_to raise_error
|
24
|
-
end
|
25
|
-
it "stores the request params" do
|
26
|
-
expect(subject.instance_variable_get(:@params)).to eq(@params)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe "#params" do
|
32
|
-
subject { Europeana::Search.new(@params) }
|
33
|
-
it "gets params attribute" do
|
34
|
-
expect(subject.params).to eq(@params)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
describe "#params=" do
|
39
|
-
subject { Europeana::Search.new }
|
40
|
-
|
41
|
-
context "valid params" do
|
42
|
-
it "sets params attribute" do
|
43
|
-
subject.params = @params
|
44
|
-
expect(subject.instance_variable_get(:@params)).to eq(@params)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
it "validates param names" do
|
49
|
-
expect { subject.params = { :invalid => "parameter" } }.to raise_error(/Unknown key: :?invalid/)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
describe "#request_uri" do
|
54
|
-
it "returns a URI" do
|
55
|
-
expect(subject.request_uri).to be_a(URI)
|
56
|
-
end
|
57
|
-
|
58
|
-
it "includes request params" do
|
59
|
-
expect(subject.request_uri.to_s).to eq("http://www.europeana.eu/api/v2/search.json?query=&wskey=#{@api_key}")
|
60
|
-
end
|
61
|
-
|
62
|
-
it "handles Hash of qf params" do
|
63
|
-
subject.params[:qf] = { :where => [ "London", "Paris" ], :what => "Photograph" }
|
64
|
-
expect(subject.request_uri.to_s).to eq("http://www.europeana.eu/api/v2/search.json?query=&wskey=#{@api_key}&qf=where:London&qf=where:Paris&qf=what:Photograph")
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
describe "#params_with_authentication" do
|
69
|
-
subject { Europeana::Search.new }
|
70
|
-
|
71
|
-
context "with API key" do
|
72
|
-
it "adds API key to params" do
|
73
|
-
subject.params = @params
|
74
|
-
expect(subject.params_with_authentication).to eq(@params.merge(:wskey => @api_key))
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
context "without API key" do
|
79
|
-
it "raises an error" do
|
80
|
-
subject.params = @params
|
81
|
-
Europeana.api_key = nil
|
82
|
-
expect { subject.params_with_authentication }.to raise_error(Europeana::Errors::MissingAPIKeyError)
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
describe "#execute" do
|
88
|
-
subject { Europeana::Search.new(@params).execute }
|
89
|
-
it_behaves_like "search request"
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
data/spec/europeana_spec.rb
DELETED
@@ -1,81 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Europeana do
|
4
|
-
before(:each) do
|
5
|
-
Europeana.defaults!
|
6
|
-
end
|
7
|
-
|
8
|
-
describe "::URL" do
|
9
|
-
it "returns 'http://www.europeana.eu/api/v2'" do
|
10
|
-
expect(Europeana::URL).to eq("http://www.europeana.eu/api/v2")
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
describe ".api_key=" do
|
15
|
-
before(:all) do
|
16
|
-
@api_key = "xyz"
|
17
|
-
end
|
18
|
-
it "sets the API key" do
|
19
|
-
Europeana.api_key = @api_key
|
20
|
-
expect(Europeana.instance_variable_get(:@api_key)).to eq(@api_key)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe ".api_key" do
|
25
|
-
before(:all) do
|
26
|
-
@api_key = "xyz"
|
27
|
-
end
|
28
|
-
it "gets the API key" do
|
29
|
-
Europeana.instance_variable_set(:@api_key, @api_key)
|
30
|
-
expect(Europeana.api_key).to eq(@api_key)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
describe ".max_retries" do
|
35
|
-
it "defaults to 5" do
|
36
|
-
expect(Europeana.max_retries).to eq(5)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
describe ".max_retries=" do
|
41
|
-
it "sets the maximum number of retries" do
|
42
|
-
Europeana.max_retries = 2
|
43
|
-
expect(Europeana.max_retries).to eq(2)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
describe ".retry_delay" do
|
48
|
-
it "defaults to 10" do
|
49
|
-
expect(Europeana.retry_delay).to eq(10)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
describe ".retry_delay=" do
|
54
|
-
it "sets the retry delay" do
|
55
|
-
Europeana.retry_delay = 3
|
56
|
-
expect(Europeana.retry_delay).to eq(3)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
describe ".defaults!" do
|
61
|
-
it "sets retry delay to its default" do
|
62
|
-
Europeana.retry_delay = 3
|
63
|
-
expect { Europeana.defaults! }.to change { Europeana.retry_delay }.from(3).to(10)
|
64
|
-
end
|
65
|
-
|
66
|
-
it "sets max retries to its default" do
|
67
|
-
Europeana.max_retries = 3
|
68
|
-
expect { Europeana.defaults! }.to change { Europeana.max_retries }.from(3).to(5)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
describe ".search" do
|
73
|
-
subject { Europeana.search(@params) }
|
74
|
-
it_behaves_like "search request"
|
75
|
-
end
|
76
|
-
|
77
|
-
describe ".record" do
|
78
|
-
subject { Europeana.record(@record_id, @params) }
|
79
|
-
it_behaves_like "record request"
|
80
|
-
end
|
81
|
-
end
|