restforce 3.0.1 → 4.2.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.
Files changed (37) hide show
  1. checksums.yaml +5 -5
  2. data/.circleci/config.yml +9 -9
  3. data/.rubocop.yml +10 -12
  4. data/.rubocop_todo.yml +128 -81
  5. data/CHANGELOG.md +30 -1
  6. data/Gemfile +2 -1
  7. data/README.md +124 -12
  8. data/lib/restforce.rb +22 -1
  9. data/lib/restforce/abstract_client.rb +1 -0
  10. data/lib/restforce/attachment.rb +1 -0
  11. data/lib/restforce/concerns/api.rb +9 -6
  12. data/lib/restforce/concerns/authentication.rb +10 -0
  13. data/lib/restforce/concerns/base.rb +2 -0
  14. data/lib/restforce/concerns/batch_api.rb +87 -0
  15. data/lib/restforce/concerns/canvas.rb +1 -0
  16. data/lib/restforce/concerns/picklists.rb +2 -1
  17. data/lib/restforce/concerns/streaming.rb +75 -3
  18. data/lib/restforce/config.rb +4 -0
  19. data/lib/restforce/document.rb +1 -0
  20. data/lib/restforce/middleware/authentication.rb +3 -2
  21. data/lib/restforce/middleware/authentication/jwt_bearer.rb +38 -0
  22. data/lib/restforce/middleware/multipart.rb +1 -0
  23. data/lib/restforce/middleware/raise_error.rb +24 -8
  24. data/lib/restforce/signed_request.rb +1 -0
  25. data/lib/restforce/sobject.rb +1 -0
  26. data/lib/restforce/tooling/client.rb +3 -3
  27. data/lib/restforce/version.rb +1 -1
  28. data/restforce.gemspec +8 -7
  29. data/spec/fixtures/test_private.key +27 -0
  30. data/spec/integration/abstract_client_spec.rb +42 -1
  31. data/spec/support/fixture_helpers.rb +2 -2
  32. data/spec/unit/concerns/authentication_spec.rb +35 -0
  33. data/spec/unit/concerns/batch_api_spec.rb +107 -0
  34. data/spec/unit/concerns/streaming_spec.rb +144 -4
  35. data/spec/unit/middleware/authentication/jwt_bearer_spec.rb +62 -0
  36. data/spec/unit/middleware/raise_error_spec.rb +32 -11
  37. metadata +53 -32
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ describe Restforce::Middleware::Authentication::JWTBearer do
5
+ let(:jwt_key) { File.read('spec/fixtures/test_private.key') }
6
+
7
+ let(:options) do
8
+ { host: 'login.salesforce.com',
9
+ client_id: 'client_id',
10
+ username: 'foo',
11
+ jwt_key: jwt_key,
12
+ instance_url: 'https://na1.salesforce.com',
13
+ adapter: :net_http }
14
+ end
15
+
16
+ it_behaves_like 'authentication middleware' do
17
+ let(:success_request) do
18
+ stub_login_request(
19
+ body: "grant_type=grant_type—urn:ietf:params:oauth:grant-type:jwt-bearer&" \
20
+ "assertion=abc1234567890"
21
+ ).to_return(status: 200, body: fixture(:auth_success_response))
22
+ end
23
+
24
+ let(:fail_request) do
25
+ stub_login_request(
26
+ body: "grant_type=grant_type—urn:ietf:params:oauth:grant-type:jwt-bearer&" \
27
+ "assertion=abc1234567890"
28
+ ).to_return(status: 400, body: fixture(:refresh_error_response))
29
+ end
30
+ end
31
+
32
+ context 'allows jwt_key as string' do
33
+ let(:jwt_key) do
34
+ File.read('spec/fixtures/test_private.key')
35
+ end
36
+
37
+ let(:options) do
38
+ { host: 'login.salesforce.com',
39
+ client_id: 'client_id',
40
+ username: 'foo',
41
+ jwt_key: jwt_key,
42
+ instance_url: 'https://na1.salesforce.com',
43
+ adapter: :net_http }
44
+ end
45
+
46
+ it_behaves_like 'authentication middleware' do
47
+ let(:success_request) do
48
+ stub_login_request(
49
+ body: "grant_type=grant_type—urn:ietf:params:oauth:grant-type:jwt-bearer&" \
50
+ "assertion=abc1234567890"
51
+ ).to_return(status: 200, body: fixture(:auth_success_response))
52
+ end
53
+
54
+ let(:fail_request) do
55
+ stub_login_request(
56
+ body: "grant_type=grant_type—urn:ietf:params:oauth:grant-type:jwt-bearer&" \
57
+ "assertion=abc1234567890"
58
+ ).to_return(status: 400, body: fixture(:refresh_error_response))
59
+ end
60
+ end
61
+ end
62
+ end
@@ -13,34 +13,46 @@ describe Restforce::Middleware::RaiseError do
13
13
  context 'when the status code is 404' do
14
14
  let(:status) { 404 }
15
15
 
16
- it "raises an error" do
17
- expect { on_complete }.to raise_error Faraday::Error::ResourceNotFound,
16
+ it 'raises Restforce::NotFoundError' do
17
+ expect { on_complete }.to raise_error Restforce::NotFoundError,
18
18
  'INVALID_FIELD: error_message'
19
19
  end
20
+
21
+ it 'raises an error that inherits from Faraday::Error::ResourceNotFound' do
22
+ expect { on_complete }.to raise_error Faraday::Error::ResourceNotFound
23
+ end
20
24
  end
21
25
 
22
26
  context 'when the status code is 300' do
23
27
  let(:status) { 300 }
24
28
 
25
- it "raises an error" do
26
- expect { on_complete }.to raise_error Faraday::Error::ClientError,
29
+ it 'raises Restforce::MatchesMultipleError' do
30
+ expect { on_complete }.to raise_error Restforce::MatchesMultipleError,
27
31
  /300: The external ID provided/
28
32
  end
33
+
34
+ it 'raises an error that inherits from Faraday::Error::ClientError' do
35
+ expect { on_complete }.to raise_error Faraday::Error::ClientError
36
+ end
29
37
  end
30
38
 
31
39
  context 'when the status code is 400' do
32
40
  let(:status) { 400 }
33
41
 
34
- it "raises an error" do
35
- expect { on_complete }.to raise_error Faraday::Error::ClientError,
42
+ it "raises an error derived from the response's errorCode" do
43
+ expect { on_complete }.to raise_error Restforce::ErrorCode::InvalidField,
36
44
  'INVALID_FIELD: error_message'
37
45
  end
46
+
47
+ it 'raises an error that inherits from Faraday::Error::ClientError' do
48
+ expect { on_complete }.to raise_error Faraday::Error::ClientError
49
+ end
38
50
  end
39
51
 
40
52
  context 'when the status code is 401' do
41
53
  let(:status) { 401 }
42
54
 
43
- it "raises an error" do
55
+ it 'raises Restforce::UnauthorizedError' do
44
56
  expect { on_complete }.to raise_error Restforce::UnauthorizedError,
45
57
  'INVALID_FIELD: error_message'
46
58
  end
@@ -49,17 +61,26 @@ describe Restforce::Middleware::RaiseError do
49
61
  context 'when the status code is 413' do
50
62
  let(:status) { 413 }
51
63
 
52
- it "raises an error" do
53
- expect { on_complete }.to raise_error Faraday::Error::ClientError,
64
+ it 'raises Restforce::EntityTooLargeError' do
65
+ expect { on_complete }.to raise_error Restforce::EntityTooLargeError,
54
66
  '413: Request Entity Too Large'
55
67
  end
68
+
69
+ it 'raises an error that inherits from Faraday::Error::ClientError' do
70
+ expect { on_complete }.to raise_error Faraday::Error::ClientError
71
+ end
56
72
  end
57
73
 
58
74
  context 'when status is 400+ and body is a string' do
59
75
  let(:body) { 'An error occured' }
60
- let(:status) { 404 }
76
+ let(:status) { 400 }
77
+
78
+ it 'raises a generic Restforce::ResponseError' do
79
+ expect { on_complete }.to raise_error Restforce::ResponseError,
80
+ "(error code missing): #{body}"
81
+ end
61
82
 
62
- it 'raises an error with a non-existing error code' do
83
+ it 'raises an error that inherits from Faraday::Error::ClientError' do
63
84
  expect { on_complete }.to raise_error Faraday::Error::ClientError,
64
85
  "(error code missing): #{body}"
65
86
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restforce
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.1
4
+ version: 4.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric J. Holmes
@@ -9,28 +9,28 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-08-04 00:00:00.000000000 Z
12
+ date: 2019-10-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - "<="
19
- - !ruby/object:Gem::Version
20
- version: '1.0'
21
18
  - - ">="
22
19
  - !ruby/object:Gem::Version
23
20
  version: 0.9.0
21
+ - - "<="
22
+ - !ruby/object:Gem::Version
23
+ version: '1.0'
24
24
  type: :runtime
25
25
  prerelease: false
26
26
  version_requirements: !ruby/object:Gem::Requirement
27
27
  requirements:
28
- - - "<="
29
- - !ruby/object:Gem::Version
30
- version: '1.0'
31
28
  - - ">="
32
29
  - !ruby/object:Gem::Version
33
30
  version: 0.9.0
31
+ - - "<="
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: faraday_middleware
36
36
  requirement: !ruby/object:Gem::Requirement
@@ -65,6 +65,20 @@ dependencies:
65
65
  - - ">="
66
66
  - !ruby/object:Gem::Version
67
67
  version: 1.7.5
68
+ - !ruby/object:Gem::Dependency
69
+ name: jwt
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 1.5.6
75
+ type: :runtime
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: 1.5.6
68
82
  - !ruby/object:Gem::Dependency
69
83
  name: hashie
70
84
  requirement: !ruby/object:Gem::Requirement
@@ -86,89 +100,89 @@ dependencies:
86
100
  - !ruby/object:Gem::Version
87
101
  version: '4.0'
88
102
  - !ruby/object:Gem::Dependency
89
- name: rspec
103
+ name: faye
90
104
  requirement: !ruby/object:Gem::Requirement
91
105
  requirements:
92
- - - "~>"
106
+ - - ">="
93
107
  - !ruby/object:Gem::Version
94
- version: 2.14.0
108
+ version: '0'
95
109
  type: :development
96
110
  prerelease: false
97
111
  version_requirements: !ruby/object:Gem::Requirement
98
112
  requirements:
99
- - - "~>"
113
+ - - ">="
100
114
  - !ruby/object:Gem::Version
101
- version: 2.14.0
115
+ version: '0'
102
116
  - !ruby/object:Gem::Dependency
103
- name: webmock
117
+ name: rspec
104
118
  requirement: !ruby/object:Gem::Requirement
105
119
  requirements:
106
120
  - - "~>"
107
121
  - !ruby/object:Gem::Version
108
- version: 3.4.0
122
+ version: 2.14.0
109
123
  type: :development
110
124
  prerelease: false
111
125
  version_requirements: !ruby/object:Gem::Requirement
112
126
  requirements:
113
127
  - - "~>"
114
128
  - !ruby/object:Gem::Version
115
- version: 3.4.0
129
+ version: 2.14.0
116
130
  - !ruby/object:Gem::Dependency
117
- name: simplecov
131
+ name: rspec_junit_formatter
118
132
  requirement: !ruby/object:Gem::Requirement
119
133
  requirements:
120
134
  - - "~>"
121
135
  - !ruby/object:Gem::Version
122
- version: 0.15.0
136
+ version: 0.4.1
123
137
  type: :development
124
138
  prerelease: false
125
139
  version_requirements: !ruby/object:Gem::Requirement
126
140
  requirements:
127
141
  - - "~>"
128
142
  - !ruby/object:Gem::Version
129
- version: 0.15.0
143
+ version: 0.4.1
130
144
  - !ruby/object:Gem::Dependency
131
145
  name: rubocop
132
146
  requirement: !ruby/object:Gem::Requirement
133
147
  requirements:
134
148
  - - "~>"
135
149
  - !ruby/object:Gem::Version
136
- version: 0.50.0
150
+ version: 0.75.0
137
151
  type: :development
138
152
  prerelease: false
139
153
  version_requirements: !ruby/object:Gem::Requirement
140
154
  requirements:
141
155
  - - "~>"
142
156
  - !ruby/object:Gem::Version
143
- version: 0.50.0
157
+ version: 0.75.0
144
158
  - !ruby/object:Gem::Dependency
145
- name: rspec_junit_formatter
159
+ name: simplecov
146
160
  requirement: !ruby/object:Gem::Requirement
147
161
  requirements:
148
162
  - - "~>"
149
163
  - !ruby/object:Gem::Version
150
- version: 0.3.0
164
+ version: 0.17.1
151
165
  type: :development
152
166
  prerelease: false
153
167
  version_requirements: !ruby/object:Gem::Requirement
154
168
  requirements:
155
169
  - - "~>"
156
170
  - !ruby/object:Gem::Version
157
- version: 0.3.0
171
+ version: 0.17.1
158
172
  - !ruby/object:Gem::Dependency
159
- name: faye
173
+ name: webmock
160
174
  requirement: !ruby/object:Gem::Requirement
161
175
  requirements:
162
- - - ">="
176
+ - - "~>"
163
177
  - !ruby/object:Gem::Version
164
- version: '0'
178
+ version: 3.7.6
165
179
  type: :development
166
180
  prerelease: false
167
181
  version_requirements: !ruby/object:Gem::Requirement
168
182
  requirements:
169
- - - ">="
183
+ - - "~>"
170
184
  - !ruby/object:Gem::Version
171
- version: '0'
185
+ version: 3.7.6
172
186
  description: A lightweight ruby client for the Salesforce REST API.
173
187
  email:
174
188
  - eric@ejholmes.net
@@ -197,6 +211,7 @@ files:
197
211
  - lib/restforce/concerns/api.rb
198
212
  - lib/restforce/concerns/authentication.rb
199
213
  - lib/restforce/concerns/base.rb
214
+ - lib/restforce/concerns/batch_api.rb
200
215
  - lib/restforce/concerns/caching.rb
201
216
  - lib/restforce/concerns/canvas.rb
202
217
  - lib/restforce/concerns/connection.rb
@@ -209,6 +224,7 @@ files:
209
224
  - lib/restforce/mash.rb
210
225
  - lib/restforce/middleware.rb
211
226
  - lib/restforce/middleware/authentication.rb
227
+ - lib/restforce/middleware/authentication/jwt_bearer.rb
212
228
  - lib/restforce/middleware/authentication/password.rb
213
229
  - lib/restforce/middleware/authentication/token.rb
214
230
  - lib/restforce/middleware/authorization.rb
@@ -265,6 +281,7 @@ files:
265
281
  - spec/fixtures/sobject/upsert_multiple_error_response.json
266
282
  - spec/fixtures/sobject/upsert_updated_success_response.json
267
283
  - spec/fixtures/sobject/write_error_response.json
284
+ - spec/fixtures/test_private.key
268
285
  - spec/integration/abstract_client_spec.rb
269
286
  - spec/integration/data/client_spec.rb
270
287
  - spec/spec_helper.rb
@@ -281,6 +298,7 @@ files:
281
298
  - spec/unit/concerns/api_spec.rb
282
299
  - spec/unit/concerns/authentication_spec.rb
283
300
  - spec/unit/concerns/base_spec.rb
301
+ - spec/unit/concerns/batch_api_spec.rb
284
302
  - spec/unit/concerns/caching_spec.rb
285
303
  - spec/unit/concerns/canvas_spec.rb
286
304
  - spec/unit/concerns/connection_spec.rb
@@ -289,6 +307,7 @@ files:
289
307
  - spec/unit/data/client_spec.rb
290
308
  - spec/unit/document_spec.rb
291
309
  - spec/unit/mash_spec.rb
310
+ - spec/unit/middleware/authentication/jwt_bearer_spec.rb
292
311
  - spec/unit/middleware/authentication/password_spec.rb
293
312
  - spec/unit/middleware/authentication/token_spec.rb
294
313
  - spec/unit/middleware/authentication_spec.rb
@@ -316,15 +335,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
316
335
  requirements:
317
336
  - - ">="
318
337
  - !ruby/object:Gem::Version
319
- version: '2.3'
338
+ version: '2.4'
320
339
  required_rubygems_version: !ruby/object:Gem::Requirement
321
340
  requirements:
322
341
  - - ">="
323
342
  - !ruby/object:Gem::Version
324
343
  version: '0'
325
344
  requirements: []
326
- rubyforge_project:
327
- rubygems_version: 2.6.14.1
345
+ rubygems_version: 3.0.3
328
346
  signing_key:
329
347
  specification_version: 4
330
348
  summary: A lightweight ruby client for the Salesforce REST API.
@@ -363,6 +381,7 @@ test_files:
363
381
  - spec/fixtures/sobject/upsert_multiple_error_response.json
364
382
  - spec/fixtures/sobject/upsert_updated_success_response.json
365
383
  - spec/fixtures/sobject/write_error_response.json
384
+ - spec/fixtures/test_private.key
366
385
  - spec/integration/abstract_client_spec.rb
367
386
  - spec/integration/data/client_spec.rb
368
387
  - spec/spec_helper.rb
@@ -379,6 +398,7 @@ test_files:
379
398
  - spec/unit/concerns/api_spec.rb
380
399
  - spec/unit/concerns/authentication_spec.rb
381
400
  - spec/unit/concerns/base_spec.rb
401
+ - spec/unit/concerns/batch_api_spec.rb
382
402
  - spec/unit/concerns/caching_spec.rb
383
403
  - spec/unit/concerns/canvas_spec.rb
384
404
  - spec/unit/concerns/connection_spec.rb
@@ -387,6 +407,7 @@ test_files:
387
407
  - spec/unit/data/client_spec.rb
388
408
  - spec/unit/document_spec.rb
389
409
  - spec/unit/mash_spec.rb
410
+ - spec/unit/middleware/authentication/jwt_bearer_spec.rb
390
411
  - spec/unit/middleware/authentication/password_spec.rb
391
412
  - spec/unit/middleware/authentication/token_spec.rb
392
413
  - spec/unit/middleware/authentication_spec.rb