europeana-api 0.3.0 → 0.3.1
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/README.md +17 -8
- data/europeana-api.gemspec +2 -0
- data/lib/europeana/api.rb +21 -23
- data/lib/europeana/api/record.rb +17 -7
- data/lib/europeana/api/request.rb +2 -2
- data/lib/europeana/api/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 900783456e54538f5ac9ddcff6fd9ad7b0a42336
|
4
|
+
data.tar.gz: b8fcd2aeab490cd197ecb7f6eb1985afeafc4c11
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb4f2822e5235c4eb46b7c975dc5271b7ec25d87d3be5f591143b92a4f398d34c5896343d7c4b184956e4dc3167eeb8f7aee0ffbd5c6b43211fcb903a4ef4d33
|
7
|
+
data.tar.gz: 12f747dcda20e90b737e1cb6193c9d373dd9b2d1eb82ba32342afba9a79dbb88681789862bc577caf05a7cd1dad3c2577d8114cd5be64516791ddb38d18a2b2f
|
data/README.md
CHANGED
@@ -7,7 +7,9 @@ REST API](http://labs.europeana.eu/api/introduction/).
|
|
7
7
|
|
8
8
|
Add this line to your application's Gemfile:
|
9
9
|
|
10
|
-
|
10
|
+
```ruby
|
11
|
+
gem 'europeana-api'
|
12
|
+
```
|
11
13
|
|
12
14
|
And then execute:
|
13
15
|
|
@@ -29,21 +31,28 @@ Sign up for an API key at: http://labs.europeana.eu/api/registration/
|
|
29
31
|
|
30
32
|
Configure your application with the API key:
|
31
33
|
|
32
|
-
|
34
|
+
```ruby
|
35
|
+
require 'europeana/api'
|
36
|
+
Europeana::API.api_key = 'xyz'
|
37
|
+
```
|
33
38
|
|
34
39
|
### Search
|
35
40
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
41
|
+
```ruby
|
42
|
+
search = Europeana::API.search(query: '"first world war"') # => { "success" => true, "items" => [ ... ], "totalResults" => 1234, ... }
|
43
|
+
search['items'] # => [ item1, item2, ... ]
|
44
|
+
search['totalResults'] # => 1234
|
45
|
+
```
|
46
|
+
|
40
47
|
See http://labs.europeana.eu/api/search/ for details of the data returned in
|
41
48
|
the search response.
|
42
49
|
|
43
50
|
### Record
|
44
51
|
|
45
|
-
|
46
|
-
|
52
|
+
```ruby
|
53
|
+
record = Europeana::API.record('abc/1234') # => { "success" => true, "object" => { ... }, ... }
|
54
|
+
record['object'] # => { "title" => "...", "proxies" => [ ... ], "aggregations" => [ ... ]
|
55
|
+
```
|
47
56
|
|
48
57
|
See http://labs.europeana.eu/api/record/ for details of the data returned in
|
49
58
|
the record response.
|
data/europeana-api.gemspec
CHANGED
@@ -18,6 +18,8 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(/^(test|spec|features)\//)
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
|
+
spec.required_ruby_version = '>= 1.9.2'
|
22
|
+
|
21
23
|
spec.add_dependency 'activesupport', '>= 3.0'
|
22
24
|
spec.add_dependency 'multi_json', '~> 1.0'
|
23
25
|
|
data/lib/europeana/api.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
require 'europeana/api/version'
|
2
|
-
require 'uri'
|
3
|
-
require 'logger'
|
4
1
|
require 'active_support/core_ext/object'
|
5
2
|
require 'active_support/hash_with_indifferent_access'
|
3
|
+
require 'europeana/api/version'
|
4
|
+
require 'logger'
|
5
|
+
require 'uri'
|
6
6
|
|
7
|
-
##
|
8
|
-
# Europeana REST API client
|
9
7
|
module Europeana
|
8
|
+
##
|
9
|
+
# Europeana REST API client
|
10
10
|
module API
|
11
11
|
API_VERSION = 'v2'
|
12
12
|
URL = "http://www.europeana.eu/api/#{API_VERSION}"
|
@@ -27,7 +27,6 @@ module Europeana
|
|
27
27
|
# retries before giving up.
|
28
28
|
#
|
29
29
|
# @return [Integer]
|
30
|
-
#
|
31
30
|
attr_accessor :max_retries
|
32
31
|
|
33
32
|
##
|
@@ -36,12 +35,10 @@ module Europeana
|
|
36
35
|
# The default is 10 seconds.
|
37
36
|
#
|
38
37
|
# @return [Integer]
|
39
|
-
#
|
40
38
|
attr_accessor :retry_delay
|
41
39
|
|
42
40
|
##
|
43
41
|
# Sets configuration values to their defaults
|
44
|
-
#
|
45
42
|
def defaults!
|
46
43
|
self.max_retries = 5
|
47
44
|
self.retry_delay = 10
|
@@ -51,13 +48,12 @@ module Europeana
|
|
51
48
|
# Sends a Search request to the Europeana API
|
52
49
|
#
|
53
50
|
# Equivalent to:
|
54
|
-
# search = Europeana::Search.new(params)
|
51
|
+
# search = Europeana::API::Search.new(params)
|
55
52
|
# search.execute
|
56
53
|
#
|
57
54
|
# @param [Hash] params Query parameters
|
58
55
|
# @return [Hash] search response
|
59
|
-
# @see Europeana::Search#execute
|
60
|
-
#
|
56
|
+
# @see Europeana::API::Search#execute
|
61
57
|
def search(params = {})
|
62
58
|
Search.new(params).execute
|
63
59
|
end
|
@@ -66,27 +62,29 @@ module Europeana
|
|
66
62
|
# Sends a Record request to the Europeana API
|
67
63
|
#
|
68
64
|
# Equivalent to:
|
69
|
-
#
|
70
|
-
# record.get
|
65
|
+
# record = Europeana::API::Record.new(record_id, params)
|
66
|
+
# record.get(options)
|
71
67
|
#
|
72
68
|
# @param [String] Record ID
|
73
69
|
# @param [Hash] params Query parameters
|
70
|
+
# @param [Hash] options (see Europeana::API::Record#get)
|
74
71
|
# @return [Hash] search response
|
75
|
-
# @see Europeana::Record#get
|
76
|
-
|
77
|
-
|
78
|
-
Record.new(record_id, params).get
|
72
|
+
# @see Europeana::API::Record#get
|
73
|
+
def record(record_id, params = {}, options = {})
|
74
|
+
Record.new(record_id, params).get(options)
|
79
75
|
end
|
80
76
|
|
81
77
|
def logger
|
82
|
-
unless @logger
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
78
|
+
return @logger unless @logger.nil?
|
79
|
+
|
80
|
+
@logger = case
|
81
|
+
when defined?(Rails) && Rails.logger
|
82
|
+
Rails.logger
|
83
|
+
else
|
84
|
+
Logger.new(STDOUT).tap do |logger|
|
85
|
+
logger.progname = 'Europeana::API'
|
87
86
|
end
|
88
87
|
end
|
89
|
-
@logger
|
90
88
|
end
|
91
89
|
end
|
92
90
|
|
data/lib/europeana/api/record.rb
CHANGED
@@ -62,9 +62,14 @@ module Europeana
|
|
62
62
|
##
|
63
63
|
# Gets the URI for this Record request with parameters
|
64
64
|
#
|
65
|
+
# @param [Hash{Symbol => Object}] options
|
66
|
+
# @option options [Boolean] :ld (false)
|
67
|
+
# Request JSON-LD
|
65
68
|
# @return [URI]
|
66
|
-
def request_uri
|
67
|
-
|
69
|
+
def request_uri(options = {})
|
70
|
+
url = Europeana::API::URL + "/record#{@id}.json"
|
71
|
+
url << 'ld' if options[:ld]
|
72
|
+
uri = URI.parse(url)
|
68
73
|
uri.query = params_with_authentication.to_query
|
69
74
|
uri
|
70
75
|
end
|
@@ -72,19 +77,24 @@ module Europeana
|
|
72
77
|
##
|
73
78
|
# Sends a request for this record to the API
|
74
79
|
#
|
75
|
-
# @
|
80
|
+
# @param [Hash{Symbol => Object}] options
|
81
|
+
# @option options [Boolean] :ld (false)
|
82
|
+
# Request JSON-LD
|
83
|
+
# @return [Hash]
|
76
84
|
# @raise [Europeana::Errors::ResponseError] if API response could not be
|
77
85
|
# parsed as JSON
|
78
86
|
# @raise [Europeana::Errors::RequestError] if API response has
|
79
87
|
# `success:false`
|
80
88
|
# @raise [Europeana::Errors::RequestError] if API response has 404 status
|
81
89
|
# code
|
82
|
-
def get
|
83
|
-
request = Request.new(request_uri)
|
90
|
+
def get(options = {})
|
91
|
+
request = Request.new(request_uri(options))
|
84
92
|
response = request.execute
|
85
93
|
body = JSON.parse(response.body)
|
86
|
-
|
87
|
-
|
94
|
+
if (options[:ld] && !(200..299).include?(response.code.to_i)) || (!options[:ld] && !body['success'])
|
95
|
+
fail Errors::RequestError, response.code
|
96
|
+
end
|
97
|
+
body
|
88
98
|
rescue JSON::ParserError
|
89
99
|
if response.code.to_i == 404
|
90
100
|
# Handle HTML 404 responses on malformed record ID, emulating API's
|
@@ -21,9 +21,9 @@ module Europeana
|
|
21
21
|
|
22
22
|
# @return (see Net::HTTP#request)
|
23
23
|
def execute
|
24
|
-
logger.
|
24
|
+
logger.info("Request URL: #{uri}")
|
25
25
|
|
26
|
-
benchmark("
|
26
|
+
benchmark("Request query", level: :info) do
|
27
27
|
http = Net::HTTP.new(uri.host, uri.port)
|
28
28
|
request = Net::HTTP::Get.new(uri.request_uri)
|
29
29
|
retries = Europeana::API.max_retries
|
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.1
|
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-
|
11
|
+
date: 2015-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -133,7 +133,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
133
133
|
requirements:
|
134
134
|
- - ">="
|
135
135
|
- !ruby/object:Gem::Version
|
136
|
-
version:
|
136
|
+
version: 1.9.2
|
137
137
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
138
|
requirements:
|
139
139
|
- - ">="
|