ecoportal-api 0.2.0 → 0.2.1
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 +4 -4
- data/lib/ecoportal/api/common/batch_operation.rb +8 -6
- data/lib/ecoportal/api/common/batch_response.rb +15 -2
- data/lib/ecoportal/api/common/wrapped_response.rb +7 -1
- data/lib/ecoportal/api/internal/account.rb +14 -0
- data/lib/ecoportal/api/v1/person_schema.rb +4 -0
- data/lib/ecoportal/api/v1/schema_field_value.rb +3 -3
- data/lib/ecoportal/api/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc61e1dcd4fce98df40134e6d8803ecb1cf173dfc3fc2e728fffe1651b9b00be
|
4
|
+
data.tar.gz: edc0798d69fc802c50f0f6fce556e9bb62c4242a05145286332148c3ee4fce72
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29ea3c284644656303b702dd507e1d133319bf9cd6b48403ae2b738b4e16ba19d93692ffcd20b110070c571086f0cda7b3ea1db2b0a7f8afd69b7c56bb261b64
|
7
|
+
data.tar.gz: aeb583b4065f68809d52145913854faac2feb8098ff0e2f993db03916df08fa55a70d3fe27383c02bdc01ebf1988602c20c55e801b5f553abe961f7af7ef2ea7
|
@@ -28,10 +28,11 @@ module Ecoportal
|
|
28
28
|
body = subresponse["response"]
|
29
29
|
method = @operations[idx][:method]
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
callback.call batch_response,
|
31
|
+
if status == 200 && method == "GET"
|
32
|
+
batch_response = BatchResponse.new(status, body, @wrapper.new(body))
|
33
|
+
callback.call batch_response, batch_response.result
|
34
34
|
else
|
35
|
+
batch_response = BatchResponse.new(status, body)
|
35
36
|
callback.call batch_response
|
36
37
|
end
|
37
38
|
end
|
@@ -61,10 +62,11 @@ module Ecoportal
|
|
61
62
|
end
|
62
63
|
|
63
64
|
def upsert(doc)
|
64
|
-
id
|
65
|
-
|
65
|
+
id = get_id(doc)
|
66
|
+
external_id = get_external_id(doc)
|
67
|
+
body = get_body(doc)
|
66
68
|
@operations << {
|
67
|
-
path: @base_path + "/" + CGI::escape(id),
|
69
|
+
path: @base_path + "/" + CGI::escape(external_id || id),
|
68
70
|
method: "POST",
|
69
71
|
body: body,
|
70
72
|
callback: block_given? && Proc.new
|
@@ -2,14 +2,27 @@ module Ecoportal
|
|
2
2
|
module API
|
3
3
|
module Common
|
4
4
|
class BatchResponse
|
5
|
-
attr_reader :status, :body
|
6
|
-
def initialize(status, body)
|
5
|
+
attr_reader :status, :body, :result
|
6
|
+
def initialize(status, body, result = nil)
|
7
7
|
@status = status
|
8
8
|
@body = body
|
9
|
+
@result = result
|
9
10
|
end
|
10
11
|
def success?
|
11
12
|
(0..299).include?(status)
|
12
13
|
end
|
14
|
+
def each
|
15
|
+
[*@result].each do |doc|
|
16
|
+
yield doc
|
17
|
+
end
|
18
|
+
end
|
19
|
+
def print
|
20
|
+
if success?
|
21
|
+
each(&:print)
|
22
|
+
else
|
23
|
+
puts "Request failed."
|
24
|
+
end
|
25
|
+
end
|
13
26
|
end
|
14
27
|
end
|
15
28
|
end
|
@@ -18,17 +18,23 @@ module Ecoportal
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
21
|
+
def body
|
22
|
+
response.body.to_s
|
23
|
+
end
|
21
24
|
def each
|
22
25
|
[*@result].each do |doc|
|
23
26
|
yield doc
|
24
27
|
end
|
25
28
|
end
|
29
|
+
def status
|
30
|
+
@response.status.code
|
31
|
+
end
|
26
32
|
def success?
|
27
33
|
@response.success?
|
28
34
|
end
|
29
35
|
def print
|
30
36
|
if success?
|
31
|
-
|
37
|
+
each(&:print)
|
32
38
|
else
|
33
39
|
puts "Request failed."
|
34
40
|
end
|
@@ -4,10 +4,24 @@ module Ecoportal
|
|
4
4
|
class Account < Common::BaseModel
|
5
5
|
passthrough :policy_group_ids, :landing_page_id, :permissions_preset, :permissions_custom, :preferences, :prefilter, :filter_tags, :login_provider_ids, :starred_ids, to: :doc
|
6
6
|
|
7
|
+
VALID_TAG_REGEX = /^[A-Za-z0-9 &_'\/-]+$/
|
8
|
+
|
7
9
|
def preset=(value)
|
8
10
|
self.permissions_preset = value == "custom" ? nil : value
|
9
11
|
end
|
10
12
|
|
13
|
+
def filter_tags=(value)
|
14
|
+
unless value.is_a?(Array)
|
15
|
+
raise "filter_tags= needs to be passed an Array, got #{value.class}"
|
16
|
+
end
|
17
|
+
doc["filter_tags"] = value.map do |tag|
|
18
|
+
unless tag.match(VALID_TAG_REGEX)
|
19
|
+
raise "Invalid filter tag #{tag.inspect}"
|
20
|
+
end
|
21
|
+
tag.upcase
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
11
25
|
def preset
|
12
26
|
self.permissions_preset.nil? ? "custom" : self.permissions_preset
|
13
27
|
end
|
@@ -41,6 +41,10 @@ module Ecoportal
|
|
41
41
|
"value" => field.multiple ? [] : nil
|
42
42
|
)
|
43
43
|
end
|
44
|
+
# Patch out static data from as_update
|
45
|
+
original = details.instance_variable_get("@original_doc")
|
46
|
+
original["fields"] = JSON.parse(details.doc["fields"].to_json)
|
47
|
+
return
|
44
48
|
end
|
45
49
|
|
46
50
|
private
|
@@ -12,7 +12,7 @@ module Ecoportal
|
|
12
12
|
when "date"
|
13
13
|
if doc["value"]
|
14
14
|
maybe_multiple(doc["value"]) do |v|
|
15
|
-
|
15
|
+
Date.iso8601(v)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
else
|
@@ -37,13 +37,13 @@ module Ecoportal
|
|
37
37
|
doc["value"] = @value = !!value
|
38
38
|
when "date"
|
39
39
|
maybe_multiple(value) do |v|
|
40
|
-
unless v.nil? || v.respond_to?(:
|
40
|
+
unless v.nil? || v.respond_to?(:to_date)
|
41
41
|
raise "Invalid date type #{v.class}"
|
42
42
|
end
|
43
43
|
end
|
44
44
|
@value = value
|
45
45
|
doc["value"] = maybe_multiple(@value) do |v|
|
46
|
-
v&.
|
46
|
+
v&.to_date&.to_s
|
47
47
|
end
|
48
48
|
else
|
49
49
|
raise "Unknown type #{type}"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ecoportal-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tapio Saarinen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-08-
|
11
|
+
date: 2018-08-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|