ecoportal-api 0.1.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 +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +53 -0
- data/README.md +34 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/ecoportal-api.gemspec +28 -0
- data/lib/ecoportal/api.rb +11 -0
- data/lib/ecoportal/api/common.rb +13 -0
- data/lib/ecoportal/api/common/base_model.rb +39 -0
- data/lib/ecoportal/api/common/batch_operation.rb +94 -0
- data/lib/ecoportal/api/common/batch_response.rb +16 -0
- data/lib/ecoportal/api/common/client.rb +58 -0
- data/lib/ecoportal/api/common/doc_helpers.rb +27 -0
- data/lib/ecoportal/api/common/hash_diff.rb +37 -0
- data/lib/ecoportal/api/common/response.rb +22 -0
- data/lib/ecoportal/api/common/wrapped_response.rb +38 -0
- data/lib/ecoportal/api/internal.rb +31 -0
- data/lib/ecoportal/api/internal/.git-keep +0 -0
- data/lib/ecoportal/api/internal/account.rb +31 -0
- data/lib/ecoportal/api/internal/login_provider.rb +9 -0
- data/lib/ecoportal/api/internal/login_providers.rb +18 -0
- data/lib/ecoportal/api/internal/people.rb +19 -0
- data/lib/ecoportal/api/internal/permissions.rb +9 -0
- data/lib/ecoportal/api/internal/person.rb +40 -0
- data/lib/ecoportal/api/internal/person_details.rb +13 -0
- data/lib/ecoportal/api/internal/person_schema.rb +14 -0
- data/lib/ecoportal/api/internal/person_schemas.rb +15 -0
- data/lib/ecoportal/api/internal/policy_group.rb +9 -0
- data/lib/ecoportal/api/internal/policy_groups.rb +18 -0
- data/lib/ecoportal/api/internal/preferences.rb +9 -0
- data/lib/ecoportal/api/internal/schema_field.rb +8 -0
- data/lib/ecoportal/api/internal/schema_field_value.rb +8 -0
- data/lib/ecoportal/api/v1.rb +23 -0
- data/lib/ecoportal/api/v1/.git-keep +0 -0
- data/lib/ecoportal/api/v1/people.rb +98 -0
- data/lib/ecoportal/api/v1/person.rb +50 -0
- data/lib/ecoportal/api/v1/person_details.rb +51 -0
- data/lib/ecoportal/api/v1/person_schema.rb +46 -0
- data/lib/ecoportal/api/v1/person_schemas.rb +24 -0
- data/lib/ecoportal/api/v1/schema_field.rb +9 -0
- data/lib/ecoportal/api/v1/schema_field_value.rb +67 -0
- data/lib/ecoportal/api/version.rb +5 -0
- metadata +146 -0
@@ -0,0 +1,50 @@
|
|
1
|
+
module Ecoportal
|
2
|
+
module API
|
3
|
+
class V1
|
4
|
+
class Person < Common::BaseModel
|
5
|
+
passthrough :id, :external_id, :name, :email, :supervisor_id, to: :doc
|
6
|
+
|
7
|
+
def supervisor(client)
|
8
|
+
return @supervisor if defined?(@supervisor)
|
9
|
+
return @supervisor = nil if supervisor_id.nil?
|
10
|
+
@supervisor = client.people.get(supervisor_id).result
|
11
|
+
end
|
12
|
+
|
13
|
+
def supervisor=(person)
|
14
|
+
self.supervisor_id = person.id
|
15
|
+
end
|
16
|
+
|
17
|
+
def as_json
|
18
|
+
super.merge "details" => details&.as_json
|
19
|
+
end
|
20
|
+
|
21
|
+
def details
|
22
|
+
return @details if defined?(@details)
|
23
|
+
return @details = nil if doc["details"].nil?
|
24
|
+
@details = person_details_class.new(doc["details"])
|
25
|
+
end
|
26
|
+
|
27
|
+
def details=(value)
|
28
|
+
case value
|
29
|
+
when NilClass
|
30
|
+
doc["details"] = nil
|
31
|
+
when V1::PersonDetails
|
32
|
+
doc["details"] = JSON.parse(value.to_json)
|
33
|
+
when Hash
|
34
|
+
doc["details"] = value.slice("schema_id", "fields")
|
35
|
+
else
|
36
|
+
raise "Invalid set on details: Need nil, PersonDetails or Hash; got #{value.class}"
|
37
|
+
end
|
38
|
+
remove_instance_variable("@details")
|
39
|
+
return details
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def person_details_class
|
45
|
+
V1::PersonDetails
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Ecoportal
|
2
|
+
module API
|
3
|
+
class V1
|
4
|
+
class PersonDetails < Common::BaseModel
|
5
|
+
passthrough :schema_id, to: :doc
|
6
|
+
|
7
|
+
def as_json
|
8
|
+
super.merge "fields" => fields.map(&:as_json)
|
9
|
+
end
|
10
|
+
|
11
|
+
def schema_id=(value)
|
12
|
+
@fields = [] if value.nil?
|
13
|
+
super
|
14
|
+
end
|
15
|
+
|
16
|
+
def fields
|
17
|
+
return @fields if defined?(@fields)
|
18
|
+
@fields = (doc["fields"] || []).map do |field|
|
19
|
+
schema_field_value_class.new(field)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def index_fields
|
24
|
+
@fields_by_id = {}
|
25
|
+
@fields_by_alt_id = {}
|
26
|
+
fields.each do |wrapped|
|
27
|
+
@fields_by_id[wrapped.id] = wrapped
|
28
|
+
@fields_by_id[wrapped.alt_id] = wrapped
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def [](id)
|
33
|
+
@fields_by_id or index_fields
|
34
|
+
(@fields_by_id[id] || @fields_by_alt_id[id])&.value
|
35
|
+
end
|
36
|
+
def []=(id, value)
|
37
|
+
@fields_by_id or index_fields
|
38
|
+
if field = (@fields_by_id[id] || @fields_by_alt_id[id])
|
39
|
+
field.value = value
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def schema_field_value_class
|
46
|
+
V1::SchemaFieldValue
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Ecoportal
|
2
|
+
module API
|
3
|
+
class V1
|
4
|
+
class PersonSchema < Common::BaseModel
|
5
|
+
passthrough :id, :name, to: :doc
|
6
|
+
|
7
|
+
def fields
|
8
|
+
@fields_by_id or index_fields
|
9
|
+
@fields_by_id.values
|
10
|
+
end
|
11
|
+
|
12
|
+
def fields_by_id
|
13
|
+
@fields_by_id or index_fields
|
14
|
+
@fields_by_id
|
15
|
+
end
|
16
|
+
|
17
|
+
def fields_by_alt_id
|
18
|
+
@fields_by_alt_id or index_fields
|
19
|
+
@fields_by_alt_id
|
20
|
+
end
|
21
|
+
|
22
|
+
def [](id)
|
23
|
+
@fields_by_alt_id or index_fields
|
24
|
+
@fields_by_id[id] || @fields_by_alt_id[id]
|
25
|
+
end
|
26
|
+
|
27
|
+
def index_fields
|
28
|
+
@fields_by_id = {}
|
29
|
+
@fields_by_alt_id = {}
|
30
|
+
doc["fields"].each do |field|
|
31
|
+
wrapped = schema_field_class.new(field)
|
32
|
+
@fields_by_id[wrapped.id] = wrapped
|
33
|
+
@fields_by_id[wrapped.alt_id] = wrapped
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def schema_field_class
|
40
|
+
V1::SchemaField
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
require 'ecoportal/api/v1/schema_field'
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Ecoportal
|
2
|
+
module API
|
3
|
+
class V1
|
4
|
+
class PersonSchemas
|
5
|
+
attr_reader :client
|
6
|
+
def initialize(client)
|
7
|
+
@client = client
|
8
|
+
end
|
9
|
+
def get_all
|
10
|
+
response = @client.get("/person_schemas")
|
11
|
+
Common::WrappedResponse.new(response, person_schema_class)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def person_schema_class
|
17
|
+
V1::PersonSchema
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
require 'ecoportal/api/v1/person_schema'
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module Ecoportal
|
2
|
+
module API
|
3
|
+
class V1
|
4
|
+
class SchemaFieldValue < Common::BaseModel
|
5
|
+
passthrough :id, :alt_id, :type, :name, :shared, :multiple, to: :doc
|
6
|
+
|
7
|
+
def value
|
8
|
+
return @value if defined?(@value)
|
9
|
+
@value = case type
|
10
|
+
when "text", "phone_number", "number", "boolean", "select"
|
11
|
+
doc["value"]
|
12
|
+
when "date"
|
13
|
+
if doc["value"]
|
14
|
+
maybe_multiple(doc["value"]) do |v|
|
15
|
+
DateTime.iso8601(v)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
else
|
19
|
+
raise "Unknown type #{type}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def value=(value)
|
24
|
+
case type
|
25
|
+
when "text", "phone_number", "select"
|
26
|
+
doc["value"] = @value = maybe_multiple(value) do |v|
|
27
|
+
v&.to_s
|
28
|
+
end
|
29
|
+
when "number"
|
30
|
+
maybe_multiple(value) do |v|
|
31
|
+
unless v.nil? || v.is_a?(Numeric)
|
32
|
+
raise "Invalid number type #{v.class}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
doc["value"] = @value = value
|
36
|
+
when "boolean"
|
37
|
+
doc["value"] = @value = !!value
|
38
|
+
when "date"
|
39
|
+
maybe_multiple(value) do |v|
|
40
|
+
unless v.nil? || v.respond_to?(:iso8601)
|
41
|
+
raise "Invalid date type #{v.class}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
@value = value
|
45
|
+
doc["value"] = maybe_multiple(@value) do |v|
|
46
|
+
v&.iso8601
|
47
|
+
end
|
48
|
+
else
|
49
|
+
raise "Unknown type #{type}"
|
50
|
+
end
|
51
|
+
@value
|
52
|
+
end
|
53
|
+
|
54
|
+
def maybe_multiple(value)
|
55
|
+
if multiple
|
56
|
+
unless value.is_a?(Array)
|
57
|
+
raise "Expected Array, got #{value.class}"
|
58
|
+
end
|
59
|
+
value.map {|v| yield v }
|
60
|
+
else
|
61
|
+
yield value
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
metadata
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ecoportal-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tapio Saarinen
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-06-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: http
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- tapio@ecoportal.co.nz
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".travis.yml"
|
79
|
+
- Gemfile
|
80
|
+
- Gemfile.lock
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- bin/console
|
84
|
+
- bin/setup
|
85
|
+
- ecoportal-api.gemspec
|
86
|
+
- lib/ecoportal/api.rb
|
87
|
+
- lib/ecoportal/api/common.rb
|
88
|
+
- lib/ecoportal/api/common/base_model.rb
|
89
|
+
- lib/ecoportal/api/common/batch_operation.rb
|
90
|
+
- lib/ecoportal/api/common/batch_response.rb
|
91
|
+
- lib/ecoportal/api/common/client.rb
|
92
|
+
- lib/ecoportal/api/common/doc_helpers.rb
|
93
|
+
- lib/ecoportal/api/common/hash_diff.rb
|
94
|
+
- lib/ecoportal/api/common/response.rb
|
95
|
+
- lib/ecoportal/api/common/wrapped_response.rb
|
96
|
+
- lib/ecoportal/api/internal.rb
|
97
|
+
- lib/ecoportal/api/internal/.git-keep
|
98
|
+
- lib/ecoportal/api/internal/account.rb
|
99
|
+
- lib/ecoportal/api/internal/login_provider.rb
|
100
|
+
- lib/ecoportal/api/internal/login_providers.rb
|
101
|
+
- lib/ecoportal/api/internal/people.rb
|
102
|
+
- lib/ecoportal/api/internal/permissions.rb
|
103
|
+
- lib/ecoportal/api/internal/person.rb
|
104
|
+
- lib/ecoportal/api/internal/person_details.rb
|
105
|
+
- lib/ecoportal/api/internal/person_schema.rb
|
106
|
+
- lib/ecoportal/api/internal/person_schemas.rb
|
107
|
+
- lib/ecoportal/api/internal/policy_group.rb
|
108
|
+
- lib/ecoportal/api/internal/policy_groups.rb
|
109
|
+
- lib/ecoportal/api/internal/preferences.rb
|
110
|
+
- lib/ecoportal/api/internal/schema_field.rb
|
111
|
+
- lib/ecoportal/api/internal/schema_field_value.rb
|
112
|
+
- lib/ecoportal/api/v1.rb
|
113
|
+
- lib/ecoportal/api/v1/.git-keep
|
114
|
+
- lib/ecoportal/api/v1/people.rb
|
115
|
+
- lib/ecoportal/api/v1/person.rb
|
116
|
+
- lib/ecoportal/api/v1/person_details.rb
|
117
|
+
- lib/ecoportal/api/v1/person_schema.rb
|
118
|
+
- lib/ecoportal/api/v1/person_schemas.rb
|
119
|
+
- lib/ecoportal/api/v1/schema_field.rb
|
120
|
+
- lib/ecoportal/api/v1/schema_field_value.rb
|
121
|
+
- lib/ecoportal/api/version.rb
|
122
|
+
homepage: https://www.ecoportal.com
|
123
|
+
licenses:
|
124
|
+
- MIT
|
125
|
+
metadata: {}
|
126
|
+
post_install_message:
|
127
|
+
rdoc_options: []
|
128
|
+
require_paths:
|
129
|
+
- lib
|
130
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
requirements: []
|
141
|
+
rubyforge_project:
|
142
|
+
rubygems_version: 2.7.6
|
143
|
+
signing_key:
|
144
|
+
specification_version: 4
|
145
|
+
summary: A collection of helpers for interacting with the ecoPortal MS's various APIs
|
146
|
+
test_files: []
|