restforce 2.1.2 → 2.1.3

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: 307702db9af787319aab32acd6a4d2d6969be792
4
- data.tar.gz: b62523a1931297c0598f7c52043b5e4dbf0afe0b
3
+ metadata.gz: 6856a7534599d3903698a710a379d2af99866a80
4
+ data.tar.gz: 1d888bc1f8d088abd95361718b131b2111f7c693
5
5
  SHA512:
6
- metadata.gz: f8a11572c3132c5f223ddc6d3159908957c4a250b4fb7805a4156c7f258e5789b30a58c6ce93a07f23c86d8b1068741a041326c8d5c8dcaad7f7c7bee4c7ba35
7
- data.tar.gz: 17d37b8a1b9546fd3b90e211c73baa7ae6bb3cd7c429a22dd8f062c3e90a59bbfe5fe20aa36e86ed70ba8d10895c0b01f952edb099ebe52da69d2de6fa11f53e
6
+ metadata.gz: 98686516419562bc5ac3c2ca2748197d642373c5a508fc937921a00cfbec34ab835af2813acce8d95bd0595a8228a3b9fe26374d116f179bc0c9bfc70058f2db
7
+ data.tar.gz: d67b50a3bc94beed337823ea61abb4e196ce0cd0eaa1c57818ff1e6791cb78737ac4554e28e16e6628d80dfec84c4732bba6e590b08d0ffb9d6f5afecf8cffea
@@ -1,3 +1,12 @@
1
+ ## 2.1.3 (Mar 9, 2016)
2
+
3
+ * Raise a `Restforce::ServerError` when Salesforce responds with a `500` due to an internal error (@greysteil)
4
+ * Improving handling of response body in errors (@kuono)
5
+
6
+ ## 2.1.2 (Nov 2, 2015)
7
+
8
+ * Always parse the JSON response before errors are raised to improve exceptions (@kouno)
9
+
1
10
  ## 2.1.1 (Aug 20, 2015)
2
11
 
3
12
  * Added support for `get_updated` call (@web-connect)
data/README.md CHANGED
@@ -61,21 +61,41 @@ It is also important to note that the client object should not be reused across
61
61
  #### OAuth token authentication
62
62
 
63
63
  ```ruby
64
- client = Restforce.new :oauth_token => 'oauth token',
64
+ client = Restforce.new :oauth_token => 'access_token',
65
65
  :instance_url => 'instance url'
66
66
  ```
67
67
 
68
- Although the above will work, you'll probably want to take advantage of the
69
- (re)authentication middleware by specifying a `refresh_token`, `client_id` and `client_secret`:
68
+ Although the above will work, you'll probably want to take advantage of the (re)authentication middleware by specifying `refresh_token`, `client_id`, `client_secret`, and `authentication_callback`:
70
69
 
71
70
  ```ruby
72
- client = Restforce.new :oauth_token => 'oauth token',
73
- :refresh_token => 'refresh token',
74
- :instance_url => 'instance url',
75
- :client_id => 'client_id',
76
- :client_secret => 'client_secret'
71
+ client = Restforce.new :oauth_token => 'access_token',
72
+ :refresh_token => 'refresh token',
73
+ :instance_url => 'instance url',
74
+ :client_id => 'client_id',
75
+ :client_secret => 'client_secret',
76
+ :authentication_callback => Proc.new {|x| Rails.logger.debug x.to_s}
77
77
  ```
78
78
 
