europeana-api 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.codeclimate.yml +5 -0
- data/.rubocop.yml +3 -0
- data/.ruby-style.yml +114 -176
- data/.travis.yml +11 -3
- data/Gemfile +8 -0
- data/README.md +7 -10
- data/europeana-api.gemspec +4 -5
- data/lib/europeana/api/record.rb +2 -0
- data/lib/europeana/api/record/lang_map.rb +106 -0
- data/lib/europeana/api/version.rb +2 -1
- data/spec/europeana/api/record/lang_map_spec.rb +108 -0
- data/spec/spec_helper.rb +5 -3
- metadata +23 -34
- data/.hound.yml +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f14b39bae1cf885de3216f4cf7ebf404c10c71edca2835e8368dcd97d7bbad4f
|
4
|
+
data.tar.gz: bd8edd6d721b6a7821f433d1c03f12e6e072b9621b2cb5591c03f9788311890d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8392c7700d06bae929246578515fe13d9809be5c4062dfe5a757a11a414abf38b33ee7d24f84da4ad4b6e3a7e25fbcb6e69a8a3996920939fc73dad03db4a604
|
7
|
+
data.tar.gz: b1d638bff24d90092427b8cd475556286ac2dcc2f8c19e22a1dc2baacb507fdc5dbadc29d4cfec42ebcd01f27346537f330b52d0e3dac312090716eb41f19057
|
data/.codeclimate.yml
ADDED
data/.rubocop.yml
CHANGED
data/.ruby-style.yml
CHANGED
@@ -1,12 +1,100 @@
|
|
1
|
+
---
|
1
2
|
AllCops:
|
2
3
|
Exclude:
|
3
|
-
|
4
|
-
|
4
|
+
- vendor/**/*
|
5
|
+
- db/schema.rb
|
6
|
+
- tmp/**/*
|
5
7
|
UseCache: false
|
6
8
|
TargetRubyVersion: 2.3
|
9
|
+
Layout/DotPosition:
|
10
|
+
Enabled: true
|
11
|
+
EnforcedStyle: trailing
|
12
|
+
SupportedStyles:
|
13
|
+
- leading
|
14
|
+
- trailing
|
15
|
+
Lint/AssignmentInCondition:
|
16
|
+
Enabled: false
|
17
|
+
AllowSafeAssignment: true
|
18
|
+
Lint/EachWithObjectArgument:
|
19
|
+
Enabled: true
|
20
|
+
Lint/HandleExceptions:
|
21
|
+
Enabled: false
|
22
|
+
Lint/LiteralAsCondition:
|
23
|
+
Enabled: false
|
24
|
+
Lint/LiteralInInterpolation:
|
25
|
+
Enabled: false
|
26
|
+
Metrics/AbcSize:
|
27
|
+
Enabled: false
|
28
|
+
Max: 15
|
29
|
+
Metrics/BlockLength:
|
30
|
+
Exclude:
|
31
|
+
- Rakefile
|
32
|
+
- "**/*.rake"
|
33
|
+
- spec/**/*.rb
|
34
|
+
- config/routes.rb
|
35
|
+
ExcludedMethods:
|
36
|
+
- aasm
|
37
|
+
- class_methods
|
38
|
+
Metrics/ClassLength:
|
39
|
+
Enabled: false
|
40
|
+
CountComments: false
|
41
|
+
Max: 100
|
42
|
+
Metrics/CyclomaticComplexity:
|
43
|
+
Enabled: false
|
44
|
+
Max: 6
|
45
|
+
Metrics/LineLength:
|
46
|
+
Max: 140
|
47
|
+
AllowHeredoc: true
|
48
|
+
AllowURI: true
|
49
|
+
URISchemes:
|
50
|
+
- http
|
51
|
+
- https
|
52
|
+
Metrics/MethodLength:
|
53
|
+
Enabled: false
|
54
|
+
CountComments: false
|
55
|
+
Max: 10
|
56
|
+
Metrics/ModuleLength:
|
57
|
+
CountComments: false
|
58
|
+
Max: 100
|
59
|
+
Enabled: false
|
60
|
+
Metrics/ParameterLists:
|
61
|
+
Enabled: false
|
62
|
+
Max: 5
|
63
|
+
CountKeywordArgs: true
|
64
|
+
Metrics/PerceivedComplexity:
|
65
|
+
Enabled: false
|
66
|
+
Max: 7
|
67
|
+
Naming/AccessorMethodName:
|
68
|
+
Enabled: false
|
69
|
+
Naming/FileName:
|
70
|
+
Enabled: false
|
71
|
+
Exclude: []
|
72
|
+
Naming/PredicateName:
|
73
|
+
Enabled: true
|
74
|
+
NamePrefix:
|
75
|
+
- is_
|
76
|
+
- has_
|
77
|
+
- have_
|
78
|
+
NamePrefixBlacklist:
|
79
|
+
- is_
|
80
|
+
Exclude:
|
81
|
+
- spec/**/*
|
82
|
+
Naming/UncommunicativeMethodParamName:
|
83
|
+
MinNameLength: 3
|
84
|
+
AllowNamesEndingInNumbers: true
|
85
|
+
AllowedNames:
|
86
|
+
- io
|
87
|
+
- id
|
88
|
+
- to
|
89
|
+
- by
|
90
|
+
- 'on'
|
91
|
+
- in
|
92
|
+
- at
|
93
|
+
- '_'
|
94
|
+
ForbiddenNames: []
|
95
|
+
Style/Alias:
|
96
|
+
Enabled: false
|
7
97
|
Style/CollectionMethods:
|
8
|
-
Description: Preferred collection methods.
|
9
|
-
StyleGuide: https://github.com/bbatsov/ruby-style-guide#map-find-select-reduce-size
|
10
98
|
Enabled: true
|
11
99
|
PreferredMethods:
|
12
100
|
collect: map
|
@@ -14,35 +102,31 @@ Style/CollectionMethods:
|
|
14
102
|
find: detect
|
15
103
|
find_all: select
|
16
104
|
reduce: inject
|
17
|
-
Style/
|
18
|
-
|
19
|
-
|
20
|
-
Enabled:
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
- trailing
|
25
|
-
Style/FileName:
|
26
|
-
Description: Use snake_case for source file names.
|
27
|
-
StyleGuide: https://github.com/bbatsov/ruby-style-guide#snake-case-files
|
105
|
+
Style/Documentation:
|
106
|
+
Enabled: false
|
107
|
+
Style/DoubleNegation:
|
108
|
+
Enabled: false
|
109
|
+
Style/EachWithObject:
|
110
|
+
Enabled: false
|
111
|
+
Style/EmptyLiteral:
|
28
112
|
Enabled: false
|
29
|
-
Exclude: []
|
30
113
|
Style/GuardClause:
|
31
|
-
Description: Check for conditionals that can be replaced with guard clauses
|
32
|
-
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-nested-conditionals
|
33
114
|
Enabled: false
|
34
115
|
MinBodyLength: 1
|
35
116
|
Style/IfUnlessModifier:
|
36
|
-
Description: Favor modifier if/unless usage when you have a single-line body.
|
37
|
-
StyleGuide: https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier
|
38
117
|
Enabled: false
|
39
|
-
|
118
|
+
Style/InlineComment:
|
119
|
+
Enabled: false
|
120
|
+
Style/MethodMissing:
|
121
|
+
Exclude:
|
122
|
+
- app/presenters/**/*
|
123
|
+
Style/ModuleFunction:
|
124
|
+
Enabled: false
|
125
|
+
Style/OneLineConditional:
|
126
|
+
Enabled: false
|
40
127
|
Style/OptionHash:
|
41
|
-
Description: Don't use option hashes when you can use keyword arguments.
|
42
128
|
Enabled: false
|
43
129
|
Style/PercentLiteralDelimiters:
|
44
|
-
Description: Use `%`-literal delimiters consistently
|
45
|
-
StyleGuide: https://github.com/bbatsov/ruby-style-guide#percent-literal-braces
|
46
130
|
Enabled: false
|
47
131
|
PreferredDelimiters:
|
48
132
|
"%": "()"
|
@@ -54,29 +138,17 @@ Style/PercentLiteralDelimiters:
|
|
54
138
|
"%w": "()"
|
55
139
|
"%W": "()"
|
56
140
|
"%x": "()"
|
57
|
-
Style/
|
58
|
-
|
59
|
-
StyleGuide: https://github.com/bbatsov/ruby-style-guide#bool-methods-qmark
|
60
|
-
Enabled: true
|
61
|
-
NamePrefix:
|
62
|
-
- is_
|
63
|
-
- has_
|
64
|
-
- have_
|
65
|
-
NamePrefixBlacklist:
|
66
|
-
- is_
|
67
|
-
Exclude:
|
68
|
-
- spec/**/*
|
141
|
+
Style/PerlBackrefs:
|
142
|
+
Enabled: false
|
69
143
|
Style/RaiseArgs:
|
70
|
-
Description: Checks the arguments passed to raise/fail.
|
71
|
-
StyleGuide: https://github.com/bbatsov/ruby-style-guide#exception-class-messages
|
72
144
|
Enabled: false
|
73
145
|
EnforcedStyle: exploded
|
74
146
|
SupportedStyles:
|
75
147
|
- compact
|
76
148
|
- exploded
|
149
|
+
Style/Send:
|
150
|
+
Enabled: false
|
77
151
|
Style/SignalException:
|
78
|
-
Description: Checks for proper usage of fail and raise.
|
79
|
-
StyleGuide: https://github.com/bbatsov/ruby-style-guide#fail-method
|
80
152
|
Enabled: false
|
81
153
|
EnforcedStyle: semantic
|
82
154
|
SupportedStyles:
|
@@ -84,8 +156,6 @@ Style/SignalException:
|
|
84
156
|
- only_fail
|
85
157
|
- semantic
|
86
158
|
Style/SingleLineBlockParams:
|
87
|
-
Description: Enforces the names of some block params.
|
88
|
-
StyleGuide: https://github.com/bbatsov/ruby-style-guide#reduce-blocks
|
89
159
|
Enabled: false
|
90
160
|
Methods:
|
91
161
|
- reduce:
|
@@ -95,158 +165,26 @@ Style/SingleLineBlockParams:
|
|
95
165
|
- a
|
96
166
|
- e
|
97
167
|
Style/SingleLineMethods:
|
98
|
-
Description: Avoid single-line methods.
|
99
|
-
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-single-line-methods
|
100
168
|
Enabled: false
|
101
169
|
AllowIfMethodIsEmpty: true
|
170
|
+
Style/SpecialGlobalVars:
|
171
|
+
Enabled: false
|
102
172
|
Style/StringLiterals:
|
103
|
-
Description: Checks if uses of quotes match the configured preference.
|
104
|
-
StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-string-literals
|
105
173
|
Enabled: true
|
106
174
|
EnforcedStyle: single_quotes
|
107
175
|
SupportedStyles:
|
108
176
|
- single_quotes
|
109
177
|
- double_quotes
|
110
178
|
Style/StringLiteralsInInterpolation:
|
111
|
-
Description: Checks if uses of quotes inside expressions in interpolated strings
|
112
|
-
match the configured preference.
|
113
179
|
Enabled: true
|
114
180
|
EnforcedStyle: single_quotes
|
115
181
|
SupportedStyles:
|
116
182
|
- single_quotes
|
117
183
|
- double_quotes
|
118
184
|
Style/TrailingCommaInArguments:
|
119
|
-
Description: 'Checks for trailing comma in argument lists.'
|
120
|
-
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas'
|
121
|
-
Enabled: false
|
122
|
-
EnforcedStyleForMultiline: no_comma
|
123
|
-
SupportedStyles:
|
124
|
-
- comma
|
125
|
-
- consistent_comma
|
126
|
-
- no_comma
|
127
|
-
Style/TrailingCommaInLiteral:
|
128
|
-
Description: 'Checks for trailing comma in array and hash literals.'
|
129
|
-
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas'
|
130
185
|
Enabled: false
|
131
186
|
EnforcedStyleForMultiline: no_comma
|
132
|
-
SupportedStyles:
|
133
|
-
- comma
|
134
|
-
- consistent_comma
|
135
|
-
- no_comma
|
136
|
-
Metrics/AbcSize:
|
137
|
-
Description: A calculated magnitude based on number of assignments, branches, and
|
138
|
-
conditions.
|
139
|
-
Enabled: false
|
140
|
-
Max: 15
|
141
|
-
Metrics/ClassLength:
|
142
|
-
Description: Avoid classes longer than 100 lines of code.
|
143
|
-
Enabled: false
|
144
|
-
CountComments: false
|
145
|
-
Max: 100
|
146
|
-
Metrics/LineLength:
|
147
|
-
Description: Limit lines to max 140 characters
|
148
|
-
Max: 140
|
149
|
-
AllowHeredoc: true
|
150
|
-
AllowURI: true
|
151
|
-
URISchemes:
|
152
|
-
- http
|
153
|
-
- https
|
154
|
-
Metrics/ModuleLength:
|
155
|
-
CountComments: false
|
156
|
-
Max: 100
|
157
|
-
Description: Avoid modules longer than 100 lines of code.
|
158
|
-
Enabled: false
|
159
|
-
Metrics/CyclomaticComplexity:
|
160
|
-
Description: A complexity metric that is strongly correlated to the number of test
|
161
|
-
cases needed to validate a method.
|
162
|
-
Enabled: false
|
163
|
-
Max: 6
|
164
|
-
Metrics/MethodLength:
|
165
|
-
Description: Avoid methods longer than 10 lines of code.
|
166
|
-
StyleGuide: https://github.com/bbatsov/ruby-style-guide#short-methods
|
167
|
-
Enabled: false
|
168
|
-
CountComments: false
|
169
|
-
Max: 10
|
170
|
-
Metrics/ParameterLists:
|
171
|
-
Description: Avoid parameter lists longer than three or four parameters.
|
172
|
-
StyleGuide: https://github.com/bbatsov/ruby-style-guide#too-many-params
|
173
|
-
Enabled: false
|
174
|
-
Max: 5
|
175
|
-
CountKeywordArgs: true
|
176
|
-
Metrics/PerceivedComplexity:
|
177
|
-
Description: A complexity metric geared towards measuring complexity for a human
|
178
|
-
reader.
|
179
|
-
Enabled: false
|
180
|
-
Max: 7
|
181
|
-
Lint/AssignmentInCondition:
|
182
|
-
Description: Don't use assignment in conditions.
|
183
|
-
StyleGuide: https://github.com/bbatsov/ruby-style-guide#safe-assignment-in-condition
|
184
|
-
Enabled: false
|
185
|
-
AllowSafeAssignment: true
|
186
|
-
Style/InlineComment:
|
187
|
-
Description: Avoid inline comments.
|
188
|
-
Enabled: false
|
189
|
-
Style/AccessorMethodName:
|
190
|
-
Description: Check the naming of accessor methods for get_/set_.
|
191
|
-
Enabled: false
|
192
|
-
Style/Alias:
|
193
|
-
Description: Use alias_method instead of alias.
|
194
|
-
StyleGuide: https://github.com/bbatsov/ruby-style-guide#alias-method
|
195
|
-
Enabled: false
|
196
|
-
Style/Documentation:
|
197
|
-
Description: Document classes and non-namespace modules.
|
198
|
-
Enabled: false
|
199
|
-
Style/DoubleNegation:
|
200
|
-
Description: Checks for uses of double negation (!!).
|
201
|
-
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-bang-bang
|
202
|
-
Enabled: false
|
203
|
-
Style/EachWithObject:
|
204
|
-
Description: Prefer `each_with_object` over `inject` or `reduce`.
|
205
|
-
Enabled: false
|
206
|
-
Style/EmptyLiteral:
|
207
|
-
Description: Prefer literals to Array.new/Hash.new/String.new.
|
208
|
-
StyleGuide: https://github.com/bbatsov/ruby-style-guide#literal-array-hash
|
209
|
-
Enabled: false
|
210
|
-
Style/ModuleFunction:
|
211
|
-
Description: Checks for usage of `extend self` in modules.
|
212
|
-
StyleGuide: https://github.com/bbatsov/ruby-style-guide#module-function
|
213
|
-
Enabled: false
|
214
|
-
Style/OneLineConditional:
|
215
|
-
Description: Favor the ternary operator(?:) over if/then/else/end constructs.
|
216
|
-
StyleGuide: https://github.com/bbatsov/ruby-style-guide#ternary-operator
|
217
|
-
Enabled: false
|
218
|
-
Style/PerlBackrefs:
|
219
|
-
Description: Avoid Perl-style regex back references.
|
220
|
-
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-perl-regexp-last-matchers
|
221
|
-
Enabled: false
|
222
|
-
Style/Send:
|
223
|
-
Description: Prefer `Object#__send__` or `Object#public_send` to `send`, as `send`
|
224
|
-
may overlap with existing methods.
|
225
|
-
StyleGuide: https://github.com/bbatsov/ruby-style-guide#prefer-public-send
|
226
|
-
Enabled: false
|
227
|
-
Style/SpecialGlobalVars:
|
228
|
-
Description: Avoid Perl-style global variables.
|
229
|
-
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-cryptic-perlisms
|
230
|
-
Enabled: false
|
231
187
|
Style/VariableInterpolation:
|
232
|
-
Description: Don't interpolate global, instance and class variables directly in
|
233
|
-
strings.
|
234
|
-
StyleGuide: https://github.com/bbatsov/ruby-style-guide#curlies-interpolate
|
235
188
|
Enabled: false
|
236
189
|
Style/WhenThen:
|
237
|
-
Description: Use when x then ... for one-line cases.
|
238
|
-
StyleGuide: https://github.com/bbatsov/ruby-style-guide#one-line-cases
|
239
|
-
Enabled: false
|
240
|
-
Lint/EachWithObjectArgument:
|
241
|
-
Description: Check for immutable argument given to each_with_object.
|
242
|
-
Enabled: true
|
243
|
-
Lint/HandleExceptions:
|
244
|
-
Description: Don't suppress exception.
|
245
|
-
StyleGuide: https://github.com/bbatsov/ruby-style-guide#dont-hide-exceptions
|
246
|
-
Enabled: false
|
247
|
-
Lint/LiteralInCondition:
|
248
|
-
Description: Checks of literals used in conditions.
|
249
|
-
Enabled: false
|
250
|
-
Lint/LiteralInInterpolation:
|
251
|
-
Description: Checks for literals used in interpolation.
|
252
190
|
Enabled: false
|
data/.travis.yml
CHANGED
@@ -1,14 +1,22 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
- 2.
|
4
|
-
- 2.2.3
|
3
|
+
- 2.3.0
|
5
4
|
- 2.3.1
|
6
5
|
- 2.3.3
|
7
6
|
- 2.4.0
|
7
|
+
- 2.5.0
|
8
8
|
notifications:
|
9
9
|
email: false
|
10
10
|
sudo: false
|
11
11
|
cache:
|
12
12
|
bundler: true
|
13
13
|
before_install:
|
14
|
-
- gem update --system
|
14
|
+
- gem update --system
|
15
|
+
before_script:
|
16
|
+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
17
|
+
- chmod +x ./cc-test-reporter
|
18
|
+
- ./cc-test-reporter before-build
|
19
|
+
script:
|
20
|
+
- bundle exec rspec
|
21
|
+
after_script:
|
22
|
+
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
# Europeana API
|
2
2
|
|
3
|
-
[![Build Status](https://travis-ci.org/europeana/europeana-api-client-ruby.svg?branch=develop)](https://travis-ci.org/europeana/europeana-api-client-ruby) [![
|
3
|
+
[![Build Status](https://travis-ci.org/europeana/europeana-api-client-ruby.svg?branch=develop)](https://travis-ci.org/europeana/europeana-api-client-ruby) [![Security](https://hakiri.io/github/europeana/europeana-api-client-ruby/develop.svg)](https://hakiri.io/github/europeana/europeana-api-client-ruby/develop) [![Maintainability](https://api.codeclimate.com/v1/badges/ee765a461fd16730c02d/maintainability)](https://codeclimate.com/github/europeana/europeana-api-client-ruby/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/ee765a461fd16730c02d/test_coverage)](https://codeclimate.com/github/europeana/europeana-api-client-ruby/test_coverage)
|
4
4
|
|
5
5
|
Ruby client library for the search and retrieval of records from the [Europeana
|
6
|
-
REST
|
6
|
+
REST APIs](https://pro.europeana.eu/resources/apis).
|
7
7
|
|
8
8
|
## Requirements
|
9
9
|
|
10
|
-
* Ruby >= 2.
|
10
|
+
* Ruby >= 2.3
|
11
11
|
|
12
12
|
## Installation
|
13
13
|
|
@@ -35,7 +35,7 @@ gem install europeana-api
|
|
35
35
|
|
36
36
|
Authentication by API key is *required* for all requests to the Europeana API.
|
37
37
|
|
38
|
-
Sign up for an API key at:
|
38
|
+
Sign up for an API key at: https://pro.europeana.eu/get-api
|
39
39
|
|
40
40
|
Configure your application with the API key:
|
41
41
|
|
@@ -66,7 +66,7 @@ search[:items] # => [ item1, item2, ... ]
|
|
66
66
|
search[:totalResults] # => 81530
|
67
67
|
```
|
68
68
|
|
69
|
-
See
|
69
|
+
See https://pro.europeana.eu/resources/apis/search for details of the available request
|
70
70
|
parameters, and of the data returned in the search response.
|
71
71
|
|
72
72
|
#### Fetch
|
@@ -77,7 +77,7 @@ record[:object][:title] # => ["Panorama des Schafberges in Ober-Österreich. Bla
|
|
77
77
|
record[:object][:proxies].first[:dcCreator][:def] # => ["Simony, Friedrich"]
|
78
78
|
```
|
79
79
|
|
80
|
-
See
|
80
|
+
See https://pro.europeana.eu/resources/apis/record for details of the data returned in
|
81
81
|
the record response.
|
82
82
|
|
83
83
|
#### Hierarchies
|
@@ -97,12 +97,9 @@ Europeana::API.record.following_siblings
|
|
97
97
|
Europeana::API.record.ancestor_self_siblings
|
98
98
|
```
|
99
99
|
|
100
|
-
See http://labs.europeana.eu/api/hierarchical-records for details of the various
|
101
|
-
hierarchy methods and their responses.
|
102
|
-
|
103
100
|
### Annotations
|
104
101
|
|
105
|
-
See
|
102
|
+
See https://pro.europeana.eu/resources/apis/annotations for details of the responses
|
106
103
|
received from the Annotations API methods.
|
107
104
|
|
108
105
|
#### Search
|
data/europeana-api.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.name = 'europeana-api'
|
9
9
|
spec.version = Europeana::API::VERSION
|
10
10
|
spec.authors = ['Richard Doe']
|
11
|
-
spec.email =
|
11
|
+
spec.email = %w(richard.doe@europeana.eu)
|
12
12
|
spec.description = 'Search and retrieve records from the Europeana REST API'
|
13
13
|
spec.summary = 'Ruby client library for the Europeana API'
|
14
14
|
spec.homepage = 'https://github.com/europeana/europeana-api-client-ruby'
|
@@ -17,25 +17,24 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.files = `git ls-files`.split($RS)
|
18
18
|
spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
|
19
19
|
spec.test_files = spec.files.grep(/^(test|spec|features)\//)
|
20
|
-
spec.require_paths =
|
20
|
+
spec.require_paths = %w(lib)
|
21
21
|
|
22
|
-
spec.required_ruby_version = '>= 2.
|
22
|
+
spec.required_ruby_version = '>= 2.3.0'
|
23
23
|
|
24
24
|
spec.add_dependency 'activesupport', '>= 4.2', '< 6.0'
|
25
25
|
# Locked to < v0.12.2 due to incompatibility with v0.12.2
|
26
26
|
# TODO: resolve incompatibility and unlock
|
27
27
|
spec.add_dependency 'faraday', '~> 0.9', '< 0.12.2'
|
28
28
|
spec.add_dependency 'faraday_middleware'
|
29
|
+
spec.add_dependency 'iso-639', '~> 0.2.5'
|
29
30
|
spec.add_dependency 'multi_json', '~> 1.0'
|
30
31
|
spec.add_dependency 'rack', '> 1.6.2'
|
31
32
|
spec.add_dependency 'typhoeus', '~> 1.1'
|
32
33
|
|
33
34
|
spec.add_development_dependency 'bundler', '~> 1.3'
|
34
|
-
spec.add_development_dependency 'coveralls'
|
35
35
|
spec.add_development_dependency 'dotenv'
|
36
36
|
spec.add_development_dependency 'rake'
|
37
37
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
38
|
-
spec.add_development_dependency 'rubocop', '0.39.0' # only update when Hound does
|
39
38
|
spec.add_development_dependency 'shoulda-matchers', '~> 3.1'
|
40
39
|
spec.add_development_dependency 'webmock', '~> 1.18.0'
|
41
40
|
end
|
data/lib/europeana/api/record.rb
CHANGED
@@ -0,0 +1,106 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'iso-639'
|
4
|
+
|
5
|
+
module Europeana
|
6
|
+
module API
|
7
|
+
class Record
|
8
|
+
##
|
9
|
+
# Methods for working with "LangMap" data types in Record API JSON responses
|
10
|
+
#
|
11
|
+
# @see https://pro.europeana.eu/resources/apis/search#json-langmap
|
12
|
+
module LangMap
|
13
|
+
# @see https://www.loc.gov/standards/iso639-2/php/code_changes.php
|
14
|
+
DEPRECATED_ISO_LANG_CODES = %w(in iw jaw ji jw mo mol scc scr sh)
|
15
|
+
|
16
|
+
# Special keys API may return in a LangMap, not ISO codes
|
17
|
+
# TODO: Empty key acceptance is a workaround for malformed API data
|
18
|
+
# output; remove when fixed at source
|
19
|
+
NON_ISO_LANG_CODES = ['def', '']
|
20
|
+
|
21
|
+
class << self
|
22
|
+
# Is the argument a language map?
|
23
|
+
#
|
24
|
+
# Critera:
|
25
|
+
# * Must be a +Hash+.
|
26
|
+
# * Must have only keys which are known language codes
|
27
|
+
#
|
28
|
+
# @param candidate [Object] Object to check
|
29
|
+
# @return [Boolean]
|
30
|
+
def lang_map?(candidate)
|
31
|
+
return false unless candidate.is_a?(Hash)
|
32
|
+
candidate.keys.map(&:to_s).all? { |key| known_lang_map_key?(key) }
|
33
|
+
end
|
34
|
+
|
35
|
+
# Is the argument a known language map key?
|
36
|
+
#
|
37
|
+
# @param key [String] String to check
|
38
|
+
# @return [Boolean]
|
39
|
+
def known_lang_map_key?(key)
|
40
|
+
key = key.dup.downcase
|
41
|
+
DEPRECATED_ISO_LANG_CODES.include?(key) ||
|
42
|
+
NON_ISO_LANG_CODES.include?(key) ||
|
43
|
+
!ISO_639.find(key.split('-').first).nil?
|
44
|
+
end
|
45
|
+
|
46
|
+
# Localise a language map
|
47
|
+
#
|
48
|
+
# 1. If the argument is not a language map, return as-is
|
49
|
+
# 2. If the language map has a key for the current locale, return that
|
50
|
+
# value
|
51
|
+
# 3. If the language map has a key for the default locale, return that
|
52
|
+
# value
|
53
|
+
# 4. Else, return all values
|
54
|
+
#
|
55
|
+
# Arrays will be recursed over, localising each element.
|
56
|
+
#
|
57
|
+
# @param lang_map [Object] Object to attempt to localise
|
58
|
+
# @return [Object,Array<Object>] Localised value
|
59
|
+
def localise_lang_map(lang_map)
|
60
|
+
if lang_map.is_a?(Array)
|
61
|
+
return lang_map.map { |val| localise_lang_map(val) }
|
62
|
+
end
|
63
|
+
|
64
|
+
return lang_map unless lang_map?(lang_map)
|
65
|
+
|
66
|
+
lang_map_value(lang_map, ::I18n.locale.to_s) ||
|
67
|
+
lang_map_value(lang_map, ::I18n.default_locale.to_s) ||
|
68
|
+
lang_map_value(lang_map, 'def') ||
|
69
|
+
lang_map.values
|
70
|
+
end
|
71
|
+
|
72
|
+
# Fetch the language map value for a given locale
|
73
|
+
#
|
74
|
+
# @param lang_map [Hash] Verified language map
|
75
|
+
# @param locale [String] Locale to fetch the value for
|
76
|
+
# @return [Array<Object>,nil] Array of value(s) for the given locale,
|
77
|
+
# or nil if none are present
|
78
|
+
def lang_map_value(lang_map, locale)
|
79
|
+
keys = salient_lang_map_keys(lang_map, locale)
|
80
|
+
return nil unless keys.present?
|
81
|
+
keys.map { |k| lang_map[k] }.flatten.uniq
|
82
|
+
end
|
83
|
+
|
84
|
+
protected
|
85
|
+
|
86
|
+
# @return [Array<String>] valid keys in the language map for the given locale
|
87
|
+
def salient_lang_map_keys(lang_map, locale)
|
88
|
+
iso_code = locale.split('-').first
|
89
|
+
iso_locale = ISO_639.find(iso_code)
|
90
|
+
|
91
|
+
# Favour exact matches
|
92
|
+
keys = lang_map.keys.select do |k|
|
93
|
+
[locale, iso_locale&.alpha2, iso_locale&.alpha3].include?(k)
|
94
|
+
end.flatten.compact
|
95
|
+
return keys unless keys.blank?
|
96
|
+
|
97
|
+
# Any sub-code will do
|
98
|
+
lang_map.keys.select do |k|
|
99
|
+
k =~ %r{\A#{iso_code}-}
|
100
|
+
end.flatten.compact
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Europeana::API::Record::LangMap do
|
4
|
+
before do
|
5
|
+
I18n.config.available_locales = %i(de en fr nl)
|
6
|
+
end
|
7
|
+
let(:lang_map_hash) do
|
8
|
+
{ 'def' => 'this', 'en' => 'this', 'fr' => 'ce' }
|
9
|
+
end
|
10
|
+
let(:non_lang_map_hash) do
|
11
|
+
{ 'first' => 'this', 'then' => 'that' }
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '.lang_map?' do
|
15
|
+
subject { described_class.lang_map?(var) }
|
16
|
+
|
17
|
+
context 'when not a Hash' do
|
18
|
+
let(:var) { [] }
|
19
|
+
it { is_expected.to be false }
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'when a Hash' do
|
23
|
+
context 'with non-language code keys' do
|
24
|
+
let(:var) { non_lang_map_hash }
|
25
|
+
it { is_expected.to be false }
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'with language code keys' do
|
29
|
+
let(:var) { lang_map_hash }
|
30
|
+
it { is_expected.to be true }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe '.localise_lang_map' do
|
36
|
+
subject { described_class.localise_lang_map(var) }
|
37
|
+
|
38
|
+
context 'when an Array' do
|
39
|
+
let(:var) { [lang_map_hash, lang_map_hash] }
|
40
|
+
before do
|
41
|
+
I18n.locale = :fr
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'localises each element' do
|
45
|
+
expect(subject).to eq([[lang_map_hash['fr']], [lang_map_hash['fr']]])
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'when not an Array' do
|
50
|
+
context 'when a language map' do
|
51
|
+
let(:var) { lang_map_hash }
|
52
|
+
context 'when current locale is present' do
|
53
|
+
before do
|
54
|
+
I18n.locale = :fr
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'is returned in array' do
|
58
|
+
expect(subject).to eq([var['fr']])
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'when current locale is not present' do
|
63
|
+
before do
|
64
|
+
I18n.locale = :de
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'when default locale is present' do
|
68
|
+
before do
|
69
|
+
I18n.default_locale = :en
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'is returned in array' do
|
73
|
+
expect(subject).to eq([var['en']])
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context 'when default locale is not present' do
|
78
|
+
before do
|
79
|
+
I18n.default_locale = :nl
|
80
|
+
end
|
81
|
+
|
82
|
+
context 'when "def" is present' do
|
83
|
+
it 'is returned in array' do
|
84
|
+
expect(subject).to eq([var['def']])
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context 'when "def" is not present' do
|
89
|
+
before do
|
90
|
+
lang_map_hash.delete('def')
|
91
|
+
end
|
92
|
+
it 'returns all values' do
|
93
|
+
expect(subject).to eq(var.values)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
context 'when not a language map' do
|
101
|
+
let(:var) { non_lang_map_hash }
|
102
|
+
it 'returns the argument' do
|
103
|
+
expect(subject).to eq(var)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
2
|
+
|
3
|
+
# Generate Simplecov report
|
4
|
+
require 'simplecov'
|
5
|
+
SimpleCov.start
|
6
|
+
|
3
7
|
require 'europeana/api'
|
4
8
|
require 'shoulda/matchers'
|
5
9
|
require 'webmock/rspec'
|
6
10
|
|
7
11
|
Dir['./spec/support/**/*.rb'].each { |f| require f }
|
8
12
|
|
9
|
-
Coveralls.wear! unless Coveralls.will_run?.nil?
|
10
|
-
|
11
13
|
Europeana::API.logger.level = Logger::ERROR
|
12
14
|
|
13
15
|
RSpec.configure do |config|
|
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: 1.
|
4
|
+
version: 1.1.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:
|
11
|
+
date: 2018-07-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -64,6 +64,20 @@ dependencies:
|
|
64
64
|
- - ">="
|
65
65
|
- !ruby/object:Gem::Version
|
66
66
|
version: '0'
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
name: iso-639
|
69
|
+
requirement: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - "~>"
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: 0.2.5
|
74
|
+
type: :runtime
|
75
|
+
prerelease: false
|
76
|
+
version_requirements: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - "~>"
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 0.2.5
|
67
81
|
- !ruby/object:Gem::Dependency
|
68
82
|
name: multi_json
|
69
83
|
requirement: !ruby/object:Gem::Requirement
|
@@ -120,20 +134,6 @@ dependencies:
|
|
120
134
|
- - "~>"
|
121
135
|
- !ruby/object:Gem::Version
|
122
136
|
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
137
|
- !ruby/object:Gem::Dependency
|
138
138
|
name: dotenv
|
139
139
|
requirement: !ruby/object:Gem::Requirement
|
@@ -176,20 +176,6 @@ dependencies:
|
|
176
176
|
- - "~>"
|
177
177
|
- !ruby/object:Gem::Version
|
178
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
179
|
- !ruby/object:Gem::Dependency
|
194
180
|
name: shoulda-matchers
|
195
181
|
requirement: !ruby/object:Gem::Requirement
|
@@ -220,14 +206,14 @@ dependencies:
|
|
220
206
|
version: 1.18.0
|
221
207
|
description: Search and retrieve records from the Europeana REST API
|
222
208
|
email:
|
223
|
-
- richard.doe@
|
209
|
+
- richard.doe@europeana.eu
|
224
210
|
executables:
|
225
211
|
- console
|
226
212
|
extensions: []
|
227
213
|
extra_rdoc_files: []
|
228
214
|
files:
|
215
|
+
- ".codeclimate.yml"
|
229
216
|
- ".gitignore"
|
230
|
-
- ".hound.yml"
|
231
217
|
- ".rspec"
|
232
218
|
- ".rubocop.yml"
|
233
219
|
- ".ruby-style.yml"
|
@@ -251,6 +237,7 @@ files:
|
|
251
237
|
- lib/europeana/api/logger.rb
|
252
238
|
- lib/europeana/api/queue.rb
|
253
239
|
- lib/europeana/api/record.rb
|
240
|
+
- lib/europeana/api/record/lang_map.rb
|
254
241
|
- lib/europeana/api/request.rb
|
255
242
|
- lib/europeana/api/resource.rb
|
256
243
|
- lib/europeana/api/response.rb
|
@@ -260,6 +247,7 @@ files:
|
|
260
247
|
- spec/europeana/api/entity_spec.rb
|
261
248
|
- spec/europeana/api/faraday_middleware/request/authenticated_request_spec.rb
|
262
249
|
- spec/europeana/api/queue_spec.rb
|
250
|
+
- spec/europeana/api/record/lang_map_spec.rb
|
263
251
|
- spec/europeana/api/record_spec.rb
|
264
252
|
- spec/europeana/api/request_spec.rb
|
265
253
|
- spec/europeana/api/resource_spec.rb
|
@@ -279,7 +267,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
279
267
|
requirements:
|
280
268
|
- - ">="
|
281
269
|
- !ruby/object:Gem::Version
|
282
|
-
version: 2.
|
270
|
+
version: 2.3.0
|
283
271
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
284
272
|
requirements:
|
285
273
|
- - ">="
|
@@ -287,7 +275,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
287
275
|
version: '0'
|
288
276
|
requirements: []
|
289
277
|
rubyforge_project:
|
290
|
-
rubygems_version: 2.
|
278
|
+
rubygems_version: 2.7.3
|
291
279
|
signing_key:
|
292
280
|
specification_version: 4
|
293
281
|
summary: Ruby client library for the Europeana API
|
@@ -297,6 +285,7 @@ test_files:
|
|
297
285
|
- spec/europeana/api/entity_spec.rb
|
298
286
|
- spec/europeana/api/faraday_middleware/request/authenticated_request_spec.rb
|
299
287
|
- spec/europeana/api/queue_spec.rb
|
288
|
+
- spec/europeana/api/record/lang_map_spec.rb
|
300
289
|
- spec/europeana/api/record_spec.rb
|
301
290
|
- spec/europeana/api/request_spec.rb
|
302
291
|
- spec/europeana/api/resource_spec.rb
|