restforce 2.5.0 → 2.5.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of restforce might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9e798ab8d32c43d1ae3b424d3e48d7e75cac1450
4
- data.tar.gz: 5f79e271ed9e74ad7657dc954d1dccb04f4adb0c
3
+ metadata.gz: 6a2edec8fbe80bbf028b896e38efbe598ce91ba9
4
+ data.tar.gz: 567b7ede645cc03d358320ac85898efd106f9415
5
5
  SHA512:
6
- metadata.gz: 5f5758308c6f4ba3be1171f4228772c36700f62726136b6dc2789b4dcce9cf1bbf469e2eeafe6b0e71737525cc00929eec4f7d25ca9ff6bc79b4f9e0fa26b3d2
7
- data.tar.gz: b2e7a13436430a980f558e65a05be0176765f15dbbcece508813e25c5d50baf114d7915cc0955bd4533962f0bed05e47617892d4e91b62a0a3e3e05b14b4d227
6
+ metadata.gz: 902362f2c9cc5c24d70c945873f3afc182b1225925cb7d2dd8d5419a1b5ba02d4fc3f1f833813981118620c33994a843bf3c244e4dc42546c85fb85d79896861
7
+ data.tar.gz: 42a7923a9ae9e2e8c9d2928b746fe2832b5f40ed0a81882aed777cf8cd0e8fee91fc76f8e42f1e7e9212b1d9a280c5d3411535409b5a81e431b8b219e65bc982
@@ -4,10 +4,13 @@ rvm:
4
4
  - 2.1
5
5
  - 2.2
6
6
  - 2.3.1
7
- - ruby-2.4.0-preview2
7
+ - ruby-2.4.0
8
8
  gemfile:
9
9
  - Gemfile.travis
10
10
  script:
11
11
  - bundle exec rubocop
12
12
  - bundle exec rspec spec
13
13
  sudo: false
14
+ before_install:
15
+ - gem update --system
16
+ - gem update bundler
@@ -1,3 +1,9 @@
1
+ ## 2.5.1 (Mar 16, 2017)
2
+
3
+ * Allow setting custom headers, [required by parts of the Salesforce API](https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/headers.htm), by specifiying a `:request_headers` option when instantiating the client (@moskeyombus)
4
+ * Add support for `upsert`ing using an ID (see the [Salesforce docs](https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_upsert.htm) for more details) (@ecbypi)
5
+ * Relax `faraday` dependency to allow upgrading to Faraday 1.0 (@tinogomes, @alexluke)
6
+
1
7
  ## 2.5.0 (Dec 7, 2016)
2
8
 
