gocardless_pro 2.1.0 → 2.2.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/.rubocop.yml +5 -0
 - data/circle.yml +11 -3
 - data/demo.rb +3 -3
 - data/gocardless_pro.gemspec +6 -6
 - data/lib/gocardless_pro.rb +2 -1
 - data/lib/gocardless_pro/api_service.rb +3 -2
 - data/lib/gocardless_pro/client.rb +6 -6
 - data/lib/gocardless_pro/error.rb +4 -4
 - data/lib/gocardless_pro/middlewares/raise_gocardless_errors.rb +4 -4
 - data/lib/gocardless_pro/request.rb +2 -2
 - data/lib/gocardless_pro/resources/bank_details_lookup.rb +1 -0
 - data/lib/gocardless_pro/resources/creditor.rb +1 -0
 - data/lib/gocardless_pro/resources/creditor_bank_account.rb +1 -0
 - data/lib/gocardless_pro/resources/customer.rb +1 -0
 - data/lib/gocardless_pro/resources/customer_bank_account.rb +1 -0
 - data/lib/gocardless_pro/resources/event.rb +1 -0
 - data/lib/gocardless_pro/resources/mandate.rb +1 -0
 - data/lib/gocardless_pro/resources/mandate_pdf.rb +1 -0
 - data/lib/gocardless_pro/resources/payment.rb +1 -0
 - data/lib/gocardless_pro/resources/payout.rb +1 -0
 - data/lib/gocardless_pro/resources/redirect_flow.rb +1 -0
 - data/lib/gocardless_pro/resources/refund.rb +1 -0
 - data/lib/gocardless_pro/resources/subscription.rb +1 -0
 - data/lib/gocardless_pro/services/base_service.rb +1 -1
 - data/lib/gocardless_pro/version.rb +1 -1
 - data/spec/api_service_spec.rb +49 -49
 - data/spec/client_spec.rb +1 -1
 - data/spec/error_spec.rb +13 -13
 - data/spec/middlewares/raise_gocardless_errors_spec.rb +15 -16
 - data/spec/resources/bank_details_lookup_spec.rb +18 -18
 - data/spec/resources/creditor_bank_account_spec.rb +46 -46
 - data/spec/resources/creditor_spec.rb +42 -42
 - data/spec/resources/customer_bank_account_spec.rb +48 -48
 - data/spec/resources/customer_spec.rb +42 -42
 - data/spec/resources/event_spec.rb +18 -18
 - data/spec/resources/mandate_pdf_spec.rb +18 -18
 - data/spec/resources/mandate_spec.rb +54 -54
 - data/spec/resources/payment_spec.rb +54 -54
 - data/spec/resources/payout_spec.rb +18 -18
 - data/spec/resources/redirect_flow_spec.rb +36 -36
 - data/spec/resources/refund_spec.rb +42 -42
 - data/spec/resources/subscription_spec.rb +48 -48
 - data/spec/response_spec.rb +1 -2
 - data/spec/services/bank_details_lookups_service_spec.rb +25 -25
 - data/spec/services/creditor_bank_accounts_service_spec.rb +86 -86
 - data/spec/services/creditors_service_spec.rb +87 -87
 - data/spec/services/customer_bank_accounts_service_spec.rb +95 -95
 - data/spec/services/customers_service_spec.rb +87 -87
 - data/spec/services/events_service_spec.rb +49 -49
 - data/spec/services/mandate_pdfs_service_spec.rb +25 -25
 - data/spec/services/mandates_service_spec.rb +103 -103
 - data/spec/services/payments_service_spec.rb +103 -103
 - data/spec/services/payouts_service_spec.rb +49 -49
 - data/spec/services/redirect_flows_service_spec.rb +52 -52
 - data/spec/services/refunds_service_spec.rb +87 -87
 - data/spec/services/subscriptions_service_spec.rb +95 -95
 - metadata +10 -10
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 39c5c4f0dcfab5cebeeba56aa2e1801e9775a6d0
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: c1cc2f6d595d13011d219282b08fe37301e7e0c2
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 3180f056a519890bea499e2daf2c983e296709432c63fb4de98df96ffa446217c5bf595e3df4ffe8e06bf3b1b0204647d377aebfb4ff675113ac1650b0bfdc31
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 85bb043efad721d43dc239865411f3ba5ce962841153ec92fcdf590cb2ee068ce4f19bca397385415e6c5599786e8bf1b29975ca1be323fd8e81a8a4d3c515c8
         
     | 
    
        data/.rubocop.yml
    ADDED
    
    
    
        data/circle.yml
    CHANGED
    
    | 
         @@ -1,3 +1,11 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
             
     | 
| 
       2 
     | 
    
         
            -
               
     | 
| 
       3 
     | 
    
         
            -
                 
     | 
| 
      
 1 
     | 
    
         
            +
            dependencies:
         
     | 
| 
      
 2 
     | 
    
         
            +
              override:
         
     | 
| 
      
 3 
     | 
    
         
            +
                - 'rvm-exec 2.2.7 bundle install'
         
     | 
| 
      
 4 
     | 
    
         
            +
                - 'rvm-exec 2.3.4 bundle install'
         
     | 
| 
      
 5 
     | 
    
         
            +
                - 'rvm-exec 2.4.1 bundle install'
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            test:
         
     | 
| 
      
 8 
     | 
    
         
            +
              override:
         
     | 
| 
      
 9 
     | 
    
         
            +
                - 'rvm-exec 2.2.7 bundle exec rspec'
         
     | 
| 
      
 10 
     | 
    
         
            +
                - 'rvm-exec 2.3.4 bundle exec rspec'
         
     | 
| 
      
 11 
     | 
    
         
            +
                - 'rvm-exec 2.4.1 bundle exec rspec'
         
     | 
    
        data/demo.rb
    CHANGED
    
    | 
         @@ -1,9 +1,9 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
             
     | 
| 
      
 1 
     | 
    
         
            +
            require_relative 'lib/gocardless_pro'
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            @client = GoCardlessPro::Client.new(
         
     | 
| 
       4 
     | 
    
         
            -
              access_token: ENV[ 
     | 
| 
      
 4 
     | 
    
         
            +
              access_token: ENV['GOCARDLESS_TOKEN'],
         
     | 
| 
       5 
5 
     | 
    
         
             
              environment: :sandbox
         
     | 
| 
       6 
6 
     | 
    
         
             
            )
         
     | 
| 
       7 
7 
     | 
    
         | 
| 
       8 
     | 
    
         
            -
            puts  
     | 
| 
      
 8 
     | 
    
         
            +
            puts 'Your first customer:'
         
     | 
| 
       9 
9 
     | 
    
         
             
            puts "-> #{@client.customers.list.records.first.inspect}"
         
     | 
    
        data/gocardless_pro.gemspec
    CHANGED
    
    | 
         @@ -4,23 +4,23 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 
     | 
|
| 
       4 
4 
     | 
    
         
             
            require 'gocardless_pro/version'
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
       6 
6 
     | 
    
         
             
            Gem::Specification.new do |spec|
         
     | 
| 
       7 
     | 
    
         
            -
              spec.name          =  
     | 
| 
      
 7 
     | 
    
         
            +
              spec.name          = 'gocardless_pro'
         
     | 
| 
       8 
8 
     | 
    
         
             
              spec.version       = GoCardlessPro::VERSION
         
     | 
| 
       9 
9 
     | 
    
         
             
              spec.authors       = %w(GoCardless)
         
     | 
| 
       10 
10 
     | 
    
         
             
              spec.email         = %w(engineering@gocardless.com)
         
     | 
| 
       11 
11 
     | 
    
         
             
              spec.summary       = %q{A gem for calling the GoCardless Pro API}
         
     | 
| 
       12 
     | 
    
         
            -
              spec.homepage      =  
     | 
| 
       13 
     | 
    
         
            -
              spec.license       =  
     | 
| 
      
 12 
     | 
    
         
            +
              spec.homepage      = 'https://github.com/gocardless/gocardless-pro-ruby'
         
     | 
| 
      
 13 
     | 
    
         
            +
              spec.license       = 'MIT'
         
     | 
| 
       14 
14 
     | 
    
         | 
| 
       15 
15 
     | 
    
         
             
              spec.files         = `git ls-files -z`.split("\x0")
         
     | 
| 
       16 
16 
     | 
    
         
             
              spec.executables   = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
         
     | 
| 
       17 
17 
     | 
    
         
             
              spec.test_files    = spec.files.grep(%r{^(test|spec|features)/})
         
     | 
| 
       18 
     | 
    
         
            -
              spec.require_paths = [ 
     | 
| 
      
 18 
     | 
    
         
            +
              spec.require_paths = ['lib']
         
     | 
| 
       19 
19 
     | 
    
         | 
| 
       20 
20 
     | 
    
         
             
              spec.add_development_dependency 'rspec', '~> 3.1'
         
     | 
| 
       21 
21 
     | 
    
         
             
              spec.add_development_dependency 'webmock', '~> 1.18'
         
     | 
| 
       22 
     | 
    
         
            -
              spec.add_development_dependency 'rubocop', '~> 0. 
     | 
| 
      
 22 
     | 
    
         
            +
              spec.add_development_dependency 'rubocop', '~> 0.49.1'
         
     | 
| 
       23 
23 
     | 
    
         
             
              spec.add_development_dependency 'yard', '~> 0.8.7.6'
         
     | 
| 
       24 
24 
     | 
    
         | 
| 
       25 
     | 
    
         
            -
              spec.add_dependency 'faraday', ['>= 0. 
     | 
| 
      
 25 
     | 
    
         
            +
              spec.add_dependency 'faraday', ['>= 0.9.2', '< 1.0']
         
     | 
| 
       26 
26 
     | 
    
         
             
            end
         
     | 
    
        data/lib/gocardless_pro.rb
    CHANGED
    
    | 
         @@ -1,4 +1,5 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # encoding: utf-8
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       2 
3 
     | 
    
         
             
            #
         
     | 
| 
       3 
4 
     | 
    
         
             
            # This client is automatically generated from a template and JSON schema definition.
         
     | 
| 
       4 
5 
     | 
    
         
             
            # See https://github.com/gocardless/gocardless-pro-ruby#contributing before editing.
         
     | 
| 
         @@ -19,7 +20,7 @@ version_file = 'gocardless_pro/version' 
     | 
|
| 
       19 
20 
     | 
    
         
             
            if File.file? File.expand_path("#{version_file}.rb", File.dirname(__FILE__))
         
     | 
| 
       20 
21 
     | 
    
         
             
              require_relative version_file
         
     | 
| 
       21 
22 
     | 
    
         
             
            else
         
     | 
| 
       22 
     | 
    
         
            -
              GoCardlessPro::VERSION = ''
         
     | 
| 
      
 23 
     | 
    
         
            +
              GoCardlessPro::VERSION = ''.freeze
         
     | 
| 
       23 
24 
     | 
    
         
             
            end
         
     | 
| 
       24 
25 
     | 
    
         | 
| 
       25 
26 
     | 
    
         
             
            require_relative 'gocardless_pro/api_service'
         
     | 
| 
         @@ -1,4 +1,5 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # encoding: utf-8
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       2 
3 
     | 
    
         
             
            #
         
     | 
| 
       3 
4 
     | 
    
         
             
            # This client is automatically generated from a template and JSON schema definition.
         
     | 
| 
       4 
5 
     | 
    
         
             
            # See https://github.com/gocardless/gocardless-pro-ruby#contributing before editing.
         
     | 
| 
         @@ -38,7 +39,7 @@ module GoCardlessPro 
     | 
|
| 
       38 
39 
     | 
    
         
             
                # @param path [String] the URL (without the base domain) to make the request to
         
     | 
| 
       39 
40 
     | 
    
         
             
                # @param options [Hash] the options hash
         
     | 
| 
       40 
41 
     | 
    
         
             
                def make_request(method, path, options = {})
         
     | 
| 
       41 
     | 
    
         
            -
                   
     | 
| 
      
 42 
     | 
    
         
            +
                  raise ArgumentError, 'options must be a hash' unless options.is_a?(Hash)
         
     | 
| 
       42 
43 
     | 
    
         
             
                  options[:headers] ||= {}
         
     | 
| 
       43 
44 
     | 
    
         
             
                  options[:headers] = @headers.merge(options[:headers])
         
     | 
| 
       44 
45 
     | 
    
         
             
                  Request.new(@connection, method, @path_prefix + path, options).request
         
     | 
| 
         @@ -50,7 +51,7 @@ module GoCardlessPro 
     | 
|
| 
       50 
51 
     | 
    
         
             
                  url.password = 'REDACTED' unless url.password.nil?
         
     | 
| 
       51 
52 
     | 
    
         
             
                  "#<GoCardlessPro::Client url=\"#{url}\">"
         
     | 
| 
       52 
53 
     | 
    
         
             
                end
         
     | 
| 
       53 
     | 
    
         
            -
                 
     | 
| 
      
 54 
     | 
    
         
            +
                alias to_s inspect
         
     | 
| 
       54 
55 
     | 
    
         | 
| 
       55 
56 
     | 
    
         
             
                private
         
     | 
| 
       56 
57 
     | 
    
         | 
| 
         @@ -79,7 +79,7 @@ module GoCardlessPro 
     | 
|
| 
       79 
79 
     | 
    
         
             
                #   authentication.
         
     | 
| 
       80 
80 
     | 
    
         
             
                #
         
     | 
| 
       81 
81 
     | 
    
         
             
                def initialize(options)
         
     | 
| 
       82 
     | 
    
         
            -
                  access_token = options.delete(:access_token) ||  
     | 
| 
      
 82 
     | 
    
         
            +
                  access_token = options.delete(:access_token) || raise('No Access Token given to GoCardless Client')
         
     | 
| 
       83 
83 
     | 
    
         
             
                  environment = options.delete(:environment) || :live
         
     | 
| 
       84 
84 
     | 
    
         
             
                  url = options.delete(:url) || url_for_environment(environment)
         
     | 
| 
       85 
85 
     | 
    
         
             
                  options = custom_options(options)
         
     | 
| 
         @@ -94,7 +94,7 @@ module GoCardlessPro 
     | 
|
| 
       94 
94 
     | 
    
         
             
                  elsif environment === :sandbox
         
     | 
| 
       95 
95 
     | 
    
         
             
                    'https://api-sandbox.gocardless.com'
         
     | 
| 
       96 
96 
     | 
    
         
             
                  else
         
     | 
| 
       97 
     | 
    
         
            -
                     
     | 
| 
      
 97 
     | 
    
         
            +
                    raise "Unknown environment key: #{environment}"
         
     | 
| 
       98 
98 
     | 
    
         
             
                  end
         
     | 
| 
       99 
99 
     | 
    
         
             
                end
         
     | 
| 
       100 
100 
     | 
    
         | 
| 
         @@ -115,11 +115,11 @@ module GoCardlessPro 
     | 
|
| 
       115 
115 
     | 
    
         
             
                  {
         
     | 
| 
       116 
116 
     | 
    
         
             
                    default_headers: {
         
     | 
| 
       117 
117 
     | 
    
         
             
                      'GoCardless-Version' => '2015-07-06',
         
     | 
| 
       118 
     | 
    
         
            -
                      'User-Agent' =>  
     | 
| 
      
 118 
     | 
    
         
            +
                      'User-Agent' => user_agent.to_s,
         
     | 
| 
       119 
119 
     | 
    
         
             
                      'Content-Type' => 'application/json',
         
     | 
| 
       120 
120 
     | 
    
         
             
                      'GoCardless-Client-Library' => 'gocardless-pro-ruby',
         
     | 
| 
       121 
     | 
    
         
            -
                      'GoCardless-Client-Version' => '2. 
     | 
| 
       122 
     | 
    
         
            -
                    }
         
     | 
| 
      
 121 
     | 
    
         
            +
                      'GoCardless-Client-Version' => '2.2.0',
         
     | 
| 
      
 122 
     | 
    
         
            +
                    },
         
     | 
| 
       123 
123 
     | 
    
         
             
                  }
         
     | 
| 
       124 
124 
     | 
    
         
             
                end
         
     | 
| 
       125 
125 
     | 
    
         | 
| 
         @@ -139,7 +139,7 @@ module GoCardlessPro 
     | 
|
| 
       139 
139 
     | 
    
         
             
                      comment = [
         
     | 
| 
       140 
140 
     | 
    
         
             
                        "#{ruby_engine}/#{ruby_version}",
         
     | 
| 
       141 
141 
     | 
    
         
             
                        "#{RUBY_ENGINE}/#{interpreter_version}",
         
     | 
| 
       142 
     | 
    
         
            -
                         
     | 
| 
      
 142 
     | 
    
         
            +
                        RUBY_PLATFORM.to_s,
         
     | 
| 
       143 
143 
     | 
    
         
             
                      ]
         
     | 
| 
       144 
144 
     | 
    
         
             
                      comment << "faraday/#{Faraday::VERSION}"
         
     | 
| 
       145 
145 
     | 
    
         
             
                      "#{gem_info} #{comment.join(' ')}"
         
     | 
    
        data/lib/gocardless_pro/error.rb
    CHANGED
    
    | 
         @@ -6,7 +6,7 @@ module GoCardlessPro 
     | 
|
| 
       6 
6 
     | 
    
         
             
                # intialize a new error
         
     | 
| 
       7 
7 
     | 
    
         
             
                #  @param error the error from the API
         
     | 
| 
       8 
8 
     | 
    
         
             
                def initialize(error)
         
     | 
| 
       9 
     | 
    
         
            -
                   
     | 
| 
      
 9 
     | 
    
         
            +
                  raise ArgumentError, 'GoCardless errors expect a hash' unless error.is_a?(Hash)
         
     | 
| 
       10 
10 
     | 
    
         
             
                  @error = error
         
     | 
| 
       11 
11 
     | 
    
         
             
                end
         
     | 
| 
       12 
12 
     | 
    
         | 
| 
         @@ -22,9 +22,9 @@ module GoCardlessPro 
     | 
|
| 
       22 
22 
     | 
    
         | 
| 
       23 
23 
     | 
    
         
             
                def to_s
         
     | 
| 
       24 
24 
     | 
    
         
             
                  if errors.any?
         
     | 
| 
       25 
     | 
    
         
            -
                    errors
         
     | 
| 
       26 
     | 
    
         
            -
                       
     | 
| 
       27 
     | 
    
         
            -
                       
     | 
| 
      
 25 
     | 
    
         
            +
                    errors.
         
     | 
| 
      
 26 
     | 
    
         
            +
                      map { |err| "#{err['field']} #{err['message']}" }.
         
     | 
| 
      
 27 
     | 
    
         
            +
                      join(', ')
         
     | 
| 
       28 
28 
     | 
    
         
             
                  else
         
     | 
| 
       29 
29 
     | 
    
         
             
                    @error['message']
         
     | 
| 
       30 
30 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -6,13 +6,13 @@ module GoCardlessPro 
     | 
|
| 
       6 
6 
     | 
    
         | 
| 
       7 
7 
     | 
    
         
             
                  def on_complete(env)
         
     | 
| 
       8 
8 
     | 
    
         
             
                    if !json?(env) || API_ERROR_STATUSES.include?(env.status)
         
     | 
| 
       9 
     | 
    
         
            -
                       
     | 
| 
      
 9 
     | 
    
         
            +
                      raise ApiError, generate_error_data(env)
         
     | 
| 
       10 
10 
     | 
    
         
             
                    end
         
     | 
| 
       11 
11 
     | 
    
         | 
| 
       12 
12 
     | 
    
         
             
                    if CLIENT_ERROR_STATUSES.include?(env.status)
         
     | 
| 
       13 
13 
     | 
    
         
             
                      json_body ||= JSON.parse(env.body) unless env.body.empty?
         
     | 
| 
       14 
14 
     | 
    
         
             
                      error_type = json_body['error']['type']
         
     | 
| 
       15 
     | 
    
         
            -
                       
     | 
| 
      
 15 
     | 
    
         
            +
                      raise(error_class_for_type(error_type), json_body['error'])
         
     | 
| 
       16 
16 
     | 
    
         
             
                    end
         
     | 
| 
       17 
17 
     | 
    
         
             
                  end
         
     | 
| 
       18 
18 
     | 
    
         | 
| 
         @@ -23,7 +23,7 @@ module GoCardlessPro 
     | 
|
| 
       23 
23 
     | 
    
         
             
                      validation_failed: GoCardlessPro::ValidationError,
         
     | 
| 
       24 
24 
     | 
    
         
             
                      gocardless: GoCardlessPro::GoCardlessError,
         
     | 
| 
       25 
25 
     | 
    
         
             
                      invalid_api_usage: GoCardlessPro::InvalidApiUsageError,
         
     | 
| 
       26 
     | 
    
         
            -
                      invalid_state: GoCardlessPro::InvalidStateError
         
     | 
| 
      
 26 
     | 
    
         
            +
                      invalid_state: GoCardlessPro::InvalidStateError,
         
     | 
| 
       27 
27 
     | 
    
         
             
                    }.fetch(type.to_sym)
         
     | 
| 
       28 
28 
     | 
    
         
             
                  end
         
     | 
| 
       29 
29 
     | 
    
         | 
| 
         @@ -33,7 +33,7 @@ module GoCardlessPro 
     | 
|
| 
       33 
33 
     | 
    
         
             
                                   "code: #{env.status}\n" \
         
     | 
| 
       34 
34 
     | 
    
         
             
                                   "headers: #{env.response_headers}\n" \
         
     | 
| 
       35 
35 
     | 
    
         
             
                                   "body: #{env.body}",
         
     | 
| 
       36 
     | 
    
         
            -
                      'code' => env.status
         
     | 
| 
      
 36 
     | 
    
         
            +
                      'code' => env.status,
         
     | 
| 
       37 
37 
     | 
    
         
             
                    }
         
     | 
| 
       38 
38 
     | 
    
         
             
                  end
         
     | 
| 
       39 
39 
     | 
    
         | 
| 
         @@ -71,10 +71,10 @@ module GoCardlessPro 
     | 
|
| 
       71 
71 
     | 
    
         
             
                def request_body
         
     | 
| 
       72 
72 
     | 
    
         
             
                  if @method == :get
         
     | 
| 
       73 
73 
     | 
    
         
             
                    nil
         
     | 
| 
       74 
     | 
    
         
            -
                  elsif [ 
     | 
| 
      
 74 
     | 
    
         
            +
                  elsif %i[post put delete].include?(@method)
         
     | 
| 
       75 
75 
     | 
    
         
             
                    @given_options.fetch(:params, {})
         
     | 
| 
       76 
76 
     | 
    
         
             
                  else
         
     | 
| 
       77 
     | 
    
         
            -
                     
     | 
| 
      
 77 
     | 
    
         
            +
                    raise "Unknown request method #{@method}"
         
     | 
| 
       78 
78 
     | 
    
         
             
                  end
         
     | 
| 
       79 
79 
     | 
    
         
             
                end
         
     | 
| 
       80 
80 
     | 
    
         | 
    
        data/spec/api_service_spec.rb
    CHANGED
    
    | 
         @@ -7,14 +7,14 @@ describe GoCardlessPro::ApiService do 
     | 
|
| 
       7 
7 
     | 
    
         
             
                {
         
     | 
| 
       8 
8 
     | 
    
         
             
                  status: 200,
         
     | 
| 
       9 
9 
     | 
    
         
             
                  body: '{}',
         
     | 
| 
       10 
     | 
    
         
            -
                  headers: { 'Content-Type' => 'application/json' }
         
     | 
| 
      
 10 
     | 
    
         
            +
                  headers: { 'Content-Type' => 'application/json' },
         
     | 
| 
       11 
11 
     | 
    
         
             
                }
         
     | 
| 
       12 
12 
     | 
    
         
             
              end
         
     | 
| 
       13 
13 
     | 
    
         | 
| 
       14 
14 
     | 
    
         
             
              it 'uses basic auth' do
         
     | 
| 
       15 
     | 
    
         
            -
                stub = stub_request(:get, 'https://api.example.com/customers')
         
     | 
| 
       16 
     | 
    
         
            -
                        
     | 
| 
       17 
     | 
    
         
            -
                        
     | 
| 
      
 15 
     | 
    
         
            +
                stub = stub_request(:get, 'https://api.example.com/customers').
         
     | 
| 
      
 16 
     | 
    
         
            +
                       with(headers: { 'Authorization' => 'Bearer secret_token' }).
         
     | 
| 
      
 17 
     | 
    
         
            +
                       to_return(default_response)
         
     | 
| 
       18 
18 
     | 
    
         | 
| 
       19 
19 
     | 
    
         
             
                service.make_request(:get, '/customers')
         
     | 
| 
       20 
20 
     | 
    
         
             
                expect(stub).to have_been_requested
         
     | 
| 
         @@ -22,17 +22,17 @@ describe GoCardlessPro::ApiService do 
     | 
|
| 
       22 
22 
     | 
    
         | 
| 
       23 
23 
     | 
    
         
             
              describe 'making a get request without any parameters' do
         
     | 
| 
       24 
24 
     | 
    
         
             
                it 'is expected to call the correct stub' do
         
     | 
| 
       25 
     | 
    
         
            -
                  stub = stub_request(:get, /.*api.example.com\/customers/)
         
     | 
| 
       26 
     | 
    
         
            -
                          
     | 
| 
      
 25 
     | 
    
         
            +
                  stub = stub_request(:get, /.*api.example.com\/customers/).
         
     | 
| 
      
 26 
     | 
    
         
            +
                         to_return(default_response)
         
     | 
| 
       27 
27 
     | 
    
         | 
| 
       28 
28 
     | 
    
         
             
                  service.make_request(:get, '/customers')
         
     | 
| 
       29 
29 
     | 
    
         
             
                  expect(stub).to have_been_requested
         
     | 
| 
       30 
30 
     | 
    
         
             
                end
         
     | 
| 
       31 
31 
     | 
    
         | 
| 
       32 
32 
     | 
    
         
             
                it "doesn't include an idempotency key" do
         
     | 
| 
       33 
     | 
    
         
            -
                  stub = stub_request(:get, /.*api.example.com\/customers/)
         
     | 
| 
       34 
     | 
    
         
            -
                          
     | 
| 
       35 
     | 
    
         
            -
                          
     | 
| 
      
 33 
     | 
    
         
            +
                  stub = stub_request(:get, /.*api.example.com\/customers/).
         
     | 
| 
      
 34 
     | 
    
         
            +
                         with { |request| !request.headers.key?('Idempotency-Key') }.
         
     | 
| 
      
 35 
     | 
    
         
            +
                         to_return(default_response)
         
     | 
| 
       36 
36 
     | 
    
         | 
| 
       37 
37 
     | 
    
         
             
                  service.make_request(:get, '/customers')
         
     | 
| 
       38 
38 
     | 
    
         
             
                  expect(stub).to have_been_requested
         
     | 
| 
         @@ -41,17 +41,17 @@ describe GoCardlessPro::ApiService do 
     | 
|
| 
       41 
41 
     | 
    
         | 
| 
       42 
42 
     | 
    
         
             
              describe 'making a get request with query parameters' do
         
     | 
| 
       43 
43 
     | 
    
         
             
                it 'correctly passes the query parameters' do
         
     | 
| 
       44 
     | 
    
         
            -
                  stub = stub_request(:get, /.*api.example.com\/customers\?a=1&b=2/)
         
     | 
| 
       45 
     | 
    
         
            -
                          
     | 
| 
      
 44 
     | 
    
         
            +
                  stub = stub_request(:get, /.*api.example.com\/customers\?a=1&b=2/).
         
     | 
| 
      
 45 
     | 
    
         
            +
                         to_return(default_response)
         
     | 
| 
       46 
46 
     | 
    
         | 
| 
       47 
47 
     | 
    
         
             
                  service.make_request(:get, '/customers', params: { a: 1, b: 2 })
         
     | 
| 
       48 
48 
     | 
    
         
             
                  expect(stub).to have_been_requested
         
     | 
| 
       49 
49 
     | 
    
         
             
                end
         
     | 
| 
       50 
50 
     | 
    
         | 
| 
       51 
51 
     | 
    
         
             
                it "doesn't include an idempotency key" do
         
     | 
| 
       52 
     | 
    
         
            -
                  stub = stub_request(:get, /.*api.example.com\/customers\?a=1&b=2/)
         
     | 
| 
       53 
     | 
    
         
            -
                          
     | 
| 
       54 
     | 
    
         
            -
                          
     | 
| 
      
 52 
     | 
    
         
            +
                  stub = stub_request(:get, /.*api.example.com\/customers\?a=1&b=2/).
         
     | 
| 
      
 53 
     | 
    
         
            +
                         with { |request| !request.headers.key?('Idempotency-Key') }.
         
     | 
| 
      
 54 
     | 
    
         
            +
                         to_return(default_response)
         
     | 
| 
       55 
55 
     | 
    
         | 
| 
       56 
56 
     | 
    
         
             
                  service.make_request(:get, '/customers', params: { a: 1, b: 2 })
         
     | 
| 
       57 
57 
     | 
    
         
             
                  expect(stub).to have_been_requested
         
     | 
| 
         @@ -60,13 +60,13 @@ describe GoCardlessPro::ApiService do 
     | 
|
| 
       60 
60 
     | 
    
         | 
| 
       61 
61 
     | 
    
         
             
              describe 'making a post request with some data' do
         
     | 
| 
       62 
62 
     | 
    
         
             
                it 'passes the data in as the post body' do
         
     | 
| 
       63 
     | 
    
         
            -
                  stub = stub_request(:post, /.*api.example.com\/customers/)
         
     | 
| 
       64 
     | 
    
         
            -
                          
     | 
| 
       65 
     | 
    
         
            -
                          
     | 
| 
      
 63 
     | 
    
         
            +
                  stub = stub_request(:post, /.*api.example.com\/customers/).
         
     | 
| 
      
 64 
     | 
    
         
            +
                         with(body: { given_name: 'Jack', family_name: 'Franklin' }).
         
     | 
| 
      
 65 
     | 
    
         
            +
                         to_return(default_response)
         
     | 
| 
       66 
66 
     | 
    
         | 
| 
       67 
67 
     | 
    
         
             
                  service.make_request(:post, '/customers', params: {
         
     | 
| 
       68 
68 
     | 
    
         
             
                                         given_name: 'Jack',
         
     | 
| 
       69 
     | 
    
         
            -
                                         family_name: 'Franklin'
         
     | 
| 
      
 69 
     | 
    
         
            +
                                         family_name: 'Franklin',
         
     | 
| 
       70 
70 
     | 
    
         
             
                                       })
         
     | 
| 
       71 
71 
     | 
    
         
             
                  expect(stub).to have_been_requested
         
     | 
| 
       72 
72 
     | 
    
         
             
                end
         
     | 
| 
         @@ -74,16 +74,16 @@ describe GoCardlessPro::ApiService do 
     | 
|
| 
       74 
74 
     | 
    
         
             
                it 'generates a random idempotency key' do
         
     | 
| 
       75 
75 
     | 
    
         
             
                  allow(SecureRandom).to receive(:uuid).and_return('random-uuid')
         
     | 
| 
       76 
76 
     | 
    
         | 
| 
       77 
     | 
    
         
            -
                  stub = stub_request(:post, /.*api.example.com\/customers/)
         
     | 
| 
       78 
     | 
    
         
            -
                          
     | 
| 
      
 77 
     | 
    
         
            +
                  stub = stub_request(:post, /.*api.example.com\/customers/).
         
     | 
| 
      
 78 
     | 
    
         
            +
                         with(
         
     | 
| 
       79 
79 
     | 
    
         
             
                           body: { given_name: 'Jack', family_name: 'Franklin' },
         
     | 
| 
       80 
80 
     | 
    
         
             
                           headers: { 'Idempotency-Key' => 'random-uuid' }
         
     | 
| 
       81 
     | 
    
         
            -
                         )
         
     | 
| 
       82 
     | 
    
         
            -
                          
     | 
| 
      
 81 
     | 
    
         
            +
                         ).
         
     | 
| 
      
 82 
     | 
    
         
            +
                         to_return(default_response)
         
     | 
| 
       83 
83 
     | 
    
         | 
| 
       84 
84 
     | 
    
         
             
                  service.make_request(:post, '/customers', params: {
         
     | 
| 
       85 
85 
     | 
    
         
             
                                         given_name: 'Jack',
         
     | 
| 
       86 
     | 
    
         
            -
                                         family_name: 'Franklin'
         
     | 
| 
      
 86 
     | 
    
         
            +
                                         family_name: 'Franklin',
         
     | 
| 
       87 
87 
     | 
    
         
             
                                       })
         
     | 
| 
       88 
88 
     | 
    
         
             
                  expect(stub).to have_been_requested
         
     | 
| 
       89 
89 
     | 
    
         
             
                end
         
     | 
| 
         @@ -91,19 +91,19 @@ describe GoCardlessPro::ApiService do 
     | 
|
| 
       91 
91 
     | 
    
         | 
| 
       92 
92 
     | 
    
         
             
              describe 'making a post request with data and custom header' do
         
     | 
| 
       93 
93 
     | 
    
         
             
                it 'passes the data in as the post body' do
         
     | 
| 
       94 
     | 
    
         
            -
                  stub = stub_request(:post, /.*api.example.com\/customers/)
         
     | 
| 
       95 
     | 
    
         
            -
                          
     | 
| 
      
 94 
     | 
    
         
            +
                  stub = stub_request(:post, /.*api.example.com\/customers/).
         
     | 
| 
      
 95 
     | 
    
         
            +
                         with(
         
     | 
| 
       96 
96 
     | 
    
         
             
                           body: { given_name: 'Jack', family_name: 'Franklin' },
         
     | 
| 
       97 
97 
     | 
    
         
             
                           headers: { 'Foo' => 'Bar' }
         
     | 
| 
       98 
     | 
    
         
            -
                         )
         
     | 
| 
       99 
     | 
    
         
            -
                          
     | 
| 
      
 98 
     | 
    
         
            +
                         ).
         
     | 
| 
      
 99 
     | 
    
         
            +
                         to_return(default_response)
         
     | 
| 
       100 
100 
     | 
    
         | 
| 
       101 
101 
     | 
    
         
             
                  service.make_request(:post, '/customers', params: {
         
     | 
| 
       102 
102 
     | 
    
         
             
                                         given_name: 'Jack',
         
     | 
| 
       103 
     | 
    
         
            -
                                         family_name: 'Franklin'
         
     | 
| 
      
 103 
     | 
    
         
            +
                                         family_name: 'Franklin',
         
     | 
| 
       104 
104 
     | 
    
         
             
                                       },
         
     | 
| 
       105 
105 
     | 
    
         
             
                                                            headers: {
         
     | 
| 
       106 
     | 
    
         
            -
                                                              'Foo' => 'Bar'
         
     | 
| 
      
 106 
     | 
    
         
            +
                                                              'Foo' => 'Bar',
         
     | 
| 
       107 
107 
     | 
    
         
             
                                                            })
         
     | 
| 
       108 
108 
     | 
    
         
             
                  expect(stub).to have_been_requested
         
     | 
| 
       109 
109 
     | 
    
         
             
                end
         
     | 
| 
         @@ -111,38 +111,38 @@ describe GoCardlessPro::ApiService do 
     | 
|
| 
       111 
111 
     | 
    
         
             
                it 'merges in a random idempotency key' do
         
     | 
| 
       112 
112 
     | 
    
         
             
                  allow(SecureRandom).to receive(:uuid).and_return('random-uuid')
         
     | 
| 
       113 
113 
     | 
    
         | 
| 
       114 
     | 
    
         
            -
                  stub = stub_request(:post, /.*api.example.com\/customers/)
         
     | 
| 
       115 
     | 
    
         
            -
                          
     | 
| 
      
 114 
     | 
    
         
            +
                  stub = stub_request(:post, /.*api.example.com\/customers/).
         
     | 
| 
      
 115 
     | 
    
         
            +
                         with(
         
     | 
| 
       116 
116 
     | 
    
         
             
                           body: { given_name: 'Jack', family_name: 'Franklin' },
         
     | 
| 
       117 
117 
     | 
    
         
             
                           headers: { 'Idempotency-Key' => 'random-uuid', 'Foo' => 'Bar' }
         
     | 
| 
       118 
     | 
    
         
            -
                         )
         
     | 
| 
       119 
     | 
    
         
            -
                          
     | 
| 
      
 118 
     | 
    
         
            +
                         ).
         
     | 
| 
      
 119 
     | 
    
         
            +
                         to_return(default_response)
         
     | 
| 
       120 
120 
     | 
    
         | 
| 
       121 
121 
     | 
    
         
             
                  service.make_request(:post, '/customers', params: {
         
     | 
| 
       122 
122 
     | 
    
         
             
                                         given_name: 'Jack',
         
     | 
| 
       123 
     | 
    
         
            -
                                         family_name: 'Franklin'
         
     | 
| 
      
 123 
     | 
    
         
            +
                                         family_name: 'Franklin',
         
     | 
| 
       124 
124 
     | 
    
         
             
                                       },
         
     | 
| 
       125 
125 
     | 
    
         
             
                                                            headers: {
         
     | 
| 
       126 
     | 
    
         
            -
                                                              'Foo' => 'Bar'
         
     | 
| 
      
 126 
     | 
    
         
            +
                                                              'Foo' => 'Bar',
         
     | 
| 
       127 
127 
     | 
    
         
             
                                                            })
         
     | 
| 
       128 
128 
     | 
    
         
             
                  expect(stub).to have_been_requested
         
     | 
| 
       129 
129 
     | 
    
         
             
                end
         
     | 
| 
       130 
130 
     | 
    
         | 
| 
       131 
131 
     | 
    
         
             
                context 'with a custom idempotency key' do
         
     | 
| 
       132 
132 
     | 
    
         
             
                  it "doesn't replace it with a randomly-generated idempotency key" do
         
     | 
| 
       133 
     | 
    
         
            -
                    stub = stub_request(:post, /.*api.example.com\/customers/)
         
     | 
| 
       134 
     | 
    
         
            -
                            
     | 
| 
      
 133 
     | 
    
         
            +
                    stub = stub_request(:post, /.*api.example.com\/customers/).
         
     | 
| 
      
 134 
     | 
    
         
            +
                           with(
         
     | 
| 
       135 
135 
     | 
    
         
             
                             body: { given_name: 'Jack', family_name: 'Franklin' },
         
     | 
| 
       136 
136 
     | 
    
         
             
                             headers: { 'Idempotency-Key' => 'my-custom-idempotency-key' }
         
     | 
| 
       137 
     | 
    
         
            -
                           )
         
     | 
| 
       138 
     | 
    
         
            -
                            
     | 
| 
      
 137 
     | 
    
         
            +
                           ).
         
     | 
| 
      
 138 
     | 
    
         
            +
                           to_return(default_response)
         
     | 
| 
       139 
139 
     | 
    
         | 
| 
       140 
140 
     | 
    
         
             
                    service.make_request(:post, '/customers', params: {
         
     | 
| 
       141 
141 
     | 
    
         
             
                                           given_name: 'Jack',
         
     | 
| 
       142 
     | 
    
         
            -
                                           family_name: 'Franklin'
         
     | 
| 
      
 142 
     | 
    
         
            +
                                           family_name: 'Franklin',
         
     | 
| 
       143 
143 
     | 
    
         
             
                                         },
         
     | 
| 
       144 
144 
     | 
    
         
             
                                                              headers: {
         
     | 
| 
       145 
     | 
    
         
            -
                                                                'Idempotency-Key' => 'my-custom-idempotency-key'
         
     | 
| 
      
 145 
     | 
    
         
            +
                                                                'Idempotency-Key' => 'my-custom-idempotency-key',
         
     | 
| 
       146 
146 
     | 
    
         
             
                                                              })
         
     | 
| 
       147 
147 
     | 
    
         
             
                    expect(stub).to have_been_requested
         
     | 
| 
       148 
148 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -151,25 +151,25 @@ describe GoCardlessPro::ApiService do 
     | 
|
| 
       151 
151 
     | 
    
         | 
| 
       152 
152 
     | 
    
         
             
              describe 'making a put request with some data' do
         
     | 
| 
       153 
153 
     | 
    
         
             
                it 'passes the data in as the request body' do
         
     | 
| 
       154 
     | 
    
         
            -
                  stub = stub_request(:put, /.*api.example.com\/customers\/CU123/)
         
     | 
| 
       155 
     | 
    
         
            -
                          
     | 
| 
       156 
     | 
    
         
            -
                          
     | 
| 
      
 154 
     | 
    
         
            +
                  stub = stub_request(:put, /.*api.example.com\/customers\/CU123/).
         
     | 
| 
      
 155 
     | 
    
         
            +
                         with(body: { given_name: 'Jack', family_name: 'Franklin' }).
         
     | 
| 
      
 156 
     | 
    
         
            +
                         to_return(default_response)
         
     | 
| 
       157 
157 
     | 
    
         | 
| 
       158 
158 
     | 
    
         
             
                  service.make_request(:put, '/customers/CU123', params: {
         
     | 
| 
       159 
159 
     | 
    
         
             
                                         given_name: 'Jack',
         
     | 
| 
       160 
     | 
    
         
            -
                                         family_name: 'Franklin'
         
     | 
| 
      
 160 
     | 
    
         
            +
                                         family_name: 'Franklin',
         
     | 
| 
       161 
161 
     | 
    
         
             
                                       })
         
     | 
| 
       162 
162 
     | 
    
         
             
                  expect(stub).to have_been_requested
         
     | 
| 
       163 
163 
     | 
    
         
             
                end
         
     | 
| 
       164 
164 
     | 
    
         | 
| 
       165 
165 
     | 
    
         
             
                it "doesn't include an idempotency key" do
         
     | 
| 
       166 
     | 
    
         
            -
                  stub = stub_request(:put, /.*api.example.com\/customers\/CU123/)
         
     | 
| 
       167 
     | 
    
         
            -
                          
     | 
| 
       168 
     | 
    
         
            -
                          
     | 
| 
      
 166 
     | 
    
         
            +
                  stub = stub_request(:put, /.*api.example.com\/customers\/CU123/).
         
     | 
| 
      
 167 
     | 
    
         
            +
                         with { |request| !request.headers.key?('Idempotency-Key') }.
         
     | 
| 
      
 168 
     | 
    
         
            +
                         to_return(default_response)
         
     | 
| 
       169 
169 
     | 
    
         | 
| 
       170 
170 
     | 
    
         
             
                  service.make_request(:put, '/customers/CU123', params: {
         
     | 
| 
       171 
171 
     | 
    
         
             
                                         given_name: 'Jack',
         
     | 
| 
       172 
     | 
    
         
            -
                                         family_name: 'Franklin'
         
     | 
| 
      
 172 
     | 
    
         
            +
                                         family_name: 'Franklin',
         
     | 
| 
       173 
173 
     | 
    
         
             
                                       })
         
     | 
| 
       174 
174 
     | 
    
         
             
                  expect(stub).to have_been_requested
         
     | 
| 
       175 
175 
     | 
    
         
             
                end
         
     |