puree 0.15.0 → 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,25 +4,31 @@ module Puree
4
4
  #
5
5
  class Publisher < Resource
6
6
 
7
- # @param endpoint [String]
8
- # @param optional username [String]
9
- # @param optional password [String]
10
- # @param optional basic_auth [Boolean]
11
- def initialize(endpoint: nil, username: nil, password: nil, basic_auth: nil)
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
12
  super(api: :publisher,
13
- endpoint: endpoint,
13
+ base_url: base_url,
14
14
  username: username,
15
15
  password: password,
16
16
  basic_auth: basic_auth)
17
17
  end
18
18
 
19
-
20
-
21
19
  # All metadata
22
20
  #
23
21
  # @return [Hash]
24
22
  def metadata
25
- super
23
+ @metadata
24
+ end
25
+
26
+
27
+ private
28
+
29
+ def combine_metadata
30
+ o = super
31
+ @metadata = o
26
32
  end
27
33
 
28
34
  end
@@ -7,20 +7,20 @@ module Puree
7
7
  attr_reader :response
8
8
 
9
9
  # @param api [String]
10
- # @param endpoint [String]
11
- # @param optional username [String]
12
- # @param optional password [String]
13
- # @param optional bleeding [Boolean]
14
- # @param optional basic_auth [Boolean]
10
+ # @param base_url [String]
11
+ # @param username [String]
12
+ # @param password [String]
13
+ # @param bleeding [Boolean]
14
+ # @param basic_auth [Boolean]
15
15
  def initialize( api: nil,
16
- endpoint: nil,
16
+ base_url: nil,
17
17
  username: nil,
18
18
  password: nil,
19
19
  bleeding: true,
20
20
  basic_auth: nil)
21
21
  @resource_type = api
22
22
  @api_map = Puree::Map.new.get
23
- @endpoint = endpoint.nil? ? Puree.endpoint : endpoint
23
+ @base_url = base_url.nil? ? Puree.base_url : base_url
24
24
  @latest_api = bleeding
25
25
  @basic_auth = basic_auth.nil? ? Puree.basic_auth : basic_auth
26
26
  if @basic_auth === true
@@ -55,7 +55,7 @@ module Puree
55
55
  end
56
56
 
57
57
  # strip any trailing slash
58
- @endpoint = @endpoint.sub(/(\/)+$/, '')
58
+ @base_url = @base_url.sub(/(\/)+$/, '')
59
59
 
60
60
  headers = {}
61
61
  headers['Accept'] = 'application/xml'
@@ -94,7 +94,7 @@ module Puree
94
94
  puts 'HTTP::Error '+ e.message
95
95
  end
96
96
 
97
- get_data? ? metadata : {}
97
+ get_data? ? combine_metadata : {}
98
98
 
99
99
  end
100
100
 
@@ -116,10 +116,14 @@ module Puree
116
116
  @content ? @content : {}
117
117
  end
118
118
 
119
+
120
+
121
+ private
122
+
119
123
  # Created (UTC datetime)
120
124
  #
121
125
  # @return [String]
122
- def created
126
+ def extract_created
123
127
  path = '/created'
124
128
  xpath_query_for_single_value path
125
129
  end
@@ -127,7 +131,7 @@ module Puree
127
131
  # Modified (UTC datetime)
128
132
  #
129
133
  # @return [String]
130
- def modified
134
+ def extract_modified
131
135
  path = '/modified'
132
136
  xpath_query_for_single_value path
133
137
  end
@@ -135,7 +139,7 @@ module Puree
135
139
  # UUID
136
140
  #
137
141
  # @return [String]
138
- def uuid
142
+ def extract_uuid
139
143
  path = '/@uuid'
140
144
  xpath_query_for_single_value path
141
145
  end
@@ -143,19 +147,14 @@ module Puree
143
147
  # All metadata
144
148
  #
145
149
  # @return [Hash]
146
- def metadata
150
+ def combine_metadata
147
151
  o = {}
148
- o['uuid'] = uuid
149
- o['created'] = created
150
- o['modified'] = modified
152
+ o['uuid'] = extract_uuid
153
+ o['created'] = extract_created
154
+ o['modified'] = extract_modified
151
155
  o