3
9
  * __Deprecate support for Ruby 1.9__, since [official support was dropped nearly two years ago](https://www.ruby-lang.org/en/news/2014/01/10/ruby-1-9-3-will-end-on-2015/), and it's causing problems with keeping our dependencies up to date
data/README.md CHANGED
@@ -25,7 +25,7 @@ Features include:
25
25
 
26
26
  Add this line to your application's Gemfile:
27
27
 
28
- gem 'restforce', '~> 2.5.0'
28
+ gem 'restforce', '~> 2.5.1'
29
29
 
30
30
  And then execute:
31
31
 
@@ -194,6 +194,23 @@ to do some custom error handling. The bang methods will raise exceptions, while
194
194
  non-bang methods will return false in the event that an exception is raised. This
195
195
  works similarly to ActiveRecord.
196
196
 
197
+
198
+ ### Custom Headers
199
+
200
+ Salesforce allows the addition of
201
+ [custom headers](https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/headers.htm)
202
+ in REST API requests to trigger specific logic. In order to pass any custom headers along with API requests,
203
+ you can specify a hash of `:request_headers` upon client initialization. The example below demonstrates how
204
+ to include the `sforce-auto-assign` header in all client HTTP requests:
205
+
206
+ ```ruby
207
+ client = Restforce.new(oauth_token: 'access_token',
208
+ instance_url: 'instance url',
209
+ api_version: '38.0',
210
+ request_headers: { 'sforce-auto-assign' => 'FALSE' })
211
+
212
+ ```
213
+
197
214
  * * *
198
215
 
199
216
  ### query
@@ -361,12 +361,17 @@ module Restforce
361
361
  # error returned if the external ID provided matches multiple records (in which
362
362
  # case the conflicting IDs can be found by looking at the response on the error)
363
363
  def upsert!(sobject, field, attrs)
364
- external_id = attrs.
365
- fetch(attrs.keys.find { |k, v| k.to_s.downcase == field.to_s.downcase }, nil)
366
- attrs_without_field = attrs.
367
- reject { |k, v| k.to_s.downcase == field.to_s.downcase }
368
- response = api_patch "sobjects/#{sobject}/#{field}/#{URI.encode(external_id)}",
369
- attrs_without_field
364
+ external_id =
365
+ extract_case_insensitive_string_or_symbol_key_from_hash!(attrs, field)
366
+
367
+ response =
368
+ if field.to_s == "Id" && (external_id.nil? || external_id.strip.empty?)
369
+ version_guard(37.0) do
370
+ api_post "sobjects/#{sobject}/#{field}", attrs
371
+ end
372
+ else
373
+ api_patch "sobjects/#{sobject}/#{field}/#{URI.encode(external_id)}", attrs
374
+ end
370
375
 
371
376
  (response.body && response.body['id']) ? response.body['id'] : true
372
377
  end
@@ -484,6 +489,14 @@ module Restforce
484
489
  end
485
490
  end
486
491
 
492
+ def extract_case_insensitive_string_or_symbol_key_from_hash!(hash, key)
493
+ value = hash.delete(key.to_sym)
494
+ value ||= hash.delete(key.to_s)
495
+ value ||= hash.delete(key.to_s.downcase)
496
+ value ||= hash.delete(key.to_s.downcase.to_sym)
497
+ value
498
+ end
499
+
487
500
  # Internal: Errors that should be rescued from in non-bang methods
488
501
  def exceptions
489
502
  [Faraday::Error::ClientError]
@@ -50,6 +50,10 @@ module Restforce
50
50
  #
51
51
  # :authentication_callback - A Proc that is called with the response body
52
52
  # after a successful authentication.
53
+ #
54
+ # :request_headers - A hash containing custom headers that will be
55
+ # appended to each request
56
+
53
57
  def initialize(opts = {})
54
58
  raise ArgumentError, 'Please specify a hash of options' unless opts.is_a?(Hash)
55
59
 
@@ -52,6 +52,8 @@ module Restforce
52
52
  options if Restforce.log?
53
53
  # Compress/Decompress the request/response
54
54
  builder.use Restforce::Middleware::Gzip, self, options
55
+ # Inject custom headers into requests
56
+ builder.use Restforce::Middleware::CustomHeaders, self, options
55
57
 
56
58
  builder.adapter adapter
57
59
  end
@@ -11,6 +11,7 @@ module Restforce
11
11
  autoload :Caching, 'restforce/middleware/caching'
12
12
  autoload :Logger, 'restforce/middleware/logger'
13
13
  autoload :Gzip, 'restforce/middleware/gzip'
14
+ autoload :CustomHeaders, 'restforce/middleware/custom_headers'
14
15
 
15
16
  def initialize(app, client, options)
16
17
  @app = app
@@ -0,0 +1,12 @@
1
+ module Restforce
2
+ # Middleware that allows you to specify custom request headers
3
+ # when initializing Restforce client
4
+ class Middleware::CustomHeaders < Restforce::Middleware
5
+ def call(env)
6
+ headers = @options[:request_headers]
7
+ env[:request_headers].merge!(headers) if headers.is_a?(Hash)
8
+
9
+ @app.call(env)
10
+ end
11
+ end
12
+ end
@@ -1,3 +1,3 @@
1
1
  module Restforce
2
- VERSION = '2.5.0'
2
+ VERSION = '2.5.1'
3
3
  end
@@ -18,8 +18,8 @@ Gem::Specification.new do |gem|
18
18
 
19
19
  gem.required_ruby_version = '>= 2.0'
20
20
 
21
- gem.add_dependency 'faraday', '~> 0.9.0'
22
- gem.add_dependency 'faraday_middleware', '>= 0.8.8'
21
+ gem.add_dependency 'faraday', ['>= 0.9.0', '<= 1.0']
22
+ gem.add_dependency 'faraday_middleware', ['>= 0.8.8', '<= 1.0']
23
23
 
24
24
  gem.add_dependency 'json', '>= 1.7.5'
25
25
 
@@ -25,7 +25,8 @@ module ClientIntegrationExampleGroup
25
25
  security_token: security_token,
26
26
  client_id: client_id,
27
27
  client_secret: client_secret,
28
- cache: cache
28
+ cache: cache,
29
+ request_headers: { 'x-test-header' => 'Test Header' }
29
30
  }
30
31
  end
31
32
 
@@ -342,6 +342,41 @@ describe Restforce::Concerns::API do
342
342
  expect(result).to eq '4321'
343
343
  end
344
344
  end
345
+
346
+ context 'when using Id as the attribute' do
347
+ let(:field) { :Id }
348
+ let(:attrs) { { 'Id' => '4321' } }
349
+
350
+ context 'and the value for Id is provided' do
351
+ it 'returns the id of the record' do
352
+ response.body.stub(:[]).with('id').and_return('4321')
353
+ client.should_receive(:api_patch).
354
+ with('sobjects/Whizbang/Id/4321', {}).
355
+ and_return(response)
356
+ expect(result).to eq '4321'
357
+ end
358
+ end
359
+
360
+ context 'and no value for Id is provided' do
361
+ let(:attrs) { { 'External_ID__c' => '1234' } }
362
+
363
+ it 'uses POST to create the record' do
364
+ response.body.stub(:[]).with('id').and_return('4321')
365
+ client.should_receive(:options).and_return(api_version: 38.0)
366
+ client.should_receive(:api_post).
367
+ with('sobjects/Whizbang/Id', attrs).
368
+ and_return(response)
369
+ expect(result).to eq '4321'
370
+ end
371
+
372
+ it 'guards functionality for unsupported API versions' do
373
+ client.should_receive(:options).and_return(api_version: 35.0)
374
+ expect do
375
+ client.upsert!(sobject, field, attrs)
376
+ end.to raise_error Restforce::APIVersionError
377
+ end
378
+ end
379
+ end
345
380
  end
346
381
 
347
382
  describe '.upsert! with multi bytes character' do
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe Restforce::Middleware::CustomHeaders do
4
+ describe '.call' do
5
+ subject { lambda { middleware.call(env) } }
6
+
7
+ context 'when :request_headers are a Hash' do
8
+ let(:options) { { request_headers: { 'x-test-header' => 'Test Value' } } }
9
+
10
+ it { should change { env[:request_headers]['x-test-header'] }.to eq 'Test Value' }
11
+ end
12
+
13
+ context 'when :request_headers are not a Hash' do
14
+ let(:options) { { request_headers: 'bad header' } }
15
+
16
+ it { should_not change { env[:request_headers] } }
17
+ end
18
+ end
19
+ 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: 2.5.0
4
+ version: 2.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric J. Holmes
@@ -9,22 +9,28 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-12-07 00:00:00.000000000 Z
12
+ date: 2017-03-16 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
- - - "~>"
18
+ - - ">="
19
19
  - !ruby/object:Gem::Version
20
20
  version: 0.9.0
21
+ - - "<="
22
+ - !ruby/object:Gem::Version
23
+ version: '1.0'
21
24
  type: :runtime
22
25
  prerelease: false
23
26
  version_requirements: !ruby/object:Gem::Requirement
24
27
  requirements:
25
- - - "~>"
28
+ - - ">="
26
29
  - !ruby/object:Gem::Version
27
30
  version: 0.9.0
31
+ - - "<="
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
28
34
  - !ruby/object:Gem::Dependency
29
35
  name: faraday_middleware
30
36
  requirement: !ruby/object:Gem::Requirement
@@ -32,6 +38,9 @@ dependencies:
32
38
  - - ">="
33
39
  - !ruby/object:Gem::Version
34
40
  version: 0.8.8
41
+ - - "<="
42
+ - !ruby/object:Gem::Version
43
+ version: '1.0'
35
44
  type: :runtime
36
45
  prerelease: false
37
46
  version_requirements: !ruby/object:Gem::Requirement
@@ -39,6 +48,9 @@ dependencies:
39
48
  - - ">="
40
49
  - !ruby/object:Gem::Version
41
50
  version: 0.8.8
51
+ - - "<="
52
+ - !ruby/object:Gem::Version
53
+ version: '1.0'
42
54
  - !ruby/object:Gem::Dependency
43
55
  name: json
44
56
  requirement: !ruby/object:Gem::Requirement
@@ -188,6 +200,7 @@ files:
188
200
  - lib/restforce/middleware/authentication/token.rb
189
201
  - lib/restforce/middleware/authorization.rb
190
202
  - lib/restforce/middleware/caching.rb
203
+ - lib/restforce/middleware/custom_headers.rb
191
204
  - lib/restforce/middleware/gzip.rb
192
205
  - lib/restforce/middleware/instance_url.rb
193
206
  - lib/restforce/middleware/logger.rb
@@ -267,6 +280,7 @@ files:
267
280
  - spec/unit/middleware/authentication/token_spec.rb
268
281
  - spec/unit/middleware/authentication_spec.rb
269
282
  - spec/unit/middleware/authorization_spec.rb
283
+ - spec/unit/middleware/custom_headers_spec.rb
270
284
  - spec/unit/middleware/gzip_spec.rb
271
285
  - spec/unit/middleware/instance_url_spec.rb
272
286
  - spec/unit/middleware/logger_spec.rb
@@ -295,7 +309,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
295
309
  version: '0'
296
310
  requirements: []
297
311
  rubyforge_project:
298
- rubygems_version: 2.5.1
312
+ rubygems_version: 2.6.8
299
313
  signing_key:
300
314
  specification_version: 4
301
315
  summary: A lightweight ruby client for the Salesforce REST API.
@@ -362,6 +376,7 @@ test_files:
362
376
  - spec/unit/middleware/authentication/token_spec.rb
363
377
  - spec/unit/middleware/authentication_spec.rb
364
378
  - spec/unit/middleware/authorization_spec.rb
379
+ - spec/unit/middleware/custom_headers_spec.rb
365
380
  - spec/unit/middleware/gzip_spec.rb
366
381
  - spec/unit/middleware/instance_url_spec.rb
367
382
  - spec/unit/middleware/logger_spec.rb
@@ -370,3 +385,4 @@ test_files:
370
385
  - spec/unit/signed_request_spec.rb
371
386
  - spec/unit/sobject_spec.rb
372
387
  - spec/unit/tooling/client_spec.rb
388
+ has_rdoc: