restforce 6.2.2 → 7.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 18f985dc2a3f2b1776f442009e24453e35c19d946f1d0f6ecdd42af56693c8ca
4
- data.tar.gz: a9ab15688f2eaf7122b57bdca9bdbd54724983f6c38ee311aed095cd7ed3c950
3
+ metadata.gz: 6654e481c857ecb9ac254b03727287038371662899d1ef0a136c49c1cd5e86d6
4
+ data.tar.gz: 5a78a982b7bc65c3332320682d44bc7f2a46a234b9afc5360bca79fa0c8eddeb
5
5
  SHA512:
6
- metadata.gz: 22bdd50789784b18f20dabaa86358db0d05e37e630770ea70da379b5c3410059b8b003e7e8a26347c3ee0141f8b81dc1d422d796454e32bca7531b9f81f72041
7
- data.tar.gz: 520de3d9f192d6f658fc8bca961975550432054b8c6db5710a5198bb7947c0b485b5a9ff112a1e4cf1848a13344f6cdc0adb2ef498a2ea5175c76582f4bdd395
6
+ metadata.gz: 62fdf7157d265d3d8af5b37ecec52a98f1462a1dcc62e72471b2ddb29380821a90b0e38cb5cd111dc4b925182af169bda56f131e0798277e1f2c55f1132ec5d8
7
+ data.tar.gz: a62df632fca2528e5dd991dbf4ab95f5cb7cc201819dbfeed5dfb4d021bdf47b567a10eda7ed9cc2e7436acbf89951cd7f85e0d57bd421438a7b9870aa2ed8fb
@@ -6,10 +6,10 @@ jobs:
6
6
  strategy:
7
7
  fail-fast: false
8
8
  matrix:
9
- ruby_version: ['2.7', '3.0', '3.1', '3.2']
9
+ ruby_version: ['3.0', '3.1', '3.2', '3.3']
10
10
  steps:
11
11
  - name: Checkout code
12
- uses: actions/checkout@v3
12
+ uses: actions/checkout@v4
13
13
  - name: Setup Ruby ${{ matrix.ruby_version }}
14
14
  uses: ruby/setup-ruby@v1
15
15
  with:
@@ -10,12 +10,12 @@ jobs:
10
10
  # For v2.0.x, we test v2.0.0 and v2.0.1 because v2.0.0 has a special behaviour where
11
11
  # the Net::HTTP adapter is not included. See
12
12
  # https://github.com/lostisland/faraday/blob/main/UPGRADING.md#faraday-20.
13
- faraday_version: ['1.1.0', '1.2.0', '1.3.1', '1.4.3', '1.5.1', '1.6.0', '1.7.2', '1.8.0', '1.9.3', '1.10.3', '2.0.0', '2.0.1', '2.1.0', '2.2.0', '2.3.0', '2.4.0', '2.5.2', '2.6.0', '2.7.4']
13
+ faraday_version: ['1.1.0', '1.2.0', '1.3.1', '1.4.3', '1.5.1', '1.6.0', '1.7.2', '1.8.0', '1.9.3', '1.10.3', '2.0.0', '2.0.1', '2.1.0', '2.2.0', '2.3.0', '2.4.0', '2.5.2', '2.6.0', '2.7.12', '2.8.1', '2.9.0']
14
14
  env:
15
15
  FARADAY_VERSION: ~> ${{ matrix.faraday_version }}
16
16
  steps:
17
17
  - name: Checkout code
18
- uses: actions/checkout@v3
18
+ uses: actions/checkout@v4
19
19
  - name: Setup Ruby ${{ matrix.ruby_version }}
20
20
  uses: ruby/setup-ruby@v1
21
21
  with:
data/.rubocop.yml CHANGED
@@ -8,7 +8,7 @@ AllCops:
8
8
  - .*/**/*
9
9
  - vendor/**/*
10
10
  NewCops: enable
11
- TargetRubyVersion: 2.7
11
+ TargetRubyVersion: 3.0
12
12
 
13
13
  # Limit lines to 90 characters.
14
14
  Layout/LineLength:
