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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9d80e47704d3b09489e1edbaed39ae4066fbb150
4
- data.tar.gz: 9b7d7798b9bb9531e8456e14428d688add2f3b45
3
+ metadata.gz: 5e60507c8e8dc5319c78e0a3ac52e8607d5f1612
4
+ data.tar.gz: 4ed8fd8a37de256d4bea39fbdd1a681177225858
5
5
  SHA512:
6
- metadata.gz: 0a1de32f7dd7001eaff9f0388e0d1cbe25751ea17e1b1138d4eddc58a395c669d976a7a20b39cbb6968b512705809c24ad9550d803a42188452152d8c999dd76
7
- data.tar.gz: 1503c8b82c8e175031f87dc17b6edbe5bd8832502017ecb4a1e77ce0b9d9cdcab1c891117df18b91c73cb9b7a8db8b540ac587736da34aeef2d81d3ba118bb58
6
+ metadata.gz: 722db92332c4af3cef65a4521defd06e3b9bc405115b11e8ac0c505c3889fe3088c86ede80bdae523ac10a659daefcdc8e6cdbb172dc5d4e31da5c4d8f925698
7
+ data.tar.gz: 5b67320510f741164e972918fd2a102e0cc57b30233a7f432961b837ee3a0821277846023f771d1c3bb758d95b35437242c9cd1b899ce79270fcfd0c72e21802
data/Gemfile CHANGED
@@ -2,3 +2,11 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in europeana.gemspec
4
4
  gemspec
5
+
6
+ group :test do
7
+ gem 'coveralls'
8
+ end
9
+
10
+ group :test, :develop do
11
+ gem 'rubocop'
12
+ end
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
 
@@ -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 = {})
@@ -2,6 +2,6 @@ module Europeana
2
2
  ##
3
3
  # Sets the *gem* version (not the *API* version)
4
4
  module API
5
- VERSION = '0.3.3'
5
+ VERSION = '0.3.4'
6
6
  end
7
7
  end
@@ -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 "search request" do
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 "API request"
7
+ it_behaves_like 'API request'
8
8
 
9
- context "with API key" do
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 "sends a Search request to the API" do
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 "without query" do
24
- it "sets an empty query" do
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?query=})).
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 "with query" do
31
+ context 'with query' do
32
32
  let(:params) { { query: 'test' } }
33
33
 
34
- it "sends query" do
34
+ it 'sends query' do
35
35
  subject
36
- expect(a_request(:get, %r{www.europeana.eu/api/v2/search.json?query=test})).
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.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-07 00:00:00.000000000 Z
11
+ date: 2015-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport