rdstation-ruby-client 2.3.1 → 2.4.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +3 -2
- data/lib/rdstation/error.rb +1 -0
- data/lib/rdstation/error/format.rb +8 -0
- data/lib/rdstation/error/formatter.rb +16 -1
- data/lib/rdstation/error_handler.rb +2 -1
- data/lib/rdstation/version.rb +1 -1
- data/spec/lib/rdstation/error/format_spec.rb +17 -0
- data/spec/lib/rdstation/error/formatter_spec.rb +30 -0
- metadata +6 -7
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: d51df272057d17abe280b0fe23f7a97f9ef2ceb543f823db1ce8b047788d1887
         | 
| 4 | 
            +
              data.tar.gz: d59bd8063663bb95df477c672066e4c6655172a193d9b2244bba6b8608a92869
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 1451abf2db818f4551575ea88befdb63b6f8f8b1afa3270b96ee50b059f0f69676d6c6104a6e217d58e9c84384527d77e81d257d5a222a1ab2df74e1ed525446
         | 
| 7 | 
            +
              data.tar.gz: 06c2620cdf413e945207f7b0bad15bcdb762038b360ef3c9ed5371e2ff06edc4949f97602fc0c3ffc352ff14bf66774234c398b291a5606d34931ab0eded84e9
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    | @@ -1,3 +1,7 @@ | |
| 1 | 
            +
            ## 2.4.0
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            - Add the TooManyRequests errors in case of rate limit exceeded. See [API request limit](https://developers.rdstation.com/en/request-limit) for more details
         | 
| 4 | 
            +
             | 
| 1 5 | 
             
            ## 2.3.1
         | 
| 2 6 |  | 
| 3 7 | 
             
            - Fixed a bug when no error is found in the known errors list (issue [#52](https://github.com/ResultadosDigitais/rdstation-ruby-client/issues/52))
         | 
    
        data/README.md
    CHANGED
    
    | @@ -93,7 +93,7 @@ RDStation.configure do |config| | |
| 93 93 | 
             
                # authorization.access_token_expires_in is the time (in seconds for with the token is valid)
         | 
| 94 94 | 
             
                # authorization.access_token is the new token
         | 
| 95 95 | 
             
                # authorization.refresh_token is the existing refresh_token
         | 
| 96 | 
            -
                # | 
| 96 | 
            +
                #
         | 
| 97 97 | 
             
                # If you are using ActiveRecord, you may want to update the stored access_token, like in the following code:
         | 
| 98 98 | 
             
                MyStoredAuth.where(refresh_token: authorization.refresh_token).update_all(access_token: authorization.access_token)
         | 
| 99 99 | 
             
              end
         | 
| @@ -232,7 +232,7 @@ client.fields.create builder.build | |
| 232 232 | 
             
            ```ruby
         | 
| 233 233 | 
             
            payload = {} # hash representing the payload
         | 
| 234 234 | 
             
            client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'refresh_token')
         | 
| 235 | 
            -
            client.fields.update('FIELD_UUID', payload) | 
| 235 | 
            +
            client.fields.update('FIELD_UUID', payload)
         | 
| 236 236 | 
             
            ```
         | 
| 237 237 | 
             
            Or you can use the new `RDStation::Builder::Field`
         | 
| 238 238 |  | 
| @@ -315,6 +315,7 @@ Each endpoint may raise errors accoording to the HTTP response code from RDStati | |
| 315 315 | 
             
            - `RDStation::Error::Conflict` (409)
         | 
| 316 316 | 
             
            - `RDStation::Error::UnsupportedMediaType` (415)
         | 
| 317 317 | 
             
            - `RDStation::Error::UnprocessableEntity` (422)
         | 
| 318 | 
            +
            - `RDStation::Error::TooManyRequests` (429)
         | 
| 318 319 | 
             
            - `RDStation::Error::InternalServerError` (500)
         | 
| 319 320 | 
             
            - `RDStation::Error::NotImplemented` (501)
         | 
| 320 321 | 
             
            - `RDStation::Error::BadGateway` (502)
         | 
    
        data/lib/rdstation/error.rb
    CHANGED
    
    | @@ -19,6 +19,7 @@ module RDStation | |
| 19 19 | 
             
                class Conflict < Error; end
         | 
| 20 20 | 
             
                class UnsupportedMediaType < Error; end
         | 
| 21 21 | 
             
                class UnprocessableEntity < Error; end
         | 
| 22 | 
            +
                class TooManyRequests < Error; end
         | 
| 22 23 | 
             
                class InternalServerError < Error; end
         | 
| 23 24 | 
             
                class NotImplemented < Error; end
         | 
| 24 25 | 
             
                class BadGateway < Error; end
         | 
| @@ -8,6 +8,7 @@ module RDStation | |
| 8 8 | 
             
                  ARRAY_OF_HASHES = 'ARRAY_OF_HASHES'
         | 
| 9 9 | 
             
                  HASH_OF_MULTIPLE_TYPES = 'HASH_OF_MULTIPLE_TYPES'
         | 
| 10 10 | 
             
                  HASH_OF_HASHES = 'HASH_OF_HASHES'
         | 
| 11 | 
            +
                  SINGLE_HASH = 'SINGLE_HASH'
         | 
| 11 12 |  | 
| 12 13 | 
             
                  def initialize(errors)
         | 
| 13 14 | 
             
                    @errors = errors
         | 
| @@ -15,6 +16,7 @@ module RDStation | |
| 15 16 |  | 
| 16 17 | 
             
                  def format
         | 
| 17 18 | 
             
                    return FLAT_HASH if flat_hash?
         | 
| 19 | 
            +
                    return SINGLE_HASH if single_hash?
         | 
| 18 20 | 
             
                    return HASH_OF_ARRAYS if hash_of_arrays?
         | 
| 19 21 | 
             
                    return HASH_OF_HASHES if hash_of_hashes?
         | 
| 20 22 | 
             
                    return HASH_OF_MULTIPLE_TYPES if hash_of_multiple_types?
         | 
| @@ -24,6 +26,12 @@ module RDStation | |
| 24 26 |  | 
| 25 27 | 
             
                  private
         | 
| 26 28 |  | 
| 29 | 
            +
                  def single_hash?
         | 
| 30 | 
            +
                    return unless @errors.is_a?(Hash)
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                    @errors.key?('error')
         | 
| 33 | 
            +
                  end
         | 
| 34 | 
            +
             | 
| 27 35 | 
             
                  def flat_hash?
         | 
| 28 36 | 
             
                    return unless @errors.is_a?(Hash)
         | 
| 29 37 |  | 
| @@ -13,6 +13,8 @@ module RDStation | |
| 13 13 | 
             
                    return @error_response unless @error_response.is_a?(Hash)
         | 
| 14 14 |  | 
| 15 15 | 
             
                    case error_format.format
         | 
| 16 | 
            +
                    when RDStation::Error::Format::SINGLE_HASH
         | 
| 17 | 
            +
                      return from_single_hash
         | 
| 16 18 | 
             
                    when RDStation::Error::Format::FLAT_HASH
         | 
| 17 19 | 
             
                      return from_flat_hash
         | 
| 18 20 | 
             
                    when RDStation::Error::Format::HASH_OF_ARRAYS
         | 
| @@ -26,6 +28,19 @@ module RDStation | |
| 26 28 | 
             
                    errors
         | 
| 27 29 | 
             
                  end
         | 
| 28 30 |  | 
| 31 | 
            +
                  def from_single_hash
         | 
| 32 | 
            +
                    error_hash = @error_response.dup
         | 
| 33 | 
            +
                    error_message = error_hash.delete('error')
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                    [
         | 
| 36 | 
            +
                      {
         | 
| 37 | 
            +
                        'error_type' => 'TOO_MANY_REQUESTS',
         | 
| 38 | 
            +
                        'error_message' => error_message,
         | 
| 39 | 
            +
                        'details' => error_hash
         | 
| 40 | 
            +
                      }
         | 
| 41 | 
            +
                    ]
         | 
| 42 | 
            +
                  end
         | 
| 43 | 
            +
             | 
| 29 44 | 
             
                  def from_flat_hash
         | 
| 30 45 | 
             
                    [errors]
         | 
| 31 46 | 
             
                  end
         | 
| @@ -60,7 +75,7 @@ module RDStation | |
| 60 75 | 
             
                  end
         | 
| 61 76 |  | 
| 62 77 | 
             
                  def errors
         | 
| 63 | 
            -
                    @errors ||= @error_response | 
| 78 | 
            +
                    @errors ||= @error_response.fetch('errors', @error_response)
         | 
| 64 79 | 
             
                  end
         | 
| 65 80 |  | 
| 66 81 | 
             
                  private
         | 
| @@ -32,6 +32,7 @@ module RDStation | |
| 32 32 | 
             
                  when 409      then RDStation::Error::Conflict
         | 
| 33 33 | 
             
                  when 415      then RDStation::Error::UnsupportedMediaType
         | 
| 34 34 | 
             
                  when 422      then RDStation::Error::UnprocessableEntity
         | 
| 35 | 
            +
                  when 429      then RDStation::Error::TooManyRequests
         | 
| 35 36 | 
             
                  when 500      then RDStation::Error::InternalServerError
         | 
| 36 37 | 
             
                  when 501      then RDStation::Error::NotImplemented
         | 
| 37 38 | 
             
                  when 502      then RDStation::Error::BadGateway
         | 
| @@ -57,7 +58,7 @@ module RDStation | |
| 57 58 | 
             
                end
         | 
| 58 59 |  | 
| 59 60 | 
             
                def additional_error_attributes
         | 
| 60 | 
            -
                  {
         | 
| 61 | 
            +
                  attrs = {
         | 
| 61 62 | 
             
                    'headers' => response.headers,
         | 
| 62 63 | 
             
                    'body' => JSON.parse(response.body),
         | 
| 63 64 | 
             
                    'http_status' => response.code,
         | 
    
        data/lib/rdstation/version.rb
    CHANGED
    
    
| @@ -98,5 +98,22 @@ RSpec.describe RDStation::Error::Format do | |
| 98 98 | 
             
                    expect(result).to eq(RDStation::Error::Format::HASH_OF_HASHES)
         | 
| 99 99 | 
             
                  end
         | 
| 100 100 | 
             
                end
         | 
| 101 | 
            +
             | 
| 102 | 
            +
                context 'when receives a single hash with error' do
         | 
| 103 | 
            +
                  let(:errors) do
         | 
| 104 | 
            +
                    {
         | 
| 105 | 
            +
                      'error' => "'lead_limiter' rate limit exceeded for 86400 second(s) period for key ...",
         | 
| 106 | 
            +
                      'max' => 24,
         | 
| 107 | 
            +
                      'usage' => 55,
         | 
| 108 | 
            +
                      'remaining_time' => 20745,
         | 
| 109 | 
            +
                    }
         | 
| 110 | 
            +
                  end
         | 
| 111 | 
            +
             | 
| 112 | 
            +
                  it 'returns the SINGLE_HASH format' do
         | 
| 113 | 
            +
                    result = error_format.format
         | 
| 114 | 
            +
                    expect(result).to eq(RDStation::Error::Format::SINGLE_HASH)
         | 
| 115 | 
            +
                  end
         | 
| 116 | 
            +
             | 
| 117 | 
            +
                end
         | 
| 101 118 | 
             
              end
         | 
| 102 119 | 
             
            end
         | 
| @@ -215,5 +215,35 @@ RSpec.describe RDStation::Error::Formatter do | |
| 215 215 | 
             
                    expect(result).to eq(expected_result)
         | 
| 216 216 | 
             
                  end
         | 
| 217 217 | 
             
                end
         | 
| 218 | 
            +
             | 
| 219 | 
            +
                context 'when receives a single hash of errors' do
         | 
| 220 | 
            +
                  let(:error_format) { instance_double(RDStation::Error::Format, format: RDStation::Error::Format::SINGLE_HASH) }
         | 
| 221 | 
            +
             | 
| 222 | 
            +
                  let(:error_response) do
         | 
| 223 | 
            +
                    {
         | 
| 224 | 
            +
                      'error' => "'lead_limiter' rate limit exceeded for 86400 second(s) period for key",
         | 
| 225 | 
            +
                      'max' => 24,
         | 
| 226 | 
            +
                      'usage' => 55,
         | 
| 227 | 
            +
                      'remaining_time' => 20745
         | 
| 228 | 
            +
                    }
         | 
| 229 | 
            +
                  end
         | 
| 230 | 
            +
             | 
| 231 | 
            +
                  let(:error_formatter) { described_class.new(error_response) }
         | 
| 232 | 
            +
             | 
| 233 | 
            +
                  let(:expected_result) do
         | 
| 234 | 
            +
                    [
         | 
| 235 | 
            +
                      {
         | 
| 236 | 
            +
                        'error_type' => 'TOO_MANY_REQUESTS',
         | 
| 237 | 
            +
                        'error_message' => "'lead_limiter' rate limit exceeded for 86400 second(s) period for key",
         | 
| 238 | 
            +
                        'details' => { 'max' => 24, 'usage' => 55, 'remaining_time' => 20745 }
         | 
| 239 | 
            +
                      }
         | 
| 240 | 
            +
                    ]
         | 
| 241 | 
            +
                  end
         | 
| 242 | 
            +
             | 
| 243 | 
            +
                  it 'returns an array of errors' do
         | 
| 244 | 
            +
                    result = error_formatter.to_array
         | 
| 245 | 
            +
                    expect(result).to eq(expected_result)
         | 
| 246 | 
            +
                  end
         | 
| 247 | 
            +
                end
         | 
| 218 248 | 
             
              end
         | 
| 219 249 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: rdstation-ruby-client
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 2. | 
| 4 | 
            +
              version: 2.4.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Paulo L F Casaretto
         | 
| 8 | 
            -
            autorequire: | 
| 8 | 
            +
            autorequire:
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2020- | 
| 11 | 
            +
            date: 2020-09-16 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: bundler
         | 
| @@ -190,7 +190,7 @@ homepage: http://resultadosdigitais.com.br | |
| 190 190 | 
             
            licenses:
         | 
| 191 191 | 
             
            - MIT
         | 
| 192 192 | 
             
            metadata: {}
         | 
| 193 | 
            -
            post_install_message: | 
| 193 | 
            +
            post_install_message:
         | 
| 194 194 | 
             
            rdoc_options: []
         | 
| 195 195 | 
             
            require_paths:
         | 
| 196 196 | 
             
            - lib
         | 
| @@ -205,9 +205,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 205 205 | 
             
                - !ruby/object:Gem::Version
         | 
| 206 206 | 
             
                  version: '0'
         | 
| 207 207 | 
             
            requirements: []
         | 
| 208 | 
            -
             | 
| 209 | 
            -
             | 
| 210 | 
            -
            signing_key: 
         | 
| 208 | 
            +
            rubygems_version: 3.0.8
         | 
| 209 | 
            +
            signing_key:
         | 
| 211 210 | 
             
            specification_version: 4
         | 
| 212 211 | 
             
            summary: Ruby API wrapper for RD Station
         | 
| 213 212 | 
             
            test_files:
         |