restforce 4.2.0 → 5.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +9 -9
  3. data/.github/ISSUE_TEMPLATE/unhandled-salesforce-error.md +17 -0
  4. data/.rubocop.yml +4 -3
  5. data/.rubocop_todo.yml +2 -2
  6. data/CHANGELOG.md +42 -0
  7. data/CONTRIBUTING.md +21 -1
  8. data/Dockerfile +31 -0
  9. data/Gemfile +0 -1
  10. data/README.md +43 -19
  11. data/UPGRADING.md +38 -0
  12. data/docker-compose.yml +7 -0
  13. data/lib/restforce.rb +10 -13
  14. data/lib/restforce/collection.rb +7 -2
  15. data/lib/restforce/concerns/api.rb +1 -1
  16. data/lib/restforce/concerns/caching.rb +7 -0
  17. data/lib/restforce/concerns/connection.rb +3 -3
  18. data/lib/restforce/concerns/picklists.rb +1 -1
  19. data/lib/restforce/config.rb +4 -1
  20. data/lib/restforce/error_code.rb +416 -0
  21. data/lib/restforce/file_part.rb +24 -0
  22. data/lib/restforce/mash.rb +8 -3
  23. data/lib/restforce/middleware.rb +2 -0
  24. data/lib/restforce/middleware/authentication.rb +4 -1
  25. data/lib/restforce/middleware/caching.rb +1 -1
  26. data/lib/restforce/middleware/instance_url.rb +1 -1
  27. data/lib/restforce/middleware/logger.rb +3 -2
  28. data/lib/restforce/middleware/raise_error.rb +3 -4
  29. data/lib/restforce/version.rb +1 -1
  30. data/restforce.gemspec +12 -13
  31. data/spec/integration/abstract_client_spec.rb +18 -6
  32. data/spec/spec_helper.rb +14 -1
  33. data/spec/support/fixture_helpers.rb +1 -3
  34. data/spec/unit/collection_spec.rb +18 -0
  35. data/spec/unit/concerns/api_spec.rb +1 -1
  36. data/spec/unit/concerns/caching_spec.rb +26 -0
  37. data/spec/unit/concerns/connection_spec.rb +2 -2
  38. data/spec/unit/error_code_spec.rb +61 -0
  39. data/spec/unit/mash_spec.rb +5 -0
  40. data/spec/unit/middleware/authentication_spec.rb +27 -4
  41. data/spec/unit/middleware/raise_error_spec.rb +19 -10
  42. data/spec/unit/signed_request_spec.rb +1 -1
  43. data/spec/unit/sobject_spec.rb +2 -5
  44. metadata +33 -40
  45. data/lib/restforce/upload_io.rb +0 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d1eb25f3f88951d1770c5850c41a9d673d3b0406a76d0c35e54288d52ee5dc00
4
- data.tar.gz: 51af3a7a4a1e701a4f5e8a79c21452ca5417581aa889188e7f5b5e010fb8f39a
3
+ metadata.gz: 6b5b0552d40edc08c24070cfcd8b34b359e8240a2121dd5cb4e50e15bd99b873
4
+ data.tar.gz: 85b8a63c6e37474344d266c11d578ba7a2f0d9fdc11afcb1275a76eb29e5e2b4
5
5
  SHA512:
6
- metadata.gz: eabc94739d7bbdb2e88fcf3b2ff4bfb3c0b4272f74f50d6fef3f549ca559cd52ab212b5fbd6988da0237257aef7d092b4f654e275a797beb28947b268263f07d
7
- data.tar.gz: 56ac8e739182f941a45cffe4c8b28364d8b99243128c8c7864820e15e752785af3938c8f99377e3428dcc9a61ac98a72703850675455cc88effe5b68bdca454b
6
+ metadata.gz: 493fe598b73948b072723a4d9f158aaa62191cb7556c40a36952a75b26a9fe128f2ae0c0cdef29720bde0f47dcfe1515e7149379d3c0d924f7f86d9fa4d5569f
7
+ data.tar.gz: 253579496be482255d6b384035c9394f2f122262b482472e45f30590be3d760975e9490eafea2531ad56c9bf1fa7a23b28a6fd21e9dbf5a5828482bf1a26037c
@@ -34,23 +34,23 @@ references:
34
34
  destination: test-results
35
35
 
36
36
  jobs:
37
- build-ruby265:
37
+ build-ruby271:
38
38
  docker:
39
- - image: circleci/ruby:2.6.5
39
+ - image: circleci/ruby:2.7.1
40
40
  steps: *steps
41
- build-ruby257:
41
+ build-ruby266:
42
42
  docker:
43
- - image: circleci/ruby:2.5.7
43
+ - image: circleci/ruby:2.6.6
44
44
  steps: *steps
45
- build-ruby249:
45
+ build-ruby258:
46
46
  docker:
47
- - image: circleci/ruby:2.4.9
47
+ - image: circleci/ruby:2.5.8
48
48
  steps: *steps
49
49
 
50
50
  workflows:
51
51
  version: 2
52
52
  tests:
53
53
  jobs:
54
- - build-ruby265
55
- - build-ruby257
56
- - build-ruby249
54
+ - build-ruby271
55
+ - build-ruby266
56
+ - build-ruby258
@@ -0,0 +1,17 @@
1
+ ---
2
+ name: Unhandled Salesforce error
3
+ about: We've recently changed the way we handle Salesforce errors to define them ahead
4
+ of time, rather than dynamically. This might mean we're missing some errors. Please
5
+ use this template to report them.
6
+ title: 'Unhandled Salesforce error: <insert error code here>'
7
+ labels: bug
8
+ assignees: timrogers
9
+
10
+ ---
11
+
12
+ Restforce doesn't have a definition for the error code `INSERT ERROR CODE HERE`.
13
+
14
+ I discovered this missing error code because:
15
+
16
+ - [ ] I tried to `rescue` it or refer to it in my code
17
+ - [ ] I got this error back from Salesforce
@@ -7,10 +7,11 @@ AllCops:
7
7
  Exclude:
8
8
  - .*/**/*
9
9
  - vendor/**/*
10
- TargetRubyVersion: 2.4
10
+ NewCops: enable
11
+ TargetRubyVersion: 2.5
11
12
 
12
- # Limit lines to 80 characters.
13
- Metrics/LineLength:
13
+ # Limit lines to 90 characters.
14
+ Layout/LineLength:
14
15
  Max: 90
15
16
 
16
17
  Metrics/ClassLength:
@@ -12,7 +12,7 @@
12
12
  # SupportedHashRocketStyles: key, separator, table
13
13
  # SupportedColonStyles: key, separator, table
14
14
  # SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit
15
- Layout/AlignHash:
15
+ Layout/HashAlignment:
16
16
  Exclude:
17
17
  - 'lib/restforce/middleware/logger.rb'
18
18
  - 'restforce.gemspec'
@@ -23,7 +23,7 @@ Layout/AlignHash:
23
23
  # Cop supports --auto-correct.
24
24
  # Configuration parameters: EnforcedStyle, IndentationWidth.
25
25
  # SupportedStyles: special_inside_parentheses, consistent, align_braces
26
- Layout/IndentFirstHashElement:
26
+ Layout/FirstHashElementIndentation:
27
27
  Exclude:
28
28
  - 'lib/restforce/concerns/connection.rb'
29
29
 
@@ -1,3 +1,45 @@
1
+ ## 5.0.2 (Sep 6, 2020)
2
+
3
+ * Handle the undocumented `REQUEST_LIMIT_EXCEEDED` error returned by Salesforce (@wkirkby, @timrogers)
4
+ * Handle the undocumented `SERVER_UNAVAILABLE` error returned by Salesforce (@wkirkby, @timrogers)
5
+ * Refactor the library to be compatible with Rubocop 0.90's cops (this shouldn't introduce any noticeable changes see #569 for detailed changes) (@timrogers)
6
+
7
+ ## 5.0.1 (Aug 13, 2020)
8
+
9
+ * Handle the undocumented `API_CURRENTLY_DISABLED` error returned by Salesforce (@ruipserra, @timrogers)
10
+ * Handle the undocumented `MALFORMED_QUERY` error returned by Salesforce (@scottserok, @timrogers)
11
+ * Handle the undocumented `INVALID_QUERY_FILTER_OPERATOR` error returned by Salesforce (@Dantemss, @timrogers)
12
+ * Add documentation and scripts for running the
13
+ library's tests using Docker (@ryansch)
14
+
15
+ ## 5.0.0 (Jul 10, 2020)
16
+
17
+ For instructions on upgrading from Restforce 4.x to 5.x, see our ["Upgrading from Restforce 4.x to 5.x"](https://github.com/restforce/restforce/blob/master/UPGRADING.md) guide.
18
+
19
+ ### Breaking changes
20
+
21
+ * __⚠️ Define exception classes for Salesforce errors up-front instead of dynamically at runtime__, *running the risk that we might miss some errors which should be defined*. If any errors are missed, they will be added in patch versions (e.g. `5.0.1`). For more details on this change, see the ["Upgrading from Restforce 4.x to 5.x"](https://github.com/restforce/restforce/blob/master/UPGRADING.md) guide (@presidentbeef, @timrogers).
22
+ * __⚠️ Deprecate support for Ruby 2.4__, since [Ruby 2.4 reached its end-of-life](https://www.ruby-lang.org/en/news/2020/04/05/support-of-ruby-2-4-has-ended/) in April 2020 (@timrogers)
23
+ * __⚠️ Change the ancestry of `Restforce::UnauthorizedError` so it inherits from `Faraday::ClientError`, not `Restforce::Error`__. This breaking change was required to expose the response body returned by the API as part of this error - see the non-breaking changes entry below for further details (@michaldbianchi).
24
+
25
+ ### Non-breaking changes
26
+
27
+ * Add support for `lostisland/faraday` v1.x, whilst maintaining support for v0.9.x (@ryansch)
28
+ * Add `#empty?` method to `Restforce::Collection`, returning whether they are any items in a collection (@bubaflub)
29
+ * Allow opting-in to caching on a per-call basis with `Restforce::Client#with_caching` (@swaincreates)
30
+ * Expose the response body from Salesforce on `Restforce::UnauthorizedError` and `Restforce::NotFoundError` (@michaeldbianchi)
31
+ * Remove the unnecessary depending on the `json` gem, which has been part of the Ruby standard library since v1.9 (@vonTronje)
32
+
33
+
34
+ ## 4.2.2 (Jan 23, 2020)
35
+
36
+ * Fix `NoMethodError: undefined method '[]' for nil:NilClass` error when generating objects to return (@apurkiss)
37
+
38
+ ## 4.2.1 (Dec 4, 2019)
39
+
40
+ * Handle empty response bodies returned with authentication errors (@sylvandor)
41
+ * Fix Faraday deprecation warning in newer Faraday versions (`v0.17.1` onwards) caused by inheriting from a deprecated class
42
+
1
43
  ## 4.2.0 (Oct 23, 2019)
2
44
 
3
45
  * Add support for platform events, CDC, generic events, etc. in the Streaming API (@nathanKramer)
@@ -34,4 +34,24 @@ Some things that will increase the chance that your pull request is accepted:
34
34
  * Write tests.
35
35
  * Write a [good commit message](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html).
36
36
 
37
- *Adapted from [factory_girl_rails's CONTRIBUTING.md](https://github.com/thoughtbot/factory_girl_rails/blob/master/CONTRIBUTING.md).*
37
+ *Adapted from [factory_bot_rails's CONTRIBUTING.md](https://github.com/thoughtbot/factory_bot_rails/blob/master/CONTRIBUTING.md).*
38
+
39
+ ## Docker
40
+
41
+ If you'd rather use a docker container to run the tests, you can use the following instructions.
42
+
43
+ To set up the container image:
44
+
45
+ `docker-compose build --pull`
46
+
47
+ To run specs:
48
+
49
+ `docker-compose run --rm restforce rspec`
50
+
51
+ To run rubocop:
52
+
53
+ `docker-compose run --rm restforce rubocop`
54
+
55
+ To reset the bundler cache:
56
+
57
+ `docker-compose down -v`
@@ -0,0 +1,31 @@
1
+ FROM ruby:2.6.5-alpine
2
+
3
+ RUN apk add --no-cache \
4
+ ca-certificates \
5
+ wget \
6
+ openssl \
7
+ bash \
8
+ build-base \
9
+ git \
10
+ sqlite-dev \
11
+ tzdata \
12
+ tini
13
+
14
+ ENV LANG en_US.UTF-8
15
+ ENV LANGUAGE en_US:en
16
+ ENV LC_ALL en_US.UTF-8
17
+
18
+ ENV BUNDLER_VERSION 2.1.4
19
+ RUN gem install bundler -v ${BUNDLER_VERSION} -i /usr/local/lib/ruby/gems/$(ls /usr/local/lib/ruby/gems) --force
20
+
21
+ WORKDIR /srv
22
+
23
+ COPY Gemfile restforce.gemspec /srv/
24
+ COPY lib/restforce/version.rb /srv/lib/restforce/version.rb
25
+
26
+ RUN bundle install
27
+
28
+ COPY . /srv/
29
+
30
+ ENTRYPOINT ["/sbin/tini", "-g", "--", "bundle", "exec"]
31
+ CMD ["rspec"]
data/Gemfile CHANGED
@@ -3,7 +3,6 @@
3
3
  source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
- gem 'faraday', '~> 0.17.0'
7
6
  gem 'jruby-openssl', platforms: :jruby
8
7
  gem 'jwt'
9
8
  gem 'rake'
data/README.md CHANGED
@@ -8,7 +8,7 @@ Restforce is a ruby gem for the [Salesforce REST api](http://www.salesforce.com/
8
8
  Features include:
9
9
 
10
10
  * A clean and modular architecture using [Faraday middleware](https://github.com/technoweenie/faraday) and [Hashie::Mash](https://github.com/intridea/hashie/tree/v1.2.0)'d responses.
11
- * Support for interacting with multiple users from different orgs.
11
+ * Support for interacting with multiple users from different organizations.
12
12
  * Support for parent-to-child relationships.
13
13
  * Support for aggregate queries.
14
14
  * Support for the [Streaming API](#streaming)
@@ -19,13 +19,13 @@ Features include:
19
19
  * Support for dependent picklists.
20
20
  * Support for decoding [Force.com Canvas](http://www.salesforce.com/us/developer/docs/platform_connectpre/canvas_framework.pdf) signed requests. (NEW!)
21
21
 
22
- [Official Website](http://restforce.org/) | [Documentation](http://rubydoc.info/gems/restforce/frames) | [Changelog](https://github.com/restforce/restforce/tree/master/CHANGELOG.md)
22
+ [Official Website](https://restforce.github.io/) | [Documentation](http://rubydoc.info/gems/restforce/frames) | [Changelog](https://github.com/restforce/restforce/tree/master/CHANGELOG.md)
23
23
 
24
24
  ## Installation
25
25
 
26
26
  Add this line to your application's Gemfile:
27
27
 
28
- gem 'restforce', '~> 4.2.0'
28
+ gem 'restforce', '~> 5.0.2'
29
29
 
30
30
  And then execute:
31
31
 
@@ -35,7 +35,12 @@ Or install it yourself as:
35
35
 
36
36
  $ gem install restforce
37
37
 
38
- __As of [version 4.0.0](https://github.com/restforce/restforce/blob/master/CHANGELOG.md#400-oct-9-2019), this gem is only compatible with Ruby 2.4.0 and later.__ You'll need to use version 3.2.0 or earlier if you're running on Ruby 2.3. If you're running on Ruby 2.2, 2.1 or 2.0, use version 2.5.3 or earlier. For Ruby 1.9.3, you'll need to manually specify that you wish to use version 2.4.2.
38
+ __As of version 5.0.0, this gem is only compatible with Ruby 2.5.0 and later.__ If you're using an earlier Ruby version:
39
+
40
+ * for Ruby 2.4, use version 4.2.2 or earlier
41
+ * for Ruby 2.3, use version 3.2.0 or earlier
42
+ * for Ruby versions 2.2, 2.1 and 2.0, use version 2.5.3 or earlier
43
+ * for Ruby 1.9.3, use version 2.4.2
39
44
 
40
45
  This gem is versioned using [Semantic Versioning](http://semver.org/), so you can be confident when updating that there will not be breaking changes outside of a major version (following format MAJOR.MINOR.PATCH, so for instance moving from 3.1.0 to 4.0.0 would be allowed to include incompatible API changes). See the [changelog](https://github.com/restforce/restforce/tree/master/CHANGELOG.md) for details on what has changed in each version.
41
46
 
@@ -48,7 +53,7 @@ so you can do things like `client.query('select Id, (select Name from Children__
48
53
  ### Initialization
49
54
 
50
55
  Which authentication method you use really depends on your use case. If you're
51
- building an application where many users from different orgs are authenticated
56
+ building an application where many users from different organizations are authenticated
52
57
  through oauth and you need to interact with data in their org on their behalf,
53
58
  you should use the OAuth token authentication method.
54
59
 
@@ -78,7 +83,7 @@ client = Restforce.new(oauth_token: 'access_token',
78
83
  api_version: '41.0')
79
84
  ```
80
85
 
81
- The middleware will use the `refresh_token` automatically to acquire a new `access_token` if the existing `access_token` is invalid.
86
+ The middleware will use the `refresh_token` automatically to acquire a new `access_token` if the existing `access_token` is invalid. The refresh process uses the `host` option so make sure that is set correctly for sandbox organizations.
82
87
 
83
88
  `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".
84
89
 
@@ -142,7 +147,17 @@ export SALESFORCE_API_VERSION="41.0"
142
147
  client = Restforce.new
143
148
  ```
144
149
 
145
- ### Proxy Support
150
+ #### Sandbox Organizations
151
+
152
+ You can connect to sandbox organizations by specifying a host. The default host is
153
+ 'login.salesforce.com':
154
+
155
+ ```ruby
156
+ client = Restforce.new(host: 'test.salesforce.com')
157
+ ```
158
+ The host can also be set with the environment variable `SALESFORCE_HOST`.
159
+
160
+ #### Proxy Support
146
161
 
147
162
  You can specify a HTTP proxy using the `proxy_uri` option, as follows, or by setting the `SALESFORCE_PROXY_URI` environment variable:
148
163
 
@@ -158,16 +173,6 @@ client = Restforce.new(username: 'foo',
158
173
 
159
174
  You may specify a username and password for the proxy with a URL along the lines of 'http://user:password@proxy.example.com:123'.
160
175
 
161
- #### Sandbox Orgs
162
-
163
- You can connect to sandbox orgs by specifying a host. The default host is
164
- 'login.salesforce.com':
165
-
166
- ```ruby
167
- client = Restforce.new(host: 'test.salesforce.com')
168
- ```
169
- The host can also be set with the environment variable `SALESFORCE_HOST`.
170
-
171
176
  #### Global configuration
172
177
 
173
178
  You can set any of the options passed into `Restforce.new` globally:
@@ -328,8 +333,11 @@ client.update('Account', Id: '0016000000MRatd', Name: 'Whizbang Corp')
328
333
  ```ruby
329
334
  # Update the record with external `External__c` external ID set to '12'
330
335
  client.upsert('Account', 'External__c', External__c: 12, Name: 'Foobar')
336
+ # => true or "RecordId"
331
337
  ```
332
338
 
339
+ The upsert method will return the record Id if included in the response body from the Salesforce API; otherwise, it returns true. Currently the Salesforce API only returns the Id for newly created records.
340
+
333
341
  ### destroy
334
342
 
335
343
  ```ruby
@@ -457,7 +465,7 @@ Using the new [Blob Data](http://www.salesforce.com/us/developer/docs/api_rest/C
457
465
  client.create('Document', FolderId: '00lE0000000FJ6H',
458
466
  Description: 'Document test',
459
467
  Name: 'My image',
460
- Body: Restforce::UploadIO.new(File.expand_path('image.jpg', __FILE__), 'image/jpeg')
468
+ Body: Restforce::FilePart.new(File.expand_path('image.jpg', __FILE__), 'image/jpeg')
461
469
  ```
462
470
 
463
471
  Using base64 encoded data (37.5mb limit):
@@ -688,7 +696,23 @@ client.without_caching do
688
696
  end
689
697
  ```
690
698
 
691
- Caching is done on based on your authentication credentials, so cached responses will not be shared between different Salesforce logins.
699
+ If you prefer to opt in to caching on a per-request, you can do so by using .with_caching and
700
+ setting the `use_cache` config option to false:
701
+
702
+ ```ruby
703
+ Restforce.configure do |config|
704
+ config.cache = Rails.cache
705
+ config.use_cache = false
706
+ end
707
+ ```
708
+
709
+ ```ruby
710
+ client.with_caching do
711
+ client.query('select Id from Account')
712
+ end
713
+ ```
714
+
715
+ Caching is done based on your authentication credentials, so cached responses will not be shared between different Salesforce logins.
692
716
 
693
717
  * * *
694
718
 
@@ -0,0 +1,38 @@
1
+ # Upgrading from Restforce 4.x to 5.x
2
+
3
+ __There are three breaking changes introduced in Restforce 5.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.
4
+
5
+ ## Error classes are now defined up-front, rather than dynamically at runtime
6
+
7
+ __Likelyhood of impact__: Moderate
8
+
9
+ The Salesforce REST API can return a range of `errorCode`s representing different kinds of errors. To make these easy to
10
+ handle in your code, we want to turn these into individual, specific exception classes in the `Restforce::ErrorCode` namespace that inherit from `Restforce:: ResponseError`.
11
+
12
+ Up until now, these exception classes have been defined dynamically at runtime which has some disadvantages - see the [pull request](https://github.com/restforce/restforce/pull/551) for more details.
13
+
14
+ In this version, we switch to defining them up-front in the code based on a list in the Salesforce documentation. There is a risk that we might have missed some errors which should be defined. If any errors are missed, they will be added in patch versions (e.g. `5.0.1`).
15
+
16
+ If your application won't run because you are referring to an exception class that no longer exists, or you see warnings logged anywhere, please [create an issue](https://github.com/restforce/restforce/issues/new?template=unhandled-salesforce-error.md&title=Unhandled+Salesforce+error%3A+%3Cinsert+error+code+here%3E).
17
+
18
+ ## Ruby 2.4 is no longer supported
19
+
20
+ __Likelyhood of impact__: Moderate
21
+
22
+ As of [5th April 2020](https://www.ruby-lang.org/en/news/2020/04/05/support-of-ruby-2-4-has-ended/), Ruby 2.4 is no longer officially supported as an active version of the Ruby language. That means that it will not receive patches and security fixes.
23
+
24
+ Accordingly, we've dropped support for Ruby 2.4 and earlier in the Restforce library. It *may* be compatible, bu we don't guarantee this or enforce it with automated tests.
25
+
26
+ Before you update to Restforce 5.x, you'll need to switch to Ruby 2.5 or later. The current version of Ruby at the time of wriing is 2.7.
27
+
28
+ ## `Restforce::UnauthorizedError` no longer inherits from `Restforce::Error`
29
+
30
+ __Likelyhood of impact__: Low
31
+
32
+ Previously, the `Restforce::UnauthorizedError` returned when the library couldn't authenticate with the Salesforce API inherits from `Restforce::Error`. So, if you used `rescue Restforce::Error` in your code, you'd catch these exceptions.
33
+
34
+ We've now changed this exception class to inherit from `Faraday::ClientError` which allows the response body returned from the Salesforce API to be attached to the error.
35
+
36
+ If you refer to `Restforce::Error` anywhere in your code, you should check whether you also need to take into account `Restforce::UnauthorizedError`.
37
+
38
+ If you refer to `Faraday::ClientError` anywhere in your code, you should check that you want the case where Restforce can't authenticate to be included.
@@ -0,0 +1,7 @@
1
+ version: "3.6"
2
+ services:
3
+ restforce:
4
+ build: .
5
+ image: restforce:dev
6
+ volumes:
7
+ - .:/srv
@@ -15,7 +15,8 @@ module Restforce
15
15
  autoload :Middleware, 'restforce/middleware'
16
16
  autoload :Attachment, 'restforce/attachment'
17
17
  autoload :Document, 'restforce/document'
18
- autoload :UploadIO, 'restforce/upload_io'
18
+ autoload :FilePart, 'restforce/file_part'
19
+ autoload :UploadIO, 'restforce/file_part' # Deprecated
19
20
  autoload :SObject, 'restforce/sobject'
20
21
  autoload :Client, 'restforce/client'
21
22
  autoload :Mash, 'restforce/mash'
@@ -44,27 +45,23 @@ module Restforce
44
45
  Error = Class.new(StandardError)
45
46
  ServerError = Class.new(Error)
46
47
  AuthenticationError = Class.new(Error)
47
- UnauthorizedError = Class.new(Error)
48
+ UnauthorizedError = Class.new(Faraday::ClientError)
48
49
  APIVersionError = Class.new(Error)
49
50
  BatchAPIError = Class.new(Error)
50
51
 
51
- # Inherit from Faraday::Error::ResourceNotFound for backwards-compatibility
52
- # Consumers of this library that rescue and handle Faraday::Error::ResourceNotFound
52
+ # Inherit from Faraday::ResourceNotFound for backwards-compatibility
53
+ # Consumers of this library that rescue and handle Faraday::ResourceNotFound
53
54
  # can continue to do so.
54
- NotFoundError = Class.new(Faraday::Error::ResourceNotFound)
55
+ NotFoundError = Class.new(Faraday::ResourceNotFound)
55
56
 
56
- # Inherit from Faraday::Error::ClientError for backwards-compatibility
57
- # Consumers of this library that rescue and handle Faraday::Error::ClientError
57
+ # Inherit from Faraday::ClientError for backwards-compatibility
58
+ # Consumers of this library that rescue and handle Faraday::ClientError
58
59
  # can continue to do so.
59
- ResponseError = Class.new(Faraday::Error::ClientError)
60
+ ResponseError = Class.new(Faraday::ClientError)
60
61
  MatchesMultipleError= Class.new(ResponseError)
61
62
  EntityTooLargeError = Class.new(ResponseError)
62
63
 
63
- module ErrorCode
64
- def self.const_missing(constant_name)
65
- const_set constant_name, Class.new(ResponseError)
66
- end
67
- end
64
+ require 'restforce/error_code'
68
65
 
69
66
  class << self
70
67
  # Alias for Restforce::Data::Client.new
@@ -12,12 +12,12 @@ module Restforce
12
12
  end
13
13
 
14
14
  # Yield each value on each page.
15
- def each
15
+ def each(&block)
16
16
  @raw_page['records'].each { |record| yield Restforce::Mash.build(record, @client) }
17
17
 
18
18
  np = next_page
19
19
  while np
20
- np.current_page.each { |record| yield record }
20
+ np.current_page.each(&block)
21
21
  np = np.next_page
22
22
  end
23
23
  end
@@ -33,6 +33,11 @@ module Restforce
33
33
  end
34
34
  alias length size
35
35
 
36
+ # Returns true if the size of the Collection is zero.
37
+ def empty?
38
+ size.zero?
39
+ end
40
+
36
41
  # Return array of the elements on the current page
37
42
  def current_page
38
43
  first(@raw_page['records'].size)