4me-sdk 1.2.0 → 2.0.0.pre.rc.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/4me-sdk.gemspec +12 -13
- data/Gemfile.lock +51 -30
- data/LICENSE +1 -1
- data/README.md +31 -23
- data/lib/sdk4me.rb +6 -5
- data/lib/sdk4me/ca-bundle.crt +1327 -1802
- data/lib/sdk4me/client.rb +96 -84
- data/lib/sdk4me/client/attachments.rb +103 -116
- data/lib/sdk4me/client/multipart.rb +16 -18
- data/lib/sdk4me/client/response.rb +17 -19
- data/lib/sdk4me/client/version.rb +1 -1
- data/spec/lib/sdk4me/attachments_spec.rb +282 -203
- data/spec/lib/sdk4me/certificate_spec.rb +3 -4
- data/spec/lib/sdk4me/client_spec.rb +165 -157
- data/spec/lib/sdk4me/response_spec.rb +25 -29
- data/spec/lib/sdk4me_spec.rb +7 -7
- data/spec/spec_helper.rb +5 -8
- data/spec/support/matchers/never_raise.rb +16 -21
- data/spec/support/util.rb +2 -2
- metadata +35 -20
@@ -13,28 +13,28 @@ describe Sdk4me::Response do
|
|
13
13
|
|
14
14
|
def credentials(authentication)
|
15
15
|
if authentication == :api_token
|
16
|
-
{ basic_auth: [
|
16
|
+
{ basic_auth: %w[secret x] }
|
17
17
|
else
|
18
|
-
{ headers: {'Authorization' => 'Bearer secret'} }
|
18
|
+
{ headers: { 'Authorization' => 'Bearer secret' } }
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
[
|
22
|
+
%i[api_token access_token].each do |authentication|
|
23
23
|
context "#{authentication} - " do
|
24
24
|
before(:each) do
|
25
25
|
@person_hash = {
|
26
|
-
addresses:[],
|
27
|
-
contacts:[
|
26
|
+
addresses: [],
|
27
|
+
contacts: [{ id: 1365, label: 'work', telephone: '7139872946' }],
|
28
28
|
id: 562,
|
29
29
|
information: 'Info about John.',
|
30
30
|
job_title: 'rolling stone',
|
31
31
|
locale: 'en-US',
|
32
32
|
location: 'Top of John Hill',
|
33
33
|
name: 'John',
|
34
|
-
organization: {id: 20, name: 'SDK4ME Institute'},
|
34
|
+
organization: { id: 20, name: 'SDK4ME Institute' },
|
35
35
|
picture_uri: nil,
|
36
36
|
primary_email: 'john@example.com',
|
37
|
-
site: {id:14, name: 'IT Training Facility'},
|
37
|
+
site: { id: 14, name: 'IT Training Facility' },
|
38
38
|
time_format_24h: false,
|
39
39
|
time_zone: 'Central Time (US & Canada)'
|
40
40
|
}
|
@@ -42,9 +42,9 @@ describe Sdk4me::Response do
|
|
42
42
|
@response_hash = client(authentication).get('me')
|
43
43
|
|
44
44
|
@people_array = [
|
45
|
-
{id: 562, name: 'John', organization: { id: 20, name: 'SDK4ME Institute'}, site: {id: 14, name: 'IT Training Facility'} },
|
46
|
-
{id: 560, name: 'Lucas', organization: { id: 20, name: 'SDK4ME Institute', office: { name: 'The Office'}}, site: {id: 14, name: 'IT Training Facility'} },
|
47
|
-
{id: 561, name: 'Sheryl', organization: { id: 20, name: 'SDK4ME Institute'}, site: {id: 14, name: 'IT Training Facility'} }
|
45
|
+
{ id: 562, name: 'John', organization: { id: 20, name: 'SDK4ME Institute' }, site: { id: 14, name: 'IT Training Facility' } },
|
46
|
+
{ id: 560, name: 'Lucas', organization: { id: 20, name: 'SDK4ME Institute', office: { name: 'The Office' } }, site: { id: 14, name: 'IT Training Facility' } },
|
47
|
+
{ id: 561, name: 'Sheryl', organization: { id: 20, name: 'SDK4ME Institute' }, site: { id: 14, name: 'IT Training Facility' } }
|
48
48
|
]
|
49
49
|
stub_request(:get, 'https://api.4me.com/v1/people').to_return(body: @people_array.to_json).with(credentials(authentication))
|
50
50
|
@response_array = client(authentication).get('people')
|
@@ -98,7 +98,7 @@ describe Sdk4me::Response do
|
|
98
98
|
end
|
99
99
|
|
100
100
|
it 'should add a message if the HTTP response is not OK' do
|
101
|
-
stub_request(:get, 'https://api.4me.com/v1/organizations').with(credentials(authentication)).to_return(status: 429, body: {message: 'Too Many Requests'}.to_json)
|
101
|
+
stub_request(:get, 'https://api.4me.com/v1/organizations').with(credentials(authentication)).to_return(status: 429, body: { message: 'Too Many Requests' }.to_json)
|
102
102
|
response = client(authentication).get('organizations')
|
103
103
|
|
104
104
|
message = '429: Too Many Requests'
|
@@ -124,7 +124,6 @@ describe Sdk4me::Response do
|
|
124
124
|
it 'should have a blank message when single record is succesfully retrieved' do
|
125
125
|
expect(@response_array.message).to be_nil
|
126
126
|
end
|
127
|
-
|
128
127
|
end
|
129
128
|
|
130
129
|
it 'should define empty' do
|
@@ -138,12 +137,12 @@ describe Sdk4me::Response do
|
|
138
137
|
|
139
138
|
context 'valid' do
|
140
139
|
it 'should be valid when the message is nil' do
|
141
|
-
expect(@response_hash).to receive(:message){ nil }
|
140
|
+
expect(@response_hash).to receive(:message) { nil }
|
142
141
|
expect(@response_hash.valid?).to be_truthy
|
143
142
|
end
|
144
143
|
|
145
144
|
it 'should not be valid when the message is not nil' do
|
146
|
-
expect(@response_array).to receive(:message){ 'invalid' }
|
145
|
+
expect(@response_array).to receive(:message) { 'invalid' }
|
147
146
|
expect(@response_array.valid?).to be_falsey
|
148
147
|
end
|
149
148
|
end
|
@@ -165,7 +164,7 @@ describe Sdk4me::Response do
|
|
165
164
|
|
166
165
|
context 'list of records' do
|
167
166
|
it 'should delegate [] to the json of each record' do
|
168
|
-
expect(@response_array['name']).to eq([
|
167
|
+
expect(@response_array['name']).to eq(%w[John Lucas Sheryl])
|
169
168
|
end
|
170
169
|
|
171
170
|
it 'should allow multiple keys' do
|
@@ -188,7 +187,7 @@ describe Sdk4me::Response do
|
|
188
187
|
end
|
189
188
|
|
190
189
|
it 'should return nil if an error message is present' do
|
191
|
-
expect(@response_hash).to receive(:message){ 'error message' }
|
190
|
+
expect(@response_hash).to receive(:message) { 'error message' }
|
192
191
|
expect(@response_hash.size).to eq(0)
|
193
192
|
end
|
194
193
|
end
|
@@ -203,7 +202,7 @@ describe Sdk4me::Response do
|
|
203
202
|
end
|
204
203
|
|
205
204
|
it 'should return nil if an error message is present' do
|
206
|
-
expect(@response_hash).to receive(:message){ 'error message' }
|
205
|
+
expect(@response_hash).to receive(:message) { 'error message' }
|
207
206
|
expect(@response_hash.count).to eq(0)
|
208
207
|
end
|
209
208
|
end
|
@@ -215,9 +214,9 @@ describe Sdk4me::Response do
|
|
215
214
|
'X-Pagination-Current-Page' => 1,
|
216
215
|
'X-Pagination-Total-Pages' => 2,
|
217
216
|
'X-Pagination-Total-Entries' => 5,
|
218
|
-
'Link' => '<https://api.4me.com/v1/people?page=1&per_page=3>; rel="first",<https://api.4me.com/v1/people?page=2&per_page=3>; rel="next", <https://api.4me.com/v1/people?page=2&per_page=3>; rel="last"'
|
217
|
+
'Link' => '<https://api.4me.com/v1/people?page=1&per_page=3>; rel="first",<https://api.4me.com/v1/people?page=2&per_page=3>; rel="next", <https://api.4me.com/v1/people?page=2&per_page=3>; rel="last"'
|
219
218
|
}
|
220
|
-
allow(@response_array.response).to receive('header'){ @pagination_header }
|
219
|
+
allow(@response_array.response).to receive('header') { @pagination_header }
|
221
220
|
end
|
222
221
|
|
223
222
|
it "should retrieve per_page from the 'X-Pagination-Per-Page' header" do
|
@@ -236,19 +235,17 @@ describe Sdk4me::Response do
|
|
236
235
|
expect(@response_array.total_entries).to eq(5)
|
237
236
|
end
|
238
237
|
|
239
|
-
{first: 'https://api.4me.com/v1/people?page=1&per_page=3',
|
240
|
-
|
241
|
-
|
242
|
-
|
238
|
+
{ first: 'https://api.4me.com/v1/people?page=1&per_page=3',
|
239
|
+
next: 'https://api.4me.com/v1/people?page=2&per_page=3',
|
240
|
+
last: 'https://api.4me.com/v1/people?page=2&per_page=3' }.each do |relation, link|
|
243
241
|
it "should define pagination link for :#{relation}" do
|
244
242
|
expect(@response_array.pagination_link(relation)).to eq(link)
|
245
243
|
end
|
246
244
|
end
|
247
245
|
|
248
|
-
{first: '/v1/people?page=1&per_page=3',
|
249
|
-
|
250
|
-
|
251
|
-
|
246
|
+
{ first: '/v1/people?page=1&per_page=3',
|
247
|
+
next: '/v1/people?page=2&per_page=3',
|
248
|
+
last: '/v1/people?page=2&per_page=3' }.each do |relation, link|
|
252
249
|
it "should define pagination relative link for :#{relation}" do
|
253
250
|
expect(@response_array.pagination_relative_link(relation)).to eq(link)
|
254
251
|
end
|
@@ -268,7 +265,7 @@ describe Sdk4me::Response do
|
|
268
265
|
end
|
269
266
|
|
270
267
|
it 'should check the return message' do
|
271
|
-
stub_request(:get, 'https://api.4me.com/v1/organizations').with(credentials(authentication)).to_return(status: 500, body: {message: 'Too Many Requests'}.to_json
|
268
|
+
stub_request(:get, 'https://api.4me.com/v1/organizations').with(credentials(authentication)).to_return(status: 500, body: { message: 'Too Many Requests' }.to_json)
|
272
269
|
response = client(authentication).get('organizations')
|
273
270
|
expect(response.throttled?).to be_truthy
|
274
271
|
end
|
@@ -285,7 +282,6 @@ describe Sdk4me::Response do
|
|
285
282
|
expect(response.to_s).to eq('429: empty body')
|
286
283
|
end
|
287
284
|
end
|
288
|
-
|
289
285
|
end
|
290
286
|
end
|
291
287
|
end
|
data/spec/lib/sdk4me_spec.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Sdk4me do
|
4
|
-
it
|
4
|
+
it 'should define a default configuration' do
|
5
5
|
conf = Sdk4me.configuration.current
|
6
6
|
|
7
|
-
expect(conf.keys.sort).to eq([
|
7
|
+
expect(conf.keys.sort).to eq(%i[access_token account api_token api_version block_at_rate_limit ca_file host logger max_retry_time max_throttle_time proxy_host proxy_password proxy_port proxy_user read_timeout source])
|
8
8
|
|
9
9
|
expect(conf[:logger].class).to eq(::Logger)
|
10
10
|
expect(conf[:host]).to eq('https://api.4me.com')
|
@@ -16,18 +16,18 @@ describe Sdk4me do
|
|
16
16
|
|
17
17
|
expect(conf[:proxy_port]).to eq(8080)
|
18
18
|
|
19
|
-
[
|
19
|
+
%i[access_token api_token account source proxy_host proxy_user proxy_password].each do |no_default|
|
20
20
|
expect(conf[no_default]).to be_nil
|
21
21
|
end
|
22
22
|
|
23
23
|
expect(conf[:ca_file]).to eq('../ca-bundle.crt')
|
24
24
|
end
|
25
25
|
|
26
|
-
it
|
26
|
+
it 'should define a logger' do
|
27
27
|
expect(Sdk4me.logger.class).to eq(::Logger)
|
28
28
|
end
|
29
29
|
|
30
|
-
it
|
31
|
-
expect { raise ::Sdk4me::Exception
|
30
|
+
it 'should define an exception class' do
|
31
|
+
expect { raise ::Sdk4me::Exception, 'test' }.to raise_error('test')
|
32
32
|
end
|
33
|
-
end
|
33
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
1
|
dir = File.dirname(__FILE__)
|
3
|
-
$LOAD_PATH.unshift dir
|
2
|
+
$LOAD_PATH.unshift "#{dir}/../lib"
|
4
3
|
$LOAD_PATH.unshift dir
|
5
4
|
|
6
|
-
|
5
|
+
warn("Running specs using ruby version #{RUBY_VERSION}")
|
7
6
|
|
8
7
|
require 'simplecov'
|
9
8
|
SimpleCov.start
|
@@ -26,12 +25,12 @@ require 'sdk4me/client'
|
|
26
25
|
|
27
26
|
# Requires supporting ruby files with custom matchers and macros, etc,
|
28
27
|
# in spec/support/ and its subdirectories.
|
29
|
-
Dir["#{dir}/support/**/*.rb"].each { |f| require f }
|
28
|
+
Dir["#{dir}/support/**/*.rb"].sort.each { |f| require f }
|
30
29
|
|
31
30
|
RSpec.configure do |config|
|
32
31
|
config.before(:each) do
|
33
|
-
log_dir = File.dirname(__FILE__)
|
34
|
-
Dir.mkdir(log_dir) unless File.
|
32
|
+
log_dir = "#{File.dirname(__FILE__)}/log"
|
33
|
+
Dir.mkdir(log_dir) unless File.exist?(log_dir)
|
35
34
|
Sdk4me.configuration.logger = Logger.new("#{log_dir}/test.log")
|
36
35
|
@spec_dir = dir
|
37
36
|
@fixture_dir = "#{dir}/support/fixtures"
|
@@ -43,6 +42,4 @@ RSpec.configure do |config|
|
|
43
42
|
# the seed, which is printed after each run.
|
44
43
|
# --seed 1234
|
45
44
|
config.order = 'random'
|
46
|
-
|
47
45
|
end
|
48
|
-
|
@@ -19,28 +19,23 @@ RSpec::Matchers.define :never_raise do |exception_class|
|
|
19
19
|
end
|
20
20
|
|
21
21
|
match do |block|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
raise
|
37
|
-
|
38
|
-
else
|
39
|
-
true # everything ran, nothing raised at all, thus code did in fact not raise anything
|
40
|
-
end
|
22
|
+
block.call
|
23
|
+
rescue exception_class => e
|
24
|
+
global_result = "expected #{block.source_location[0]}:#{block.source_location[1]} to never raise #{exception_class.name}, but did: #{e.message}"
|
25
|
+
false # we did NOT never raise this exception
|
26
|
+
rescue RSpec::Expectations::ExpectationNotMetError => e
|
27
|
+
global_result = "expectation failed inside block at #{block.source_location[0]}:#{block.source_location[1]}: #{e}"
|
28
|
+
# give us a pretty error message in addition to the error message from the exception
|
29
|
+
raise e
|
30
|
+
rescue StandardError
|
31
|
+
# handle other exceptions by reraising them. They are exceptional!!!
|
32
|
+
# (also, no pretty error messages here)
|
33
|
+
raise
|
34
|
+
else
|
35
|
+
true # everything ran, nothing raised at all, thus code did in fact not raise anything
|
41
36
|
end
|
42
37
|
|
43
|
-
failure_message do |
|
38
|
+
failure_message do |_player|
|
44
39
|
global_result
|
45
40
|
end
|
46
|
-
end
|
41
|
+
end
|
data/spec/support/util.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
def expect_log(text, level = :info, logger = Sdk4me.configuration.logger)
|
2
|
-
expect(logger).to
|
3
|
-
end
|
2
|
+
expect(logger).to(receive(level).ordered { |&args| expect(args.call).to eq(text) })
|
3
|
+
end
|
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: 4me-sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0.pre.rc.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- 4me
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '4.2'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '4.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: gem_config
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0.3'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0.3'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: mime-types
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -95,19 +95,19 @@ dependencies:
|
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '3.3'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: rubocop
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- - "
|
101
|
+
- - ">="
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version:
|
103
|
+
version: 0.49.0
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- - "
|
108
|
+
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
110
|
+
version: 0.49.0
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: simplecov
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,7 +122,21 @@ dependencies:
|
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
|
-
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: webmock
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '3'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '3'
|
139
|
+
description: SDK for accessing the 4me REST API
|
126
140
|
email: developers@4me.com
|
127
141
|
executables: []
|
128
142
|
extensions: []
|
@@ -163,18 +177,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
163
177
|
requirements:
|
164
178
|
- - ">="
|
165
179
|
- !ruby/object:Gem::Version
|
166
|
-
version: 2.
|
180
|
+
version: 2.5.0
|
167
181
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
168
182
|
requirements:
|
169
|
-
- - "
|
183
|
+
- - ">"
|
170
184
|
- !ruby/object:Gem::Version
|
171
|
-
version:
|
185
|
+
version: 1.3.1
|
172
186
|
requirements: []
|
173
|
-
|
187
|
+
rubyforge_project:
|
188
|
+
rubygems_version: 2.7.9
|
174
189
|
signing_key:
|
175
190
|
specification_version: 4
|
176
|
-
summary: The official 4me SDK for Ruby. Provides easy access to the APIs found
|
177
|
-
https://developer.4me.com
|
191
|
+
summary: The official 4me SDK for Ruby. Provides easy access to the REST APIs found
|
192
|
+
at https://developer.4me.com
|
178
193
|
test_files:
|
179
194
|
- spec/lib/sdk4me/attachments_spec.rb
|
180
195
|
- spec/lib/sdk4me/certificate_spec.rb
|