ecoportal-api-v2 1.1.7 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.markdownlint.json +4 -0
- data/.rubocop.yml +54 -15
- data/.ruby-version +1 -0
- data/CHANGELOG.md +485 -373
- data/ecoportal-api-v2.gemspec +13 -12
- data/lib/ecoportal/api/common/concerns/benchmarkable.rb +47 -34
- data/lib/ecoportal/api/common/concerns/threadable.rb +41 -0
- data/lib/ecoportal/api/common/concerns.rb +1 -0
- data/lib/ecoportal/api/common/content/array_model.rb +85 -79
- data/lib/ecoportal/api/common/content/class_helpers.rb +34 -31
- data/lib/ecoportal/api/common/content/collection_model.rb +77 -65
- data/lib/ecoportal/api/common/content/double_model.rb +105 -87
- data/lib/ecoportal/api/common/content/wrapped_response.rb +11 -11
- data/lib/ecoportal/api/v2/page/component/reference_field.rb +17 -13
- data/lib/ecoportal/api/v2/page/component.rb +67 -68
- data/lib/ecoportal/api/v2/page/components.rb +9 -9
- data/lib/ecoportal/api/v2/page/force.rb +6 -7
- data/lib/ecoportal/api/v2/page/stages.rb +5 -6
- data/lib/ecoportal/api/v2/page.rb +35 -33
- data/lib/ecoportal/api/v2/pages/page_stage.rb +22 -20
- data/lib/ecoportal/api/v2/pages.rb +18 -14
- data/lib/ecoportal/api/v2/people.rb +2 -3
- data/lib/ecoportal/api/v2/registers.rb +28 -13
- data/lib/ecoportal/api/v2/s3/data.rb +27 -0
- data/lib/ecoportal/api/v2/s3/files/batch_upload.rb +110 -0
- data/lib/ecoportal/api/v2/s3/files/poll.rb +82 -0
- data/lib/ecoportal/api/v2/s3/files/poll_status.rb +52 -0
- data/lib/ecoportal/api/v2/s3/files.rb +132 -0
- data/lib/ecoportal/api/v2/s3/upload.rb +154 -0
- data/lib/ecoportal/api/v2/s3.rb +66 -0
- data/lib/ecoportal/api/v2.rb +10 -3
- data/lib/ecoportal/api/v2_version.rb +1 -1
- metadata +53 -54
@@ -0,0 +1,66 @@
|
|
1
|
+
module Ecoportal
|
2
|
+
module API
|
3
|
+
class V2
|
4
|
+
# @attr_reader client [Common::Client] a `Common::Client` object that holds the configuration of the api connection.
|
5
|
+
class S3
|
6
|
+
class MissingLocalFile < ArgumentError; end
|
7
|
+
class CredentialsGetFailed < StandardError; end
|
8
|
+
|
9
|
+
extend Common::BaseClass
|
10
|
+
|
11
|
+
class_resolver :data_class, "Ecoportal::API::V2::S3::Data"
|
12
|
+
class_resolver :files_class, "Ecoportal::API::V2::S3::Files"
|
13
|
+
|
14
|
+
attr_reader :client
|
15
|
+
|
16
|
+
# @param client [Common::Client] a `Common::Client` object that holds the configuration of the api connection.
|
17
|
+
# @return [Schemas] an instance object ready to make schema api requests.
|
18
|
+
def initialize(client)
|
19
|
+
@client = client
|
20
|
+
end
|
21
|
+
|
22
|
+
# Gets the S3 credentials to upload files
|
23
|
+
# @return [Ecoportal::API::V2::S3::Data]
|
24
|
+
def data
|
25
|
+
response = client.get("/s3/data")
|
26
|
+
body = body_data(response.body)
|
27
|
+
|
28
|
+
return data_class.new(body) if response.success?
|
29
|
+
|
30
|
+
msg = "Could not get S3 credentials - Error #{response.status}: #{body}"
|
31
|
+
raise CredentialsGetFailed, msg
|
32
|
+
end
|
33
|
+
|
34
|
+
# @param file [String] full path to existing local file
|
35
|
+
# @param credentials [Ecoportal::API::V2::S3::Data, NilClass]
|
36
|
+
# @return [Hash, NilClass] with the s3_file_reference on success, and `nil` otherwise
|
37
|
+
def upload_file(file, credentials: data, &block)
|
38
|
+
msg = "The file '#{file}' does not exist"
|
39
|
+
raise MissingLocalFile, msg unless File.exist?(file)
|
40
|
+
|
41
|
+
credentials ||= data
|
42
|
+
Upload.new(credentials, file: file).upload!(&block)
|
43
|
+
end
|
44
|
+
|
45
|
+
# Obtain specific object for eP file api requests.
|
46
|
+
# @return [Files] an instance object ready to make eP file api requests.
|
47
|
+
def files
|
48
|
+
files_class.new(client, s3_api: self)
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def body_data(body)
|
54
|
+
return body unless body.is_a?(Hash)
|
55
|
+
return body unless body.key?("data")
|
56
|
+
|
57
|
+
body["data"]
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
require 'ecoportal/api/v2/s3/data'
|
65
|
+
require 'ecoportal/api/v2/s3/upload'
|
66
|
+
require 'ecoportal/api/v2/s3/files'
|
data/lib/ecoportal/api/v2.rb
CHANGED
@@ -8,10 +8,10 @@ module Ecoportal
|
|
8
8
|
extend Common::BaseClass
|
9
9
|
include Common::Logging
|
10
10
|
|
11
|
-
VERSION = "v2"
|
11
|
+
VERSION = "v2".freeze
|
12
12
|
|
13
13
|
class << self
|
14
|
-
def v2key
|
14
|
+
def v2key(ukey, gkey)
|
15
15
|
Base64.urlsafe_encode64({
|
16
16
|
organization: gkey,
|
17
17
|
user: ukey
|
@@ -22,6 +22,7 @@ module Ecoportal
|
|
22
22
|
class_resolver :people_class, "Ecoportal::API::V2::People"
|
23
23
|
class_resolver :registers_class, "Ecoportal::API::V2::Registers"
|
24
24
|
class_resolver :pages_class, "Ecoportal::API::V2::Pages"
|
25
|
+
class_resolver :s3_class, "Ecoportal::API::V2::S3"
|
25
26
|
|
26
27
|
attr_reader :client, :logger
|
27
28
|
|
@@ -64,6 +65,12 @@ module Ecoportal
|
|
64
65
|
pages_class.new(client)
|
65
66
|
end
|
66
67
|
|
68
|
+
# Obtain specific object for file api requests.
|
69
|
+
# @return [S3] an instance object ready to make files api requests.
|
70
|
+
def s3 # rubocop:disable Naming/VariableNumber
|
71
|
+
s3_class.new(client)
|
72
|
+
end
|
73
|
+
|
67
74
|
private
|
68
75
|
|
69
76
|
def get_key(api_key: nil, user_key: nil, org_key: nil)
|
@@ -72,7 +79,6 @@ module Ecoportal
|
|
72
79
|
raise "You need to provide either an api_key or user_key" unless user_key
|
73
80
|
raise "You need to provide an org_key as well (not just a user_key)" unless org_key
|
74
81
|
end
|
75
|
-
|
76
82
|
end
|
77
83
|
end
|
78
84
|
end
|
@@ -80,3 +86,4 @@ end
|
|
80
86
|
require 'ecoportal/api/v2/people'
|
81
87
|
require 'ecoportal/api/v2/pages'
|
82
88
|
require 'ecoportal/api/v2/registers'
|
89
|
+
require 'ecoportal/api/v2/s3'
|
metadata
CHANGED
@@ -1,55 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ecoportal-api-v2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oscar Segura
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-08-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 2.4.12
|
20
|
-
- - "<"
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: '3'
|
23
|
-
type: :development
|
24
|
-
prerelease: false
|
25
|
-
version_requirements: !ruby/object:Gem::Requirement
|
26
|
-
requirements:
|
27
|
-
- - ">="
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: 2.4.12
|
30
|
-
- - "<"
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: '3'
|
33
|
-
- !ruby/object:Gem::Dependency
|
34
|
-
name: rspec
|
14
|
+
name: pry
|
35
15
|
requirement: !ruby/object:Gem::Requirement
|
36
16
|
requirements:
|
37
17
|
- - ">="
|
38
18
|
- !ruby/object:Gem::Version
|
39
|
-
version:
|
40
|
-
- - "<"
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
version: '4'
|
19
|
+
version: '0.14'
|
43
20
|
type: :development
|
44
21
|
prerelease: false
|
45
22
|
version_requirements: !ruby/object:Gem::Requirement
|
46
23
|
requirements:
|
47
24
|
- - ">="
|
48
25
|
- !ruby/object:Gem::Version
|
49
|
-
version:
|
50
|
-
- - "<"
|
51
|
-
- !ruby/object:Gem::Version
|
52
|
-
version: '4'
|
26
|
+
version: '0.14'
|
53
27
|
- !ruby/object:Gem::Dependency
|
54
28
|
name: rake
|
55
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -71,32 +45,32 @@ dependencies:
|
|
71
45
|
- !ruby/object:Gem::Version
|
72
46
|
version: '14'
|
73
47
|
- !ruby/object:Gem::Dependency
|
74
|
-
name:
|
48
|
+
name: redcarpet
|
75
49
|
requirement: !ruby/object:Gem::Requirement
|
76
50
|
requirements:
|
77
51
|
- - ">="
|
78
52
|
- !ruby/object:Gem::Version
|
79
|
-
version:
|
53
|
+
version: 3.6.0
|
80
54
|
- - "<"
|
81
55
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
56
|
+
version: '4'
|
83
57
|
type: :development
|
84
58
|
prerelease: false
|
85
59
|
version_requirements: !ruby/object:Gem::Requirement
|
86
60
|
requirements:
|
87
61
|
- - ">="
|
88
62
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
63
|
+
version: 3.6.0
|
90
64
|
- - "<"
|
91
65
|
- !ruby/object:Gem::Version
|
92
|
-
version: '
|
66
|
+
version: '4'
|
93
67
|
- !ruby/object:Gem::Dependency
|
94
|
-
name:
|
68
|
+
name: rspec
|
95
69
|
requirement: !ruby/object:Gem::Requirement
|
96
70
|
requirements:
|
97
71
|
- - ">="
|
98
72
|
- !ruby/object:Gem::Version
|
99
|
-
version: 3.
|
73
|
+
version: 3.12.0
|
100
74
|
- - "<"
|
101
75
|
- !ruby/object:Gem::Version
|
102
76
|
version: '4'
|
@@ -106,44 +80,58 @@ dependencies:
|
|
106
80
|
requirements:
|
107
81
|
- - ">="
|
108
82
|
- !ruby/object:Gem::Version
|
109
|
-
version: 3.
|
83
|
+
version: 3.12.0
|
110
84
|
- - "<"
|
111
85
|
- !ruby/object:Gem::Version
|
112
86
|
version: '4'
|
113
87
|
- !ruby/object:Gem::Dependency
|
114
|
-
name:
|
88
|
+
name: yard
|
115
89
|
requirement: !ruby/object:Gem::Requirement
|
116
90
|
requirements:
|
117
|
-
- - "
|
91
|
+
- - "~>"
|
118
92
|
- !ruby/object:Gem::Version
|
119
|
-
version:
|
93
|
+
version: 0.9.34
|
120
94
|
type: :development
|
121
95
|
prerelease: false
|
122
96
|
version_requirements: !ruby/object:Gem::Requirement
|
123
97
|
requirements:
|
124
|
-
- - "
|
98
|
+
- - "~>"
|
125
99
|
- !ruby/object:Gem::Version
|
126
|
-
version:
|
100
|
+
version: 0.9.34
|
127
101
|
- !ruby/object:Gem::Dependency
|
128
102
|
name: ecoportal-api
|
129
103
|
requirement: !ruby/object:Gem::Requirement
|
130
104
|
requirements:
|
131
|
-
- - "
|
132
|
-
- !ruby/object:Gem::Version
|
133
|
-
version: 0.9.6
|
134
|
-
- - "<"
|
105
|
+
- - "~>"
|
135
106
|
- !ruby/object:Gem::Version
|
136
107
|
version: '0.10'
|
137
108
|
type: :runtime
|
138
109
|
prerelease: false
|
139
110
|
version_requirements: !ruby/object:Gem::Requirement
|
140
111
|
requirements:
|
112
|
+
- - "~>"
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0.10'
|
115
|
+
- !ruby/object:Gem::Dependency
|
116
|
+
name: mime-types
|
117
|
+
requirement: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - "~>"
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '3.5'
|
141
122
|
- - ">="
|
142
123
|
- !ruby/object:Gem::Version
|
143
|
-
version:
|
144
|
-
|
124
|
+
version: 3.5.2
|
125
|
+
type: :runtime
|
126
|
+
prerelease: false
|
127
|
+
version_requirements: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
145
130
|
- !ruby/object:Gem::Version
|
146
|
-
version: '
|
131
|
+
version: '3.5'
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: 3.5.2
|
147
135
|
description:
|
148
136
|
email:
|
149
137
|
- rien@ecoportal.co.nz
|
@@ -154,8 +142,10 @@ extensions: []
|
|
154
142
|
extra_rdoc_files: []
|
155
143
|
files:
|
156
144
|
- ".gitignore"
|
145
|
+
- ".markdownlint.json"
|
157
146
|
- ".rspec"
|
158
147
|
- ".rubocop.yml"
|
148
|
+
- ".ruby-version"
|
159
149
|
- ".yardopts"
|
160
150
|
- CHANGELOG.md
|
161
151
|
- Gemfile
|
@@ -169,6 +159,7 @@ files:
|
|
169
159
|
- lib/ecoportal/api/common.v2.rb
|
170
160
|
- lib/ecoportal/api/common/concerns.rb
|
171
161
|
- lib/ecoportal/api/common/concerns/benchmarkable.rb
|
162
|
+
- lib/ecoportal/api/common/concerns/threadable.rb
|
172
163
|
- lib/ecoportal/api/common/content.rb
|
173
164
|
- lib/ecoportal/api/common/content/array_model.rb
|
174
165
|
- lib/ecoportal/api/common/content/class_helpers.rb
|
@@ -249,11 +240,19 @@ files:
|
|
249
240
|
- lib/ecoportal/api/v2/registers/stage_result.rb
|
250
241
|
- lib/ecoportal/api/v2/registers/stages_result.rb
|
251
242
|
- lib/ecoportal/api/v2/registers/template.rb
|
243
|
+
- lib/ecoportal/api/v2/s3.rb
|
244
|
+
- lib/ecoportal/api/v2/s3/data.rb
|
245
|
+
- lib/ecoportal/api/v2/s3/files.rb
|
246
|
+
- lib/ecoportal/api/v2/s3/files/batch_upload.rb
|
247
|
+
- lib/ecoportal/api/v2/s3/files/poll.rb
|
248
|
+
- lib/ecoportal/api/v2/s3/files/poll_status.rb
|
249
|
+
- lib/ecoportal/api/v2/s3/upload.rb
|
252
250
|
- lib/ecoportal/api/v2_version.rb
|
253
251
|
homepage: https://www.ecoportal.com
|
254
252
|
licenses:
|
255
253
|
- MIT
|
256
|
-
metadata:
|
254
|
+
metadata:
|
255
|
+
rubygems_mfa_required: 'true'
|
257
256
|
post_install_message:
|
258
257
|
rdoc_options: []
|
259
258
|
require_paths:
|
@@ -262,14 +261,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
262
261
|
requirements:
|
263
262
|
- - ">="
|
264
263
|
- !ruby/object:Gem::Version
|
265
|
-
version: 2.
|
264
|
+
version: 3.2.2
|
266
265
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
267
266
|
requirements:
|
268
267
|
- - ">="
|
269
268
|
- !ruby/object:Gem::Version
|
270
269
|
version: '0'
|
271
270
|
requirements: []
|
272
|
-
rubygems_version: 3.
|
271
|
+
rubygems_version: 3.5.6
|
273
272
|
signing_key:
|
274
273
|
specification_version: 4
|
275
274
|
summary: A collection of helpers for interacting with the ecoPortal MS's V2 API
|