79
+ The middleware will use the `refresh_token` automatically to acquire a new `access_token` if the existing `access_token` is invalid.
80
+
81
+ `authentication_callback` is a proc that handles the response from Salesforce when the `refresh_token` is used to obtain a new `access_token`. This allows the `access_token` to be saved for re-use later, otherwise subsequent API calls will continue the cycle of "auth failure/issue new access_token/auth success".
82
+
83
+ The proc is passed one argument, a `Hashie::Mash` of the response from the [Salesforce API](https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/intro_understanding_refresh_token_oauth.htm):
84
+
85
+ ```ruby
86
+ {
87
+ "access_token" => "00Dx0000000BV7z!AR8AQP0jITN80ESEsj5EbaZTFG0RNBaT1cyWk7T5rqoDjoNIWQ2ME_sTZzBjfmOE6zMHq6y8PIW4eWze9JksNEkWUl.Cju7m4",
88
+ "signature" => "SSSbLO/gBhmmyNUvN18ODBDFYHzakxOMgqYtu+hDPsc=",
89
+ "scope" => "refresh_token full",
90
+ "instance_url" => "https://na1.salesforce.com",
91
+ "id" => "https://login.salesforce.com/id/00Dx0000000BV7z/005x00000012Q9P",
92
+ "token_type" => "Bearer",
93
+ "issued_at" => "1278448384422"
94
+ }
95
+ ```
96
+
97
+ The `id` field can be used to [uniquely identify](https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/intro_understanding_refresh_token_oauth.htm) the user that the `access_token` and `refresh_token` belong to.
98
+
79
99
  #### Username/Password authentication
80
100
 
81
101
  If you prefer to use a username and password to authenticate:
@@ -116,7 +136,7 @@ client = Restforce.new :username => 'foo',
116
136
  :proxy_uri => 'http://proxy.example.com:123'
117
137
  ```
118
138
 
119
- You may specify a username and password for the proxy with a URL along the lines of 'http://user@password:proxy.example.com:123'.
139
+ You may specify a username and password for the proxy with a URL along the lines of 'http://user:password@proxy.example.com:123'.
120
140
 
121
141
  #### Sandbox Orgs
122
142
 
@@ -199,6 +219,7 @@ account.destroy
199
219
  ```ruby
200
220
  accounts = client.query_all("select Id, Something__c from Account where isDeleted = true")
201
221
  # => #<Restforce::Collection >
222
+ ```
202
223
 
203
224
  query_all allows you to include results from your query that Salesforce hides in the default "query" method. These include soft-deleted records and archived records (e.g. Task and Event records which are usually archived automatically after they are a year old).
204
225
 
@@ -353,7 +374,7 @@ Retrieves the list of individual record IDs that have been updated (added or cha
353
374
 
354
375
  ```ruby
355
376
  # Get the ids of all accounts which have been updated in the last day
356
- client.get_updated('Account', Time.local(2015,8,18) Time.local(2015,8,19))
377
+ client.get_updated('Account', Time.local(2015,8,18), Time.local(2015,8,19))
357
378
  # => { ... }
358
379
  ```
359
380
 
@@ -37,6 +37,7 @@ module Restforce
37
37
  end
38
38
 
39
39
  Error = Class.new(StandardError)
40
+ ServerError = Class.new(Error)
40
41
  AuthenticationError = Class.new(Error)
41
42
  UnauthorizedError = Class.new(Error)
42
43
  APIVersionError = Class.new(Error)
@@ -22,7 +22,9 @@ module Restforce
22
22
  req.body = encode_www_form(params)
23
23
  end
24
24
 
25
- if response.status != 200
25
+ if response.status >= 500
26
+ raise Restforce::ServerError, error_message(response)
27
+ elsif response.status != 200
26
28
  raise Restforce::AuthenticationError, error_message(response)
27
29
  end
28
30
 
@@ -20,7 +20,7 @@ module Restforce
20
20
  end
21
21
 
22
22
  def body
23
- @body = (@env[:body].respond_to?(:first) ? @env[:body].first : @env[:body])
23
+ @body = (@env[:body].is_a?(Array) ? @env[:body].first : @env[:body])
24
24
 
25
25
  case @body
26
26
  when Hash
@@ -1,3 +1,3 @@
1
1
  module Restforce
2
- VERSION = '2.1.2'
2
+ VERSION = '2.1.3'
3
3
  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.1.2
4
+ version: 2.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric J. Holmes
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-11-02 00:00:00.000000000 Z
12
+ date: 2016-03-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday