puree 0.14.0 → 0.15.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 +25 -1
- data/README.md +16 -339
- data/lib/puree.rb +15 -2
- data/lib/puree/collection.rb +161 -32
- data/lib/puree/configuration.rb +1 -5
- data/lib/puree/dataset.rb +95 -88
- data/lib/puree/download.rb +170 -12
- data/lib/puree/event.rb +16 -11
- data/lib/puree/journal.rb +5 -2
- data/lib/puree/map.rb +13 -2
- data/lib/puree/organisation.rb +16 -15
- data/lib/puree/person.rb +38 -16
- data/lib/puree/project.rb +163 -3
- data/lib/puree/publication.rb +132 -15
- data/lib/puree/publisher.rb +6 -2
- data/lib/puree/resource.rb +95 -70
- data/lib/puree/server.rb +147 -0
- data/lib/puree/version.rb +1 -1
- data/puree.gemspec +2 -2
- data/spec/collection.rb +15 -6
- data/spec/dataset.rb +25 -24
- data/spec/spec_helper.rb +14 -2
- metadata +8 -7
data/lib/puree/server.rb
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
module Puree
|
2
|
+
|
3
|
+
# Server
|
4
|
+
#
|
5
|
+
class Server
|
6
|
+
|
7
|
+
attr_reader :response
|
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,
|
14
|
+
username: nil,
|
15
|
+
password: nil,
|
16
|
+
basic_auth: nil)
|
17
|
+
@resource_type = :server
|
18
|
+
@api_map = Puree::Map.new.get
|
19
|
+
@endpoint = endpoint.nil? ? Puree.endpoint : endpoint
|
20
|
+
@basic_auth = basic_auth.nil? ? Puree.basic_auth : basic_auth
|
21
|
+
if @basic_auth === true
|
22
|
+
@username = username.nil? ? Puree.username : username
|
23
|
+
@password = password.nil? ? Puree.password : password
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# Get
|
28
|
+
#
|
29
|
+
# @return [Hash]
|
30
|
+
def get
|
31
|
+
missing = missing_credentials
|
32
|
+
if !missing.empty?
|
33
|
+
missing.each do |m|
|
34
|
+
puts "#{self.class.name}" + '#' + "#{__method__} missing #{m}"
|
35
|
+
end
|
36
|
+
exit
|
37
|
+
end
|
38
|
+
|
39
|
+
# strip any trailing slash
|
40
|
+
@endpoint = @endpoint.sub(/(\/)+$/, '')
|
41
|
+
@auth = Base64::strict_encode64(@username + ':' + @password)
|
42
|
+
|
43
|
+
@options = {
|
44
|
+
basic_auth: @basic_auth,
|
45
|
+
latest_api: true,
|
46
|
+
resource_type: @resource_type.to_sym,
|
47
|
+
rendering: :system,
|
48
|
+
}
|
49
|
+
headers = {
|
50
|
+
'Accept' => 'application/xml',
|
51
|
+
'Authorization' => 'Basic ' + @auth
|
52
|
+
}
|
53
|
+
query = {}
|
54
|
+
query['rendering'] = @options[:rendering]
|
55
|
+
|
56
|
+
begin
|
57
|
+
url = build_url
|
58
|
+
req = HTTP.headers accept: headers['Accept']
|
59
|
+
if @options[:basic_auth]
|
60
|
+
req = req.auth headers['Authorization']
|
61
|
+
end
|
62
|
+
@response = req.get(url, params: query)
|
63
|
+
@doc = Nokogiri::XML @response.body
|
64
|
+
@doc.remove_namespaces!
|
65
|
+
rescue HTTP::Error => e
|
66
|
+
puts 'HTTP::Error '+ e.message
|
67
|
+
end
|
68
|
+
|
69
|
+
get_data? ? metadata : {}
|
70
|
+
end
|
71
|
+
|
72
|
+
# All metadata
|
73
|
+
#
|
74
|
+
# @return [Hash]
|
75
|
+
def metadata
|
76
|
+
o = {}
|
77
|
+
o['version'] = version
|
78
|
+
o
|
79
|
+
end
|
80
|
+
|
81
|
+
# Version
|
82
|
+
#
|
83
|
+
# @return [String]
|
84
|
+
def version
|
85
|
+
path = service_response_name + '/baseVersion'
|
86
|
+
xpath_query(path).text.strip
|
87
|
+
end
|
88
|
+
|
89
|
+
private
|
90
|
+
|
91
|
+
|
92
|
+
# Is there any data after get?
|
93
|
+
#
|
94
|
+
# @return [Boolean]
|
95
|
+
def get_data?
|
96
|
+
# n.b. arbitrary element existence check
|
97
|
+
path = service_response_name + '/baseVersion'
|
98
|
+
xpath_result = @doc.xpath path
|
99
|
+
xpath_result.size ? true : false
|
100
|
+
end
|
101
|
+
|
102
|
+
def service_name
|
103
|
+
resource_type = @options[:resource_type]
|
104
|
+
@api_map[:resource_type][resource_type][:service]
|
105
|
+
end
|
106
|
+
|
107
|
+
def service_response_name
|
108
|
+
resource_type = @options[:resource_type]
|
109
|
+
@api_map[:resource_type][resource_type][:response]
|
110
|
+
end
|
111
|
+
|
112
|
+
def build_url
|
113
|
+
service = service_name
|
114
|
+
if @options[:latest_api] === false
|
115
|
+
service_api_mode = service
|
116
|
+
else
|
117
|
+
service_api_mode = service + '.current'
|
118
|
+
end
|
119
|
+
@endpoint + '/' + service_api_mode
|
120
|
+
end
|
121
|
+
|
122
|
+
def xpath_query(path)
|
123
|
+
xml = @response.body
|
124
|
+
doc = Nokogiri::XML xml
|
125
|
+
doc.remove_namespaces!
|
126
|
+
doc.xpath path
|
127
|
+
end
|
128
|
+
|
129
|
+
def missing_credentials
|
130
|
+
missing = []
|
131
|
+
if @endpoint.nil?
|
132
|
+
missing << 'endpoint'
|
133
|
+
end
|
134
|
+
if @username.nil?
|
135
|
+
missing << 'username'
|
136
|
+
end
|
137
|
+
if @password.nil?
|
138
|
+
missing << 'password'
|
139
|
+
end
|
140
|
+
missing
|
141
|
+
end
|
142
|
+
|
143
|
+
alias :find :get
|
144
|
+
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
data/lib/puree/version.rb
CHANGED
data/puree.gemspec
CHANGED
@@ -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{
|
12
|
+
spec.description = %q{Purée 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
|
|
@@ -20,6 +20,6 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.required_ruby_version = '~> 2.1'
|
22
22
|
|
23
|
-
spec.add_runtime_dependency '
|
23
|
+
spec.add_runtime_dependency 'http', '~> 2.0'
|
24
24
|
spec.add_runtime_dependency 'nokogiri', '~> 1.6'
|
25
25
|
end
|
data/spec/collection.rb
CHANGED
@@ -3,7 +3,15 @@ require 'spec_helper'
|
|
3
3
|
describe 'Collection' do
|
4
4
|
|
5
5
|
it '#new' do
|
6
|
-
|
6
|
+
endpoint = ENV['PURE_ENDPOINT']
|
7
|
+
username = ENV['PURE_USERNAME']
|
8
|
+
password = ENV['PURE_PASSWORD']
|
9
|
+
p = Puree::Collection.new(resource: :dataset,
|
10
|
+
endpoint: endpoint,
|
11
|
+
username: username,
|
12
|
+
password: password,
|
13
|
+
basic_auth: true
|
14
|
+
)
|
7
15
|
expect(p).to be_an_instance_of Puree::Collection
|
8
16
|
end
|
9
17
|
|
@@ -12,15 +20,16 @@ describe 'Collection' do
|
|
12
20
|
endpoint = ENV['PURE_ENDPOINT']
|
13
21
|
username = ENV['PURE_USERNAME']
|
14
22
|
password = ENV['PURE_PASSWORD']
|
15
|
-
@p = Puree::Collection.new(
|
23
|
+
@p = Puree::Collection.new(resource: :dataset,
|
16
24
|
endpoint: endpoint,
|
17
25
|
username: username,
|
18
|
-
password: password
|
19
|
-
|
26
|
+
password: password,
|
27
|
+
basic_auth: true)
|
28
|
+
@metadata = @p.find limit: 5
|
20
29
|
end
|
21
30
|
|
22
|
-
it '
|
23
|
-
expect(@
|
31
|
+
it '@metadata' do
|
32
|
+
expect(@metadata).to be_an_instance_of(Array)
|
24
33
|
end
|
25
34
|
|
26
35
|
end
|
data/spec/dataset.rb
CHANGED
@@ -15,84 +15,85 @@ describe 'Dataset' do
|
|
15
15
|
uuid = ENV['PURE_DATASET_UUID']
|
16
16
|
@p = Puree::Dataset.new(endpoint: endpoint,
|
17
17
|
username: username,
|
18
|
-
password: password
|
19
|
-
|
18
|
+
password: password,
|
19
|
+
basic_auth: true)
|
20
|
+
@metadata = @p.find uuid: uuid
|
21
|
+
end
|
22
|
+
|
23
|
+
it '@metadata' do
|
24
|
+
expect(@metadata).to be_an_instance_of(Hash)
|
20
25
|
end
|
21
26
|
|
22
27
|
it '#access' do
|
23
|
-
expect(@
|
28
|
+
expect(@metadata['access']).to be_an_instance_of(String)
|
24
29
|
end
|
25
30
|
|
26
31
|
it '#associated' do
|
27
|
-
expect(@
|
32
|
+
expect(@metadata['associated']).to be_an_instance_of(Array)
|
28
33
|
end
|
29
34
|
|
30
35
|
it '#available' do
|
31
|
-
expect(@
|
36
|
+
expect(@metadata['available']).to be_an_instance_of(Hash)
|
32
37
|
end
|
33
38
|
|
34
39
|
it '#created' do
|
35
|
-
expect(@
|
40
|
+
expect(@metadata['created']).to be_an_instance_of(String)
|
36
41
|
end
|
37
42
|
|
38
43
|
it '#description' do
|
39
|
-
expect(@
|
44
|
+
expect(@metadata['description']).to be_an_instance_of(String)
|
40
45
|
end
|
41
46
|
|
42
47
|
it '#doi' do
|
43
|
-
expect(@
|
48
|
+
expect(@metadata['doi']).to be_an_instance_of(String)
|
44
49
|
end
|
45
50
|
|
46
51
|
it '#file' do
|
47
|
-
expect(@
|
52
|
+
expect(@metadata['file']).to be_an_instance_of(Array)
|
48
53
|
end
|
49
54
|
|
50
55
|
it '#geographical' do
|
51
|
-
expect(@
|
56
|
+
expect(@metadata['geographical']).to be_an_instance_of(Array)
|
52
57
|
end
|
53
58
|
|
54
59
|
it '#keyword' do
|
55
|
-
expect(@
|
60
|
+
expect(@metadata['keyword']).to be_an_instance_of(Array)
|
56
61
|
end
|
57
62
|
|
58
63
|
it '#link' do
|
59
|
-
expect(@
|
60
|
-
end
|
61
|
-
|
62
|
-
it '#metadata' do
|
63
|
-
expect(@p.metadata).to be_an_instance_of(Hash)
|
64
|
+
expect(@metadata['link']).to be_an_instance_of(Array)
|
64
65
|
end
|
65
66
|
|
66
67
|
it '#modified' do
|
67
|
-
expect(@
|
68
|
+
expect(@metadata['modified']).to be_an_instance_of(String)
|
68
69
|
end
|
69
70
|
|
70
71
|
it '#person' do
|
71
|
-
expect(@
|
72
|
+
expect(@metadata['person']).to be_an_instance_of(Hash)
|
72
73
|
end
|
73
74
|
|
74
75
|
it '#production' do
|
75
|
-
expect(@
|
76
|
+
expect(@metadata['production']).to be_an_instance_of(Hash)
|
76
77
|
end
|
77
78
|
|
78
79
|
it '#project' do
|
79
|
-
expect(@
|
80
|
+
expect(@metadata['project']).to be_an_instance_of(Array)
|
80
81
|
end
|
81
82
|
|
82
83
|
it '#publication' do
|
83
|
-
expect(@
|
84
|
+
expect(@metadata['publication']).to be_an_instance_of(Array)
|
84
85
|
end
|
85
86
|
|
86
87
|
it '#publisher' do
|
87
|
-
expect(@
|
88
|
+
expect(@metadata['publisher']).to be_an_instance_of(String)
|
88
89
|
end
|
89
90
|
|
90
91
|
it '#temporal' do
|
91
|
-
expect(@
|
92
|
+
expect(@metadata['temporal']).to be_an_instance_of(Hash)
|
92
93
|
end
|
93
94
|
|
94
95
|
it '#title' do
|
95
|
-
expect(@
|
96
|
+
expect(@metadata['title']).to be_an_instance_of(String)
|
96
97
|
end
|
97
98
|
|
98
99
|
|
data/spec/spec_helper.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'http'
|
2
2
|
require 'nokogiri'
|
3
3
|
require 'puree/configuration'
|
4
4
|
require 'puree/date'
|
@@ -12,4 +12,16 @@ require 'puree/person'
|
|
12
12
|
require 'puree/project'
|
13
13
|
require 'puree/publication'
|
14
14
|
require 'puree/publisher'
|
15
|
-
require 'puree/collection'
|
15
|
+
require 'puree/collection'
|
16
|
+
require 'puree/download'
|
17
|
+
require 'puree/server'
|
18
|
+
|
19
|
+
module Puree
|
20
|
+
|
21
|
+
class << self
|
22
|
+
|
23
|
+
include Puree::Configuration
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.15.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-
|
11
|
+
date: 2016-06-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: http
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0
|
19
|
+
version: '2.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0
|
26
|
+
version: '2.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: nokogiri
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,8 +38,8 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.6'
|
41
|
-
description:
|
42
|
-
|
41
|
+
description: Purée consumes the Pure Research Information System API and puts
|
42
|
+
the metadata into simple data structures.
|
43
43
|
email:
|
44
44
|
- a.albin-clark@lancaster.ac.uk
|
45
45
|
executables: []
|
@@ -67,6 +67,7 @@ files:
|
|
67
67
|
- lib/puree/publication.rb
|
68
68
|
- lib/puree/publisher.rb
|
69
69
|
- lib/puree/resource.rb
|
70
|
+
- lib/puree/server.rb
|
70
71
|
- lib/puree/version.rb
|
71
72
|
- puree.gemspec
|
72
73
|
- spec/collection.rb
|