data/CHANGELOG.md CHANGED
@@ -1,3 +1,34 @@
1
+ # 7.3.0 (Feb 14, 2024 🧡)
2
+
3
+ - Add support for making `GET` requests using the Composite API (@shravan097)
4
+
5
+ # 7.2.0 (Jan 23, 2024)
6
+
7
+ - Add support for `faraday` v2.9.x (@timrogers)
8
+
9
+ # 7.1.1 (Jan 23, 2024)
10
+
11
+ - Handle the `APEX_REST_SERVICES_DISABLED` error returned by the Salesforce API (@timrogers)
12
+
13
+ # 7.1.0 (Dec 20, 2023)
14
+
15
+ - Add support for the [OAuth 2.0 Client Credentials authentication flow](https://help.salesforce.com/s/articleView?id=sf.remoteaccess_oauth_client_credentials_flow.htm&type=5) (@rh-taro)
16
+ - Add support for `faraday` v2.8.x (@timrogers)
17
+
18
+ # 7.0.0 (Oct 6, 2023)
19
+
20
+ __This version contains breaking changes. For help with upgrading, see [`UPGRADING.md`](https://github.com/restforce/restforce/blob/main/UPGRADING.md).__
21
+
22
+ * __⚠️ Drop support for Ruby 2.7__, since [Ruby 2.7 has reached its end-of-life](https://www.ruby-lang.org/en/downloads/) (@timrogers)
23
+
24
+ # 6.2.4 (Oct 6, 2023)
25
+
26
+ * Register the custom JSON middleware for Faraday with a more unique name to avoid clashes with other middleware (@dbackeus)
27
+
28
+ # 6.2.3 (Jun 18 2023)
29
+
30
+ * Handle the `CANNOT_DELETE_OWNER`, `CANNOT_POST_TO_ARCHIVED_GROUP`, `INVALID_INPUT`, `INVALID_MARKUP` and `INVALID_SEARCH` errors returned by the Salesforce API (@spurton)
31
+
1
32
  # 6.2.2 (Mar 24 2023)
2
33
 
3
34
  * Handle the `INSUFFICIENT_ACCESS` error returned by the Salesforce API (@timrogers, @nstuart-at-salesforce)
@@ -9,7 +40,7 @@
9
40
  # 6.2.0 (Jan 18 2023)
10
41
 
11
42
  * Add support for `faraday` v2.7.x (@timrogers)
12
- * Expose the Faraday `Response` on `CompositeAPIError`s (@shravan097)
43
+ * Expose the Faraday `Response` on` `CompositeAPIError`s (@shravan097)
13
44
 
14
45
  # 6.1.0 (Nov 18 2022)
15
46
 
data/Gemfile CHANGED
@@ -3,20 +3,20 @@
3
3
  source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
- faraday_version = ENV.fetch('FARADAY_VERSION', '~> 2.7.3')
6
+ faraday_version = ENV.fetch('FARADAY_VERSION', '~> 2.9.0')
7
7
 
8
8
  # Enable us to explicitly pick a Faraday version when running tests
9
9
  gem 'faraday', faraday_version
10
- gem 'faraday-typhoeus', '~> 1.0.0' unless faraday_version.start_with?("~> 1")
10
+ gem 'faraday-typhoeus', '~> 1.1.0' unless faraday_version.start_with?("~> 1")
11
11
  gem 'faye' unless RUBY_PLATFORM == 'java'
12
12
  gem 'guard-rspec'
13
13
  gem 'guard-rubocop'
14
14
  gem 'jruby-openssl', platforms: :jruby
15
15
  gem 'rake'
16
- gem 'rspec', '~> 3.12.0'
16
+ gem 'rspec', '~> 3.13.0'
17
17
  gem 'rspec-collection_matchers', '~> 1.2.0'
18
18
  gem 'rspec-its', '~> 1.3.0'
19
19
  gem 'rspec_junit_formatter', '~> 0.6.0'
20
- gem 'rubocop', '~> 1.48.0'
20
+ gem 'rubocop', '~> 1.60.1'
21
21
  gem 'simplecov', '~> 0.22.0'
22
- gem 'webmock', '~> 3.18.1'
22
+ gem 'webmock', '~> 3.20.0'
data/README.md CHANGED
@@ -27,7 +27,7 @@ Features include:
27
27
 
28
28
  Add this line to your application's Gemfile:
29
29
 
30
- gem 'restforce', '~> 6.2.2'
30
+ gem 'restforce', '~> 7.3.0'
31
31
 
32
32
  And then execute:
33
33
 
@@ -37,8 +37,9 @@ Or install it yourself as:
37
37
 
38
38
  $ gem install restforce
39
39
 
40
- __As of version 6.0.0, this gem is only compatible with Ruby 2.7.0 and later.__ If you're using an earlier Ruby version:
40
+ __As of version 7.0.0, this gem is only compatible with Ruby 3.0.0 and later.__ If you're using an earlier Ruby version:
41
41
 
42
+ * for Ruby 2.7, use version 6.2.4 or earlier
42
43
  * for Ruby 2.6, use version 5.3.1 or earlier
43
44
  * for Ruby 2.5, use version 5.0.6 or earlier
44
45
  * for Ruby 2.4, use version 4.3.0 or earlier
@@ -58,7 +59,7 @@ so you can do things like `client.query('select Id, (select Name from Children__
58
59
 
59
60
  Which authentication method you use really depends on your use case. If you're
60
61
  building an application where many users from different organizations are authenticated
61
- through oauth and you need to interact with data in their org on their behalf,
62
+ through OAuth and you need to interact with data in their org on their behalf,
62
63
  you should use the OAuth token authentication method.
63
64
 
64
65
  If you're using the gem to interact with a single org (maybe you're building some
@@ -154,6 +155,17 @@ client = Restforce.new
154
155
 
155
156
  **Note:** Restforce library does not cache JWT Bearer tokens automatically. This means that every instantiation of the Restforce class will be treated as a new login by Salesforce. Remember that Salesforce enforces [rate limits on login requests](https://help.salesforce.com/s/articleView?id=000312767&type=1). If you are building an application that will instantiate the Restforce class more than this specified rate limit, you might want to consider caching the Bearer token either in-memory or in your own storage by leveraging the `authentication_callback` method.
156
157
 
158
+ ## Client Credentials
159
+
160
+ If you want to authenticate as an application, you can use the [Client Credentials flow](https://help.salesforce.com/s/articleView?id=sf.remoteaccess_oauth_client_credentials_flow.htm&type=5):
161
+
162
+ ```ruby
163
+ client = Restforce.new(client_id: 'client_id',
164
+ client_secret: 'client_secret',
165
+ api_version: '55.0',
166
+ instance_url: 'instance_url')
167
+ ```
168
+
157
169
  #### Sandbox Organizations
158
170
 
159
171
  You can connect to sandbox organizations by specifying a host. The default host is
@@ -588,7 +600,6 @@ This feature permits the user to send a composite object—that is, a complex
588
600
  object with nested children—in a single API call. Up to 25 requests may be
589
601
  included in a single composite.
590
602
 
591
- Note that `GET` is not yet implemented for this API.
592
603
 
593
604
  ```ruby
594
605
  # build up an array of requests:
@@ -831,13 +842,6 @@ client.create!("CustomField", {
831
842
  })
832
843
  ```
833
844
 
834
- ## Links
835
-
836
- If you need a full Active Record experience, may be you can use
837
- [ActiveForce](https://github.com/ionia-corporation/active_force) that wraps
838
- Restforce and adds Associations, Query Building (like AREL), Validations and
839
- Callbacks.
840
-
841
845
  ## Contributing
842
846
 
843
847
  We welcome all contributions - they help us make Restforce the best gem possible.
data/UPGRADING.md CHANGED
@@ -1,3 +1,15 @@
1
+ # Upgrading from Restforce 6.x to 7.x
2
+
3
+ ## Ruby 2.7 is no longer supported
4
+
5
+ __Likelyhood of impact__: Moderate
6
+
7
+ Ruby 2.7 is no longer officially supported as an active version of the Ruby language. That means that it will not receive patches and security fixes.
8
+
9
+ Accordingly, we've dropped support for Ruby 2.7 in the Restforce library. The gemspec now specifies that only 3.0 onwards is supported, and this will be enforced by RubyGems.
10
+
11
+ Before you update to Restforce 7.x, you'll need to switch to Ruby 3.0.0 or later. The current version of Ruby at the time of writing is 3.2.2.
12
+
1
13
  # Upgrading from Restforce 5.x to 6.x
2
14
 
3
15
  __There are two breaking changes introduced in Restforce 6.x__. In this guide, you'll learn about these changes and what you should check in your code to make sure that it will work with the latest version of the library.
@@ -21,6 +21,8 @@ module Restforce
21
21
  Restforce::Middleware::Authentication::Token
22
22
  elsif jwt?
23
23
  Restforce::Middleware::Authentication::JWTBearer
24
+ elsif client_credential?
25
+ Restforce::Middleware::Authentication::ClientCredential
24
26
  end
25
27
  end
26
28
 
@@ -48,6 +50,12 @@ module Restforce
48
50
  options[:username] &&
49
51
  options[:client_id]
50
52
  end
53
+
54
+ # Internal: Returns true if client credential flow should be used for
55
+ # authentication.
56
+ def client_credential?
57
+ options[:client_id] && options[:client_secret]
58
+ end
51
59
  end
52
60
  end
53
61
  end
@@ -93,6 +93,14 @@ module Restforce
93
93
  }
94
94
  end
95
95
 
96
+ def find(sobject, reference_id, id)
97
+ requests << {
98
+ method: 'GET',
99
+ url: composite_api_path("#{sobject}/#{id}"),
100
+ referenceId: reference_id
101
+ }
102
+ end
103
+
96
104
  private
97
105
 
98
106
  def composite_api_path(path)
@@ -33,7 +33,7 @@ module Restforce
33
33
  # Handles multipart file uploads for blobs.
34
34
  builder.use Restforce::Middleware::Multipart
35
35
  # Converts the request into JSON.
36
- builder.request :json
36
+ builder.request :restforce_json
37
37
  # Handles reauthentication for 403 responses.
38
38
  if authentication_middleware
39
39
  builder.use authentication_middleware, self, options
@@ -52,7 +52,7 @@ module Restforce
52
52
  # Raises errors for 40x responses.
53
53
  builder.use Restforce::Middleware::RaiseError
54
54
  # Parses returned JSON response into a hash.
55
- builder.response :json, content_type: /\bjson$/
55
+ builder.response :restforce_json, content_type: /\bjson$/
56
56
  # Compress/Decompress the request/response
57
57
  unless adapter == :httpclient
58
58
  builder.use Restforce::Middleware::Gzip, self, options
@@ -19,6 +19,8 @@ module Restforce
19
19
 
20
20
  class ApexError < ResponseError; end
21
21
 
22
+ class ApexRestServicesDisabled < ResponseError; end
23
+
22
24
  class ApiCurrentlyDisabled < ResponseError; end
23
25
 
24
26
  class ApiDisabledForOrg < ResponseError; end
@@ -43,6 +45,8 @@ module Restforce
43
45
 
44
46
  class CannotDeleteLastDatedConversionRate < ResponseError; end
45
47
 
48
+ class CannotDeleteOwner < ResponseError; end
49
+
46
50
  class CannotDeleteManagedObject < ResponseError; end
47
51
 
48
52
  class CannotDisableLastAdmin < ResponseError; end
@@ -55,6 +59,8 @@ module Restforce
55
59
 
56
60
  class CannotModifyManagedObject < ResponseError; end
57
61
 
62
+ class CannotPostToArchivedGroup < ResponseError; end
63
+
58
64
  class CannotRenameApexReferencedField < ResponseError; end
59
65
 
60
66
  class CannotRenameApexReferencedObject < ResponseError; end
@@ -219,8 +225,12 @@ module Restforce
219
225
 
220
226
  class InvalidInetAddress < ResponseError; end
221
227
 
228
+ class InvalidInput < ResponseError; end
229
+
222
230
  class InvalidLineitemCloneState < ResponseError; end
223
231
 
232
+ class InvalidMarkup < ResponseError; end
233
+
224
234
  class InvalidMasterOrTranslatedSolution < ResponseError; end
225
235
 
226
236
  class InvalidMessageIdReference < ResponseError; end
@@ -247,6 +257,8 @@ module Restforce
247
257
 
248
258
  class InvalidSaveAsActivityFlag < ResponseError; end
249
259
 
260
+ class InvalidSearch < ResponseError; end
261
+
250
262
  class InvalidSessionId < ResponseError; end
251
263
 
252
264
  class InvalidSignupCountry < ResponseError; end
@@ -419,6 +431,7 @@ module Restforce
419
431
  "ALL_OR_NONE_OPERATION_ROLLED_BACK" => AllOrNoneOperationRolledBack,
420
432
  "ALREADY_IN_PROCESS" => AlreadyInProcess,
421
433
  "APEX_ERROR" => ApexError,
434
+ "APEX_REST_SERVICES_DISABLED" => ApexRestServicesDisabled,
422
435
  "API_CURRENTLY_DISABLED" => ApiCurrentlyDisabled,
423
436
  "API_DISABLED_FOR_ORG" => ApiDisabledForOrg,
424
437
  "ASSIGNEE_TYPE_REQUIRED" => AssigneeTypeRequired,
@@ -436,11 +449,13 @@ module Restforce
436
449
  "CANNOT_DELETE_LAST_DATED_CONVERSION_RATE" =>
437
450
  CannotDeleteLastDatedConversionRate,
438
451
  "CANNOT_DELETE_MANAGED_OBJECT" => CannotDeleteManagedObject,
452
+ "CANNOT_DELETE_OWNER" => CannotDeleteOwner,
439
453
  "CANNOT_DISABLE_LAST_ADMIN" => CannotDisableLastAdmin,
440
454
  "CANNOT_ENABLE_IP_RESTRICT_REQUESTS" => CannotEnableIpRestrictRequests,
441
455
  "CANNOT_EXECUTE_FLOW_TRIGGER" => CannotExecuteFlowTrigger,
442
456
  "CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY" => CannotInsertUpdateActivateEntity,
443
457
  "CANNOT_MODIFY_MANAGED_OBJECT" => CannotModifyManagedObject,
458
+ "CANNOT_POST_TO_ARCHIVED_GROUP" => CannotPostToArchivedGroup,
444
459
  "CANNOT_RENAME_APEX_REFERENCED_FIELD" => CannotRenameApexReferencedField,
445
460
  "CANNOT_RENAME_APEX_REFERENCED_OBJECT" => CannotRenameApexReferencedObject,
446
461
  "CANNOT_REPARENT_RECORD" => CannotReparentRecord,
@@ -528,7 +543,9 @@ module Restforce
528
543
  "INVALID_FILTER_ACTION" => InvalidFilterAction,
529
544
  "INVALID_ID_FIELD" => InvalidIdField,
530
545
  "INVALID_INET_ADDRESS" => InvalidInetAddress,
546
+ "INVALID_INPUT" => InvalidInput,
531
547
  "INVALID_LINEITEM_CLONE_STATE" => InvalidLineitemCloneState,
548
+ "INVALID_MARKUP" => InvalidMarkup,
532
549
  "INVALID_MASTER_OR_TRANSLATED_SOLUTION" => InvalidMasterOrTranslatedSolution,
533
550
  "INVALID_MESSAGE_ID_REFERENCE" => InvalidMessageIdReference,
534
551
  "INVALID_OPERATION" => InvalidOperation,
@@ -543,6 +560,7 @@ module Restforce
543
560
  "INVALID_READ_ONLY_USER_DML" => InvalidReadOnlyUserDml,
544
561
  "INVALID_REPLICATION_DATE" => InvalidReplicationDate,
545
562
  "INVALID_SAVE_AS_ACTIVITY_FLAG" => InvalidSaveAsActivityFlag,
563
+ "INVALID_SEARCH" => InvalidSearch,
546
564
  "INVALID_SESSION_ID" => InvalidSessionId,
547
565
  "INVALID_SIGNUP_COUNTRY" => InvalidSignupCountry,
548
566
  "INVALID_STATUS" => InvalidStatus,
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Restforce
4
+ class Middleware
5
+ class Authentication
6
+ class ClientCredential < Restforce::Middleware::Authentication
7
+ def params
8
+ { grant_type: 'client_credentials',
9
+ client_id: @options[:client_id],
10
+ client_secret: @options[:client_secret] }
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -9,6 +9,7 @@ module Restforce
9
9
  autoload :Password, 'restforce/middleware/authentication/password'
10
10
  autoload :Token, 'restforce/middleware/authentication/token'
11
11
  autoload :JWTBearer, 'restforce/middleware/authentication/jwt_bearer'
12
+ autoload :ClientCredential, 'restforce/middleware/authentication/client_credential'
12
13
 
13
14
  # Rescue from 401's, authenticate then raise the error again so the client
14
15
  # can reissue the request.
@@ -50,7 +51,7 @@ module Restforce
50
51
  builder.use Faraday::Request::UrlEncoded
51
52
  builder.use Restforce::Middleware::Mashify, nil, @options
52
53
  builder.use Faraday::FollowRedirects::Middleware
53
- builder.response :json
54
+ builder.response :restforce_json
54
55
 
55
56
  if Restforce.log?
56
57
  builder.use Restforce::Middleware::Logger,
@@ -31,7 +31,7 @@ module Restforce
31
31
  CONTENT_TYPE = 'Content-Type'
32
32
 
33
33
  MIME_TYPE = 'application/json'
34
- MIME_TYPE_REGEX = %r{^application/(vnd\..+\+)?json$}.freeze
34
+ MIME_TYPE_REGEX = %r{^application/(vnd\..+\+)?json$}
35
35
 
36
36
  #
37
37
  # Taken from `lib/faraday/middleware.rb` in the `faraday`
@@ -87,4 +87,4 @@ module Restforce
87
87
  end
88
88
  end
89
89
 
90
- Faraday::Request.register_middleware(json: Restforce::Middleware::JsonRequest)
90
+ Faraday::Request.register_middleware(restforce_json: Restforce::Middleware::JsonRequest)
@@ -82,4 +82,4 @@ module Restforce
82
82
  end
83
83
  end
84
84
 
85
- Faraday::Response.register_middleware(json: Restforce::Middleware::JsonResponse)
85
+ Faraday::Response.register_middleware(restforce_json: Restforce::Middleware::JsonResponse)
@@ -60,7 +60,7 @@ module Restforce
60
60
  }
61
61
  end
62
62
 
63
- ERROR_CODE_MATCHER = /\A[A-Z_]+\z/.freeze
63
+ ERROR_CODE_MATCHER = /\A[A-Z_]+\z/
64
64
 
65
65
  def exception_class_for_error_code(error_code)
66
66
  return Restforce::ResponseError unless ERROR_CODE_MATCHER.match?(error_code)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Restforce
4
- VERSION = '6.2.2'
4
+ VERSION = '7.3.0'
5
5
  end
data/restforce.gemspec CHANGED
@@ -22,9 +22,9 @@ Gem::Specification.new do |gem|
22
22
  'rubygems_mfa_required' => 'true'
23
23
  }
24
24
 
25
- gem.required_ruby_version = '>= 2.7'
25
+ gem.required_ruby_version = '>= 3.0'
26
26
 
27
- gem.add_dependency 'faraday', '< 2.8.0', '>= 1.1.0'
27
+ gem.add_dependency 'faraday', '< 2.10.0', '>= 1.1.0'
28
28
  gem.add_dependency 'faraday-follow_redirects', '<= 0.3.0', '< 1.0.0'
29
29
  gem.add_dependency 'faraday-multipart', '>= 1.0.0', '< 2.0.0'
30
30
  gem.add_dependency 'faraday-net_http', '< 4.0.0'
@@ -62,6 +62,17 @@ describe Restforce::Concerns::Authentication do
62
62
 
63
63
  it { should eq Restforce::Middleware::Authentication::JWTBearer }
64
64
  end
65
+
66
+ context 'when client_id and client_secret options are provided' do
67
+ before do
68
+ client.stub username_password?: false
69
+ client.stub oauth_refresh?: false
70
+ client.stub jwt?: false
71
+ client.stub client_credential?: true
72
+ end
73
+
74
+ it { should eq Restforce::Middleware::Authentication::ClientCredential }
75
+ end
65
76
  end
66
77
 
67
78
  describe '.username_password?' do
@@ -135,4 +146,26 @@ describe Restforce::Concerns::Authentication do
135
146
  it { should_not be true }
136
147
  end
137
148
  end
149
+
150
+ describe '.client_credential?' do
151
+ subject { client.client_credential? }
152
+ let(:options) { {} }
153
+
154
+ before do
155
+ client.stub options: options
156
+ end
157
+
158
+ context 'when oauth client credential options are provided' do
159
+ let(:options) do
160
+ { client_id: 'client',
161
+ client_secret: 'secret' }
162
+ end
163
+
164
+ it { should be_truthy }
165
+ end
166
+
167
+ context 'when oauth client credential options are not provided' do
168
+ it { should_not be true }
169
+ end
170
+ end
138
171
  end
@@ -82,6 +82,23 @@ describe Restforce::Concerns::CompositeAPI do
82
82
  end
83
83
  end
84
84
 
85
+ it '#find' do
86
+ client.
87
+ should_receive(:api_post).
88
+ with(endpoint, { compositeRequest: [
89
+ {
90
+ method: 'GET',
91
+ url: "/services/data/v38.0/sobjects/Object/00312345",
92
+ referenceId: 'find_ref'
93
+ }
94
+ ], allOrNone: all_or_none, collateSubrequests: false }.to_json).
95
+ and_return(response)
96
+
97
+ client.send(method) do |subrequests|
98
+ subrequests.find('Object', 'find_ref', '00312345')
99
+ end
100
+ end
101
+
85
102
  it 'multiple subrequests' do
86
103
  client.
87
104
  should_receive(:api_post).
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Restforce::Middleware::Authentication::ClientCredential do
6
+ let(:options) do
7
+ { host: 'login.salesforce.com',
8
+ client_id: 'client_id',
9
+ client_secret: 'client_secret',
10
+ adapter: :net_http }
11
+ end
12
+
13
+ it_behaves_like 'authentication middleware' do
14
+ let(:success_request) do
15
+ stub_login_request(
16
+ body: "grant_type=client_credentials&" \
17
+ "client_id=client_id&client_secret=client_secret"
18
+ ).to_return(
19
+ status: 200,
20
+ body: fixture(:auth_success_response),
21
+ headers: { "Content-Type" => "application/json" }
22
+ )
23
+ end
24
+
25
+ let(:fail_request) do
26
+ stub_login_request(
27
+ body: "grant_type=client_credentials&" \
28
+ "client_id=client_id&client_secret=client_secret"
29
+ ).to_return(
30
+ status: 400,
31
+ body: fixture(:refresh_error_response),
32
+ headers: { "Content-Type" => "application/json" }
33
+ )
34
+ end
35
+ end
36
+ 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: 6.2.2
4
+ version: 7.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Rogers
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-03-24 00:00:00.000000000 Z
12
+ date: 2024-02-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -17,7 +17,7 @@ dependencies:
17
17
  requirements:
18
18
  - - "<"
19
19
  - !ruby/object:Gem::Version
20
- version: 2.8.0
20
+ version: 2.10.0
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
23
  version: 1.1.0
@@ -27,7 +27,7 @@ dependencies:
27
27
  requirements:
28
28
  - - "<"
29
29
  - !ruby/object:Gem::Version
30
- version: 2.8.0
30
+ version: 2.10.0
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: 1.1.0
@@ -170,6 +170,7 @@ files:
170
170
  - lib/restforce/mash.rb
171
171
  - lib/restforce/middleware.rb
172
172
  - lib/restforce/middleware/authentication.rb
173
+ - lib/restforce/middleware/authentication/client_credential.rb
173
174
  - lib/restforce/middleware/authentication/jwt_bearer.rb
174
175
  - lib/restforce/middleware/authentication/password.rb
175
176
  - lib/restforce/middleware/authentication/token.rb
@@ -257,6 +258,7 @@ files:
257
258
  - spec/unit/document_spec.rb
258
259
  - spec/unit/error_code_spec.rb
259
260
  - spec/unit/mash_spec.rb
261
+ - spec/unit/middleware/authentication/client_credential_spec.rb
260
262
  - spec/unit/middleware/authentication/jwt_bearer_spec.rb
261
263
  - spec/unit/middleware/authentication/password_spec.rb
262
264
  - spec/unit/middleware/authentication/token_spec.rb
@@ -286,14 +288,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
286
288
  requirements:
287
289
  - - ">="
288
290
  - !ruby/object:Gem::Version
289
- version: '2.7'
291
+ version: '3.0'
290
292
  required_rubygems_version: !ruby/object:Gem::Requirement
291
293
  requirements:
292
294
  - - ">="
293
295
  - !ruby/object:Gem::Version
294
296
  version: '0'
295
297
  requirements: []
296
- rubygems_version: 3.4.7
298
+ rubygems_version: 3.5.3
297
299
  signing_key:
298
300
  specification_version: 4
299
301
  summary: A lightweight Ruby client for the Salesforce REST API