4me-sdk 2.0.3 → 2.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/4me-sdk.gemspec +1 -0
- data/Gemfile.lock +33 -35
- data/README.md +12 -4
- data/lib/sdk4me/client/response.rb +3 -3
- data/lib/sdk4me/client/version.rb +1 -1
- data/lib/sdk4me/client.rb +8 -0
- data/spec/lib/sdk4me/client_spec.rb +24 -2
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0fb02daf6964d0f17c4f084d8035b50497e218830a823f8b2f8a40c7af26b659
|
4
|
+
data.tar.gz: fa1a5f86490b2cc33ba9221ba2a0fd79968116b9e66988f2f25345a4dea40128
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4826f9e6545ac80ac3fc674ede10c53f20d87a27d286bfe2814ebd13c526ec80d743af7320947d5e6a1dafbfe2c8f1e501f388e9f4022e5f4cabfc889440ccf1
|
7
|
+
data.tar.gz: 8a80bccaf9cd74342aea7505c35395032c118dbe36fb119c785b9c1b8f435db2c18f9302192bbf4cb58e590379c01c76c24708577da0acbd36ec07f8abbb8e0d
|
data/4me-sdk.gemspec
CHANGED
@@ -31,6 +31,7 @@ Gem::Specification.new do |spec|
|
|
31
31
|
spec.add_runtime_dependency 'mime-types', '>= 3.0'
|
32
32
|
|
33
33
|
spec.add_development_dependency 'bundler'
|
34
|
+
spec.add_development_dependency 'json', '>= 2.6'
|
34
35
|
spec.add_development_dependency 'rake', '~> 12'
|
35
36
|
spec.add_development_dependency 'rspec', '~> 3.3'
|
36
37
|
spec.add_development_dependency 'rubocop', '>= 0.49.0'
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
4me-sdk (2.0.
|
4
|
+
4me-sdk (2.0.4)
|
5
5
|
activesupport (>= 4.2)
|
6
6
|
gem_config (>= 0.3)
|
7
7
|
mime-types (>= 3.0)
|
@@ -9,50 +9,49 @@ PATH
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
|
-
activesupport (
|
12
|
+
activesupport (7.0.1)
|
13
13
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
14
14
|
i18n (>= 1.6, < 2)
|
15
15
|
minitest (>= 5.1)
|
16
16
|
tzinfo (~> 2.0)
|
17
|
-
zeitwerk (~> 2.3)
|
18
17
|
addressable (2.7.0)
|
19
18
|
public_suffix (>= 2.0.2, < 5.0)
|
20
19
|
ast (2.4.2)
|
21
|
-
concurrent-ruby (1.1.
|
22
|
-
crack (0.4.
|
23
|
-
|
24
|
-
|
25
|
-
docile (1.3.5)
|
20
|
+
concurrent-ruby (1.1.9)
|
21
|
+
crack (0.4.4)
|
22
|
+
diff-lcs (1.3)
|
23
|
+
docile (1.3.1)
|
26
24
|
gem_config (0.3.2)
|
27
25
|
hashdiff (1.0.1)
|
28
|
-
i18n (1.8.
|
26
|
+
i18n (1.8.11)
|
29
27
|
concurrent-ruby (~> 1.0)
|
30
|
-
|
28
|
+
json (2.6.1)
|
29
|
+
mime-types (3.4.1)
|
31
30
|
mime-types-data (~> 3.2015)
|
32
|
-
mime-types-data (3.
|
33
|
-
minitest (5.
|
31
|
+
mime-types-data (3.2022.0105)
|
32
|
+
minitest (5.15.0)
|
34
33
|
parallel (1.20.1)
|
35
34
|
parser (3.0.0.0)
|
36
35
|
ast (~> 2.4.1)
|
37
36
|
public_suffix (4.0.6)
|
38
37
|
rainbow (3.0.0)
|
39
|
-
rake (12.3.
|
40
|
-
regexp_parser (2.
|
38
|
+
rake (12.3.1)
|
39
|
+
regexp_parser (2.0.3)
|
41
40
|
rexml (3.2.4)
|
42
|
-
rspec (3.
|
43
|
-
rspec-core (~> 3.
|
44
|
-
rspec-expectations (~> 3.
|
45
|
-
rspec-mocks (~> 3.
|
46
|
-
rspec-core (3.
|
47
|
-
rspec-support (~> 3.
|
48
|
-
rspec-expectations (3.
|
41
|
+
rspec (3.8.0)
|
42
|
+
rspec-core (~> 3.8.0)
|
43
|
+
rspec-expectations (~> 3.8.0)
|
44
|
+
rspec-mocks (~> 3.8.0)
|
45
|
+
rspec-core (3.8.0)
|
46
|
+
rspec-support (~> 3.8.0)
|
47
|
+
rspec-expectations (3.8.2)
|
49
48
|
diff-lcs (>= 1.2.0, < 2.0)
|
50
|
-
rspec-support (~> 3.
|
51
|
-
rspec-mocks (3.
|
49
|
+
rspec-support (~> 3.8.0)
|
50
|
+
rspec-mocks (3.8.0)
|
52
51
|
diff-lcs (>= 1.2.0, < 2.0)
|
53
|
-
rspec-support (~> 3.
|
54
|
-
rspec-support (3.
|
55
|
-
rubocop (1.
|
52
|
+
rspec-support (~> 3.8.0)
|
53
|
+
rspec-support (3.8.0)
|
54
|
+
rubocop (1.8.1)
|
56
55
|
parallel (~> 1.10)
|
57
56
|
parser (>= 3.0.0.0)
|
58
57
|
rainbow (>= 2.2.2, < 4.0)
|
@@ -64,27 +63,26 @@ GEM
|
|
64
63
|
rubocop-ast (1.4.1)
|
65
64
|
parser (>= 2.7.1.5)
|
66
65
|
ruby-progressbar (1.11.0)
|
67
|
-
simplecov (0.
|
66
|
+
simplecov (0.16.1)
|
68
67
|
docile (~> 1.1)
|
69
|
-
|
70
|
-
|
71
|
-
simplecov-html (0.
|
72
|
-
simplecov_json_formatter (0.1.2)
|
68
|
+
json (>= 1.8, < 3)
|
69
|
+
simplecov-html (~> 0.10.0)
|
70
|
+
simplecov-html (0.10.2)
|
73
71
|
tzinfo (2.0.4)
|
74
72
|
concurrent-ruby (~> 1.0)
|
75
73
|
unicode-display_width (2.0.0)
|
76
|
-
webmock (3.
|
74
|
+
webmock (3.9.1)
|
77
75
|
addressable (>= 2.3.6)
|
78
76
|
crack (>= 0.3.2)
|
79
77
|
hashdiff (>= 0.4.0, < 2.0.0)
|
80
|
-
zeitwerk (2.4.2)
|
81
78
|
|
82
79
|
PLATFORMS
|
83
|
-
|
80
|
+
ruby
|
84
81
|
|
85
82
|
DEPENDENCIES
|
86
83
|
4me-sdk!
|
87
84
|
bundler
|
85
|
+
json (>= 2.6)
|
88
86
|
rake (~> 12)
|
89
87
|
rspec (~> 3.3)
|
90
88
|
rubocop (>= 0.49.0)
|
@@ -92,4 +90,4 @@ DEPENDENCIES
|
|
92
90
|
webmock (~> 3)
|
93
91
|
|
94
92
|
BUNDLED WITH
|
95
|
-
|
93
|
+
1.17.3
|
data/README.md
CHANGED
@@ -263,7 +263,10 @@ begin
|
|
263
263
|
response = Sdk4me::Client.new.import('\tmp\people.csv', 'people', true)
|
264
264
|
puts response[:state]
|
265
265
|
puts response[:results]
|
266
|
-
puts response[:
|
266
|
+
puts response[:logfile]
|
267
|
+
unless response.valid?
|
268
|
+
puts "Import completed with errors: #{response[:message]}"
|
269
|
+
end
|
267
270
|
catch Sdk4me::UploadFailed => ex
|
268
271
|
puts "Could not upload the people import file: #{ex.message}"
|
269
272
|
catch Sdk4me::Exception => ex
|
@@ -299,8 +302,13 @@ require 'open-uri'
|
|
299
302
|
begin
|
300
303
|
response = Sdk4me::Client.new.export(['people', 'people_contact_details'], nil, true)
|
301
304
|
puts response[:state]
|
302
|
-
|
303
|
-
|
305
|
+
if response.valid?
|
306
|
+
# write the export file to disk
|
307
|
+
File.open('/tmp/export.zip', 'wb') { |f| f.write(open(response[:url]).read) }
|
308
|
+
else
|
309
|
+
puts "Export failed with errors: #{response[:message]}"
|
310
|
+
puts response[:logfile]
|
311
|
+
end
|
304
312
|
catch Sdk4me::UploadFailed => ex
|
305
313
|
puts "Could not queue the people export: #{ex.message}"
|
306
314
|
catch Sdk4me::Exception => ex
|
@@ -353,4 +361,4 @@ The changelog is available [here](CHANGELOG.md).
|
|
353
361
|
|
354
362
|
## Copyright
|
355
363
|
|
356
|
-
Copyright (c)
|
364
|
+
Copyright (c) 2022 4me, Inc. See [LICENSE](LICENSE) for further details.
|
@@ -103,9 +103,9 @@ module Sdk4me
|
|
103
103
|
def pagination_link(relation)
|
104
104
|
# split on ',' select the [url] in '<[url]>; rel="[relation]"', compact to all url's found (at most one) and take the first
|
105
105
|
(@pagination_links ||= {})[relation] ||= @response.header['Link'] &&
|
106
|
-
|
107
|
-
|
108
|
-
|
106
|
+
@response.header['Link']
|
107
|
+
.split(/,\s*(?:<|$)/)
|
108
|
+
.map { |link| link[/^\s*<?(.*?)>?;\s*rel="#{relation}"\s*$/, 1] }.compact.first
|
109
109
|
end
|
110
110
|
|
111
111
|
# pagination urls (relative paths without server) - relations :first, :prev, :next
|
data/lib/sdk4me/client.rb
CHANGED
@@ -145,9 +145,13 @@ module Sdk4me
|
|
145
145
|
token = response[:token]
|
146
146
|
loop do
|
147
147
|
response = get("/import/#{token}")
|
148
|
+
return response if response[:state] == 'error'
|
149
|
+
|
148
150
|
unless response.valid?
|
149
151
|
sleep(5)
|
150
152
|
response = get("/import/#{token}") # single retry to recover from a network error
|
153
|
+
return response if response[:state] == 'error'
|
154
|
+
|
151
155
|
raise ::Sdk4me::Exception, "Unable to monitor progress for #{type} import. #{response.message}" unless response.valid?
|
152
156
|
end
|
153
157
|
# wait 30 seconds while the response is OK and import is still busy
|
@@ -186,9 +190,13 @@ module Sdk4me
|
|
186
190
|
token = response[:token]
|
187
191
|
loop do
|
188
192
|
response = get("/export/#{token}")
|
193
|
+
return response if response[:state] == 'error'
|
194
|
+
|
189
195
|
unless response.valid?
|
190
196
|
sleep(5)
|
191
197
|
response = get("/export/#{token}") # single retry to recover from a network error
|
198
|
+
return response if response[:state] == 'error'
|
199
|
+
|
192
200
|
raise ::Sdk4me::Exception, "Unable to monitor progress for '#{data[:type]}' export. #{response.message}" unless response.valid?
|
193
201
|
end
|
194
202
|
# wait 30 seconds while the response is OK and export is still busy
|
@@ -364,8 +364,10 @@ describe Sdk4me::Client do
|
|
364
364
|
stub_request(:post, 'https://api.4me.com/v1/import').with(credentials(authentication)).with(body: @multi_part_body, headers: @multi_part_headers).to_return(body: { token: '68ef5ef0f64c0' }.to_json)
|
365
365
|
progress_stub = stub_request(:get, 'https://api.4me.com/v1/import/68ef5ef0f64c0').with(credentials(authentication)).to_return(@import_queued_response, @import_processing_response, @import_failed_response)
|
366
366
|
|
367
|
-
|
368
|
-
expect(
|
367
|
+
response = client(authentication).import("#{@fixture_dir}/people.csv", 'people', true)
|
368
|
+
expect(response.valid?).to be_falsey
|
369
|
+
expect(response[:message]).to eq('Invalid byte sequence in UTF-8 on line 2')
|
370
|
+
expect(progress_stub).to have_been_requested.times(3)
|
369
371
|
end
|
370
372
|
|
371
373
|
it 'should not continue when there is an error connecting to 4me' do
|
@@ -389,6 +391,16 @@ describe Sdk4me::Client do
|
|
389
391
|
stub_request(:post, 'https://api.4me.com/v1/import').with(credentials(authentication)).with(body: @multi_part_body, headers: @multi_part_headers).to_return(body: { message: 'oops!' }.to_json)
|
390
392
|
expect { client(authentication).import("#{@fixture_dir}/people.csv", 'people', true) }.to raise_error(Sdk4me::UploadFailed, 'Failed to queue people import. oops!')
|
391
393
|
end
|
394
|
+
|
395
|
+
it 'should return the error response when the import state is set to error' do
|
396
|
+
stub_request(:post, 'https://api.4me.com/v1/import').with(credentials(authentication)).with(body: @multi_part_body, headers: @multi_part_headers).to_return(body: { token: '68ef5ef0f64c0' }.to_json)
|
397
|
+
stub_request(:get, 'https://api.4me.com/v1/import/68ef5ef0f64c0').with(credentials(authentication)).to_return(body: { state: 'error', message: 'Too many import failures', logfile: 'foo' }.to_json)
|
398
|
+
|
399
|
+
response = client(authentication).import("#{@fixture_dir}/people.csv", 'people', true)
|
400
|
+
expect(response.valid?).to be_falsey
|
401
|
+
expect(response[:message]).to eq('Too many import failures')
|
402
|
+
expect(response[:logfile]).to eq('foo')
|
403
|
+
end
|
392
404
|
end
|
393
405
|
|
394
406
|
context 'export' do
|
@@ -480,6 +492,16 @@ describe Sdk4me::Client do
|
|
480
492
|
stub_request(:post, 'https://api.4me.com/v1/export').with(credentials(authentication)).with(body: { type: 'people' }).to_return(body: { message: 'oops!' }.to_json)
|
481
493
|
expect { client(authentication).export('people', nil, true) }.to raise_error(Sdk4me::UploadFailed, "Failed to queue 'people' export. oops!")
|
482
494
|
end
|
495
|
+
|
496
|
+
it 'should return the error response when the export state is set to error' do
|
497
|
+
stub_request(:post, 'https://api.4me.com/v1/export').with(credentials(authentication)).with(body: { type: 'people' }).to_return(body: { token: '68ef5ef0f64c0' }.to_json)
|
498
|
+
stub_request(:get, 'https://api.4me.com/v1/export/68ef5ef0f64c0').with(credentials(authentication)).to_return(body: { state: 'error', message: 'Too many export failures', logfile: 'foo' }.to_json)
|
499
|
+
|
500
|
+
response = client(authentication).export('people', nil, true)
|
501
|
+
expect(response.valid?).to be_falsey
|
502
|
+
expect(response[:message]).to eq('Too many export failures')
|
503
|
+
expect(response[:logfile]).to eq('foo')
|
504
|
+
end
|
483
505
|
end
|
484
506
|
|
485
507
|
context 'retry' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: 4me-sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- 4me
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: json
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.6'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.6'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: rake
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -184,7 +198,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
184
198
|
- !ruby/object:Gem::Version
|
185
199
|
version: '0'
|
186
200
|
requirements: []
|
187
|
-
rubygems_version: 3.
|
201
|
+
rubygems_version: 3.1.6
|
188
202
|
signing_key:
|
189
203
|
specification_version: 4
|
190
204
|
summary: The official 4me SDK for Ruby. Provides easy access to the REST APIs found
|