dmao-generic-ingesters 0.3.0 → 0.4.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fa13700de7ef18ea8b374489d9d6f06cb85abe15
4
- data.tar.gz: 2f68f9cc43db01df86153247ea61ee79983e7477
3
+ metadata.gz: 8a71389705fcf4841e99d08ff0095a27663f0502
4
+ data.tar.gz: 998ac6edd53d0b9cb88d634825e33d6540221789
5
5
  SHA512:
6
- metadata.gz: 1de03f96656da38f7566a4b681eb2390b6b1661e7ff8e1d93753d6c7841968f54cecb8dfc569b8f373d5b602cb39596e32cd0e952520102bd73999a421eada81
7
- data.tar.gz: 435f9ab0ba13bd7e9ddbecd8161343285a90459886059de36bd744e2023ed05bf826a74db1ccf5e8237bbcca1cf99d91001cb25b0cb4e92cc39cc89368e7b39d
6
+ metadata.gz: b2f670e91b1df80c0fbbf1ecae5f0e1ee3f89cc834b91eb8ab6cda7cd0b8d8da5f543151af1bf25358b6f420125001a5aabf16adbba2c016bddf942db2ff9c79
7
+ data.tar.gz: 35a6f05547877fd292b65af83ba9e1ca2a63f8f09338e5243bc0d7d5ca236cd51a9f9c6bbf55f0e0f32f4517cc64a8b0e6c94927ba102ab99b06b06639cb5231
@@ -0,0 +1,15 @@
1
+ module DMAO
2
+ module Ingesters
3
+ module Errors
4
+
5
+ class IngestEntityError < StandardError
6
+
7
+ def initialize(msg="Error ingesting entity.")
8
+ super(msg)
9
+ end
10
+
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,17 @@
1
+ require 'dmao/ingesters/errors/ingest_entity_error'
2
+
3
+ module DMAO
4
+ module Ingesters
5
+ module Errors
6
+
7
+ class IngestFunderError < IngestEntityError
8
+
9
+ def initialize(msg="Error ingesting funder.")
10
+ super(msg)
11
+ end
12
+
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -1,8 +1,10 @@
1
+ require 'dmao/ingesters/errors/ingest_entity_error'
2
+
1
3
  module DMAO
2
4
  module Ingesters
3
5
  module Errors
4
6
 
5
- class IngestOrganisationUnitError < StandardError
7
+ class IngestOrganisationUnitError < IngestEntityError
6
8
 
7
9
  def initialize(msg="Error ingesting organisation unit.")
8
10
  super(msg)
@@ -1,8 +1,10 @@
1
+ require 'dmao/ingesters/errors/ingest_entity_error'
2
+
1
3
  module DMAO
2
4
  module Ingesters
3
5
  module Errors
4
6
 
5
- class IngestPersonError < StandardError
7
+ class IngestPersonError < IngestEntityError
6
8
 
7
9
  def initialize(msg="Error ingesting person.")
8
10
  super(msg)
@@ -0,0 +1,34 @@
1
+ require 'dmao_api'
2
+ require 'dmao/ingesters/generic/ingester'
3
+ require 'dmao/ingesters/errors/ingest_funder_error'
4
+
5
+ module DMAO
6
+ module Ingesters
7
+ module Generic
8
+
9
+ class FundersIngester< Ingester
10
+
11
+ ENTITY = DMAO::API::Funder
12
+ ENTITY_ERROR = DMAO::Ingesters::Errors::IngestFunderError
13
+ INVALID_ENTITY_ERROR = DMAO::API::Errors::InvalidFunder
14
+ ENTITY_ERROR_MESSAGE = "Invalid funder details"
15
+
16
+ def ingest_funder attributes={}
17
+ ingest_entity attributes
18
+ end
19
+
20
+ private
21
+
22
+ def add_funder attributes
23
+ add_entity attributes
24
+ end
25
+
26
+ def update_funder id, attributes
27
+ update_entity id, attributes
28
+ end
29
+
30
+ end
31
+
32
+ end
33
+ end
34
+ end
@@ -2,6 +2,7 @@ require 'time'
2
2
  require 'dmao_api'
3
3
  require 'dmao/ingesters/errors/generic_ingester'
4
4
  require 'dmao/ingesters/errors/empty_attributes'
5
+ require 'dmao/ingesters/errors/ingest_entity_error'
5
6
 
6
7
  module DMAO
7
8
  module Ingesters
@@ -11,6 +12,7 @@ module DMAO
11
12
 
12
13
  ENTITY = nil
13
14
  ENTITY_ERROR = nil
15
+ INVALID_ENTITY_ERROR = nil
14
16
  ENTITY_ERROR_MESSAGE = nil
15
17
 
16
18
  def initialize(api_url=nil, api_token=nil, institution_id=nil)
@@ -27,8 +29,6 @@ module DMAO
27
29
 
28
30
  def ingest_entity attributes = {}
29
31
 
30
- entity_name = self.class::ENTITY.to_s.split('::')[-1].gsub(/[A-Z]/, " \\0").strip.downcase
31
-
32
32
  raise DMAO::Ingesters::Errors::EmptyAttributes.new("Cannot ingest #{entity_name} without attributes.") if attributes.nil? || attributes.empty?
33
33
 
34
34
  begin
@@ -66,12 +66,32 @@ module DMAO
66
66
 
67
67
  end
68
68
 
69
- def add_entity _attributes={}
70
- raise NotImplementedError
69
+ def add_entity attributes={}
70
+
71
+ begin
72
+ self.class::ENTITY.create attributes
73
+ rescue DMAO::API::Errors::InstitutionNotFound
74
+ raise self.class::ENTITY_ERROR.new("Institution not found, cannot ingest #{entity_name} to non-existent institution")
75
+ rescue self.class::INVALID_ENTITY_ERROR => e
76
+ parse_unprocessable_errors(e.errors)
77
+ end
78
+
79
+ end
80
+
81
+ def update_entity entity_id, attributes={}
82
+
83
+ begin
84
+ self.class::ENTITY.update entity_id, attributes
85
+ rescue DMAO::API::Errors::EntityNotFound
86
+ raise self.class::ENTITY_ERROR.new("#{entity_name.capitalize} not found, cannot update #{entity_name} that does not exist")
87
+ rescue self.class::INVALID_ENTITY_ERROR => e
88
+ parse_unprocessable_errors(e.errors)
89
+ end
90
+
71
91
  end
72
92
 
73
- def update_entity _entity_id, _attributes={}
74
- raise NotImplementedError
93
+ def entity_name
94
+ self.class::ENTITY.to_s.split('::')[-1].gsub(/[A-Z]/, " \\0").strip.downcase
75
95
  end
76
96
 
77
97
  end
@@ -14,6 +14,7 @@ module DMAO
14
14
 
15
15
  ENTITY = DMAO::API::Person
16
16
  ENTITY_ERROR = DMAO::Ingesters::Errors::IngestPersonError
17
+ INVALID_ENTITY_ERROR = DMAO::API::Errors::InvalidPerson
17
18
  ENTITY_ERROR_MESSAGE = "Invalid person details"
18
19
 
19
20
  def ingest_person attributes={}
@@ -22,36 +23,12 @@ module DMAO
22
23
 
23
24
  private
24
25
 
25
- def add_entity attributes
26
- add_person attributes
27
- end
28
-
29
- def update_entity id, attributes
30
- update_person id, attributes
31
- end
32
-
33
26
  def add_person attributes
34
-
35
- begin
36
- DMAO::API::Person.create attributes
37
- rescue DMAO::API::Errors::InstitutionNotFound
38
- raise DMAO::Ingesters::Errors::IngestPersonError.new("Institution not found, cannot ingest person to non-existent institution")
39
- rescue DMAO::API::Errors::InvalidPerson => e
40
- parse_unprocessable_errors(e.errors)
41
- end
42
-
27
+ add_entity attributes
43
28
  end
44
29
 
45
30
  def update_person id, attributes
46
-
47
- begin
48
- DMAO::API::Person.update id, attributes
49
- rescue DMAO::API::Errors::PersonNotFound
50
- raise DMAO::Ingesters::Errors::IngestPersonError.new("Person not found, cannot update person that does not exist")
51
- rescue DMAO::API::Errors::InvalidPerson => e
52
- parse_unprocessable_errors(e.errors)
53
- end
54
-
31
+ update_entity id, attributes
55
32
  end
56
33
 
57
34
  end
@@ -1,7 +1,7 @@
1
1
  module DMAO
2
2
  module Ingesters
3
3
  module Generic
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.0"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dmao-generic-ingesters
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Robinson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-18 00:00:00.000000000 Z
11
+ date: 2017-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dmao_api
@@ -125,10 +125,13 @@ files:
125
125
  - dmao-generic-ingesters.gemspec
126
126
  - lib/dmao/ingesters/errors/empty_attributes.rb
127
127
  - lib/dmao/ingesters/errors/generic_ingester.rb
128
+ - lib/dmao/ingesters/errors/ingest_entity_error.rb
129
+ - lib/dmao/ingesters/errors/ingest_funder_error.rb
128
130
  - lib/dmao/ingesters/errors/ingest_organisation_unit_error.rb
129
131
  - lib/dmao/ingesters/errors/ingest_person_error.rb
130
132
  - lib/dmao/ingesters/errors/link_organisation_unit_error.rb
131
133
  - lib/dmao/ingesters/generic.rb
134
+ - lib/dmao/ingesters/generic/funders_ingester.rb
132
135
  - lib/dmao/ingesters/generic/ingester.rb
133
136
  - lib/dmao/ingesters/generic/organisation_ingester.rb
134
137
  - lib/dmao/ingesters/generic/people_ingester.rb