puree 0.20.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +16 -2
  3. data/PITCHME.md +43 -21
  4. data/README.md +72 -18
  5. data/lib/puree.rb +66 -21
  6. data/lib/puree/api/api.rb +9 -0
  7. data/lib/puree/api/authentication.rb +33 -0
  8. data/lib/puree/api/configuration.rb +43 -0
  9. data/lib/puree/api/map.rb +76 -0
  10. data/lib/puree/api/request.rb +116 -0
  11. data/lib/puree/extractor/collection.rb +131 -0
  12. data/lib/puree/extractor/dataset.rb +48 -0
  13. data/lib/puree/extractor/download.rb +71 -0
  14. data/lib/puree/extractor/event.rb +33 -0
  15. data/lib/puree/extractor/extractor.rb +10 -0
  16. data/lib/puree/extractor/journal.rb +29 -0
  17. data/lib/puree/extractor/organisation.rb +34 -0
  18. data/lib/puree/extractor/person.rb +32 -0
  19. data/lib/puree/extractor/project.rb +40 -0
  20. data/lib/puree/extractor/publication.rb +40 -0
  21. data/lib/puree/extractor/publisher.rb +27 -0
  22. data/lib/puree/extractor/resource.rb +69 -0
  23. data/lib/puree/extractor/server.rb +56 -0
  24. data/lib/puree/model/address.rb +50 -0
  25. data/lib/puree/model/copyright_license.rb +26 -0
  26. data/lib/puree/model/dataset.rb +84 -0
  27. data/lib/puree/model/download_header.rb +21 -0
  28. data/lib/puree/model/endeavour_person.rb +34 -0
  29. data/lib/puree/model/event.rb +31 -0
  30. data/lib/puree/model/event_header.rb +26 -0
  31. data/lib/puree/model/file.rb +45 -0
  32. data/lib/puree/model/helper/validation.rb +15 -0
  33. data/lib/puree/model/journal.rb +20 -0
  34. data/lib/puree/model/legal_condition.rb +26 -0
  35. data/lib/puree/model/link.rb +26 -0
  36. data/lib/puree/model/model.rb +7 -0
  37. data/lib/puree/model/organisation.rb +34 -0
  38. data/lib/puree/model/organisation_header.rb +34 -0
  39. data/lib/puree/model/person.rb +28 -0
  40. data/lib/puree/model/person_name.rb +52 -0
  41. data/lib/puree/model/project.rb +49 -0
  42. data/lib/puree/model/publication.rb +53 -0
  43. data/lib/puree/model/publication_status.rb +21 -0
  44. data/lib/puree/model/publisher.rb +13 -0
  45. data/lib/puree/model/related_content_header.rb +34 -0
  46. data/lib/puree/model/resource.rb +42 -0
  47. data/lib/puree/model/server.rb +13 -0
  48. data/lib/puree/model/spatial_point.rb +16 -0
  49. data/lib/puree/model/structure.rb +18 -0
  50. data/lib/puree/model/temporal_range.rb +15 -0
  51. data/lib/puree/util/date.rb +86 -0
  52. data/lib/puree/util/util.rb +8 -0
  53. data/lib/puree/version.rb +1 -1
  54. data/lib/puree/xml_extractor/base.rb +47 -0
  55. data/lib/puree/xml_extractor/collection.rb +40 -0
  56. data/lib/puree/xml_extractor/dataset.rb +305 -0
  57. data/lib/puree/xml_extractor/download.rb +42 -0
  58. data/lib/puree/xml_extractor/event.rb +63 -0
  59. data/lib/puree/xml_extractor/journal.rb +33 -0
  60. data/lib/puree/xml_extractor/organisation.rb +75 -0
  61. data/lib/puree/xml_extractor/person.rb +57 -0
  62. data/lib/puree/xml_extractor/project.rb +135 -0
  63. data/lib/puree/xml_extractor/publication.rb +189 -0
  64. data/lib/puree/xml_extractor/publisher.rb +28 -0
  65. data/lib/puree/xml_extractor/resource.rb +71 -0
  66. data/lib/puree/xml_extractor/server.rb +32 -0
  67. data/lib/puree/xml_extractor/shared.rb +31 -0
  68. data/lib/puree/xml_extractor/xml_extractor.rb +10 -0
  69. data/puree.gemspec +11 -8
  70. data/spec/download_http_spec.rb +31 -0
  71. data/spec/open_api_dataset_http_spec.rb +15 -0
  72. data/spec/resource/collection_all_http_spec.rb +77 -0
  73. data/spec/resource/collection_http_spec.rb +65 -0
  74. data/spec/resource/dataset_http_spec.rb +104 -0
  75. data/spec/resource/event_http_spec.rb +52 -0
  76. data/spec/resource/journal_http_spec.rb +36 -0
  77. data/spec/resource/organisation_http_spec.rb +52 -0
  78. data/spec/resource/person_http_spec.rb +48 -0
  79. data/spec/resource/project_http_spec.rb +76 -0
  80. data/spec/resource/publication_http_spec.rb +78 -0
  81. data/spec/resource/publisher_http_spec.rb +26 -0
  82. data/spec/server_http_spec.rb +26 -0
  83. data/spec/spec_helper.rb +106 -21
  84. metadata +110 -46
  85. data/lib/puree/collection.rb +0 -285
  86. data/lib/puree/configuration.rb +0 -15
  87. data/lib/puree/dataset.rb +0 -483
  88. data/lib/puree/date.rb +0 -63
  89. data/lib/puree/download.rb +0 -189
  90. data/lib/puree/event.rb +0 -133
  91. data/lib/puree/journal.rb +0 -75
  92. data/lib/puree/map.rb +0 -68
  93. data/lib/puree/organisation.rb +0 -177
  94. data/lib/puree/person.rb +0 -136
  95. data/lib/puree/project.rb +0 -231
  96. data/lib/puree/publication.rb +0 -258
  97. data/lib/puree/publisher.rb +0 -64
  98. data/lib/puree/resource.rb +0 -261
  99. data/lib/puree/server.rb +0 -156
  100. data/spec/collection_spec.rb +0 -62
  101. data/spec/dataset_spec.rb +0 -148
  102. data/spec/download_spec.rb +0 -33
  103. data/spec/event_spec.rb +0 -108
  104. data/spec/journal_spec.rb +0 -92
  105. data/spec/organisation_spec.rb +0 -112
  106. data/spec/person_spec.rb +0 -104
  107. data/spec/project_spec.rb +0 -120
  108. data/spec/publication_spec.rb +0 -128
  109. data/spec/publisher_spec.rb +0 -89
  110. data/spec/server_spec.rb +0 -36
@@ -0,0 +1,34 @@
1
+ module Puree
2
+
3
+ module Extractor
4
+
5
+ # Organisation extractor.
6
+ #
7
+ class Organisation < Puree::Extractor::Resource
8
+
9
+ # @option (see Puree::Extractor::Resource#initialize)
10
+ def initialize(config)
11
+ super
12
+ setup :organisation
13
+ end
14
+
15
+ private
16
+
17
+ def combine_metadata
18
+ super
19
+ @model.address = @extractor.address
20
+ @model.email_addresses = @extractor.email_addresses
21
+ @model.name = @extractor.name
22
+ @model.organisations = @extractor.organisations
23
+ @model.parent = @extractor.parent
24
+ @model.phone_numbers = @extractor.phone_numbers
25
+ @model.type = @extractor.type
26
+ @model.urls = @extractor.urls
27
+ @model
28
+ end
29
+
30
+ end
31
+
32
+ end
33
+
34
+ end
@@ -0,0 +1,32 @@
1
+ module Puree
2
+
3
+ module Extractor
4
+
5
+ # Person extractor.
6
+ #
7
+ class Person < Puree::Extractor::Resource
8
+
9
+ # @option (see Puree::Extractor::Resource#initialize)
10
+ def initialize(config)
11
+ super
12
+ setup :person
13
+ end
14
+
15
+ private
16
+
17
+ def combine_metadata
18
+ super
19
+ @model.affiliations = @extractor.affiliations
20
+ @model.email_addresses = @extractor.email_addresses
21
+ @model.image_urls = @extractor.image_urls
22
+ @model.keywords = @extractor.keywords
23
+ @model.name = @extractor.name
24
+ @model.orcid = @extractor.orcid
25
+ @model
26
+ end
27
+
28
+ end
29
+
30
+ end
31
+
32
+ end
@@ -0,0 +1,40 @@
1
+ module Puree
2
+
3
+ module Extractor
4
+
5
+ # Project extractor.
6
+ #
7
+ class Project < Puree::Extractor::Resource
8
+
9
+ # @option (see Puree::Extractor::Resource#initialize)
10
+ def initialize(config)
11
+ super
12
+ @latest_api = false # stable API does not return person roles
13
+ setup :project
14
+ end
15
+
16
+ private
17
+
18
+ def combine_metadata
19
+ super
20
+ @model.acronym = @extractor.acronym
21
+ @model.description = @extractor.description
22
+ @model.organisations = @extractor.organisations
23
+ @model.owner = @extractor.owner
24
+ @model.persons_internal = @extractor.persons_internal
25
+ @model.persons_external = @extractor.persons_external
26
+ @model.persons_other = @extractor.persons_other
27
+ @model.status = @extractor.status
28
+ @model.temporal_actual = @extractor.temporal_actual
29
+ @model.temporal_expected = @extractor.temporal_expected
30
+ @model.title = @extractor.title
31
+ @model.type = @extractor.type
32
+ @model.url = @extractor.url
33
+ @model
34
+ end
35
+
36
+ end
37
+
38
+ end
39
+
40
+ end
@@ -0,0 +1,40 @@
1
+ module Puree
2
+
3
+ module Extractor
4
+
5
+ # Publication extractor.
6
+ #
7
+ class Publication < Puree::Extractor::Resource
8
+
9
+ # @option (see Puree::Extractor::Resource#initialize)
10
+ def initialize(config)
11
+ super
12
+ setup :publication
13
+ end
14
+
15
+ private
16
+
17
+ def combine_metadata
18
+ super
19
+ @model.category = @extractor.category
20
+ @model.description = @extractor.description
21
+ @model.doi = @extractor.doi
22
+ @model.event = @extractor.event
23
+ @model.files = @extractor.files
24
+ @model.organisations = @extractor.organisations
25
+ @model.pages = @extractor.pages
26
+ @model.persons_internal = @extractor.persons_internal
27
+ @model.persons_external = @extractor.persons_external
28
+ @model.persons_other = @extractor.persons_other
29
+ @model.statuses = @extractor.statuses
30
+ @model.subtitle = @extractor.subtitle
31
+ @model.title = @extractor.title
32
+ @model.type = @extractor.type
33
+ @model
34
+ end
35
+
36
+ end
37
+
38
+ end
39
+
40
+ end
@@ -0,0 +1,27 @@
1
+ module Puree
2
+
3
+ module Extractor
4
+
5
+ # Publisher extractor.
6
+ #
7
+ class Publisher < Puree::Extractor::Resource
8
+
9
+ # @option (see Puree::Extractor::Resource#initialize)
10
+ def initialize(config)
11
+ super
12
+ setup :publisher
13
+ end
14
+
15
+ private
16
+
17
+ def combine_metadata
18
+ super
19
+ @model.name = @extractor.name
20
+ @model
21
+ end
22
+
23
+ end
24
+
25
+ end
26
+
27
+ end
@@ -0,0 +1,69 @@
1
+ module Puree
2
+
3
+ module Extractor
4
+
5
+ # Resource extractor.
6
+ #
7
+ class Resource
8
+ include Puree::API::Authentication
9
+
10
+ # @option (see Puree::API::Authentication#configure_api)
11
+ # @param bleeding [Boolean]
12
+ def initialize(config, bleeding: true)
13
+ @latest_api = bleeding
14
+ configure_api config
15
+ end
16
+
17
+ # Get a resource.
18
+ #
19
+ # @param uuid [String]
20
+ # @param id [String]
21
+ # @return [Puree::Model::Resource subclass, nil] Resource metadata e.g. Puree::Model::Dataset
22
+ def get(uuid: nil, id: nil)
23
+ raise 'Cannot perform a request without a configuration' if @config.nil?
24
+ @response = @request.get uuid: uuid,
25
+ id: id,
26
+ latest_api: @latest_api,
27
+ resource_type: @resource_type
28
+ set_content @response.body
29
+ end
30
+
31
+ private
32
+
33
+ # Set content from XML.
34
+ #
35
+ # @param xml [String]
36
+ def set_content(xml)
37
+ if xml
38
+ make_xml_extractor xml
39
+ @extractor.get_data? ? combine_metadata : nil
40
+ end
41
+ end
42
+
43
+ def setup(resource)
44
+ @resource_type = resource
45
+ resource_class = "Puree::Model::#{resource.to_s.capitalize}"
46
+ @model = Object.const_get(resource_class).new
47
+ end
48
+
49
+ def make_xml_extractor xml
50
+ resource_class = "Puree::XMLExtractor::#{@resource_type.to_s.capitalize}"
51
+ @extractor = Object.const_get(resource_class).new xml: xml
52
+ end
53
+
54
+ # All metadata
55
+ # @return [Hash]
56
+ def combine_metadata
57
+ @model.uuid = @extractor.uuid
58
+ @model.created = @extractor.created
59
+ @model.modified = @extractor.modified
60
+ @model.locale = @extractor.locale
61
+ end
62
+
63
+ alias :find :get
64
+
65
+ end
66
+
67
+ end
68
+
69
+ end
@@ -0,0 +1,56 @@
1
+ module Puree
2
+
3
+ module Extractor
4
+
5
+ # Server extractor.
6
+ #
7
+ class Server
8
+ include Puree::API::Authentication
9
+
10
+ # @option (see Puree::API::Authentication#configure_api)
11
+ def initialize(config)
12
+ @resource_type = :server
13
+ configure_api config
14
+ end
15
+
16
+ # Get server information.
17
+ #
18
+ # @return [Puree::Model::Server, nil]
19
+ def get
20
+ raise 'Cannot perform a request without a configuration' if @config.nil?
21
+ @response = @request.get resource_type: @resource_type
22
+ set_content @response.body
23
+ end
24
+
25
+ private
26
+
27
+ def combine_metadata
28
+ model = Puree::Model::Server.new
29
+ model.version = @extractor.version
30
+ model
31
+ end
32
+
33
+ # Set content from XML. In order for metadata extraction to work, the XML must have
34
+ # been retrieved using the .current version of the Pure API endpoints
35
+ #
36
+ # @param xml [String]
37
+ # @return [Puree::Model::Server, nil]
38
+ def set_content(xml)
39
+ if xml
40
+ make_extractor
41
+ @extractor.get_data? ? combine_metadata : nil
42
+ end
43
+ end
44
+
45
+ def make_extractor
46
+ @extractor = Puree::XMLExtractor::Server.new xml: @response.body
47
+ end
48
+
49
+ alias :find :get
50
+
51
+ end
52
+
53
+ end
54
+
55
+ end
56
+
@@ -0,0 +1,50 @@
1
+ module Puree
2
+ module Model
3
+
4
+ # Address where something is located.
5
+ #
6
+ class Address < Puree::Model::Structure
7
+
8
+ # @return [String, nil]
9
+ attr_reader :street
10
+
11
+ # @return [String, nil]
12
+ attr_reader :building
13
+
14
+ # @return [String, nil]
15
+ attr_reader :postcode
16
+
17
+ # @return [String, nil]
18
+ attr_reader :city
19
+
20
+ # @return [String, nil]
21
+ attr_reader :country
22
+
23
+ # @param v [String]
24
+ def street=(v)
25
+ @street = v if v && !v.empty?
26
+ end
27
+
28
+ # @param v [String]
29
+ def building=(v)
30
+ @building = v if v && !v.empty?
31
+ end
32
+
33
+ # @param v [String]
34
+ def postcode=(v)
35
+ @postcode = v if v && !v.empty?
36
+ end
37
+
38
+ # @param v [String]
39
+ def city=(v)
40
+ @city = v if v && !v.empty?
41
+ end
42
+
43
+ # @param v [String]
44
+ def country=(v)
45
+ @country = v if v && !v.empty?
46
+ end
47
+
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,26 @@
1
+ module Puree
2
+ module Model
3
+
4
+ # A copyright license.
5
+ #
6
+ class CopyrightLicense < Puree::Model::Structure
7
+
8
+ # @return [String, nil]
9
+ attr_reader :name
10
+
11
+ # @return [String, nil]
12
+ attr_reader :url
13
+
14
+ # @param v [String]
15
+ def name=(v)
16
+ @name = v if v && !v.empty?
17
+ end
18
+
19
+ # @param v [String]
20
+ def url=(v)
21
+ @url = v if v && !v.empty?
22
+ end
23
+
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,84 @@
1
+ module Puree
2
+ module Model
3
+
4
+ # A dataset produced during some research.
5
+ #
6
+ class Dataset < Resource
7
+
8
+ # Open access permission.
9
+ # @return [String, nil]
10
+ attr_accessor :access
11
+
12
+ # Combines projects and publications.
13
+ # @return [Array<Puree::Model::RelatedContentHeader>]
14
+ attr_accessor :associated
15
+
16
+ # Date made available.
17
+ # @return [Time, nil]
18
+ attr_accessor :available
19
+
20
+ # @return [String, nil]
21
+ attr_accessor :description
22
+
23
+ # Digital Object Identifier.
24
+ # @return [String, nil]
25
+ attr_accessor :doi
26
+
27
+ # Supporting files.
28
+ # @return [Array<Puree::Model::File>]
29
+ attr_accessor :files
30
+
31
+ # @return [Array<String>]
32
+ attr_accessor :keywords
33
+
34
+ # @return [Array<Puree::Model::LegalCondition>]
35
+ attr_accessor :legal_conditions
36
+
37
+ # @return [Array<Puree::Model::Link>]
38
+ attr_accessor :links
39
+
40
+ # @return [Array<Puree::Model::OrganisationHeader>]
41
+ attr_accessor :organisations
42
+
43
+ # @return [Puree::Model::OrganisationHeader, nil]
44
+ attr_accessor :owner
45
+
46
+ # @return [Array<Puree::Model::EndeavourPerson>]
47
+ attr_accessor :persons_internal
48
+
49
+ # @return [Array<Puree::Model::EndeavourPerson>]
50
+ attr_accessor :persons_external
51
+
52
+ # @return [Array<Puree::Model::EndeavourPerson>]
53
+ attr_accessor :persons_other
54
+
55
+ # Date of data production.
56
+ # @return [Puree::Model::TemporalRange, nil]
57
+ attr_accessor :production
58
+
59
+ # @return [Array<Puree::Model::RelatedContentHeader>]
60
+ attr_accessor :projects
61
+
62
+ # @return [Array<Puree::Model::RelatedContentHeader>]
63
+ attr_accessor :publications
64
+
65
+ # @return [String, nil]
66
+ attr_accessor :publisher
67
+
68
+ # @return [Array<String>]
69
+ attr_accessor :spatial_places
70
+
71
+ # Spatial coverage point.
72
+ # @return [Puree::Model::SpatialPoint, nil]
73
+ attr_accessor :spatial_point
74
+
75
+ # Temporal coverage.
76
+ # @return [Puree::Model::TemporalRange, nil]
77
+ attr_accessor :temporal
78
+
79
+ # @return [String, nil]
80
+ attr_accessor :title
81
+
82
+ end
83
+ end
84
+ end