152
156
  end
153
157
 
154
-
155
-
156
- private
157
-
158
-
159
158
  # Is there any data after get? For a response that provides a count of the results.
160
159
  #
161
160
  # @return [Boolean]
@@ -194,7 +193,7 @@ module Puree
194
193
  else
195
194
  service_api_mode = service + '.current'
196
195
  end
197
- @endpoint + '/' + service_api_mode
196
+ @base_url + '/' + service_api_mode
198
197
  end
199
198
 
200
199
  # content based
@@ -211,8 +210,8 @@ module Puree
211
210
 
212
211
  def missing_credentials
213
212
  missing = []
214
- if @endpoint.nil?
215
- missing << 'endpoint'
213
+ if @base_url.nil?
214
+ missing << 'base_url'
216
215
  end
217
216
 
218
217
  if @options[:basic_auth] === true
@@ -6,17 +6,17 @@ module Puree
6
6
 
7
7
  attr_reader :response
8
8
 
9
- # @param endpoint [String]
10
- # @param optional username [String]
11
- # @param optional password [String]
12
- # @param optional basic_auth [Boolean]
13
- def initialize(endpoint: nil,
9
+ # @param base_url [String]
10
+ # @param username [String]
11
+ # @param password [String]
12
+ # @param basic_auth [Boolean]
13
+ def initialize(base_url: nil,
14
14
  username: nil,
15
15
  password: nil,
16
16
  basic_auth: nil)
17
17
  @resource_type = :server
18
18
  @api_map = Puree::Map.new.get
19
- @endpoint = endpoint.nil? ? Puree.endpoint : endpoint
19
+ @base_url = base_url.nil? ? Puree.base_url : base_url
20
20
  @basic_auth = basic_auth.nil? ? Puree.basic_auth : basic_auth
21
21
  if @basic_auth === true
22
22
  @username = username.nil? ? Puree.username : username
@@ -37,7 +37,7 @@ module Puree
37
37
  end
38
38
 
39
39
  # strip any trailing slash
40
- @endpoint = @endpoint.sub(/(\/)+$/, '')
40
+ @base_url = @base_url.sub(/(\/)+$/, '')
41
41
  @auth = Base64::strict_encode64(@username + ':' + @password)
42
42
 
43
43
  @options = {
@@ -66,28 +66,36 @@ module Puree
66
66
  puts 'HTTP::Error '+ e.message
67
67
  end
68
68
 
69
- get_data? ? metadata : {}
69
+ get_data? ? combine_metadata : {}
70
70
  end
71
71
 
72
72
  # All metadata
73
73
  #
74
74
  # @return [Hash]
75
75
  def metadata
76
- o = {}
77
- o['version'] = version
78
- o
76
+ @metadata
79
77
  end
80
78
 
81
79
  # Version
82
80
  #
83
81
  # @return [String]
84
82
  def version
85
- path = service_response_name + '/baseVersion'
86
- xpath_query(path).text.strip
83
+ @metadata['version']
87
84
  end
88
85
 
89
86
  private
90
87
 
88
+ def combine_metadata
89
+ o = {}
90
+ o['version'] = extract_version
91
+ @metadata = o
92
+ end
93
+
94
+ def extract_version
95
+ path = service_response_name + '/baseVersion'
96
+ xpath_query(path).text.strip
97
+ end
98
+
91
99
 
92
100
  # Is there any data after get?
93
101
  #
@@ -116,7 +124,7 @@ module Puree
116
124
  else
117
125
  service_api_mode = service + '.current'
118
126
  end
119
- @endpoint + '/' + service_api_mode
127
+ @base_url + '/' + service_api_mode
120
128
  end
121
129
 
122
130
  def xpath_query(path)
@@ -128,8 +136,8 @@ module Puree
128
136
 
129
137
  def missing_credentials
130
138
  missing = []
131
- if @endpoint.nil?
132
- missing << 'endpoint'
139
+ if @base_url.nil?
140
+ missing << 'base_url'
133
141
  end
134
142
  if @username.nil?
135
143
  missing << 'username'
@@ -1,3 +1,3 @@
1
1
  module Puree
2
- VERSION = "0.15.0"
2
+ VERSION = "0.16.0"
3
3
  end
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Adrian Albin-Clark"]
10
10
  spec.email = ["a.albin-clark@lancaster.ac.uk"]
11
11
  spec.summary = %q{A client for the Pure Research Information System API.}
12
- spec.description = %q{Pur&#233;e consumes the Pure Research Information System API and puts the metadata into simple data structures.}
12
+ spec.description = %q{Puree consumes the Pure Research Information System API and puts the metadata into simple data structures.}
13
13
  spec.homepage = "https://github.com/lulibrary/puree.git"
14
14
  spec.license = "MIT"
15
15
 
@@ -3,11 +3,11 @@ require 'spec_helper'
3
3
  describe 'Collection' do
4
4
 
5
5
  it '#new' do
6
- endpoint = ENV['PURE_ENDPOINT']
6
+ base_url = ENV['PURE_BASE_URL']
7
7
  username = ENV['PURE_USERNAME']
8
8
  password = ENV['PURE_PASSWORD']
9
9
  p = Puree::Collection.new(resource: :dataset,
10
- endpoint: endpoint,
10
+ base_url: base_url,
11
11
  username: username,
12
12
  password: password,
13
13
  basic_auth: true
@@ -17,11 +17,11 @@ describe 'Collection' do
17
17
 
18
18
  describe 'data retrieval' do
19
19
  before(:all) do
20
- endpoint = ENV['PURE_ENDPOINT']
20
+ base_url = ENV['PURE_BASE_URL']
21
21
  username = ENV['PURE_USERNAME']
22
22
  password = ENV['PURE_PASSWORD']
23
23
  @p = Puree::Collection.new(resource: :dataset,
24
- endpoint: endpoint,
24
+ base_url: base_url,
25
25
  username: username,
26
26
  password: password,
27
27
  basic_auth: true)
@@ -9,11 +9,11 @@ describe 'Dataset' do
9
9
 
10
10
  describe 'data retrieval' do
11
11
  before(:all) do
12
- endpoint = ENV['PURE_ENDPOINT']
12
+ base_url = ENV['PURE_BASE_URL']
13
13
  username = ENV['PURE_USERNAME']
14
14
  password = ENV['PURE_PASSWORD']
15
15
  uuid = ENV['PURE_DATASET_UUID']
16
- @p = Puree::Dataset.new(endpoint: endpoint,
16
+ @p = Puree::Dataset.new(base_url: base_url,
17
17
  username: username,
18
18
  password: password,
19
19
  basic_auth: true)
@@ -52,10 +52,6 @@ describe 'Dataset' do
52
52
  expect(@metadata['file']).to be_an_instance_of(Array)
53
53
  end
54
54
 
55
- it '#geographical' do
56
- expect(@metadata['geographical']).to be_an_instance_of(Array)
57
- end
58
-
59
55
  it '#keyword' do
60
56
  expect(@metadata['keyword']).to be_an_instance_of(Array)
61
57
  end
@@ -88,6 +84,10 @@ describe 'Dataset' do
88
84
  expect(@metadata['publisher']).to be_an_instance_of(String)
89
85
  end
90
86
 
87
+ it '#spatial' do
88
+ expect(@metadata['spatial']).to be_an_instance_of(Array)
89
+ end
90
+
91
91
  it '#temporal' do
92
92
  expect(@metadata['temporal']).to be_an_instance_of(Hash)
93
93
  end
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.15.0
4
+ version: 0.16.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-06-22 00:00:00.000000000 Z
11
+ date: 2016-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http
@@ -38,8 +38,8 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.6'
41
- description: Pur&#233;e consumes the Pure Research Information System API and puts
42
- the metadata into simple data structures.
41
+ description: Puree consumes the Pure Research Information System API and puts the
42
+ metadata into simple data structures.
43
43
  email:
44
44
  - a.albin-clark@lancaster.ac.uk
45
45
  executables: []