puree 0.15.0 → 0.16.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 +12 -2
- data/README.md +8 -2
- data/lib/puree/collection.rb +30 -21
- data/lib/puree/configuration.rb +1 -1
- data/lib/puree/dataset.rb +235 -162
- data/lib/puree/download.rb +21 -16
- data/lib/puree/event.rb +68 -34
- data/lib/puree/journal.rb +15 -7
- data/lib/puree/organisation.rb +95 -61
- data/lib/puree/person.rb +67 -39
- data/lib/puree/project.rb +100 -55
- data/lib/puree/publication.rb +118 -63
- data/lib/puree/publisher.rb +15 -9
- data/lib/puree/resource.rb +23 -24
- data/lib/puree/server.rb +24 -16
- data/lib/puree/version.rb +1 -1
- data/puree.gemspec +1 -1
- data/spec/collection.rb +4 -4
- data/spec/dataset.rb +6 -6
- metadata +4 -4
data/lib/puree/download.rb
CHANGED
@@ -5,17 +5,17 @@ module Puree
|
|
5
5
|
class Download
|
6
6
|
attr_reader :response
|
7
7
|
|
8
|
-
# @param
|
9
|
-
# @param
|
10
|
-
# @param
|
11
|
-
# @param
|
12
|
-
def initialize(
|
8
|
+
# @param base_url [String]
|
9
|
+
# @param username [String]
|
10
|
+
# @param password [String]
|
11
|
+
# @param basic_auth [Boolean]
|
12
|
+
def initialize(base_url: nil,
|
13
13
|
username: nil,
|
14
14
|
password: nil,
|
15
15
|
basic_auth: nil)
|
16
16
|
@resource_type = :download
|
17
17
|
@api_map = Puree::Map.new.get
|
18
|
-
@
|
18
|
+
@base_url = base_url.nil? ? Puree.base_url : base_url
|
19
19
|
@basic_auth = basic_auth.nil? ? Puree.basic_auth : basic_auth
|
20
20
|
if @basic_auth === true
|
21
21
|
@username = username.nil? ? Puree.username : username
|
@@ -25,9 +25,9 @@ module Puree
|
|
25
25
|
|
26
26
|
# Get
|
27
27
|
#
|
28
|
-
# @param
|
29
|
-
# @param
|
30
|
-
# @param
|
28
|
+
# @param limit [Integer]
|
29
|
+
# @param offset [Integer]
|
30
|
+
# @param resource [Symbol]
|
31
31
|
# @return [Array<Hash>]
|
32
32
|
def get(limit: 20,
|
33
33
|
offset: 0,
|
@@ -41,7 +41,7 @@ module Puree
|
|
41
41
|
end
|
42
42
|
|
43
43
|
# strip any trailing slash
|
44
|
-
@
|
44
|
+
@base_url = @base_url.sub(/(\/)+$/, '')
|
45
45
|
@auth = Base64::strict_encode64(@username + ':' + @password)
|
46
46
|
|
47
47
|
@options = {
|
@@ -85,7 +85,7 @@ module Puree
|
|
85
85
|
puts 'HTTP::Error '+ e.message
|
86
86
|
end
|
87
87
|
|
88
|
-
get_data? ?
|
88
|
+
get_data? ? combine_metadata : []
|
89
89
|
end
|
90
90
|
|
91
91
|
|
@@ -95,12 +95,17 @@ module Puree
|
|
95
95
|
#
|
96
96
|
# @return [Array<Hash>]
|
97
97
|
def metadata
|
98
|
-
|
98
|
+
@metadata
|
99
99
|
end
|
100
100
|
|
101
101
|
|
102
102
|
private
|
103
103
|
|
104
|
+
|
105
|
+
def combine_metadata
|
106
|
+
@metadata = extract_statistic
|
107
|
+
end
|
108
|
+
|
104
109
|
# Is there any data after get?
|
105
110
|
#
|
106
111
|
# @return [Boolean]
|
@@ -114,7 +119,7 @@ module Puree
|
|
114
119
|
# Statistic
|
115
120
|
#
|
116
121
|
# @return [Array<Hash>]
|
117
|
-
def
|
122
|
+
def extract_statistic
|
118
123
|
path = service_response_name + '/downloadCount'
|
119
124
|
xpath_result = xpath_query path
|
120
125
|
data_arr = []
|
@@ -154,7 +159,7 @@ module Puree
|
|
154
159
|
else
|
155
160
|
service_api_mode = service + '.current'
|
156
161
|
end
|
157
|
-
@
|
162
|
+
@base_url + '/' + service_api_mode
|
158
163
|
end
|
159
164
|
|
160
165
|
def xpath_query(path)
|
@@ -166,8 +171,8 @@ module Puree
|
|
166
171
|
|
167
172
|
def missing_credentials
|
168
173
|
missing = []
|
169
|
-
if @
|
170
|
-
missing << '
|
174
|
+
if @base_url.nil?
|
175
|
+
missing << 'base_url'
|
171
176
|
end
|
172
177
|
if @username.nil?
|
173
178
|
missing << 'username'
|
data/lib/puree/event.rb
CHANGED
@@ -4,94 +4,128 @@ module Puree
|
|
4
4
|
#
|
5
5
|
class Event < Resource
|
6
6
|
|
7
|
-
# @param
|
8
|
-
# @param
|
9
|
-
# @param
|
10
|
-
# @param
|
11
|
-
def initialize(
|
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: :event,
|
13
|
-
|
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
19
|
|
20
|
-
|
21
|
-
|
22
20
|
# City
|
23
21
|
#
|
24
22
|
# @return [String]
|
25
23
|
def city
|
26
|
-
|
27
|
-
xpath_query(path).text.strip
|
24
|
+
@metadata['city']
|
28
25
|
end
|
29
26
|
|
30
27
|
# Country
|
31
28
|
#
|
32
29
|
# @return [String]
|
33
30
|
def country
|
34
|
-
|
35
|
-
xpath_query(path).text.strip
|
31
|
+
@metadata['country']
|
36
32
|
end
|
37
33
|
|
38
34
|
# Date
|
39
35
|
#
|
40
36
|
# @return [Hash]
|
41
37
|
def date
|
42
|
-
|
43
|
-
path = '/dateRange'
|
44
|
-
range = xpath_query path
|
45
|
-
data['start'] = range.xpath('startDate').text.strip
|
46
|
-
data['end'] = range.xpath('startDate').text.strip
|
47
|
-
data
|
38
|
+
@metadata['date']
|
48
39
|
end
|
49
40
|
|
50
41
|
# Description
|
51
42
|
#
|
52
43
|
# @return [String]
|
53
44
|
def description
|
54
|
-
|
55
|
-
xpath_query(path).text.strip
|
45
|
+
@metadata['description']
|
56
46
|
end
|
57
47
|
|
58
48
|
# Location
|
59
49
|
#
|
60
50
|
# @return [String]
|
61
51
|
def location
|
62
|
-
|
63
|
-
xpath_query(path).text.strip
|
52
|
+
@metadata['location']
|
64
53
|
end
|
65
54
|
|
66
55
|
# Title
|
67
56
|
#
|
68
57
|
# @return [String]
|
69
58
|
def title
|
70
|
-
|
71
|
-
xpath_query_for_single_value path
|
59
|
+
@metadata['title']
|
72
60
|
end
|
73
61
|
|
74
62
|
# Type
|
75
63
|
#
|
76
64
|
# @return [String]
|
77
65
|
def type
|
78
|
-
|
79
|
-
xpath_query_for_single_value path
|
66
|
+
@metadata['type']
|
80
67
|
end
|
81
68
|
|
82
69
|
# All metadata
|
83
70
|
#
|
84
71
|
# @return [Hash]
|
85
72
|
def metadata
|
73
|
+
@metadata
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
private
|
79
|
+
|
80
|
+
def extract_city
|
81
|
+
path = '/city'
|
82
|
+
xpath_query(path).text.strip
|
83
|
+
end
|
84
|
+
|
85
|
+
def extract_country
|
86
|
+
path = '/country/term/localizedString'
|
87
|
+
xpath_query(path).text.strip
|
88
|
+
end
|
89
|
+
|
90
|
+
def extract_date
|
91
|
+
data = {}
|
92
|
+
path = '/dateRange'
|
93
|
+
range = xpath_query path
|
94
|
+
data['start'] = range.xpath('startDate').text.strip
|
95
|
+
data['end'] = range.xpath('startDate').text.strip
|
96
|
+
data
|
97
|
+
end
|
98
|
+
|
99
|
+
def extract_description
|
100
|
+
path = '/description'
|
101
|
+
xpath_query(path).text.strip
|
102
|
+
end
|
103
|
+
|
104
|
+
def extract_location
|
105
|
+
path = '/location'
|
106
|
+
xpath_query(path).text.strip
|
107
|
+
end
|
108
|
+
|
109
|
+
def extract_title
|
110
|
+
path = '/title/localizedString'
|
111
|
+
xpath_query_for_single_value path
|
112
|
+
end
|
113
|
+
|
114
|
+
def extract_type
|
115
|
+
path = '//typeClassification/term/localizedString'
|
116
|
+
xpath_query_for_single_value path
|
117
|
+
end
|
118
|
+
|
119
|
+
def combine_metadata
|
86
120
|
o = super
|
87
|
-
o['city'] =
|
88
|
-
o['country'] =
|
89
|
-
o['date'] =
|
90
|
-
o['description'] =
|
91
|
-
o['location'] =
|
92
|
-
o['title'] =
|
93
|
-
o['type'] =
|
94
|
-
o
|
121
|
+
o['city'] = extract_city
|
122
|
+
o['country'] = extract_country
|
123
|
+
o['date'] = extract_date
|
124
|
+
o['description'] = extract_description
|
125
|
+
o['location'] = extract_location
|
126
|
+
o['title'] = extract_title
|
127
|
+
o['type'] = extract_type
|
128
|
+
@metadata = o
|
95
129
|
end
|
96
130
|
|
97
131
|
end
|
data/lib/puree/journal.rb
CHANGED
@@ -4,13 +4,13 @@ module Puree
|
|
4
4
|
#
|
5
5
|
class Journal < Resource
|
6
6
|
|
7
|
-
# @param
|
8
|
-
# @param
|
9
|
-
# @param
|
10
|
-
# @param
|
11
|
-
def initialize(
|
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: :journal,
|
13
|
-
|
13
|
+
base_url: base_url,
|
14
14
|
username: username,
|
15
15
|
password: password,
|
16
16
|
basic_auth: basic_auth)
|
@@ -21,7 +21,15 @@ module Puree
|
|
21
21
|
#
|
22
22
|
# @return [Hash]
|
23
23
|
def metadata
|
24
|
-
|
24
|
+
@metadata
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def combine_metadata
|
31
|
+
o = super
|
32
|
+
@metadata = o
|
25
33
|
end
|
26
34
|
|
27
35
|
end
|
data/lib/puree/organisation.rb
CHANGED
@@ -4,123 +4,116 @@ module Puree
|
|
4
4
|
#
|
5
5
|
class Organisation < Resource
|
6
6
|
|
7
|
-
# @param
|
8
|
-
# @param
|
9
|
-
# @param
|
10
|
-
# @param
|
11
|
-
def initialize(
|
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: :organisation,
|
13
|
-
|
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
|
# Address
|
22
20
|
#
|
23
21
|
# @return [Array<Hash>]
|
24
22
|
def address
|
25
|
-
|
26
|
-
xpath_result = xpath_query path
|
27
|
-
|
28
|
-
data = []
|
29
|
-
|
30
|
-
xpath_result.each do |d|
|
31
|
-
o = {}
|
32
|
-
o['street'] = d.xpath('street').text.strip
|
33
|
-
o['building'] = d.xpath('building').text.strip
|
34
|
-
o['postcode'] = d.xpath('postalCode').text.strip
|
35
|
-
o['city'] = d.xpath('city').text.strip
|
36
|
-
o['country'] = d.xpath('country/term/localizedString').text.strip
|
37
|
-
data << o
|
38
|
-
end
|
39
|
-
data.uniq
|
23
|
+
@metadata['address']
|
40
24
|
end
|
41
25
|
|
42
26
|
# Email
|
43
27
|
#
|
44
28
|
# @return [Array<String>]
|
45
29
|
def email
|
46
|
-
|
47
|
-
xpath_result = xpath_query path
|
48
|
-
arr = []
|
49
|
-
xpath_result.each { |i| arr << i.text.strip }
|
50
|
-
arr.uniq
|
30
|
+
@metadata['email']
|
51
31
|
end
|
52
32
|
|
53
33
|
# Name
|
54
34
|
#
|
55
35
|
# @return [String]
|
56
36
|
def name
|
57
|
-
|
58
|
-
|
37
|
+
@metadata['name']
|
38
|
+
end
|
39
|
+
|
40
|
+
# Organisation
|
41
|
+
#
|
42
|
+
# @return [Array<Hash>]
|
43
|
+
def organisation
|
44
|
+
@metadata['organisation']
|
59
45
|
end
|
60
46
|
|
61
47
|
# Parent
|
62
48
|
#
|
63
49
|
# @return [Hash]
|
64
50
|
def parent
|
65
|
-
|
66
|
-
o = {}
|
67
|
-
if !data.empty?
|
68
|
-
o = data.first
|
69
|
-
end
|
70
|
-
o
|
51
|
+
@metadata['parent']
|
71
52
|
end
|
72
53
|
|
73
54
|
# Phone
|
74
55
|
#
|
75
56
|
# @return [Array<String>]
|
76
57
|
def phone
|
77
|
-
|
78
|
-
xpath_result = xpath_query path
|
79
|
-
arr = []
|
80
|
-
xpath_result.each { |i| arr << i.text.strip }
|
81
|
-
arr.uniq
|
58
|
+
@metadata['phone']
|
82
59
|
end
|
83
60
|
|
84
61
|
# Type
|
85
62
|
#
|
86
63
|
# @return [String]
|
87
64
|
def type
|
88
|
-
|
89
|
-
xpath_query_for_single_value path
|
65
|
+
@metadata['type']
|
90
66
|
end
|
91
67
|
|
92
68
|
# URL
|
93
69
|
#
|
94
70
|
# @return [Array<String>]
|
95
71
|
def url
|
96
|
-
|
97
|
-
xpath_result = xpath_query path
|
98
|
-
arr = []
|
99
|
-
xpath_result.each { |i| arr << i.text.strip }
|
100
|
-
arr.uniq
|
72
|
+
@metadata['url']
|
101
73
|
end
|
102
74
|
|
103
75
|
# All metadata
|
104
76
|
#
|
105
77
|
# @return [Hash]
|
106
78
|
def metadata
|
107
|
-
|
108
|
-
o['address'] = address
|
109
|
-
o['email'] = email
|
110
|
-
o['name'] = name
|
111
|
-
o['parent'] = parent
|
112
|
-
o['phone'] = phone
|
113
|
-
o['type'] = type
|
114
|
-
o['url'] = url
|
115
|
-
o
|
79
|
+
@metadata
|
116
80
|
end
|
117
81
|
|
118
82
|
|
83
|
+
private
|
119
84
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
85
|
+
def extract_address
|
86
|
+
path = '/addresses/classifiedAddress'
|
87
|
+
xpath_result = xpath_query path
|
88
|
+
|
89
|
+
data = []
|
90
|
+
|
91
|
+
xpath_result.each do |d|
|
92
|
+
o = {}
|
93
|
+
o['street'] = d.xpath('street').text.strip
|
94
|
+
o['building'] = d.xpath('building').text.strip
|
95
|
+
o['postcode'] = d.xpath('postalCode').text.strip
|
96
|
+
o['city'] = d.xpath('city').text.strip
|
97
|
+
o['country'] = d.xpath('country/term/localizedString').text.strip
|
98
|
+
data << o
|
99
|
+
end
|
100
|
+
data.uniq
|
101
|
+
end
|
102
|
+
|
103
|
+
def extract_email
|
104
|
+
path = '/emails/classificationDefinedStringFieldExtension/value'
|
105
|
+
xpath_result = xpath_query path
|
106
|
+
arr = []
|
107
|
+
xpath_result.each { |i| arr << i.text.strip }
|
108
|
+
arr.uniq
|
109
|
+
end
|
110
|
+
|
111
|
+
def extract_name
|
112
|
+
path = '/name/localizedString'
|
113
|
+
xpath_query_for_single_value path
|
114
|
+
end
|
115
|
+
|
116
|
+
def extract_organisation
|
124
117
|
path = '/organisations/organisation'
|
125
118
|
xpath_result = xpath_query path
|
126
119
|
|
@@ -136,6 +129,47 @@ module Puree
|
|
136
129
|
data.uniq
|
137
130
|
end
|
138
131
|
|
132
|
+
def extract_parent
|
133
|
+
data = extract_organisation
|
134
|
+
o = {}
|
135
|
+
if !data.empty?
|
136
|
+
o = data.first
|
137
|
+
end
|
138
|
+
o
|
139
|
+
end
|
140
|
+
|
141
|
+
def extract_phone
|
142
|
+
path = '/phoneNumbers/classificationDefinedStringFieldExtension/value'
|
143
|
+
xpath_result = xpath_query path
|
144
|
+
arr = []
|
145
|
+
xpath_result.each { |i| arr << i.text.strip }
|
146
|
+
arr.uniq
|
147
|
+
end
|
148
|
+
|
149
|
+
def extract_type
|
150
|
+
path = '/typeClassification/term/localizedString'
|
151
|
+
xpath_query_for_single_value path
|
152
|
+
end
|
153
|
+
|
154
|
+
def extract_url
|
155
|
+
path = '/webAddresses/classificationDefinedFieldExtension/value/localizedString'
|
156
|
+
xpath_result = xpath_query path
|
157
|
+
arr = []
|
158
|
+
xpath_result.each { |i| arr << i.text.strip }
|
159
|
+
arr.uniq
|
160
|
+
end
|
161
|
+
|
162
|
+
def combine_metadata
|
163
|
+
o = super
|
164
|
+
o['address'] = extract_address
|
165
|
+
o['email'] = extract_email
|
166
|
+
o['name'] = extract_name
|
167
|
+
o['parent'] = extract_parent
|
168
|
+
o['phone'] = extract_phone
|
169
|
+
o['type'] = extract_type
|
170
|
+
o['url'] = extract_url
|
171
|
+
@metadata = o
|
172
|
+
end
|
139
173
|
|
140
174
|
end
|
141
175
|
|