puree 0.13.0 → 0.14.0

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: 539976142cda876c73eb0caf03ae4b2eca425775
4
- data.tar.gz: f5896f3afb50cbc67bca6d20124fef8d85ae4052
3
+ metadata.gz: 6b99230d8fee3aa6a259149b6b0fcf1beb258f43
4
+ data.tar.gz: 3c6e08559c575caa1edb25c986d91f670f157384
5
5
  SHA512:
6
- metadata.gz: a6f35ad8908b500f03ff30f00b38621bf8d570fc5b3c9f53be7e24ef1b7eb024e342fe3d56e8f99b7b8d23cdeaed466e2e3c372cb73b09a0f24e47c17d9a1ed6
7
- data.tar.gz: 1b6b644bbb9157f345b29a03428805cee300a2982ac44378b5c3aa873fd8487a964bce711bb6f7553eaab3cf426c3c2e1f1abca0a0051738165d3024c67c304a
6
+ metadata.gz: 083843de876a7502201a2cea2180c39e0c0b9b7ea67d2dce14ad577e47f30243bd798a085d4a6fe48a0ec42a4be0ea901e945b0452bfe269206d4decf40fcea3
7
+ data.tar.gz: 48c0c50c3a3c1d9cddaed24ad7f9bc8ed90e750721ff244a7eed6150fbca37424827c304145b295259b44107cb9eeb5466289ebe56a6631e91f97a262cfa0031
@@ -2,6 +2,20 @@
2
2
  All notable changes to this project will be documented in this file.
3
3
  This project adheres to [Semantic Versioning](http://semver.org/).
4
4
 
5
+ ## Unreleased
6
+ - Download stats.
7
+
8
+ ## 0.14.0 - 2016-06-10
9
+ ### Added
10
+ - Dataset (organisation).
11
+ - Organisation (parent).
12
+ - Credentials set globally.
13
+ - Global credentials override in ctor of resource.
14
+ - Find as alias for get.
15
+
16
+ ### Removed
17
+ - Credentials passed with get.
18
+
5
19
  ## 0.13.0 - 2016-05-20
6
20
  ### Added
7
21
  - Collection server-side search by date range (created, modified) and paging.
data/README.md CHANGED
@@ -1,5 +1,4 @@
1
- # Purée
2
-
1
+ # Purée [![Gem Version](https://badge.fury.io/rb/puree.svg)](https://badge.fury.io/rb/puree)
3
2
  A Ruby client for the Pure Research Information System API.
4
3
 
5
4
 
@@ -18,26 +17,46 @@ Or install it yourself as:
18
17
  $ gem install puree
19
18
 
20
19
  ## Usage
20
+ Authentication
21
+
21
22
  ```ruby
22
- endpoint = 'http://example.com/ws/rest'
23
+
24
+ # Global settings together
25
+ Puree::Configuration.configure do |c|
26
+ c.endpoint = ENV['PURE_ENDPOINT']
27
+ c.username = ENV['PURE_USERNAME']
28
+ c.password = ENV['PURE_PASSWORD']
29
+ end
30
+
31
+ # Global settings individually
32
+ Puree::Configuration.endpoint = ENV['PURE_ENDPOINT']
33
+ Puree::Configuration.username = ENV['PURE_USERNAME']
34
+ Puree::Configuration.password = ENV['PURE_PASSWORD']
35
+
36
+ # Use global settings
37
+ d = Puree::Dataset.new
38
+
39
+ # Override one or more global settings in an instance
40
+ d = Puree::Dataset.new endpoint: 'http://example.com/ws/rest',
41
+ username: 'another_username',
42
+ password: 'another_password'
23
43
  ```
24
44
 
25
- Dataset.
45
+
46
+ Dataset
26
47
 
27
48
  ```ruby
49
+
28
50
  d = Puree::Dataset.new
29
51
 
30
52
  # Get metadata using ID
31
- d.get id: 12345678,
32
- endpoint: endpoint,
33
- username: username,
34
- password: password
53
+ d.find id: 12345678
54
+
55
+ # Reuse instance
56
+ d.find id: 87654321
35
57
 
36
58
  # Get metadata using UUID
37
- d.get uuid: 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx',
38
- endpoint: endpoint,
39
- username: username,
40
- password: password
59
+ d.find uuid: 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
41
60
 
42
61
  # Filter metadata into simple data structures
43
62
  d.access
@@ -51,6 +70,7 @@ d.geographical
51
70
  d.keyword
52
71
  d.link
53
72
  d.modified
73
+ d.organisation
54
74
  d.person
55
75
  d.production
56
76
  d.project
@@ -70,21 +90,18 @@ d.response.message
70
90
  d.response.headers # hash
71
91
  ```
72
92
 
73
- Collection.
93
+ Collection
74
94
 
75
95
  ```ruby
76
- c = Puree::Collection.new(resource_type: :dataset)
96
+ c = Puree::Collection.new api: :dataset
77
97
 
78
98
  # Get three minimal datasets, starting at record ten, created and modified in January 2016.
79
- c.get endpoint: endpoint,
80
- username: username,
81
- password: password,
82
- limit: 3, # optional, default 20
83
- offset: 10, # optional, default 0
84
- created_start: '2016-01-01', # optional
85
- created_end: '2016-01-31', # optional
86
- modified_start: '2016-01-01', # optional
87
- modified_end: '2016-01-31' # optional
99
+ c.find limit: 3, # optional, default 20
100
+ offset: 10, # optional, default 0
101
+ created_start: '2016-01-01', # optional
102
+ created_end: '2016-01-31', # optional
103
+ modified_start: '2016-01-01', # optional
104
+ modified_end: '2016-01-31' # optional
88
105
 
89
106
  # Get UUIDs for datasets
90
107
  uuids = c.uuid
@@ -93,10 +110,7 @@ uuids = c.uuid
93
110
  datasets = []
94
111
  uuids.each do |uuid|
95
112
  d = Puree::Dataset.new
96
- d.get endpoint: endpoint,
97
- username: username,
98
- password: password,
99
- uuid: uuid
113
+ d.find uuid: uuid
100
114
  datasets << d.metadata
101
115
  end
102
116
  ```
@@ -110,9 +124,9 @@ Date made available. If year is present, month and day will have data or an empt
110
124
 
111
125
  ```ruby
112
126
  {
113
- "year"=>"2016",
114
- "month"=>"2",
115
- "day"=>"4"
127
+ "year" => "2016",
128
+ "month" => "2",
129
+ "day" => "4"
116
130
  }
117
131
  ```
118
132
 
@@ -122,14 +136,14 @@ An array of files.
122
136
  ```ruby
123
137
  [
124
138
  {
125
- "name"=>"foo.csv",
126
- "mime"=>"application/octet-stream",
127
- "size"=>"1616665158",
128
- "url"=>"http://example.com/ws/rest/files/12345678/foo.csv",
129
- "title"=>"foo.csv",
130
- "license"=>{
131
- "name"=>"CC BY-NC",
132
- "url"=>"http://creativecommons.org/licenses/by-nc/4.0/"
139
+ "name" => "foo.csv",
140
+ "mime" => "application/octet-stream",
141
+ "size" => "1616665158",
142
+ "url" => "http://example.com/ws/rest/files/12345678/foo.csv",
143
+ "title" => "foo.csv",
144
+ "license" => {
145
+ "name" => "CC BY-NC",
146
+ "url" => "http://creativecommons.org/licenses/by-nc/4.0/"
133
147
  }
134
148
  },
135
149
  ]
@@ -141,37 +155,48 @@ An array of links.
141
155
  ```ruby
142
156
  [
143
157
  {
144
- "url": "http://www.example.com/~abc1234/xyz/",
145
- "description": "An interesting description"
158
+ "url" => "http://www.example.com/~abc1234/xyz/",
159
+ "description" => "An interesting description"
146
160
  },
147
161
  ]
148
162
  ```
149
163
 
164
+ #### organisation
165
+ Organisation responsible.
166
+
167
+ ```ruby
168
+ {
169
+ "uuid" => "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx",
170
+ "name" => "Institute for the Arts",
171
+ "type" => "Department"
172
+ }
173
+ ```
174
+
150
175
  #### person
151
176
  Contains an array of internal persons, an array of external persons and an array of other persons.
152
177
 
153
178
  ```ruby
154
179
  {
155
- "internal"=>[
180
+ "internal" => [
156
181
  {
157
- "name"=>{
158
- "first"=>"Stan",
159
- "last"=>"Laurel"
182
+ "name" => {
183
+ "first" => "Stan",
184
+ "last" => "Laurel"
160
185
  },
161
- "role"=>"Creator",
162
- "uuid"=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx"
186
+ "role" => "Creator",
187
+ "uuid" => "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx"
163
188
  },
164
189
  ],
165
- "external"=>[
190
+ "external" => [
166
191
  ],
167
- "other"=>[
192
+ "other" => [
168
193
  {
169
- "name"=>{
170
- "first"=>"Hal",
171
- "last"=>"Roach"
194
+ "name" => {
195
+ "first" => "Hal",
196
+ "last" => "Roach"
172
197
  },
173
- "role"=>"Contributor",
174
- "uuid"=>""
198
+ "role" => "Contributor",
199
+ "uuid" => ""
175
200
  },
176
201
  ]
177
202
  }
@@ -183,8 +208,8 @@ An array of projects associated with the dataset.
183
208
  ```ruby
184
209
  [
185
210
  {
186
- "title": "An interesting project title",
187
- "uuid": "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx"
211
+ "title" => "An interesting project title",
212
+ "uuid" => "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx"
188
213
  },
189
214
  ]
190
215
  ```
@@ -195,34 +220,34 @@ An array of research outputs associated with the dataset.
195
220
  ```ruby
196
221
  [
197
222
  {
198
- "type": "Journal article",
199
- "title": "An interesting journal article title",
200
- "uuid": "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx"
223
+ "type" => "Journal article",
224
+ "title" => "An interesting journal article title",
225
+ "uuid" => "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx"
201
226
  },
202
227
  {
203
- "type": "Conference paper",
204
- "title": "An interesting conference paper title",
205
- "uuid": "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx"
228
+ "type" => "Conference paper",
229
+ "title" => "An interesting conference paper title",
230
+ "uuid" => "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx"
206
231
  },
207
232
  {
208
- "type": "Working paper",
209
- "title": "An interesting working paper title",
210
- "uuid": "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx"
233
+ "type" => "Working paper",
234
+ "title" => "An interesting working paper title",
235
+ "uuid" => "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx"
211
236
  },
212
237
  {
213
- "type": "Paper",
214
- "title": "An interesting paper title",
215
- "uuid": "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx"
238
+ "type" => "Paper",
239
+ "title" => "An interesting paper title",
240
+ "uuid" => "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx"
216
241
  },
217
242
  {
218
- "type": "Dataset",
219
- "title": "An interesting dataset title",
220
- "uuid": "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx"
243
+ "type" => "Dataset",
244
+ "title" => "An interesting dataset title",
245
+ "uuid" => "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx"
221
246
  },
222
247
  {
223
- "type": "Chapter",
224
- "title": "An interesting chapter title",
225
- "uuid": "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx"
248
+ "type" => "Chapter",
249
+ "title" => "An interesting chapter title",
250
+ "uuid" => "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx"
226
251
  },
227
252
  ]
228
253
  ```
@@ -232,15 +257,15 @@ Date range. If year is present, month and day will have data or an empty string.
232
257
 
233
258
  ```ruby
234
259
  {
235
- "start"=>{
236
- "year"=>"2005",
237
- "month"=>"5",
238
- "day"=>"10"
260
+ "start" => {
261
+ "year" => "2005",
262
+ "month" => "5",
263
+ "day" => "10"
239
264
  },
240
- "end"=>{
241
- "year"=>"2011",
242
- "month"=>"9",
243
- "day"=>"18"
265
+ "end" => {
266
+ "year" => "2011",
267
+ "month" => "9",
268
+ "day" => "18"
244
269
  }
245
270
  }
246
271
  ```
@@ -253,15 +278,26 @@ An array of addresses.
253
278
  ```ruby
254
279
  [
255
280
  {
256
- "street"=>"Lancaster University",
257
- "building"=>"Bowland North",
258
- "postcode"=>"LA1 4YN",
259
- "city"=>"Lancaster",
260
- "country"=>"United Kingdom"
281
+ "street" => "Lancaster University",
282
+ "building" => "Bowland North",
283
+ "postcode" => "LA1 4YN",
284
+ "city" => "Lancaster",
285
+ "country" => "United Kingdom"
261
286
  },
262
287
  ]
263
288
  ```
264
289
 
290
+ #### parent
291
+ Parent organisation.
292
+
293
+ ```ruby
294
+ {
295
+ "uuid" => "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx",
296
+ "name" => "Institute for the Arts",
297
+ "type" => "Department"
298
+ }
299
+ ```
300
+
265
301
  ### Publication
266
302
 
267
303
  #### file
@@ -270,10 +306,10 @@ An array of files.
270
306
  ```ruby
271
307
  [
272
308
  {
273
- "name"=>"foo.csv",
274
- "mime"=>"application/octet-stream",
275
- "size"=>"1616665158",
276
- "url"=>"http://example.com/ws/rest/files/12345678/foo.csv",
309
+ "name" => "foo.csv",
310
+ "mime" => "application/octet-stream",
311
+ "size" => "1616665158",
312
+ "url" => "http://example.com/ws/rest/files/12345678/foo.csv",
277
313
  },
278
314
  ]
279
315
  ```
@@ -287,9 +323,9 @@ Puree::Date.iso d.available
287
323
  ```
288
324
  ```ruby
289
325
  {
290
- "year"=>"2016",
291
- "month"=>"4",
292
- "day"=>"18"
326
+ "year" => "2016",
327
+ "month" => "4",
328
+ "day" => "18"
293
329
  }
294
330
  ```
295
331
  becomes
@@ -1,5 +1,6 @@
1
1
  require 'httparty'
2
2
  require 'nokogiri'
3
+ require 'puree/configuration'
3
4
  require 'puree/date'
4
5
  require 'puree/map'
5
6
  require 'puree/resource'
@@ -4,30 +4,48 @@ module Puree
4
4
  #
5
5
  class Collection < Resource
6
6
 
7
- def initialize(resource_type: nil)
8
- super(resource_type)
7
+ # @param api [Symbol]
8
+ # @param endpoint [String]
9
+ # @param optional username [String]
10
+ # @param optional password [String]
11
+ def initialize(api: nil,
12
+ endpoint: nil,
13
+ username: nil,
14
+ password: nil)
15
+ super(api: api,
16
+ endpoint: endpoint,
17
+ username: username,
18
+ password: password)
9
19
  @uuids = []
10
20
  end
11
21
 
12
22
  # Get
13
23
  #
14
- # @param endpoint [String]
15
- # @param username [String]
16
- # @param password [String]
17
- # @param qty [Integer]
24
+ # @param optional limit [Integer]
25
+ # @param optional offset [Integer]
26
+ # @param optional created_start [String]
27
+ # @param optional created_end [String]
28
+ # @param optional modified_start [String]
29
+ # @param optional modified_end [String]
18
30
  # @return [HTTParty::Response]
19
- def get(endpoint: nil,
20
- username: nil,
21
- password: nil,
31
+ def get(
22
32
  limit: 20,
23
33
  offset: 0,
24
34
  created_start: nil,
25
35
  created_end: nil,
26
36
  modified_start: nil,
27
37
  modified_end: nil)
38
+
39
+ missing = missing_credentials
40
+ if !missing.empty?
41
+ missing.each do |m|
42
+ puts "#{self.class.name}" + '#' + "#{__method__} missing #{m}"
43
+ end
44
+ exit
45
+ end
28
46
  # strip any trailing slash
29
- @endpoint = endpoint.sub(/(\/)+$/, '')
30
- @auth = Base64::strict_encode64(username + ':' + password)
47
+ @endpoint = @endpoint.sub(/(\/)+$/, '')
48
+ @auth = Base64::strict_encode64(@username + ':' + @password)
31
49
 
32
50
  @options = {
33
51
  latest_api: true,
@@ -95,6 +113,7 @@ module Puree
95
113
  xpath_result.each { |i| @uuids << i.text.strip }
96
114
  end
97
115
 
116
+ alias :find :get
98
117
 
99
118
  end
100
119
 
@@ -0,0 +1,17 @@
1
+ module Puree
2
+
3
+ module Configuration
4
+
5
+ class << self
6
+
7
+ attr_accessor :endpoint, :username, :password
8
+
9
+ def configure
10
+ yield self
11
+ end
12
+
13
+ end
14
+
15
+ end
16
+
17
+ end
@@ -4,8 +4,14 @@ module Puree
4
4
  #
5
5
  class Dataset < Resource
6
6
 
7
- def initialize
8
- super(:dataset)
7
+ # @param endpoint [String]
8
+ # @param optional username [String]
9
+ # @param optional password [String]
10
+ def initialize(endpoint: nil, username: nil, password: nil)
11
+ super(api: :dataset,
12
+ endpoint: endpoint,
13
+ username: username,
14
+ password: password)
9
15
  end
10
16
 
11
17
  # Link
@@ -21,7 +27,20 @@ module Puree
21
27
  o['description'] = i.xpath('description').text.strip
22
28
  data << o
23
29
  }
24
- return data.uniq
30
+ data.uniq
31
+ end
32
+
33
+ # Organisation
34
+ #
35
+ # @return [Hash]
36
+ def organisation
37
+ path = '//content/managedBy'
38
+ xpath_result = xpath_query path
39
+ o = {}
40
+ o['uuid'] = xpath_result.xpath('@uuid').text.strip
41
+ o['name'] = xpath_result.xpath('name/localizedString').text.strip
42
+ o['type'] = xpath_result.xpath('typeClassification/term/localizedString').text.strip
43
+ o
25
44
  end
26
45
 
27
46
  # Publisher
@@ -260,6 +279,7 @@ module Puree
260
279
  o['geographical'] = geographical
261
280
  o['keyword'] = keyword
262
281
  o['link'] = link
282
+ o['organisation'] = organisation
263
283
  o['person'] = person
264
284
  o['project'] = project
265
285
  o['production'] = production
@@ -0,0 +1,26 @@
1
+ module Puree
2
+
3
+ # Download resource
4
+ #
5
+ class Download < Resource
6
+
7
+ # @param endpoint [String]
8
+ # @param optional username [String]
9
+ # @param optional password [String]
10
+ def initialize(endpoint: nil, username: nil, password: nil)
11
+ super(api: :download,
12
+ endpoint: endpoint,
13
+ username: username,
14
+ password: password)
15
+ end
16
+
17
+ # All metadata
18
+ #
19
+ # @return [Hash]
20
+ # def metadata
21
+ # super
22
+ # end
23
+
24
+ end
25
+
26
+ end
@@ -4,8 +4,14 @@ module Puree
4
4
  #
5
5
  class Event < Resource
6
6
 
7
- def initialize
8
- super(:event)
7
+ # @param endpoint [String]
8
+ # @param optional username [String]
9
+ # @param optional password [String]
10
+ def initialize(endpoint: nil, username: nil, password: nil)
11
+ super(api: :event,
12
+ endpoint: endpoint,
13
+ username: username,
14
+ password: password)
9
15
  end
10
16
 
11
17
  # City
@@ -4,8 +4,14 @@ module Puree
4
4
  #
5
5
  class Journal < Resource
6
6
 
7
- def initialize
8
- super(:journal)
7
+ # @param endpoint [String]
8
+ # @param optional username [String]
9
+ # @param optional password [String]
10
+ def initialize(endpoint: nil, username: nil, password: nil)
11
+ super(api: :journal,
12
+ endpoint: endpoint,
13
+ username: username,
14
+ password: password)
9
15
  end
10
16
 
11
17
  # All metadata
@@ -17,8 +17,13 @@ module Puree
17
17
  resource_type: {
18
18
  dataset: {
19
19
  service: 'datasets',
20
- response: 'GetDataSetsResponse'
21
- }
20
+ response: 'GetDataSetsResponse',
21
+ family: 'dk.atira.pure.modules.datasets.external.model.dataset.DataSet'
22
+ },
23
+ download: {
24
+ service: 'downloadcount',
25
+ response: 'GetDownloadCountResponse'
26
+ },
22
27
  }
23
28
  }
24
29
 
@@ -4,8 +4,14 @@ module Puree
4
4
  #
5
5
  class Organisation < Resource
6
6
 
7
- def initialize
8
- super(:organisation)
7
+ # @param endpoint [String]
8
+ # @param optional username [String]
9
+ # @param optional password [String]
10
+ def initialize(endpoint: nil, username: nil, password: nil)
11
+ super(api: :organisation,
12
+ endpoint: endpoint,
13
+ username: username,
14
+ password: password)
9
15
  end
10
16
 
11
17
  # Address
@@ -48,6 +54,18 @@ module Puree
48
54
  !data.nil? && !data.empty? ? data['localizedString']['__content__'].strip : ''
49
55
  end
50
56
 
57
+ # Parent
58
+ #
59
+ # @return [Hash]
60
+ def parent
61
+ data = organisation
62
+ o = {}
63
+ if !data.empty?
64
+ o = data.first
65
+ end
66
+ o
67
+ end
68
+
51
69
  # Phone
52
70
  #
53
71
  # @return [Array<String>]
@@ -87,12 +105,37 @@ module Puree
87
105
  o['address'] = address
88
106
  o['email'] = email
89
107
  o['name'] = name
108
+ o['parent'] = parent
90
109
  o['phone'] = phone
91
110
  o['type'] = type
92
111
  o['url'] = url
93
112
  o
94
113
  end
95
114
 
115
+
116
+ private
117
+
118
+
119
+ # Organisation
120
+ #
121
+ # @return [Array<Hash>]
122
+ def organisation
123
+ path = '//organisations/organisation'
124
+ xpath_result = xpath_query path
125
+
126
+ data = []
127
+
128
+ xpath_result.each do |d|
129
+ o = {}
130
+ o['uuid'] = d.xpath('@uuid').text.strip
131
+ o['name'] = d.xpath('name/localizedString').text.strip
132
+ o['type'] = d.xpath('typeClassification/term/localizedString').text.strip
133
+ data << o
134
+ end
135
+ data.uniq
136
+ end
137
+
138
+
96
139
  end
97
140
 
98
141
  end
@@ -4,8 +4,14 @@ module Puree
4
4
  #
5
5
  class Person < Resource
6
6
 
7
- def initialize
8
- super(:person)
7
+ # @param endpoint [String]
8
+ # @param optional username [String]
9
+ # @param optional password [String]
10
+ def initialize(endpoint: nil, username: nil, password: nil)
11
+ super(api: :person,
12
+ endpoint: endpoint,
13
+ username: username,
14
+ password: password)
9
15
  end
10
16
 
11
17
  # Affiliation
@@ -4,8 +4,14 @@ module Puree
4
4
  #
5
5
  class Project < Resource
6
6
 
7
- def initialize
8
- super(:project)
7
+ # @param endpoint [String]
8
+ # @param optional username [String]
9
+ # @param optional password [String]
10
+ def initialize(endpoint: nil, username: nil, password: nil)
11
+ super(api: :project,
12
+ endpoint: endpoint,
13
+ username: username,
14
+ password: password)
9
15
  end
10
16
 
11
17
  # All metadata
@@ -4,8 +4,14 @@ module Puree
4
4
  #
5
5
  class Publication < Resource
6
6
 
7
- def initialize
8
- super(:publication)
7
+ # @param endpoint [String]
8
+ # @param optional username [String]
9
+ # @param optional password [String]
10
+ def initialize(endpoint: nil, username: nil, password: nil)
11
+ super(api: :publication,
12
+ endpoint: endpoint,
13
+ username: username,
14
+ password: password)
9
15
  end
10
16
 
11
17
  # Description
@@ -4,8 +4,14 @@ module Puree
4
4
  #
5
5
  class Publisher < Resource
6
6
 
7
- def initialize
8
- super(:publisher)
7
+ # @param endpoint [String]
8
+ # @param optional username [String]
9
+ # @param optional password [String]
10
+ def initialize(endpoint: nil, username: nil, password: nil)
11
+ super(api: :publisher,
12
+ endpoint: endpoint,
13
+ username: username,
14
+ password: password)
9
15
  end
10
16
 
11
17
  # All metadata
@@ -4,28 +4,38 @@ module Puree
4
4
  #
5
5
  class Resource
6
6
 
7
- def initialize(resource_type)
8
- @resource_type = resource_type
7
+ # @param api [String]
8
+ # @param endpoint [String]
9
+ # @param optional username [String]
10
+ # @param optional password [String]
11
+ def initialize( api: nil,
12
+ endpoint: nil,
13
+ username: nil,
14
+ password: nil)
15
+ @resource_type = api
9
16
  @api_map = Puree::Map.new.get
17
+ @endpoint = endpoint.nil? ? Puree::Configuration.endpoint : endpoint
18
+ @username = username.nil? ? Puree::Configuration.username : username
19
+ @password = password.nil? ? Puree::Configuration.password : password
10
20
  end
11
21
 
12
22
  # Get
13
23
  #
14
- # @param endpoint [String]
15
- # @param username [String]
16
- # @param password [String]
17
24
  # @param uuid [String]
18
25
  # @param id [String]
19
26
  # @return [HTTParty::Response]
20
- def get(endpoint: nil,
21
- username: nil,
22
- password: nil,
23
- uuid: nil,
24
- id: nil
25
- )
27
+ def get(uuid: nil, id: nil)
28
+ missing = missing_credentials
29
+ if !missing.empty?
30
+ missing.each do |m|
31
+ puts "#{self.class.name}" + '#' + "#{__method__} missing #{m}"
32
+ end
33
+ exit
34
+ end
35
+
26
36
  # strip any trailing slash
27
- @endpoint = endpoint.sub(/(\/)+$/, '')
28
- @auth = Base64::strict_encode64(username + ':' + password)
37
+ @endpoint = @endpoint.sub(/(\/)+$/, '')
38
+ @auth = Base64::strict_encode64(@username + ':' + @password)
29
39
 
30
40
  @options = {
31
41
  latest_api: true,
@@ -124,9 +134,20 @@ module Puree
124
134
  o
125
135
  end
126
136
 
137
+
138
+
127
139
  private
128
140
 
129
141
 
142
+ def collect_uuid
143
+ path = '//renderedItem/@renderedContentUUID'
144
+ xpath_result = xpath_query path
145
+ xpath_result.each { |i| @uuids << i.text.strip }
146
+ end
147
+
148
+
149
+
150
+
130
151
 
131
152
  # Node
132
153
  #
@@ -171,6 +192,21 @@ module Puree
171
192
  doc.xpath path
172
193
  end
173
194
 
195
+ def missing_credentials
196
+ missing = []
197
+ if @endpoint.nil?
198
+ missing << 'endpoint'
199
+ end
200
+ if @username.nil?
201
+ missing << 'username'
202
+ end
203
+ if @password.nil?
204
+ missing << 'password'
205
+ end
206
+ missing
207
+ end
208
+
209
+ alias :find :get
174
210
 
175
211
  end
176
212
  end
@@ -1,3 +1,3 @@
1
1
  module Puree
2
- VERSION = "0.13.0"
2
+ VERSION = "0.14.0"
3
3
  end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe 'Collection' do
4
4
 
5
5
  it '#new' do
6
- p = Puree::Collection.new(resource_type: :dataset)
6
+ p = Puree::Collection.new(api: :dataset)
7
7
  expect(p).to be_an_instance_of Puree::Collection
8
8
  end
9
9
 
@@ -12,10 +12,11 @@ describe 'Collection' do
12
12
  endpoint = ENV['PURE_ENDPOINT']
13
13
  username = ENV['PURE_USERNAME']
14
14
  password = ENV['PURE_PASSWORD']
15
- @p = Puree::Collection.new(resource_type: :dataset)
16
- @p.get endpoint: endpoint,
17
- username: username,
18
- password: password
15
+ @p = Puree::Collection.new(api: :dataset,
16
+ endpoint: endpoint,
17
+ username: username,
18
+ password: password)
19
+ @p.find limit: 5
19
20
  end
20
21
 
21
22
  it '#UUID' do
@@ -13,11 +13,10 @@ describe 'Dataset' do
13
13
  username = ENV['PURE_USERNAME']
14
14
  password = ENV['PURE_PASSWORD']
15
15
  uuid = ENV['PURE_DATASET_UUID']
16
- @p = Puree::Dataset.new
17
- @p.get endpoint: endpoint,
18
- username: username,
19
- password: password,
20
- uuid: uuid
16
+ @p = Puree::Dataset.new(endpoint: endpoint,
17
+ username: username,
18
+ password: password)
19
+ @p.find uuid: uuid
21
20
  end
22
21
 
23
22
  it '#access' do
@@ -1,5 +1,6 @@
1
1
  require 'httparty'
2
2
  require 'nokogiri'
3
+ require 'puree/configuration'
3
4
  require 'puree/date'
4
5
  require 'puree/map'
5
6
  require 'puree/resource'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.0
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adrian Albin-Clark
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-20 00:00:00.000000000 Z
11
+ date: 2016-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -54,8 +54,10 @@ files:
54
54
  - Rakefile
55
55
  - lib/puree.rb
56
56
  - lib/puree/collection.rb
57
+ - lib/puree/configuration.rb
57
58
  - lib/puree/dataset.rb
58
59
  - lib/puree/date.rb
60
+ - lib/puree/download.rb
59
61
  - lib/puree/event.rb
60
62
  - lib/puree/journal.rb
61
63
  - lib/puree/map.rb