puree 1.6.0 → 1.7.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: a5f9f37e95e788189e6f4acb7a066e5732e157e8
4
- data.tar.gz: b1f37ec7f78e5adef5d0443f565b5526bc2f85c9
3
+ metadata.gz: 585ed698743104873457d87a11f27bb057dbf058
4
+ data.tar.gz: d07c203393a1bf086334717f3ba1a7522b6ad112
5
5
  SHA512:
6
- metadata.gz: 7356834acf18066281420d8794360b747828f684fe7a709f22b01a38f4cc2c67768a66aa7f72f4b3b7c7b227014115a8eae66d22e1f77221e892b5ecfc56b33d
7
- data.tar.gz: 499e3b30bedd4b2d08c957f041fd070488a63af104f5bcc06689f3df2a0086e6b290d35c2e39370c9c43aafbe5785f43439e6eacaf6aa2aabfea2e92de803560
6
+ metadata.gz: 18bf2dc5e85692a4a9f575426c8716ace87239070f84545a57de4cb9936ebee91c4321ac53a1e87e0fe7ad20409c663efd3fe09f434ac28487e15acacfc343bb
7
+ data.tar.gz: 0e6696e6c19c715186622a29bb73e2175a8ed0aed1c69bf220aed3d03f9653fbe86614ee317657d56c276d9779fc582b54aba324e0030d540b41e13c5a45a6fd
data/CHANGELOG.md CHANGED
@@ -5,6 +5,14 @@ This project adheres to [Semantic Versioning](http://semver.org/).
5
5
  ## Unreleased
6
6
  - Metadata: activity?, clipping?, externalPerson?
7
7
 
8
+ ## 1.7.0 - 2017-11-03
9
+ ### Added
10
+ - Person extractor - find by identifier.
11
+ - Person - HESA id, Scopus id.
12
+
13
+ ### Fixed
14
+ - Person - employee_id presence.
15
+
8
16
  ## 1.6.0 - 2017-10-24
9
17
  ### Added
10
18
  - ExternalOrganisation.
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Purée
1
+ # Purée
2
2
 
3
3
  Metadata extraction from the Pure Research Information System.
4
4
 
@@ -126,7 +126,7 @@ funding_query.project_funders uuid: 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
126
126
  #<Puree::Model::ExternalOrganisation:0x98986f0>
127
127
  ```
128
128
 
129
- Who are the funders (if any) for a publication, via a project?
129
+ Who are the funders (if any) for a publication?
130
130
 
131
131
  ```ruby
132
132
  funding_query.publication_funders uuid: 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
data/lib/puree.rb CHANGED
@@ -42,6 +42,7 @@ require 'puree/xml_extractor/server'
42
42
 
43
43
  require 'puree/api/map'
44
44
  require 'puree/api/request'
45
+ require 'puree/api/person_request'
45
46
  require 'puree/api/configuration'
46
47
  require 'puree/api/authentication'
47
48
 
@@ -0,0 +1,64 @@
1
+ module Puree
2
+
3
+ module API
4
+
5
+ # Handles requests to Pure.
6
+ #
7
+ class PersonRequest < Puree::API::Request
8
+
9
+ def initialize(url:)
10
+ super
11
+ end
12
+
13
+ # Perform a GET request to Pure
14
+ #
15
+ # @param uuid [String]
16
+ # @param id [String]
17
+ # @param employee_id [String]
18
+ # @param rendering [String]
19
+ # @param latest_api [Boolean]
20
+ # @param resource_type [String]
21
+ # @return [HTTP::Response]
22
+ def get(uuid: nil,
23
+ id: nil,
24
+ employee_id: nil,
25
+ rendering: :xml_long,
26
+ latest_api: true,
27
+ resource_type:)
28
+ @latest_api = latest_api
29
+ @resource_type = resource_type.to_sym
30
+ @rendering = rendering
31
+ @uuid = uuid
32
+ @id = id
33
+ @employee_id = employee_id
34
+
35
+ # strip any trailing slash
36
+ @url = @url.sub(/(\/)+$/, '')
37
+ @headers['Accept'] = 'application/xml'
38
+ @req = HTTP.headers accept: @headers['Accept']
39
+ if @headers['Authorization']
40
+ @req = @req.auth @headers['Authorization']
41
+ end
42
+ @req.get(build_url, params: parameters)
43
+ end
44
+
45
+ private
46
+
47
+ def parameters
48
+ query = {}
49
+ if @uuid
50
+ query['uuids.uuid'] = @uuid
51
+ elsif @id
52
+ query['pureInternalIds.id'] = @id
53
+ elsif @employee_id
54
+ query['personEmployeeIds.value'] = @employee_id
55
+ end
56
+ query['rendering'] = @rendering
57
+ query
58
+ end
59
+
60
+ end
61
+
62
+ end
63
+
64
+ end
@@ -25,6 +25,7 @@ module Puree
25
25
  #
26
26
  # @param uuid [String]
27
27
  # @param id [String]
28
+ # @param params [Hash]
28
29
  # @param rendering [String]
29
30
  # @param latest_api [Boolean]
30
31
  # @param resource_type [String]
@@ -38,6 +39,7 @@ module Puree
38
39
  # @return [HTTP::Response]
39
40
  def get(uuid: nil,
40
41
  id: nil,
42
+ params: {},
41
43
  rendering: :xml_long,
42
44
  latest_api: true,
43
45
  resource_type:,
@@ -53,6 +55,7 @@ module Puree
53
55
  @rendering = rendering
54
56
  @uuid = uuid
55
57
  @id = id
58
+ @params = params
56
59
  @limit = limit
57
60
  @offset = offset
58
61
  @created_start = created_start
@@ -68,12 +71,12 @@ module Puree
68
71
  if @headers['Authorization']
69
72
  @req = @req.auth @headers['Authorization']
70
73
  end
71
- @req.get(build_url, params: params)
74
+ @req.get(build_url, params: parameters)
72
75
  end
73
76
 
74
77
  private
75
78
 
76
- def params
79
+ def parameters
77
80
  query = {}
78
81
  if @uuid
79
82
  query['uuids.uuid'] = @uuid
@@ -42,6 +42,18 @@ module Puree
42
42
  @model
43
43
  end
44
44
 
45
+ def configure_api(config)
46
+ @config = Puree::API::Configuration.new url: config[:url]
47
+ @config.basic_auth username: config[:username],
48
+ password: config[:password]
49
+
50
+ @request = Puree::API::PersonRequest.new url: @config.url
51
+ if @config.basic_auth?
52
+ @request.basic_auth username: @config.username,
53
+ password: @config.password
54
+ end
55
+ end
56
+
45
57
  end
46
58
 
47
59
  end
@@ -12,6 +12,22 @@ module Puree
12
12
  setup :person
13
13
  end
14
14
 
15
+ # Find a person by identifier.
16
+ #
17
+ # @param uuid [String]
18
+ # @param id [String]
19
+ # @param employee_id [String]
20
+ # @return [Puree::Model::Person]
21
+ def find_by_id(uuid: nil, id: nil, employee_id: nil)
22
+ raise 'Cannot perform a request without a configuration' if @config.nil?
23
+ @response = @request.get uuid: uuid,
24
+ id: id,
25
+ employee_id: employee_id,
26
+ latest_api: @latest_api,
27
+ resource_type: @resource_type
28
+ set_content @response.body
29
+ end
30
+
15
31
  private
16
32
 
17
33
  def combine_metadata
@@ -19,13 +35,33 @@ module Puree
19
35
  @model.affiliations = @extractor.affiliations
20
36
  @model.email_addresses = @extractor.email_addresses
21
37
  @model.employee_id = @extractor.employee_id
38
+ @model.hesa_id = @extractor.hesa_id
22
39
  @model.image_urls = @extractor.image_urls
23
40
  @model.keywords = @extractor.keywords
24
41
  @model.name = @extractor.name
25
42
  @model.orcid = @extractor.orcid
43
+ @model.scopus_id = @extractor.scopus_id
26
44
  @model
27
45
  end
28
46
 
47
+ # Configure a Pure host for API access.
48
+ #
49
+ # @param config [Hash]
50
+ # @option config [String] :url The URL of the Pure host.
51
+ # @option config [String] :username The username of the Pure host account.
52
+ # @option config [String] :password The password of the Pure host account.
53
+ def configure_api(config)
54
+ @config = Puree::API::Configuration.new url: config[:url]
55
+ @config.basic_auth username: config[:username],
56
+ password: config[:password]
57
+
58
+ @request = Puree::API::PersonRequest.new url: @config.url
59
+ if @config.basic_auth?
60
+ @request.basic_auth username: @config.username,
61
+ password: @config.password
62
+ end
63
+ end
64
+
29
65
  end
30
66
 
31
67
  end
@@ -14,6 +14,9 @@ module Puree
14
14
  # @return [String, nil]
15
15
  attr_accessor :employee_id
16
16
 
17
+ # @return [String, nil]
18
+ attr_accessor :hesa_id
19
+
17
20
  # @return [Array<String>]
18
21
  attr_accessor :image_urls
19
22
 
@@ -26,6 +29,9 @@ module Puree
26
29
  # @return [String, nil]
27
30
  attr_accessor :orcid
28
31
 
32
+ # @return [String, nil]
33
+ attr_accessor :scopus_id
34
+
29
35
  end
30
36
  end
31
37
  end
@@ -26,7 +26,7 @@ module Puree
26
26
  end
27
27
  end
28
28
  end
29
- deduplicate_funders funders
29
+ funders.uniq { |i| i.uuid }
30
30
  end
31
31
 
32
32
  # Publication funders
@@ -44,22 +44,7 @@ module Puree
44
44
  end
45
45
  end
46
46
  end
47
- deduplicate_funders funders
48
- end
49
-
50
- private
51
-
52
- def deduplicate_funders(funders)
53
- uuids_in_list = []
54
- funder_list = []
55
- funders.each do |funder|
56
- uuid = funder.uuid
57
- unless uuids_in_list.include? uuid
58
- funder_list << funder
59
- uuids_in_list << uuid
60
- end
61
- end
62
- funder_list
47
+ funders.uniq { |i| i.uuid }
63
48
  end
64
49
 
65
50
  end
data/lib/puree/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Puree
2
2
  # Semantic version number
3
3
  #
4
- VERSION = "1.6.0"
4
+ VERSION = "1.7.0"
5
5
  end
@@ -24,14 +24,12 @@ module Puree
24
24
 
25
25
  # @return [String, nil]
26
26
  def employee_id
27
- xpath_result = xpath_query '/sources/classificationDefinedStringFieldExtension'
28
- if xpath_result
29
- xpath_result.each do |i|
30
- if i.xpath('classification/uri').text.strip === '/dk/atira/pure/person/personsources/employee'
31
- return i.xpath('value').text.strip
32
- end
33
- end
34
- end
27
+ id '/dk/atira/pure/person/personsources/employee'
28
+ end
29
+
30
+ # @return [String, nil]
31
+ def hesa_id
32
+ id '/dk/atira/pure/person/personsources/hesastaff'
35
33
  end
36
34
 
37
35
  # @return [Array<String>]
@@ -62,6 +60,26 @@ module Puree
62
60
  xpath_query_for_single_value '/orcid'
63
61
  end
64
62
 
63
+ # @return [String, nil]
64
+ def scopus_id
65
+ id '/dk/atira/pure/person/personsources/scopusauthor'
66
+ end
67
+
68
+ private
69
+
70
+ # @return [String, nil]
71
+ def id(uri)
72
+ xpath_result = xpath_query '/sources/classificationDefinedStringFieldExtension'
73
+ if xpath_result
74
+ xpath_result.each do |i|
75
+ if i.xpath('classification/uri').text.strip === uri
76
+ return i.xpath('value').text.strip
77
+ end
78
+ end
79
+ end
80
+ nil
81
+ end
82
+
65
83
  end
66
84
 
67
85
  end
@@ -25,6 +25,28 @@ describe 'Person' do
25
25
  expect(publications).to all( be_a Puree::Model::Publication )
26
26
  end
27
27
 
28
+ it '#publications_offset' do
29
+ publications = @q.publications uuid: @person_uuid,
30
+ limit: 3,
31
+ offset: 1
32
+ expect(publications).to all( be_a Puree::Model::Publication )
33
+ end
34
+
35
+ it '#publications_published_start' do
36
+ publications = @q.publications uuid: @person_uuid,
37
+ limit: 3,
38
+ published_start: '2017-01-01'
39
+ expect(publications).to all( be_a Puree::Model::Publication )
40
+ end
41
+
42
+ it '#publications_published_start_published_end' do
43
+ publications = @q.publications uuid: @person_uuid,
44
+ limit: 3,
45
+ published_start: '2017-01-01',
46
+ published_end: '2017-12-31'
47
+ expect(publications).to all( be_a Puree::Model::Publication )
48
+ end
49
+
28
50
  end
29
51
 
30
52
  end
@@ -31,6 +31,10 @@ describe 'Person' do
31
31
  expect(@p.employee_id).to be_a String if @p.employee_id
32
32
  end
33
33
 
34
+ it '#hesa_id' do
35
+ expect(@p.hesa_id).to be_a String if @p.hesa_id
36
+ end
37
+
34
38
  it '#image_urls' do
35
39
  expect(@p.image_urls).to all( be_a String )
36
40
  end
@@ -47,6 +51,10 @@ describe 'Person' do
47
51
  expect(@p.orcid).to be_a String if @p.orcid
48
52
  end
49
53
 
54
+ it '#scopus_id' do
55
+ expect(@p.scopus_id).to be_a String if @p.scopus_id
56
+ end
57
+
50
58
  end
51
59
 
52
60
  end
data/spec/spec_helper.rb CHANGED
@@ -42,6 +42,7 @@ require 'puree/xml_extractor/server'
42
42
 
43
43
  require 'puree/api/map'
44
44
  require 'puree/api/request'
45
+ require 'puree/api/person_request'
45
46
  require 'puree/api/configuration'
46
47
  require 'puree/api/authentication'
47
48
 
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: 1.6.0
4
+ version: 1.7.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: 2017-10-24 00:00:00.000000000 Z
11
+ date: 2017-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http
@@ -70,6 +70,7 @@ files:
70
70
  - lib/puree/api/authentication.rb
71
71
  - lib/puree/api/configuration.rb
72
72
  - lib/puree/api/map.rb
73
+ - lib/puree/api/person_request.rb
73
74
  - lib/puree/api/request.rb
74
75
  - lib/puree/extractor/collection.rb
75
76
  - lib/puree/extractor/conference_paper.rb