puree 2.1.1 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -0
  3. data/README.md +17 -7
  4. data/lib/puree/extractor/conference_paper.rb +5 -4
  5. data/lib/puree/extractor/dataset.rb +18 -8
  6. data/lib/puree/extractor/doctoral_thesis.rb +5 -9
  7. data/lib/puree/extractor/event.rb +18 -8
  8. data/lib/puree/extractor/external_organisation.rb +18 -8
  9. data/lib/puree/extractor/journal.rb +18 -8
  10. data/lib/puree/extractor/journal_article.rb +12 -9
  11. data/lib/puree/extractor/masters_thesis.rb +5 -9
  12. data/lib/puree/extractor/organisational_unit.rb +18 -8
  13. data/lib/puree/extractor/paper.rb +5 -4
  14. data/lib/puree/extractor/person.rb +18 -3
  15. data/lib/puree/extractor/project.rb +18 -3
  16. data/lib/puree/extractor/publisher.rb +18 -3
  17. data/lib/puree/extractor/research_output.rb +27 -3
  18. data/lib/puree/extractor/resource.rb +16 -1
  19. data/lib/puree/extractor/thesis.rb +5 -9
  20. data/lib/puree/rest/activity.rb +0 -5
  21. data/lib/puree/rest/application.rb +0 -5
  22. data/lib/puree/rest/classification_scheme.rb +0 -5
  23. data/lib/puree/rest/curricula_vitae.rb +0 -5
  24. data/lib/puree/rest/dataset.rb +0 -5
  25. data/lib/puree/rest/equipment.rb +0 -5
  26. data/lib/puree/rest/event.rb +0 -5
  27. data/lib/puree/rest/external_organisation.rb +0 -5
  28. data/lib/puree/rest/external_person.rb +0 -5
  29. data/lib/puree/rest/impact.rb +0 -5
  30. data/lib/puree/rest/journal.rb +0 -5
  31. data/lib/puree/rest/organisational_unit.rb +0 -5
  32. data/lib/puree/rest/person.rb +0 -5
  33. data/lib/puree/rest/press_media.rb +0 -5
  34. data/lib/puree/rest/prize.rb +0 -5
  35. data/lib/puree/rest/project.rb +0 -5
  36. data/lib/puree/rest/publisher.rb +0 -5
  37. data/lib/puree/rest/research_output.rb +0 -5
  38. data/lib/puree/version.rb +1 -1
  39. data/lib/puree/xml_extractor/collection.rb +14 -0
  40. data/test/extractor/resource_count_test.rb +68 -0
  41. data/test/extractor/{resource_test.rb → resource_find_test.rb} +0 -0
  42. data/test/extractor/resource_random_test.rb +66 -0
  43. data/test/test_helper.rb +1 -1
  44. metadata +8 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8606b12e11591ec4334727202ae94c999da7e2ce
4
- data.tar.gz: 8a44e408a74e383891861e0ae275945b4bcd0dda
3
+ metadata.gz: be040161fa2a4bfb0252b864310d90d56e88ac19
4
+ data.tar.gz: 1b6437a55b0e4d08da2dd59af0bb5b68278d770e
5
5
  SHA512:
6
- metadata.gz: 7b9158b6150662333fbab474f62f8fb43f81ef6d431c0fad7b00cbd4caee07e3b5d35521532262955ec79db8637594e6a8c7cfaf59fe2b9ee7f6f54411037fea
7
- data.tar.gz: 054591f8cb907856077074bca300fab524e7e9c5d8f5f5170cca1296c71b972a6ab71efd2c434427dc4cce69a57dd2358ca0be000266c9cdddc8577933baac44
6
+ metadata.gz: 8ffe42bacb00c82a8fc81c2c70fec93a30d2cfd01e171d1999b18d878741f91a6ba02769ed079e11c3af0858e84fc9cedf135923e4df2d00af8fcc00c10bd11f
7
+ data.tar.gz: bca33fed3f5467ed1c62153c2100eb26cb3252f427e66b140934fb38648b449d45dc03da742247048bc6beffc2ea85f1dafb2c3f9e943e0ae27aa26a53242b32
@@ -2,6 +2,10 @@
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
+ ## 2.2.0 2018-04-20
6
+ ### Added
7
+ - Count, random for resource extractors.
8
+
5
9
  ## 2.1.1 2018-04-18
6
10
  ### Fixed
7
11
  - Handle missing created and modified.
data/README.md CHANGED
@@ -33,15 +33,25 @@ config = {
33
33
  ```
34
34
 
35
35
  ## Extractor module
36
- Find a resource by identifier and get Ruby objects.
37
-
38
36
  ```ruby
39
- # Configure an extractor
37
+ # Configure an extractor for a resource
40
38
  extractor = Puree::Extractor::Dataset.new config
41
39
  ```
42
40
 
43
41
  ```ruby
44
- # Fetch the metadata for a resource with a particular identifier
42
+ # Find out how many records are available
43
+ extractor.count
44
+ #=> 1000
45
+ ```
46
+
47
+ ```ruby
48
+ # Fetch a random record
49
+ extractor.random
50
+ #=> #<Puree::Model::Dataset:0x00c0ffee>
51
+ ```
52
+
53
+ ```ruby
54
+ # Fetch the metadata for a record with a particular identifier
45
55
  dataset = extractor.find 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
46
56
  #=> #<Puree::Model::Dataset:0x00c0ffee>
47
57
  ```
@@ -61,7 +71,7 @@ dataset.persons_internal[0].name.last_initial
61
71
  ## XMLExtractor module
62
72
  Get Ruby objects from Pure XML.
63
73
 
64
- ### Single resource
74
+ ### Single record
65
75
  ```ruby
66
76
  xml = '<project> ... </project>'
67
77
  ```
@@ -83,7 +93,7 @@ xml_extractor.model
83
93
  #=> #<Puree::Model::Project:0x00c0ffee>
84
94
  ```
85
95
 
86
- ### Homogeneous resource collection
96
+ ### Homogeneous record collection
87
97
  ```ruby
88
98
  xml = '<result>
89
99
  <dataSet> ... </dataSet>
@@ -98,7 +108,7 @@ Puree::XMLExtractor::Collection.datasets xml
98
108
  #=> [#<Puree::Model::Dataset:0x00c0ffee>, ...]
99
109
  ```
100
110
 
101
- ### Heterogeneous resource collection
111
+ ### Heterogeneous record collection
102
112
  ```ruby
103
113
  xml = '<result>
104
114
  <contributionToJournal> ... </contributionToJournal>
@@ -3,13 +3,14 @@ module Puree
3
3
 
4
4
  # Conference paper extractor.
5
5
  #
6
- class ConferencePaper < Puree::Extractor::Paper
6
+ class ConferencePaper < Puree::Extractor::Resource
7
7
 
8
8
  # @param id [String]
9
+ # @return [Puree::Model::ConferencePaper, nil]
9
10
  def find(id)
10
- find_and_extract id: id,
11
- api_resource_type: :research_output,
12
- xml_extractor_resource_type: :conference_paper
11
+ super id: id,
12
+ api_resource_type: :research_output,
13
+ xml_extractor_resource_type: :conference_paper
13
14
  end
14
15
 
15
16
  end
@@ -6,16 +6,26 @@ module Puree
6
6
  #
7
7
  class Dataset < Puree::Extractor::Resource
8
8
 
9
- # @option (see Puree::Extractor::Resource#initialize)
10
- def initialize(config)
11
- super
12
- end
13
-
14
9
  # @param id [String]
10
+ # @return [Puree::Model::Dataset, nil]
15
11
  def find(id)
16
- find_and_extract id: id,
17
- api_resource_type: :dataset,
18
- xml_extractor_resource_type: :dataset
12
+ super id: id,
13
+ api_resource_type: :dataset,
14
+ xml_extractor_resource_type: :dataset
15
+ end
16
+
17
+ # Count of records available.
18
+ #
19
+ # @return [Fixnum]
20
+ def count
21
+ record_count :dataset
22
+ end
23
+
24
+ # Random record.
25
+ #
26
+ # @return [Puree::Model::Dataset, nil]
27
+ def random
28
+ super :dataset
19
29
  end
20
30
 
21
31
  end
@@ -3,18 +3,14 @@ module Puree
3
3
 
4
4
  # Doctoral thesis extractor.
5
5
  #
6
- class DoctoralThesis < Puree::Extractor::Thesis
7
-
8
- # @option (see Puree::Extractor::Resource#initialize)
9
- def initialize(config)
10
- super
11
- end
6
+ class DoctoralThesis < Puree::Extractor::Resource
12
7
 
13
8
  # @param id [String]
9
+ # @return [Puree::Model::DoctoralThesis, nil]
14
10
  def find(id)
15
- find_and_extract id: id,
16
- api_resource_type: :research_output,
17
- xml_extractor_resource_type: :doctoral_thesis
11
+ super id: id,
12
+ api_resource_type: :research_output,
13
+ xml_extractor_resource_type: :doctoral_thesis
18
14
  end
19
15
 
20
16
  end
@@ -6,16 +6,26 @@ module Puree
6
6
  #
7
7
  class Event < Puree::Extractor::Resource
8
8
 
9
- # @option (see Puree::Extractor::Resource#initialize)
10
- def initialize(config)
11
- super
12
- end
13
-
14
9
  # @param id [String]
10
+ # @return [Puree::Model::Event, nil]
15
11
  def find(id)
16
- find_and_extract id: id,
17
- api_resource_type: :event,
18
- xml_extractor_resource_type: :event
12
+ super id: id,
13
+ api_resource_type: :event,
14
+ xml_extractor_resource_type: :event
15
+ end
16
+
17
+ # Count of records available.
18
+ #
19
+ # @return [Fixnum]
20
+ def count
21
+ record_count :event
22
+ end
23
+
24
+ # Random record.
25
+ #
26
+ # @return [Puree::Model::Event, nil]
27
+ def random
28
+ super :event
19
29
  end
20
30
 
21
31
  end
@@ -6,16 +6,26 @@ module Puree
6
6
  #
7
7
  class ExternalOrganisation < Puree::Extractor::Resource
8
8
 
9
- # @option (see Puree::Extractor::Resource#initialize)
10
- def initialize(config)
11
- super
12
- end
13
-
14
9
  # @param id [String]
10
+ # @return [Puree::Model::ExternalOrganisation, nil]
15
11
  def find(id)
16
- find_and_extract id: id,
17
- api_resource_type: :external_organisation,
18
- xml_extractor_resource_type: :external_organisation
12
+ super id: id,
13
+ api_resource_type: :external_organisation,
14
+ xml_extractor_resource_type: :external_organisation
15
+ end
16
+
17
+ # Count of records available.
18
+ #
19
+ # @return [Fixnum]
20
+ def count
21
+ record_count :external_organisation
22
+ end
23
+
24
+ # Random record.
25
+ #
26
+ # @return [Puree::Model::ExternalOrganisation, nil]
27
+ def random
28
+ super :external_organisation
19
29
  end
20
30
 
21
31
  end
@@ -6,16 +6,26 @@ module Puree
6
6
  #
7
7
  class Journal < Puree::Extractor::Resource
8
8
 
9
- # @option (see Puree::Extractor::Resource#initialize)
10
- def initialize(config)
11
- super
12
- end
13
-
14
9
  # @param id [String]
10
+ # @return [Puree::Model::Journal, nil]
15
11
  def find(id)
16
- find_and_extract id: id,
17
- api_resource_type: :journal,
18
- xml_extractor_resource_type: :journal
12
+ super id: id,
13
+ api_resource_type: :journal,
14
+ xml_extractor_resource_type: :journal
15
+ end
16
+
17
+ # Count of records available.
18
+ #
19
+ # @return [Fixnum]
20
+ def count
21
+ record_count :journal
22
+ end
23
+
24
+ # Random record.
25
+ #
26
+ # @return [Puree::Model::Journal, nil]
27
+ def random
28
+ super :journal
19
29
  end
20
30
 
21
31
  end
@@ -3,18 +3,21 @@ module Puree
3
3
 
4
4
  # Journal article extractor.
5
5
  #
6
- class JournalArticle < Puree::Extractor::ResearchOutput
7
-
8
- # @option (see Puree::Extractor::Resource#initialize)
9
- def initialize(config)
10
- super
11
- end
6
+ class JournalArticle < Puree::Extractor::Resource
12
7
 
13
8
  # @param id [String]
9
+ # @return [Puree::Model::JournalArticle, nil]
14
10
  def find(id)
15
- find_and_extract id: id,
16
- api_resource_type: :research_output,
17
- xml_extractor_resource_type: :journal_article
11
+ super id: id,
12
+ api_resource_type: :research_output,
13
+ xml_extractor_resource_type: :journal_article
14
+ end
15
+
16
+ # Random record.
17
+ #
18
+ # @return [Puree::Model::JournalArticle, nil]
19
+ def random
20
+ record_count :journal_article
18
21
  end
19
22
 
20
23
  end
@@ -3,18 +3,14 @@ module Puree
3
3
 
4
4
  # Master's thesis extractor.
5
5
  #
6
- class MastersThesis < Puree::Extractor::Thesis
7
-
8
- # @option (see Puree::Extractor::Resource#initialize)
9
- def initialize(config)
10
- super
11
- end
6
+ class MastersThesis < Puree::Extractor::Resource
12
7
 
13
8
  # @param id [String]
9
+ # @return [Puree::Model::MastersThesis, nil]
14
10
  def find(id)
15
- find_and_extract id: id,
16
- api_resource_type: :research_output,
17
- xml_extractor_resource_type: :masters_thesis
11
+ super id: id,
12
+ api_resource_type: :research_output,
13
+ xml_extractor_resource_type: :masters_thesis
18
14
  end
19
15
 
20
16
  end
@@ -6,16 +6,26 @@ module Puree
6
6
  #
7
7
  class OrganisationalUnit < Puree::Extractor::Resource
8
8
 
9
- # @option (see Puree::Extractor::Resource#initialize)
10
- def initialize(config)
11
- super
12
- end
13
-
14
9
  # @param id [String]
10
+ # @return [Puree::Model::OrganisationalUnit, nil]
15
11
  def find(id)
16
- find_and_extract id: id,
17
- api_resource_type: :organisational_unit,
18
- xml_extractor_resource_type: :organisational_unit
12
+ super id: id,
13
+ api_resource_type: :organisational_unit,
14
+ xml_extractor_resource_type: :organisational_unit
15
+ end
16
+
17
+ # Count of records available.
18
+ #
19
+ # @return [Fixnum]
20
+ def count
21
+ record_count :organisational_unit
22
+ end
23
+
24
+ # Random record.
25
+ #
26
+ # @return [Puree::Model::OrganisationalUnit, nil]
27
+ def random
28
+ super :organisational_unit
19
29
  end
20
30
 
21
31
  end
@@ -3,13 +3,14 @@ module Puree
3
3
 
4
4
  # Paper extractor.
5
5
  #
6
- class Paper < Puree::Extractor::ResearchOutput
6
+ class Paper < Puree::Extractor::Resource
7
7
 
8
8
  # @param id [String]
9
+ # @return [Puree::Model::Paper, nil]
9
10
  def find(id)
10
- find_and_extract id: id,
11
- api_resource_type: :research_output,
12
- xml_extractor_resource_type: :paper
11
+ super id: id,
12
+ api_resource_type: :research_output,
13
+ xml_extractor_resource_type: :paper
13
14
  end
14
15
 
15
16
  end
@@ -7,10 +7,25 @@ module Puree
7
7
  class Person < Puree::Extractor::Resource
8
8
 
9
9
  # @param id [String]
10
+ # @return [Puree::Model::Person, nil]
10
11
  def find(id)
11
- find_and_extract id: id,
12
- api_resource_type: :person,
13
- xml_extractor_resource_type: :person
12
+ super id: id,
13
+ api_resource_type: :person,
14
+ xml_extractor_resource_type: :person
15
+ end
16
+
17
+ # Count of records available.
18
+ #
19
+ # @return [Fixnum]
20
+ def count
21
+ record_count :person
22
+ end
23
+
24
+ # Random record.
25
+ #
26
+ # @return [Puree::Model::Person, nil]
27
+ def random
28
+ super :person
14
29
  end
15
30
 
16
31
  end
@@ -7,10 +7,25 @@ module Puree
7
7
  class Project < Puree::Extractor::Resource
8
8
 
9
9
  # @param id [String]
10
+ # @return [Puree::Model::Project, nil]
10
11
  def find(id)
11
- find_and_extract id: id,
12
- api_resource_type: :project,
13
- xml_extractor_resource_type: :project
12
+ super id: id,
13
+ api_resource_type: :project,
14
+ xml_extractor_resource_type: :project
15
+ end
16
+
17
+ # Count of records available.
18
+ #
19
+ # @return [Fixnum]
20
+ def count
21
+ record_count :project
22
+ end
23
+
24
+ # Random record.
25
+ #
26
+ # @return [Puree::Model::Project, nil]
27
+ def random
28
+ super :project
14
29
  end
15
30
 
16
31
  end
@@ -7,10 +7,25 @@ module Puree
7
7
  class Publisher < Puree::Extractor::Resource
8
8
 
9
9
  # @param id [String]
10
+ # @return [Puree::Model::Publisher, nil]
10
11
  def find(id)
11
- find_and_extract id: id,
12
- api_resource_type: :publisher,
13
- xml_extractor_resource_type: :publisher
12
+ super id: id,
13
+ api_resource_type: :publisher,
14
+ xml_extractor_resource_type: :publisher
15
+ end
16
+
17
+ # Count of records available.
18
+ #
19
+ # @return [Fixnum]
20
+ def count
21
+ record_count :publisher
22
+ end
23
+
24
+ # Random record.
25
+ #
26
+ # @return [Puree::Model::Publisher, nil]
27
+ def random
28
+ super :publisher
14
29
  end
15
30
 
16
31
  end
@@ -7,10 +7,34 @@ module Puree
7
7
  class ResearchOutput < Puree::Extractor::Resource
8
8
 
9
9
  # @param id [String]
10
+ # @return [Puree::Model::ResearchOutput, nil]
10
11
  def find(id)
11
- find_and_extract id: id,
12
- api_resource_type: :research_output,
13
- xml_extractor_resource_type: :research_output
12
+ super id: id,
13
+ api_resource_type: :research_output,
14
+ xml_extractor_resource_type: :research_output
15
+ end
16
+
17
+ # Count of records available.
18
+ #
19
+ # @return [Fixnum]
20
+ def count
21
+ record_count :research_output
22
+ end
23
+
24
+ # Random record. Includes the metadata from Puree::Model::ResearchOutput as a minimum.
25
+ #
26
+ # @return [Puree::Model::ResearchOutput or subclass, nil]
27
+ def random
28
+ client = Puree::REST::Client.new @config
29
+ offset = rand(0..count-1)
30
+ response = client.research_outputs.all params: {size: 1, offset: offset}
31
+ research_outputs_hash = Puree::XMLExtractor::Collection.research_outputs response.to_s
32
+ research_outputs_array = []
33
+ research_outputs_hash.each do |k, v|
34
+ research_outputs_array += v
35
+ end
36
+ return nil if research_outputs_array.empty?
37
+ research_outputs_array[0]
14
38
  end
15
39
 
16
40
  end
@@ -20,7 +20,7 @@ module Puree
20
20
  # @param id [String]
21
21
  # @param api_resource_type [Symbol]
22
22
  # @param xml_extractor_resource_type [Symbol]
23
- def find_and_extract(id:, api_resource_type:, xml_extractor_resource_type:)
23
+ def find(id:, api_resource_type:, xml_extractor_resource_type:)
24
24
  api_resource = make_api_resource api_resource_type
25
25
  response = api_resource.find id: id
26
26
  return unless response.code === 200
@@ -38,6 +38,21 @@ module Puree
38
38
  Object.const_get(resource_class).new xml
39
39
  end
40
40
 
41
+ def record_count(api_resource_type)
42
+ api_resource = make_api_resource api_resource_type
43
+ response = api_resource.all params: {size: 0}
44
+ return unless response.code === 200
45
+ Puree::XMLExtractor::Collection.count response.to_s
46
+ end
47
+
48
+ def random(api_resource_type)
49
+ offset = rand(0..record_count(api_resource_type)-1)
50
+ api_resource = make_api_resource api_resource_type
51
+ response = api_resource.all params: {size: 1, offset: offset}
52
+ models = Puree::XMLExtractor::Collection.send "#{api_resource_type}s", response.to_s
53
+ return nil if models.empty?
54
+ models[0]
55
+ end
41
56
 
42
57
  end
43
58
 
@@ -3,18 +3,14 @@ module Puree
3
3
 
4
4
  # Thesis extractor.
5
5
  #
6
- class Thesis < Puree::Extractor::ResearchOutput
7
-
8
- # @option (see Puree::Extractor::Resource#initialize)
9
- def initialize(config)
10
- super
11
- end
6
+ class Thesis < Puree::Extractor::Resource
12
7
 
13
8
  # @param id [String]
9
+ # @return [Puree::Model::Thesis, nil]
14
10
  def find(id)
15
- find_and_extract id: id,
16
- api_resource_type: :research_output,
17
- xml_extractor_resource_type: :thesis
11
+ super id: id,
12
+ api_resource_type: :research_output,
13
+ xml_extractor_resource_type: :thesis
18
14
  end
19
15
 
20
16
  end
@@ -6,11 +6,6 @@ module Puree
6
6
  #
7
7
  class Activity < Puree::REST::Base
8
8
 
9
- # @option (see Puree::REST::Base#initialize)
10
- def initialize(config)
11
- super
12
- end
13
-
14
9
  private
15
10
 
16
11
  def collection
@@ -6,11 +6,6 @@ module Puree
6
6
  #
7
7
  class Application < Puree::REST::Base
8
8
 
9
- # (see Puree::REST::Base#initialize)
10
- def initialize(config)
11
- super
12
- end
13
-
14
9
  private
15
10
 
16
11
  def collection
@@ -6,11 +6,6 @@ module Puree
6
6
  #
7
7
  class ClassificationScheme < Puree::REST::Base
8
8
 
9
- # (see Puree::REST::Base#initialize)
10
- def initialize(config)
11
- super
12
- end
13
-
14
9
  private
15
10
 
16
11
  def collection
@@ -6,11 +6,6 @@ module Puree
6
6
  #
7
7
  class CurriculaVitae < Puree::REST::Base
8
8
 
9
- # (see Puree::REST::Base#initialize)
10
- def initialize(config)
11
- super
12
- end
13
-
14
9
  private
15
10
 
16
11
  def collection
@@ -6,11 +6,6 @@ module Puree
6
6
  #
7
7
  class Dataset < Puree::REST::Base
8
8
 
9
- # (see Puree::REST::Base#initialize)
10
- def initialize(config)
11
- super
12
- end
13
-
14
9
  private
15
10
 
16
11
  def collection
@@ -6,11 +6,6 @@ module Puree
6
6
  #
7
7
  class Equipment < Puree::REST::Base
8
8
 
9
- # (see Puree::REST::Base#initialize)
10
- def initialize(config)
11
- super
12
- end
13
-
14
9
  private
15
10
 
16
11
  def collection
@@ -6,11 +6,6 @@ module Puree
6
6
  #
7
7
  class Event < Puree::REST::Base
8
8
 
9
- # (see Puree::REST::Base#initialize)
10
- def initialize(config)
11
- super
12
- end
13
-
14
9
  private
15
10
 
16
11
  def collection
@@ -6,11 +6,6 @@ module Puree
6
6
  #
7
7
  class ExternalOrganisation < Puree::REST::Base
8
8
 
9
- # (see Puree::REST::Base#initialize)
10
- def initialize(config)
11
- super
12
- end
13
-
14
9
  private
15
10
 
16
11
  def collection
@@ -6,11 +6,6 @@ module Puree
6
6
  #
7
7
  class ExternalPerson < Puree::REST::Base
8
8
 
9
- # (see Puree::REST::Base#initialize)
10
- def initialize(config)
11
- super
12
- end
13
-
14
9
  private
15
10
 
16
11
  def collection
@@ -6,11 +6,6 @@ module Puree
6
6
  #
7
7
  class Impact < Puree::REST::Base
8
8
 
9
- # (see Puree::REST::Base#initialize)
10
- def initialize(config)
11
- super
12
- end
13
-
14
9
  private
15
10
 
16
11
  def collection
@@ -6,11 +6,6 @@ module Puree
6
6
  #
7
7
  class Journal < Puree::REST::Base
8
8
 
9
- # (see Puree::REST::Base#initialize)
10
- def initialize(config)
11
- super
12
- end
13
-
14
9
  private
15
10
 
16
11
  def collection
@@ -33,11 +33,6 @@ module Puree
33
33
  include Puree::REST::ResearchOutputMixin
34
34
  include Puree::REST::StudentThesisMixin
35
35
 
36
- # (see Puree::REST::Base#initialize)
37
- def initialize(config)
38
- super
39
- end
40
-
41
36
  private
42
37
 
43
38
  def collection
@@ -32,11 +32,6 @@ module Puree
32
32
  include Puree::REST::ResearchOutputMixin
33
33
  include Puree::REST::StudentThesisMixin
34
34
 
35
- # (see Puree::REST::Base#initialize)
36
- def initialize(config)
37
- super
38
- end
39
-
40
35
  # (see Puree::REST::Base#find)
41
36
  def curricula_vitae(id:, params: {}, accept: :xml)
42
37
  get_request_singleton_subcollection(id: id,
@@ -6,11 +6,6 @@ module Puree
6
6
  #
7
7
  class PressMedia < Puree::REST::Base
8
8
 
9
- # (see Puree::REST::Base#initialize)
10
- def initialize(config)
11
- super
12
- end
13
-
14
9
  private
15
10
 
16
11
  def collection
@@ -6,11 +6,6 @@ module Puree
6
6
  #
7
7
  class Prize < Puree::REST::Base
8
8
 
9
- # (see Puree::REST::Base#initialize)
10
- def initialize(config)
11
- super
12
- end
13
-
14
9
  private
15
10
 
16
11
  def collection
@@ -9,11 +9,6 @@ module Puree
9
9
  class Project < Puree::REST::Base
10
10
  include Puree::REST::ActiveMixin
11
11
 
12
- # (see Puree::REST::Base#initialize)
13
- def initialize(config)
14
- super
15
- end
16
-
17
12
  private
18
13
 
19
14
  def collection
@@ -6,11 +6,6 @@ module Puree
6
6
  #
7
7
  class Publisher < Puree::REST::Base
8
8
 
9
- # (see Puree::REST::Base#initialize)
10
- def initialize(config)
11
- super
12
- end
13
-
14
9
  # (see Puree::REST::Base#all)
15
10
  def approved(params: {}, accept: :xml)
16
11
  get_request_collection_subcollection(subcollection: 'approved',
@@ -6,11 +6,6 @@ module Puree
6
6
  #
7
7
  class ResearchOutput < Puree::REST::Base
8
8
 
9
- # (see Puree::REST::Base#initialize)
10
- def initialize(config)
11
- super
12
- end
13
-
14
9
  private
15
10
 
16
11
  def collection
@@ -1,5 +1,5 @@
1
1
  module Puree
2
2
  # Semantic version number
3
3
  #
4
- VERSION = "2.1.1"
4
+ VERSION = "2.2.0"
5
5
  end
@@ -62,6 +62,14 @@ module Puree
62
62
  models :person, xml, '/person'
63
63
  end
64
64
 
65
+ # Get models from any multi-record person XML response
66
+ #
67
+ # @param xml [String]
68
+ # @return [Array<Puree::Model::Publisher>]
69
+ def self.publishers(xml)
70
+ models :publisher, xml, '/publisher'
71
+ end
72
+
65
73
  # Get models from any multi-record Research output XML response
66
74
  #
67
75
  # @param xml [String]
@@ -102,6 +110,12 @@ module Puree
102
110
  data
103
111
  end
104
112
 
113
+ def self.count(xml)
114
+ doc = Nokogiri::XML xml
115
+ doc.remove_namespaces!
116
+ doc.xpath('/result/count').text.to_i
117
+ end
118
+
105
119
  private
106
120
 
107
121
  # Get models from any multi-record resource XML response
@@ -0,0 +1,68 @@
1
+ require 'test_helper'
2
+
3
+ class TestResourceCount < Minitest::Test
4
+
5
+ def test_dataset_count
6
+ extractor = Puree::Extractor::Dataset.new config
7
+ count = extractor.count
8
+
9
+ assert_instance_of Fixnum, count
10
+ end
11
+
12
+ def test_external_organisation_count
13
+ extractor = Puree::Extractor::ExternalOrganisation.new config
14
+ count = extractor.count
15
+
16
+ assert_instance_of Fixnum, count
17
+ end
18
+
19
+ def test_event_count
20
+ extractor = Puree::Extractor::Event.new config
21
+ count = extractor.count
22
+
23
+ assert_instance_of Fixnum, count
24
+ end
25
+
26
+ def test_journal_count
27
+ extractor = Puree::Extractor::Journal.new config
28
+ count = extractor.count
29
+
30
+ assert_instance_of Fixnum, count
31
+ end
32
+
33
+ def test_organisational_unit_count
34
+ extractor = Puree::Extractor::OrganisationalUnit.new config
35
+ count = extractor.count
36
+
37
+ assert_instance_of Fixnum, count
38
+ end
39
+
40
+ def test_person_count
41
+ extractor = Puree::Extractor::Person.new config
42
+ count = extractor.count
43
+
44
+ assert_instance_of Fixnum, count
45
+ end
46
+
47
+ def test_project_count
48
+ extractor = Puree::Extractor::Project.new config
49
+ count = extractor.count
50
+
51
+ assert_instance_of Fixnum, count
52
+ end
53
+
54
+ def test_publisher_count
55
+ extractor = Puree::Extractor::Publisher.new config
56
+ count = extractor.count
57
+
58
+ assert_instance_of Fixnum, count
59
+ end
60
+
61
+ def test_research_output_count
62
+ extractor = Puree::Extractor::ResearchOutput.new config
63
+ count = extractor.count
64
+
65
+ assert_instance_of Fixnum, count
66
+ end
67
+
68
+ end
@@ -0,0 +1,66 @@
1
+ require 'test_helper'
2
+
3
+ class TestResourceRandom < Minitest::Test
4
+
5
+ def test_dataset_random
6
+ extractor = Puree::Extractor::Dataset.new config
7
+
8
+ assert_instance_of Puree::Model::Dataset, extractor.random
9
+ end
10
+
11
+ def test_external_organisation_random
12
+ extractor = Puree::Extractor::ExternalOrganisation.new config
13
+
14
+ assert_instance_of Puree::Model::ExternalOrganisation, extractor.random
15
+ end
16
+
17
+ def test_event_random
18
+ extractor = Puree::Extractor::Event.new config
19
+
20
+ assert_instance_of Puree::Model::Event, extractor.random
21
+ end
22
+
23
+ def test_journal_random
24
+ extractor = Puree::Extractor::Journal.new config
25
+
26
+ assert_instance_of Puree::Model::Journal, extractor.random
27
+ end
28
+
29
+ def test_organisational_unit_random
30
+ extractor = Puree::Extractor::OrganisationalUnit.new config
31
+
32
+ assert_instance_of Puree::Model::OrganisationalUnit, extractor.random
33
+ end
34
+
35
+ def test_person_random
36
+ extractor = Puree::Extractor::Person.new config
37
+
38
+ assert_instance_of Puree::Model::Person, extractor.random
39
+ end
40
+
41
+ def test_project_random
42
+ extractor = Puree::Extractor::Project.new config
43
+
44
+ assert_instance_of Puree::Model::Project, extractor.random
45
+ end
46
+
47
+ def test_publisher_random
48
+ extractor = Puree::Extractor::Publisher.new config
49
+
50
+ assert_instance_of Puree::Model::Publisher, extractor.random
51
+ end
52
+
53
+ def test_research_output_random
54
+ extractor = Puree::Extractor::ResearchOutput.new config
55
+
56
+ class_possibilities = [
57
+ Puree::Model::ResearchOutput,
58
+ Puree::Model::ConferencePaper,
59
+ Puree::Model::Thesis,
60
+ Puree::Model::JournalArticle
61
+ ]
62
+ random = extractor.random
63
+ assert_includes class_possibilities, random.class
64
+ end
65
+
66
+ end
@@ -9,7 +9,7 @@ require 'puree'
9
9
 
10
10
  def config
11
11
  {
12
- url: ENV['PURE_URL_TEST_59'],
12
+ url: ENV['PURE_URL_59'],
13
13
  username: ENV['PURE_USERNAME'],
14
14
  password: ENV['PURE_PASSWORD'],
15
15
  api_key: ENV['PURE_API_KEY']
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: 2.1.1
4
+ version: 2.2.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: 2018-04-18 00:00:00.000000000 Z
11
+ date: 2018-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http
@@ -199,7 +199,9 @@ files:
199
199
  - lib/puree/xml_extractor/thesis.rb
200
200
  - lib/puree/xml_extractor/xml_extractor.rb
201
201
  - puree.gemspec
202
- - test/extractor/resource_test.rb
202
+ - test/extractor/resource_count_test.rb
203
+ - test/extractor/resource_find_test.rb
204
+ - test/extractor/resource_random_test.rb
203
205
  - test/rest/base_test.rb
204
206
  - test/rest/common_test.rb
205
207
  - test/test_extractor_helper.rb
@@ -244,7 +246,9 @@ signing_key:
244
246
  specification_version: 4
245
247
  summary: Metadata extraction from the Pure Research Information System.
246
248
  test_files:
247
- - test/extractor/resource_test.rb
249
+ - test/extractor/resource_count_test.rb
250
+ - test/extractor/resource_find_test.rb
251
+ - test/extractor/resource_random_test.rb
248
252
  - test/rest/base_test.rb
249
253
  - test/rest/common_test.rb
250
254
  - test/test_extractor_helper.rb