fulfil-io 0.4.1 → 0.4.5
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 +32 -13
 - data/lib/fulfil/client.rb +20 -5
 - data/lib/fulfil/response_parser.rb +14 -2
 - data/lib/fulfil/version.rb +1 -1
 - metadata +7 -7
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 520488638d7340fb0278fc798770d821f87f0a7427765118c418f2db16877af1
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 7c1dfb2aac58524eef56a7d38729ffd01f3350ff3413bd7e0b6fa8bf6ab37411
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 035bc157721ab0b620cf30b99afdaf3825a2f8732e289a7b9e2b309bc99d25ec81cd3f1612ce88df4dcdb98a05a56fff295e8461f7a525e741e5d3200be8c9b6
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 0bb63dba2c5ee6d608d7b4d5b22895538ea288dde9423fac5bf133c37b24bb3a00b68dd2329a1b1874d0293e755165d0ce033df72e319de3e7204d9461de151c
         
     | 
    
        data/CHANGELOG.md
    CHANGED
    
    | 
         @@ -1,6 +1,27 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            ## 0.4.5
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            * Add #delete to client.
         
     | 
| 
      
 4 
     | 
    
         
            +
            * Set up Dependabot on GitHub.
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            ## 0.4.4
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
            * Pin http dependency to ~> 4.4.0. 5.0+ introduces a frozen string error.
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
            ## 0.4.3
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
            * Add Client errors for more granular handling.
         
     | 
| 
      
 13 
     | 
    
         
            +
            * Send along info when a `NotAuthorizedError` is raised.
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
            ## 0.4.2
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
            * Raise an `UnhandledTypeError` and reveal the offender.
         
     | 
| 
      
 18 
     | 
    
         
            +
            * Convert timedelta data types to Decimals.
         
     | 
| 
      
 19 
     | 
    
         
            +
            * Don't use `.present?` to check if response is a Hash.
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
       1 
21 
     | 
    
         
             
            ## 0.4.1
         
     | 
| 
       2 
22 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
            * @cdmwebs screwed up the release process, so this is a tiny bump to fix. No 
     | 
| 
      
 23 
     | 
    
         
            +
            * @cdmwebs screwed up the release process, so this is a tiny bump to fix. No
         
     | 
| 
      
 24 
     | 
    
         
            +
              code changes.
         
     | 
| 
       4 
25 
     | 
    
         | 
| 
       5 
26 
     | 
    
         
             
            ## 0.4.0
         
     | 
| 
       6 
27 
     | 
    
         | 
| 
         @@ -12,18 +33,16 @@ 
     | 
|
| 
       12 
33 
     | 
    
         | 
| 
       13 
34 
     | 
    
         
             
            ## 0.2.0
         
     | 
| 
       14 
35 
     | 
    
         | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
            , because initially implemented in 
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
            ' class.
         
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
            - Add Gemfile.lock to .gitignore and remove it from git-tree - it shouldn't be stored in git for a gem.
         
     | 
| 
      
 36 
     | 
    
         
            +
            * Make token optional and allow specifying headers at least for enabling
         
     | 
| 
      
 37 
     | 
    
         
            +
              authentication via 'X-API-KEY' header , because initially implemented in
         
     | 
| 
      
 38 
     | 
    
         
            +
              0.1.0 bearer auth isn't working.
         
     | 
| 
      
 39 
     | 
    
         
            +
            * Fix Query `build_search_term` and `build_exclude_term` to be compatible with
         
     | 
| 
      
 40 
     | 
    
         
            +
              Ruby < 2.4, analyzing value for 'Fixnum ' class.
         
     | 
| 
      
 41 
     | 
    
         
            +
            * Fix the gem's name in gemspec to 'fulfil-io', as registered at RubyGems.
         
     | 
| 
      
 42 
     | 
    
         
            +
            * Remove Rake version constraint from gemspec.
         
     | 
| 
      
 43 
     | 
    
         
            +
            * Add Gemfile.lock to .gitignore and remove it from git-tree - it shouldn't be
         
     | 
| 
      
 44 
     | 
    
         
            +
              stored in git for a gem.
         
     | 
| 
       26 
45 
     | 
    
         | 
| 
       27 
46 
     | 
    
         
             
            ## 0.1.0
         
     | 
| 
       28 
47 
     | 
    
         | 
| 
       29 
     | 
    
         
            -
            * Initial gem release
         
     | 
| 
      
 48 
     | 
    
         
            +
            * Initial gem release.
         
     | 
    
        data/lib/fulfil/client.rb
    CHANGED
    
    | 
         @@ -10,6 +10,11 @@ module Fulfil 
     | 
|
| 
       10 
10 
     | 
    
         
             
              OAUTH_TOKEN = ENV['FULFIL_TOKEN']
         
     | 
| 
       11 
11 
     | 
    
         | 
| 
       12 
12 
     | 
    
         
             
              class Client
         
     | 
| 
      
 13 
     | 
    
         
            +
                class NotAuthorizedError < StandardError; end
         
     | 
| 
      
 14 
     | 
    
         
            +
                class UnknownHTTPError < StandardError; end
         
     | 
| 
      
 15 
     | 
    
         
            +
                class ConnectionError < StandardError; end
         
     | 
| 
      
 16 
     | 
    
         
            +
                class ResponseError < StandardError; end
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
       13 
18 
     | 
    
         
             
                def initialize(subdomain: SUBDOMAIN, token: OAUTH_TOKEN, headers: { 'X-API-KEY' => API_KEY }, debug: false)
         
     | 
| 
       14 
19 
     | 
    
         
             
                  @subdomain = subdomain
         
     | 
| 
       15 
20 
     | 
    
         
             
                  @token = token
         
     | 
| 
         @@ -73,10 +78,17 @@ module Fulfil 
     | 
|
| 
       73 
78 
     | 
    
         
             
                  parse(result: result)
         
     | 
| 
       74 
79 
     | 
    
         
             
                end
         
     | 
| 
       75 
80 
     | 
    
         | 
| 
      
 81 
     | 
    
         
            +
                def delete(model:, id:)
         
     | 
| 
      
 82 
     | 
    
         
            +
                  uri = URI(model_url(model: model, id: id))
         
     | 
| 
      
 83 
     | 
    
         
            +
             
     | 
| 
      
 84 
     | 
    
         
            +
                  result = request(verb: :delete, endpoint: uri)
         
     | 
| 
      
 85 
     | 
    
         
            +
                  parse(result: result)
         
     | 
| 
      
 86 
     | 
    
         
            +
                end
         
     | 
| 
      
 87 
     | 
    
         
            +
             
     | 
| 
       76 
88 
     | 
    
         
             
                private
         
     | 
| 
       77 
89 
     | 
    
         | 
| 
       78 
90 
     | 
    
         
             
                def parse(result: nil, results: [])
         
     | 
| 
       79 
     | 
    
         
            -
                  if result 
     | 
| 
      
 91 
     | 
    
         
            +
                  if result
         
     | 
| 
       80 
92 
     | 
    
         
             
                    parse_single(result: result)
         
     | 
| 
       81 
93 
     | 
    
         
             
                  else
         
     | 
| 
       82 
94 
     | 
    
         
             
                    parse_multiple(results: results)
         
     | 
| 
         @@ -104,20 +116,23 @@ module Fulfil 
     | 
|
| 
       104 
116 
     | 
    
         | 
| 
       105 
117 
     | 
    
         
             
                  if response.status.ok? || response.status.created?
         
     | 
| 
       106 
118 
     | 
    
         
             
                    response.parse
         
     | 
| 
      
 119 
     | 
    
         
            +
                  elsif response.code == 204
         
     | 
| 
      
 120 
     | 
    
         
            +
                    []
         
     | 
| 
       107 
121 
     | 
    
         
             
                  elsif response.code == 401
         
     | 
| 
       108 
     | 
    
         
            -
                     
     | 
| 
      
 122 
     | 
    
         
            +
                    error = response.parse
         
     | 
| 
      
 123 
     | 
    
         
            +
                    raise NotAuthorizedError, "Not authorized: #{error['error']}: #{error['error_description']}"
         
     | 
| 
       109 
124 
     | 
    
         
             
                  else
         
     | 
| 
       110 
125 
     | 
    
         
             
                    puts response.body.to_s
         
     | 
| 
       111 
126 
     | 
    
         
             
                    raise Error, 'Error encountered while processing response:'
         
     | 
| 
       112 
127 
     | 
    
         
             
                  end
         
     | 
| 
       113 
128 
     | 
    
         
             
                rescue HTTP::Error => e
         
     | 
| 
       114 
129 
     | 
    
         
             
                  puts e
         
     | 
| 
       115 
     | 
    
         
            -
                  raise  
     | 
| 
      
 130 
     | 
    
         
            +
                  raise UnknownHTTPError, 'Unhandled HTTP error encountered'
         
     | 
| 
       116 
131 
     | 
    
         
             
                rescue HTTP::ConnectionError => e
         
     | 
| 
       117 
132 
     | 
    
         
             
                  puts "Couldn't connect"
         
     | 
| 
       118 
     | 
    
         
            -
                  raise  
     | 
| 
      
 133 
     | 
    
         
            +
                  raise ConnectionError, "Can't connect to #{base_url}"
         
     | 
| 
       119 
134 
     | 
    
         
             
                rescue HTTP::ResponseError => ex
         
     | 
| 
       120 
     | 
    
         
            -
                  raise  
     | 
| 
      
 135 
     | 
    
         
            +
                  raise ResponseError, "Can't process response: #{ex}"
         
     | 
| 
       121 
136 
     | 
    
         
             
                  []
         
     | 
| 
       122 
137 
     | 
    
         
             
                end
         
     | 
| 
       123 
138 
     | 
    
         | 
| 
         @@ -1,5 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module Fulfil
         
     | 
| 
       2 
2 
     | 
    
         
             
              module ResponseParser
         
     | 
| 
      
 3 
     | 
    
         
            +
                class UnhandledTypeError < StandardError
         
     | 
| 
      
 4 
     | 
    
         
            +
                  attr_reader :value
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
                  def initialize(msg, value)
         
     | 
| 
      
 7 
     | 
    
         
            +
                    @value = value
         
     | 
| 
      
 8 
     | 
    
         
            +
                    super(msg)
         
     | 
| 
      
 9 
     | 
    
         
            +
                  end
         
     | 
| 
      
 10 
     | 
    
         
            +
                end
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
       3 
12 
     | 
    
         
             
                # Handle value objects, for example:
         
     | 
| 
       4 
13 
     | 
    
         
             
                #
         
     | 
| 
       5 
14 
     | 
    
         
             
                # "order_date": {
         
     | 
| 
         @@ -19,10 +28,13 @@ module Fulfil 
     | 
|
| 
       19 
28 
     | 
    
         
             
                  when 'datetime'
         
     | 
| 
       20 
29 
     | 
    
         
             
                    time = value.dig('iso_string')
         
     | 
| 
       21 
30 
     | 
    
         
             
                    DateTime.parse(time)
         
     | 
| 
       22 
     | 
    
         
            -
                  when 'Decimal'
         
     | 
| 
      
 31 
     | 
    
         
            +
                  when 'Decimal', 'timedelta'
         
     | 
| 
       23 
32 
     | 
    
         
             
                    value.dig('decimal').to_f
         
     | 
| 
       24 
33 
     | 
    
         
             
                  else
         
     | 
| 
       25 
     | 
    
         
            -
                    raise UnhandledTypeError 
     | 
| 
      
 34 
     | 
    
         
            +
                    raise UnhandledTypeError.new(
         
     | 
| 
      
 35 
     | 
    
         
            +
                      "received a value that we don't know how to handle: #{json_class}",
         
     | 
| 
      
 36 
     | 
    
         
            +
                      json_class
         
     | 
| 
      
 37 
     | 
    
         
            +
                    )
         
     | 
| 
       26 
38 
     | 
    
         
             
                  end
         
     | 
| 
       27 
39 
     | 
    
         
             
                end
         
     | 
| 
       28 
40 
     | 
    
         | 
    
        data/lib/fulfil/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: fulfil-io
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.4. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.4.5
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Chris Moore
         
     | 
| 
         @@ -9,22 +9,22 @@ authors: 
     | 
|
| 
       9 
9 
     | 
    
         
             
            autorequire:
         
     | 
| 
       10 
10 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       11 
11 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       12 
     | 
    
         
            -
            date:  
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2021-11-30 00:00:00.000000000 Z
         
     | 
| 
       13 
13 
     | 
    
         
             
            dependencies:
         
     | 
| 
       14 
14 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       15 
15 
     | 
    
         
             
              name: http
         
     | 
| 
       16 
16 
     | 
    
         
             
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
       17 
17 
     | 
    
         
             
                requirements:
         
     | 
| 
       18 
     | 
    
         
            -
                - - " 
     | 
| 
      
 18 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
       19 
19 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       20 
     | 
    
         
            -
                    version:  
     | 
| 
      
 20 
     | 
    
         
            +
                    version: 4.4.1
         
     | 
| 
       21 
21 
     | 
    
         
             
              type: :runtime
         
     | 
| 
       22 
22 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       23 
23 
     | 
    
         
             
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
       24 
24 
     | 
    
         
             
                requirements:
         
     | 
| 
       25 
     | 
    
         
            -
                - - " 
     | 
| 
      
 25 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
       26 
26 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       27 
     | 
    
         
            -
                    version:  
     | 
| 
      
 27 
     | 
    
         
            +
                    version: 4.4.1
         
     | 
| 
       28 
28 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       29 
29 
     | 
    
         
             
              name: bundler
         
     | 
| 
       30 
30 
     | 
    
         
             
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
         @@ -134,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       134 
134 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       135 
135 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       136 
136 
     | 
    
         
             
            requirements: []
         
     | 
| 
       137 
     | 
    
         
            -
            rubygems_version: 3. 
     | 
| 
      
 137 
     | 
    
         
            +
            rubygems_version: 3.1.6
         
     | 
| 
       138 
138 
     | 
    
         
             
            signing_key:
         
     | 
| 
       139 
139 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       140 
140 
     | 
    
         
             
            summary: Interact with the Fulfil.io API
         
     |