puree 0.20.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -2
- data/PITCHME.md +43 -21
- data/README.md +72 -18
- data/lib/puree.rb +66 -21
- data/lib/puree/api/api.rb +9 -0
- data/lib/puree/api/authentication.rb +33 -0
- data/lib/puree/api/configuration.rb +43 -0
- data/lib/puree/api/map.rb +76 -0
- data/lib/puree/api/request.rb +116 -0
- data/lib/puree/extractor/collection.rb +131 -0
- data/lib/puree/extractor/dataset.rb +48 -0
- data/lib/puree/extractor/download.rb +71 -0
- data/lib/puree/extractor/event.rb +33 -0
- data/lib/puree/extractor/extractor.rb +10 -0
- data/lib/puree/extractor/journal.rb +29 -0
- data/lib/puree/extractor/organisation.rb +34 -0
- data/lib/puree/extractor/person.rb +32 -0
- data/lib/puree/extractor/project.rb +40 -0
- data/lib/puree/extractor/publication.rb +40 -0
- data/lib/puree/extractor/publisher.rb +27 -0
- data/lib/puree/extractor/resource.rb +69 -0
- data/lib/puree/extractor/server.rb +56 -0
- data/lib/puree/model/address.rb +50 -0
- data/lib/puree/model/copyright_license.rb +26 -0
- data/lib/puree/model/dataset.rb +84 -0
- data/lib/puree/model/download_header.rb +21 -0
- data/lib/puree/model/endeavour_person.rb +34 -0
- data/lib/puree/model/event.rb +31 -0
- data/lib/puree/model/event_header.rb +26 -0
- data/lib/puree/model/file.rb +45 -0
- data/lib/puree/model/helper/validation.rb +15 -0
- data/lib/puree/model/journal.rb +20 -0
- data/lib/puree/model/legal_condition.rb +26 -0
- data/lib/puree/model/link.rb +26 -0
- data/lib/puree/model/model.rb +7 -0
- data/lib/puree/model/organisation.rb +34 -0
- data/lib/puree/model/organisation_header.rb +34 -0
- data/lib/puree/model/person.rb +28 -0
- data/lib/puree/model/person_name.rb +52 -0
- data/lib/puree/model/project.rb +49 -0
- data/lib/puree/model/publication.rb +53 -0
- data/lib/puree/model/publication_status.rb +21 -0
- data/lib/puree/model/publisher.rb +13 -0
- data/lib/puree/model/related_content_header.rb +34 -0
- data/lib/puree/model/resource.rb +42 -0
- data/lib/puree/model/server.rb +13 -0
- data/lib/puree/model/spatial_point.rb +16 -0
- data/lib/puree/model/structure.rb +18 -0
- data/lib/puree/model/temporal_range.rb +15 -0
- data/lib/puree/util/date.rb +86 -0
- data/lib/puree/util/util.rb +8 -0
- data/lib/puree/version.rb +1 -1
- data/lib/puree/xml_extractor/base.rb +47 -0
- data/lib/puree/xml_extractor/collection.rb +40 -0
- data/lib/puree/xml_extractor/dataset.rb +305 -0
- data/lib/puree/xml_extractor/download.rb +42 -0
- data/lib/puree/xml_extractor/event.rb +63 -0
- data/lib/puree/xml_extractor/journal.rb +33 -0
- data/lib/puree/xml_extractor/organisation.rb +75 -0
- data/lib/puree/xml_extractor/person.rb +57 -0
- data/lib/puree/xml_extractor/project.rb +135 -0
- data/lib/puree/xml_extractor/publication.rb +189 -0
- data/lib/puree/xml_extractor/publisher.rb +28 -0
- data/lib/puree/xml_extractor/resource.rb +71 -0
- data/lib/puree/xml_extractor/server.rb +32 -0
- data/lib/puree/xml_extractor/shared.rb +31 -0
- data/lib/puree/xml_extractor/xml_extractor.rb +10 -0
- data/puree.gemspec +11 -8
- data/spec/download_http_spec.rb +31 -0
- data/spec/open_api_dataset_http_spec.rb +15 -0
- data/spec/resource/collection_all_http_spec.rb +77 -0
- data/spec/resource/collection_http_spec.rb +65 -0
- data/spec/resource/dataset_http_spec.rb +104 -0
- data/spec/resource/event_http_spec.rb +52 -0
- data/spec/resource/journal_http_spec.rb +36 -0
- data/spec/resource/organisation_http_spec.rb +52 -0
- data/spec/resource/person_http_spec.rb +48 -0
- data/spec/resource/project_http_spec.rb +76 -0
- data/spec/resource/publication_http_spec.rb +78 -0
- data/spec/resource/publisher_http_spec.rb +26 -0
- data/spec/server_http_spec.rb +26 -0
- data/spec/spec_helper.rb +106 -21
- metadata +110 -46
- data/lib/puree/collection.rb +0 -285
- data/lib/puree/configuration.rb +0 -15
- data/lib/puree/dataset.rb +0 -483
- data/lib/puree/date.rb +0 -63
- data/lib/puree/download.rb +0 -189
- data/lib/puree/event.rb +0 -133
- data/lib/puree/journal.rb +0 -75
- data/lib/puree/map.rb +0 -68
- data/lib/puree/organisation.rb +0 -177
- data/lib/puree/person.rb +0 -136
- data/lib/puree/project.rb +0 -231
- data/lib/puree/publication.rb +0 -258
- data/lib/puree/publisher.rb +0 -64
- data/lib/puree/resource.rb +0 -261
- data/lib/puree/server.rb +0 -156
- data/spec/collection_spec.rb +0 -62
- data/spec/dataset_spec.rb +0 -148
- data/spec/download_spec.rb +0 -33
- data/spec/event_spec.rb +0 -108
- data/spec/journal_spec.rb +0 -92
- data/spec/organisation_spec.rb +0 -112
- data/spec/person_spec.rb +0 -104
- data/spec/project_spec.rb +0 -120
- data/spec/publication_spec.rb +0 -128
- data/spec/publisher_spec.rb +0 -89
- data/spec/server_spec.rb +0 -36
data/lib/puree/publication.rb
DELETED
@@ -1,258 +0,0 @@
|
|
1
|
-
module Puree
|
2
|
-
|
3
|
-
# Publication resource
|
4
|
-
#
|
5
|
-
class Publication < Resource
|
6
|
-
|
7
|
-
# @param base_url [String]
|
8
|
-
# @param username [String]
|
9
|
-
# @param password [String]
|
10
|
-
# @param basic_auth [Boolean]
|
11
|
-
def initialize(base_url: nil, username: nil, password: nil, basic_auth: nil)
|
12
|
-
super(api: :publication,
|
13
|
-
base_url: base_url,
|
14
|
-
username: username,
|
15
|
-
password: password,
|
16
|
-
basic_auth: basic_auth)
|
17
|
-
end
|
18
|
-
|
19
|
-
# Category
|
20
|
-
#
|
21
|
-
# @return [String]
|
22
|
-
def category
|
23
|
-
@metadata['category']
|
24
|
-
end
|
25
|
-
|
26
|
-
# Description
|
27
|
-
#
|
28
|
-
# @return [String]
|
29
|
-
def description
|
30
|
-
@metadata['description']
|
31
|
-
end
|
32
|
-
|
33
|
-
# Event
|
34
|
-
#
|
35
|
-
# @return [Hash]
|
36
|
-
def event
|
37
|
-
@metadata['event']
|
38
|
-
end
|
39
|
-
|
40
|
-
# Digital Object Identifier
|
41
|
-
#
|
42
|
-
# @return [String]
|
43
|
-
def doi
|
44
|
-
@metadata['doi']
|
45
|
-
end
|
46
|
-
|
47
|
-
# Supporting file
|
48
|
-
#
|
49
|
-
# @return [Array<Hash>]
|
50
|
-
def file
|
51
|
-
@metadata['file']
|
52
|
-
end
|
53
|
-
|
54
|
-
# Organisation
|
55
|
-
#
|
56
|
-
# @return [Array<Hash>]
|
57
|
-
def organisation
|
58
|
-
@metadata['organisation']
|
59
|
-
end
|
60
|
-
|
61
|
-
# Page
|
62
|
-
#
|
63
|
-
# @return [String]
|
64
|
-
def page
|
65
|
-
@metadata['page']
|
66
|
-
end
|
67
|
-
|
68
|
-
# Person (internal, external, other)
|
69
|
-
#
|
70
|
-
# @return [Hash<Array,Array,Array>]
|
71
|
-
def person
|
72
|
-
@metadata['person']
|
73
|
-
end
|
74
|
-
|
75
|
-
# Status
|
76
|
-
#
|
77
|
-
# @return [Array<Hash>]
|
78
|
-
def status
|
79
|
-
@metadata['status']
|
80
|
-
end
|
81
|
-
|
82
|
-
# Title
|
83
|
-
#
|
84
|
-
# @return [String]
|
85
|
-
def title
|
86
|
-
@metadata['title']
|
87
|
-
end
|
88
|
-
|
89
|
-
# Subtitle
|
90
|
-
#
|
91
|
-
# @return [String]
|
92
|
-
def subtitle
|
93
|
-
@metadata['subtitle']
|
94
|
-
end
|
95
|
-
|
96
|
-
# Type
|
97
|
-
#
|
98
|
-
# @return [String]
|
99
|
-
def type
|
100
|
-
@metadata['type']
|
101
|
-
end
|
102
|
-
|
103
|
-
# All metadata
|
104
|
-
#
|
105
|
-
# @return [Hash]
|
106
|
-
def metadata
|
107
|
-
@metadata
|
108
|
-
end
|
109
|
-
|
110
|
-
|
111
|
-
private
|
112
|
-
|
113
|
-
def extract_category
|
114
|
-
path = '/publicationCategory/publicationCategory/term/localizedString'
|
115
|
-
xpath_query_for_single_value path
|
116
|
-
end
|
117
|
-
|
118
|
-
def extract_description
|
119
|
-
path = '/abstract/localizedString'
|
120
|
-
xpath_query_for_single_value path
|
121
|
-
end
|
122
|
-
|
123
|
-
def extract_event
|
124
|
-
path = '/event'
|
125
|
-
xpath_result = xpath_query path
|
126
|
-
o = {}
|
127
|
-
o['uuid'] = xpath_result.xpath('@uuid').text.strip
|
128
|
-
o['title'] = xpath_result.xpath('title/localizedString').text.strip
|
129
|
-
o
|
130
|
-
end
|
131
|
-
|
132
|
-
def extract_doi
|
133
|
-
path = '//doi'
|
134
|
-
xpath_query_for_single_value path
|
135
|
-
end
|
136
|
-
|
137
|
-
def extract_file
|
138
|
-
path = '/electronicVersionAssociations/electronicVersionFileAssociations/electronicVersionFileAssociation/file'
|
139
|
-
xpath_result = xpath_query path
|
140
|
-
docs = []
|
141
|
-
xpath_result.each do |d|
|
142
|
-
doc = {}
|
143
|
-
# doc['id'] = d.xpath('id').text
|
144
|
-
doc['name'] = d.xpath('fileName').text.strip
|
145
|
-
doc['mime'] = d.xpath('mimeType').text.strip
|
146
|
-
doc['size'] = d.xpath('size').text.strip
|
147
|
-
doc['url'] = d.xpath('url').text.strip
|
148
|
-
docs << doc
|
149
|
-
end
|
150
|
-
docs.uniq
|
151
|
-
end
|
152
|
-
|
153
|
-
def extract_organisation
|
154
|
-
path = '/organisations/association/organisation'
|
155
|
-
xpath_result = xpath_query path
|
156
|
-
data = []
|
157
|
-
xpath_result.each do |i|
|
158
|
-
o = {}
|
159
|
-
o['uuid'] = i.xpath('@uuid').text.strip
|
160
|
-
o['name'] = i.xpath('name/localizedString').text.strip
|
161
|
-
o['type'] = i.xpath('typeClassification/term/localizedString').text.strip
|
162
|
-
data << o
|
163
|
-
end
|
164
|
-
data
|
165
|
-
end
|
166
|
-
|
167
|
-
def extract_page
|
168
|
-
path = '/numberOfPages'
|
169
|
-
xpath_query_for_single_value path
|
170
|
-
end
|
171
|
-
|
172
|
-
def extract_person
|
173
|
-
data = {}
|
174
|
-
path = '/persons/personAssociation'
|
175
|
-
xpath_result = xpath_query path
|
176
|
-
internal = []
|
177
|
-
external = []
|
178
|
-
other = []
|
179
|
-
|
180
|
-
xpath_result.each do |i|
|
181
|
-
o = {}
|
182
|
-
name = {}
|
183
|
-
name['first'] = i.xpath('name/firstName').text.strip
|
184
|
-
name['last'] = i.xpath('name/lastName').text.strip
|
185
|
-
o['name'] = name
|
186
|
-
o['role'] = 'Author'
|
187
|
-
|
188
|
-
uuid_internal = i.at_xpath('person/@uuid')
|
189
|
-
uuid_external = i.at_xpath('externalPerson/@uuid')
|
190
|
-
if uuid_internal
|
191
|
-
o['uuid'] = uuid_internal.text.strip
|
192
|
-
internal << o
|
193
|
-
elsif uuid_external
|
194
|
-
o['uuid'] = uuid_external.text.strip
|
195
|
-
external << o
|
196
|
-
else
|
197
|
-
other << o
|
198
|
-
o['uuid'] = ''
|
199
|
-
end
|
200
|
-
end
|
201
|
-
data['internal'] = internal
|
202
|
-
data['external'] = external
|
203
|
-
data['other'] = other
|
204
|
-
data
|
205
|
-
end
|
206
|
-
|
207
|
-
def extract_status
|
208
|
-
path = '/publicationStatuses/publicationStatus'
|
209
|
-
xpath_result = xpath_query path
|
210
|
-
data = []
|
211
|
-
xpath_result.each do |i|
|
212
|
-
o = {}
|
213
|
-
o['stage'] = i.xpath('publicationStatus/term/localizedString').text.strip
|
214
|
-
ymd = {}
|
215
|
-
ymd['year'] = i.xpath('publicationDate/year').text.strip
|
216
|
-
ymd['month'] = i.xpath('publicationDate/month').text.strip
|
217
|
-
ymd['day'] = i.xpath('publicationDate/day').text.strip
|
218
|
-
o['date'] = Puree::Date.normalise(ymd)
|
219
|
-
data << o
|
220
|
-
end
|
221
|
-
data
|
222
|
-
end
|
223
|
-
|
224
|
-
def extract_title
|
225
|
-
path = '/title'
|
226
|
-
xpath_query_for_single_value path
|
227
|
-
end
|
228
|
-
|
229
|
-
def extract_subtitle
|
230
|
-
path = '/subtitle'
|
231
|
-
xpath_query_for_single_value path
|
232
|
-
end
|
233
|
-
|
234
|
-
def extract_type
|
235
|
-
path = '/typeClassification/term/localizedString'
|
236
|
-
xpath_query_for_single_value path
|
237
|
-
end
|
238
|
-
|
239
|
-
def combine_metadata
|
240
|
-
o = super
|
241
|
-
o['category'] = extract_category
|
242
|
-
o['description'] = extract_description
|
243
|
-
o['doi'] = extract_doi
|
244
|
-
o['event'] = extract_event
|
245
|
-
o['file'] = extract_file
|
246
|
-
o['organisation'] = extract_organisation
|
247
|
-
o['page'] = extract_page
|
248
|
-
o['person'] = extract_person
|
249
|
-
o['status'] = extract_status
|
250
|
-
o['subtitle'] = extract_subtitle
|
251
|
-
o['title'] = extract_title
|
252
|
-
o['type'] = extract_type
|
253
|
-
@metadata = o
|
254
|
-
end
|
255
|
-
|
256
|
-
end
|
257
|
-
|
258
|
-
end
|
data/lib/puree/publisher.rb
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
module Puree
|
2
|
-
|
3
|
-
# Publisher resource
|
4
|
-
#
|
5
|
-
class Publisher < Resource
|
6
|
-
|
7
|
-
# @param base_url [String]
|
8
|
-
# @param username [String]
|
9
|
-
# @param password [String]
|
10
|
-
# @param basic_auth [Boolean]
|
11
|
-
def initialize(base_url: nil, username: nil, password: nil, basic_auth: nil)
|
12
|
-
super(api: :publisher,
|
13
|
-
base_url: base_url,
|
14
|
-
username: username,
|
15
|
-
password: password,
|
16
|
-
basic_auth: basic_auth)
|
17
|
-
end
|
18
|
-
|
19
|
-
# Name
|
20
|
-
#
|
21
|
-
# @return [String]
|
22
|
-
def name
|
23
|
-
@metadata['name']
|
24
|
-
end
|
25
|
-
|
26
|
-
# Adds no value as value is Publisher
|
27
|
-
# Type
|
28
|
-
#
|
29
|
-
# @return [String]
|
30
|
-
# def type
|
31
|
-
# @metadata['type']
|
32
|
-
# end
|
33
|
-
|
34
|
-
# All metadata
|
35
|
-
#
|
36
|
-
# @return [Hash]
|
37
|
-
def metadata
|
38
|
-
@metadata
|
39
|
-
end
|
40
|
-
|
41
|
-
|
42
|
-
private
|
43
|
-
|
44
|
-
def extract_name
|
45
|
-
path = '/name'
|
46
|
-
xpath_query_for_single_value path
|
47
|
-
end
|
48
|
-
|
49
|
-
# Adds no value as value is Publisher
|
50
|
-
# def extract_type
|
51
|
-
# path = '/typeClassification/term/localizedString'
|
52
|
-
# xpath_query_for_single_value path
|
53
|
-
# end
|
54
|
-
|
55
|
-
def combine_metadata
|
56
|
-
o = super
|
57
|
-
o['name'] = extract_name
|
58
|
-
# o['type'] = extract_type
|
59
|
-
@metadata = o
|
60
|
-
end
|
61
|
-
|
62
|
-
end
|
63
|
-
|
64
|
-
end
|
data/lib/puree/resource.rb
DELETED
@@ -1,261 +0,0 @@
|
|
1
|
-
module Puree
|
2
|
-
|
3
|
-
# Abstract base class for resources.
|
4
|
-
#
|
5
|
-
class Resource
|
6
|
-
|
7
|
-
attr_reader :response
|
8
|
-
|
9
|
-
# @param api [Symbol]
|
10
|
-
# @param base_url [String]
|
11
|
-
# @param username [String]
|
12
|
-
# @param password [String]
|
13
|
-
# @param bleeding [Boolean]
|
14
|
-
# @param basic_auth [Boolean]
|
15
|
-
def initialize( api: nil,
|
16
|
-
base_url: nil,
|
17
|
-
username: nil,
|
18
|
-
password: nil,
|
19
|
-
bleeding: true,
|
20
|
-
basic_auth: nil)
|
21
|
-
@resource_type = api
|
22
|
-
@api_map = Puree::Map.new.get
|
23
|
-
@base_url = base_url.nil? ? Puree.base_url : base_url
|
24
|
-
@latest_api = bleeding
|
25
|
-
@basic_auth = basic_auth.nil? ? Puree.basic_auth : basic_auth
|
26
|
-
if @basic_auth === true
|
27
|
-
@username = username.nil? ? Puree.username : username
|
28
|
-
@password = password.nil? ? Puree.password : password
|
29
|
-
end
|
30
|
-
@metadata = {}
|
31
|
-
@options = {
|
32
|
-
basic_auth: @basic_auth,
|
33
|
-
latest_api: @latest_api,
|
34
|
-
resource_type: @resource_type.to_sym
|
35
|
-
}
|
36
|
-
end
|
37
|
-
|
38
|
-
# Get
|
39
|
-
#
|
40
|
-
# @param uuid [String]
|
41
|
-
# @param id [String]
|
42
|
-
# @return [Hash]
|
43
|
-
def get(uuid: nil, id: nil, rendering: :xml_long)
|
44
|
-
reset
|
45
|
-
|
46
|
-
@options[:rendering] = rendering
|
47
|
-
@options[:uuid] = uuid
|
48
|
-
@options[:id] = id
|
49
|
-
|
50
|
-
missing = missing_credentials
|
51
|
-
if !missing.empty?
|
52
|
-
missing.each do |m|
|
53
|
-
puts "#{self.class.name}" + '#' + "#{__method__} missing #{m}"
|
54
|
-
end
|
55
|
-
exit
|
56
|
-
end
|
57
|
-
|
58
|
-
# strip any trailing slash
|
59
|
-
@base_url = @base_url.sub(/(\/)+$/, '')
|
60
|
-
|
61
|
-
headers = {}
|
62
|
-
headers['Accept'] = 'application/xml'
|
63
|
-
|
64
|
-
if @options[:basic_auth] === true
|
65
|
-
@auth = Base64::strict_encode64(@username + ':' + @password)
|
66
|
-
headers['Authorization'] = 'Basic ' + @auth
|
67
|
-
end
|
68
|
-
|
69
|
-
query = {}
|
70
|
-
query['rendering'] = @options[:rendering]
|
71
|
-
|
72
|
-
if @options[:uuid]
|
73
|
-
query['uuids.uuid'] = @options[:uuid]
|
74
|
-
else
|
75
|
-
if @options[:id]
|
76
|
-
query['pureInternalIds.id'] = @options[:id]
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
if @options[:rendering]
|
81
|
-
query['rendering'] = @options[:rendering]
|
82
|
-
end
|
83
|
-
|
84
|
-
begin
|
85
|
-
url = build_url
|
86
|
-
req = HTTP.headers accept: headers['Accept']
|
87
|
-
if @options[:basic_auth]
|
88
|
-
req = req.auth headers['Authorization']
|
89
|
-
end
|
90
|
-
@response = req.get(url, params: query)
|
91
|
-
make_doc @response.body
|
92
|
-
|
93
|
-
rescue HTTP::Error => e
|
94
|
-
puts 'HTTP::Error '+ e.message
|
95
|
-
end
|
96
|
-
|
97
|
-
get_data? ? combine_metadata : {}
|
98
|
-
|
99
|
-
end
|
100
|
-
|
101
|
-
# UUID
|
102
|
-
#
|
103
|
-
# @return [String]
|
104
|
-
def uuid
|
105
|
-
@metadata['uuid']
|
106
|
-
end
|
107
|
-
|
108
|
-
# Created (UTC datetime)
|
109
|
-
#
|
110
|
-
# @return [String]
|
111
|
-
def created
|
112
|
-
@metadata['created']
|
113
|
-
end
|
114
|
-
|
115
|
-
# Modified (UTC datetime)
|
116
|
-
#
|
117
|
-
# @return [String]
|
118
|
-
def modified
|
119
|
-
@metadata['modified']
|
120
|
-
end
|
121
|
-
|
122
|
-
# Locale (e.g. en-GB)
|
123
|
-
#
|
124
|
-
# @return [String]
|
125
|
-
def locale
|
126
|
-
@metadata['locale']
|
127
|
-
end
|
128
|
-
|
129
|
-
# Set content from XML. In order for metadata extraction to work, the XML must have
|
130
|
-
# been retrieved using the .current version of the Pure API endpoints
|
131
|
-
#
|
132
|
-
# @param xml [String]
|
133
|
-
def set_content(xml)
|
134
|
-
if xml
|
135
|
-
make_doc xml
|
136
|
-
if get_data?
|
137
|
-
combine_metadata
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
private
|
143
|
-
|
144
|
-
def make_doc(xml)
|
145
|
-
@doc = Nokogiri::XML xml
|
146
|
-
@doc.remove_namespaces!
|
147
|
-
end
|
148
|
-
|
149
|
-
def extract_created
|
150
|
-
path = '/created'
|
151
|
-
xpath_query_for_single_value path
|
152
|
-
end
|
153
|
-
|
154
|
-
def extract_modified
|
155
|
-
path = '/modified'
|
156
|
-
xpath_query_for_single_value path
|
157
|
-
end
|
158
|
-
|
159
|
-
def extract_uuid
|
160
|
-
path = '/@uuid'
|
161
|
-
xpath_query_for_single_value path
|
162
|
-
end
|
163
|
-
|
164
|
-
def extract_locale
|
165
|
-
path = '/@locale'
|
166
|
-
str = xpath_query_for_single_value path
|
167
|
-
str.gsub('_','-')
|
168
|
-
end
|
169
|
-
|
170
|
-
# All metadata
|
171
|
-
#
|
172
|
-
# @return [Hash]
|
173
|
-
def combine_metadata
|
174
|
-
o = {}
|
175
|
-
o['uuid'] = extract_uuid
|
176
|
-
o['created'] = extract_created
|
177
|
-
o['modified'] = extract_modified
|
178
|
-
o['locale'] = extract_locale
|
179
|
-
o
|
180
|
-
end
|
181
|
-
|
182
|
-
# Is there any data after get? For a response that provides a count of the results.
|
183
|
-
#
|
184
|
-
# @return [Boolean]
|
185
|
-
def get_data?
|
186
|
-
path = service_xpath_count
|
187
|
-
xpath_result = @doc.xpath path
|
188
|
-
xpath_result.text.strip === '1' ? true : false
|
189
|
-
end
|
190
|
-
|
191
|
-
def service_name
|
192
|
-
resource_type = @options[:resource_type]
|
193
|
-
@api_map[:resource_type][resource_type][:service]
|
194
|
-
end
|
195
|
-
|
196
|
-
def service_response_name
|
197
|
-
resource_type = @options[:resource_type]
|
198
|
-
@api_map[:resource_type][resource_type][:response]
|
199
|
-
end
|
200
|
-
|
201
|
-
def service_xpath_base
|
202
|
-
service_response_name + '/result/content'
|
203
|
-
end
|
204
|
-
|
205
|
-
def service_xpath_count
|
206
|
-
service_response_name + '/count'
|
207
|
-
end
|
208
|
-
|
209
|
-
def service_xpath(str_to_find)
|
210
|
-
service_xpath_base + str_to_find
|
211
|
-
end
|
212
|
-
|
213
|
-
def build_url
|
214
|
-
service = service_name
|
215
|
-
if @options[:latest_api] === false
|
216
|
-
service_api_mode = service
|
217
|
-
else
|
218
|
-
service_api_mode = service + '.current'
|
219
|
-
end
|
220
|
-
@base_url + '/' + service_api_mode
|
221
|
-
end
|
222
|
-
|
223
|
-
# content based
|
224
|
-
def xpath_query(path)
|
225
|
-
path_from_root = service_xpath path
|
226
|
-
@doc.xpath path_from_root
|
227
|
-
end
|
228
|
-
|
229
|
-
def xpath_query_for_single_value(path)
|
230
|
-
xpath_result = xpath_query path
|
231
|
-
xpath_result ? xpath_result.text.strip : ''
|
232
|
-
end
|
233
|
-
|
234
|
-
|
235
|
-
def missing_credentials
|
236
|
-
missing = []
|
237
|
-
if @base_url.nil?
|
238
|
-
missing << 'base_url'
|
239
|
-
end
|
240
|
-
|
241
|
-
if @options[:basic_auth] === true
|
242
|
-
if @username.nil?
|
243
|
-
missing << 'username'
|
244
|
-
end
|
245
|
-
if @password.nil?
|
246
|
-
missing << 'password'
|
247
|
-
end
|
248
|
-
end
|
249
|
-
|
250
|
-
missing
|
251
|
-
end
|
252
|
-
|
253
|
-
def reset
|
254
|
-
@response = nil
|
255
|
-
end
|
256
|
-
|
257
|
-
alias :find :get
|
258
|
-
|
259
|
-
|
260
|
-
end
|
261
|
-
end
|