europeana-api 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +8 -0
- data/README.md +2 -0
- data/lib/europeana/api/search.rb +14 -0
- data/lib/europeana/api/version.rb +1 -1
- data/spec/europeana/api/search_spec.rb +8 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/support/shared_examples/search_request.rb +11 -10
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e60507c8e8dc5319c78e0a3ac52e8607d5f1612
|
4
|
+
data.tar.gz: 4ed8fd8a37de256d4bea39fbdd1a681177225858
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 722db92332c4af3cef65a4521defd06e3b9bc405115b11e8ac0c505c3889fe3088c86ede80bdae523ac10a659daefcdc8e6cdbb172dc5d4e31da5c4d8f925698
|
7
|
+
data.tar.gz: 5b67320510f741164e972918fd2a102e0cc57b30233a7f432961b837ee3a0821277846023f771d1c3bb758d95b35437242c9cd1b899ce79270fcfd0c72e21802
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Europeana
|
2
2
|
|
3
|
+
[![Build Status](https://travis-ci.org/rwd/europeana-api-client-ruby.svg?branch=master)](https://travis-ci.org/rwd/europeana-api-client-ruby) [![Coverage Status](https://coveralls.io/repos/rwd/europeana-api-client-ruby/badge.svg?branch=master&service=github)](https://coveralls.io/github/rwd/europeana-api-client-ruby?branch=master) [![security](https://hakiri.io/github/rwd/europeana-api-client-ruby/master.svg)](https://hakiri.io/github/rwd/europeana-api-client-ruby/master)
|
4
|
+
|
3
5
|
Ruby client library for the search and retrieval of records from the [Europeana
|
4
6
|
REST API](http://labs.europeana.eu/api/introduction/).
|
5
7
|
|
data/lib/europeana/api/search.rb
CHANGED
@@ -10,6 +10,20 @@ module Europeana
|
|
10
10
|
# Query params
|
11
11
|
attr_accessor :params
|
12
12
|
|
13
|
+
class << self
|
14
|
+
##
|
15
|
+
# Escapes Lucene syntax special characters for use in query parameters
|
16
|
+
#
|
17
|
+
# @param [String] text Text to escape
|
18
|
+
# @return [String] Escaped text
|
19
|
+
def escape(text)
|
20
|
+
specials = %w<\\ + - & | ! ( ) { } [ ] ^ " ~ * ? : / >
|
21
|
+
specials.each_with_object(text.dup) do |char, unescaped|
|
22
|
+
unescaped.gsub!(char, '\\\\' + char) # prepends *one* backslash
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
13
27
|
##
|
14
28
|
# @param [Hash] params Europeana API request parameters for Search query
|
15
29
|
def initialize(params = {})
|
@@ -84,6 +84,14 @@ module Europeana
|
|
84
84
|
subject { described_class.new(params).execute }
|
85
85
|
it_behaves_like "search request"
|
86
86
|
end
|
87
|
+
|
88
|
+
describe '.escape' do
|
89
|
+
%w<\\ + - & | ! ( ) { } [ ] ^ " ~ * ? : />.map do |char|
|
90
|
+
it "escapes lucene special character #{char}" do
|
91
|
+
expect(described_class.escape(char)).to eq("\\#{char}")
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
87
95
|
end
|
88
96
|
end
|
89
97
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
+
require 'coveralls'
|
1
2
|
require 'europeana/api'
|
2
3
|
require 'webmock/rspec'
|
3
4
|
|
4
5
|
Dir["./spec/support/**/*.rb"].each { |f| require f }
|
5
6
|
|
7
|
+
Coveralls.wear! unless Coveralls.will_run?.nil?
|
8
|
+
|
6
9
|
RSpec.configure do |config|
|
7
10
|
config.expect_with :rspec do |c|
|
8
11
|
c.syntax = :expect
|
@@ -1,12 +1,12 @@
|
|
1
|
-
shared_examples
|
1
|
+
shared_examples 'search request' do
|
2
2
|
before(:each) do
|
3
3
|
stub_request(:get, %r{www.europeana.eu/api/v2/search.json}).
|
4
4
|
to_return(body: '{"success":true}')
|
5
5
|
end
|
6
6
|
|
7
|
-
it_behaves_like
|
7
|
+
it_behaves_like 'API request'
|
8
8
|
|
9
|
-
context
|
9
|
+
context 'with API key' do
|
10
10
|
let(:api_key) { 'xyz' }
|
11
11
|
let(:params) { {} }
|
12
12
|
|
@@ -14,26 +14,27 @@ shared_examples "search request" do
|
|
14
14
|
Europeana::API.api_key = api_key
|
15
15
|
end
|
16
16
|
|
17
|
-
it
|
17
|
+
it 'sends a Search request to the API' do
|
18
18
|
subject
|
19
19
|
expect(a_request(:get, %r{www.europeana.eu/api/v2/search.json})).
|
20
20
|
to have_been_made.once
|
21
21
|
end
|
22
22
|
|
23
|
-
context
|
24
|
-
it
|
23
|
+
context 'without query' do
|
24
|
+
it 'sends without query' do
|
25
25
|
subject
|
26
|
-
expect(a_request(:get, %r{www.europeana.eu/api/v2/search.json
|
26
|
+
expect(a_request(:get, %r{www.europeana.eu/api/v2/search.json})).
|
27
27
|
to have_been_made.once
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
context
|
31
|
+
context 'with query' do
|
32
32
|
let(:params) { { query: 'test' } }
|
33
33
|
|
34
|
-
it
|
34
|
+
it 'sends query' do
|
35
35
|
subject
|
36
|
-
expect(a_request(:get,
|
36
|
+
expect(a_request(:get, 'www.europeana.eu/api/v2/search.json').
|
37
|
+
with(query: hash_including({'query' => params[:query]}))).
|
37
38
|
to have_been_made.once
|
38
39
|
end
|
39
40
|
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.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Doe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|