gecko-ruby 0.11.0 → 0.12.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 57ccb059212f755e0b5199cb01f8b32bc190e3b614ce0fcc8c0f1313363a91bb
4
- data.tar.gz: 59271e89c7f7ac7217d53f6a44cbb1b6b453ce7d03602b2540490edc67f0abf5
3
+ metadata.gz: 4c83ec642703ff89b134c3f724eaf7552cba11b4c836417842403462a126c431
4
+ data.tar.gz: 4848a524d27dc714d78d182f9344ef8e97f8acd9fb9d7067ef520bd1c2a6f36e
5
5
  SHA512:
6
- metadata.gz: 0ecc3d0449defcebc48edc48780eeeb9419ca8cc02b7f0b28223725f3722940d1c68fe7280d8c70b4b5ef4ac14f6d0d387ef56c465824f2cc6e03ffc8c7a75f8
7
- data.tar.gz: 7e8a8f9e96f966c23bc66f7577ae735f0144553bf3011e40784cafd7ce9b4def6b64bb61cfb87b64f8a6cadd1789344268ff66d224c559ee5c9bb55950f0da7f
6
+ metadata.gz: 0d56c4816c3972f9b38a0f36a6466b62ca545454b2df3dd1fc9011a772ca1b07046feaf1f76c24d81793b6201ae9cbfb31d74ba2241373a326cf8dff10596666
7
+ data.tar.gz: b5f13eee91dd43cc7d415753cce8a01a1ee63f134cb78af03ce12b85e42f2aa2eb717edd437b3298802a71192c1b7e193f17a9257716ec5071551ffdc3cf5809
@@ -12,7 +12,7 @@ jobs:
12
12
  name: Ruby ${{ matrix.ruby }}
13
13
  steps:
14
14
  - uses: actions/checkout@v2
15
- - uses: actions/setup-ruby@v1
15
+ - uses: ruby/setup-ruby@v1
16
16
  with:
17
17
  ruby-version: ${{ matrix.ruby }}
18
18
  - name: Run Tests
data/CHANGELOG.md CHANGED
@@ -1,3 +1,18 @@
1
+ ## 0.12.2 (2020-08-12)
2
+ - Change authorize url to commerce.intuit.com
3
+ - Add `payment_due_at` to `Gecko::Record::PurchaseOrder`
4
+
5
+ ## 0.12.1 (2020-07-20)
6
+ - Add `Gecko::Record::PaymentMethod` model.
7
+
8
+ ## 0.12.0 (2020-07-09)
9
+ - Silence warnings in Ruby 2.7
10
+ - Ensure response is passed to `ActiveSupport::Notifications` on error
11
+ - Ensure `adapter.last_response` is set on error response
12
+
13
+ ## 0.11.1 (2020-04-30)
14
+ - Fix addresses on Invoice
15
+
1
16
  ## 0.11.0 (2020-04-29)
2
17
  - Store create/update responses under `adapter.last_response` as well.
3
18
 
@@ -11,7 +26,7 @@
11
26
  ## 0.9.0 (2019-07-24)
12
27
  - Added an optional `ActiveSupport::LogSubscriber` class for easy logging,
13
28
  can be enabled via `Gecko.enable_logging`.
14
- - Added an optional compatibility shim for the Liquid templating language,
29
+ - Added an optional compatibility shim for the Liquid templating language,
15
30
  can be enabled via `Gecko.install_liquid_shim`.
16
31
 
17
32
  ## 0.8.0 (2019-07-01)
data/lib/gecko.rb CHANGED
@@ -32,6 +32,7 @@ require 'gecko/record/user'
32
32
  require 'gecko/record/purchase_order'
33
33
  require 'gecko/record/purchase_order_line_item'
34
34
  require 'gecko/record/tax_type'
35
+ require 'gecko/record/payment_method'
35
36
  require 'gecko/record/payment_term'
36
37
  require 'gecko/record/webhook'
37
38
 
data/lib/gecko/client.rb CHANGED
@@ -33,6 +33,7 @@ module Gecko
33
33
  record :PurchaseOrder
34
34
  record :PurchaseOrderLineItem
35
35
  record :TaxType
36
+ record :PaymentMethod
36
37
  record :PaymentTerm
37
38
  record :Webhook
38
39
 
@@ -126,7 +127,7 @@ module Gecko
126
127
  def setup_oauth_client(client_id, client_secret, options)
127
128
  defaults = {
128
129
  site: 'https://api.tradegecko.com',
129
- authorize_url: 'https://go.tradegecko.com/oauth/authorize',
130
+ authorize_url: 'https://commerce.intuit.com/oauth/authorize',
130
131
  connection_opts: {
131
132
  headers: self.class.default_headers
132
133
  }
@@ -72,7 +72,7 @@ module Gecko
72
72
  []
73
73
  end
74
74
 
75
- build_collection_proxy(collection, {
75
+ build_collection_proxy(collection, **{
76
76
  embedded: options[:embedded],
77
77
  class_name: class_name,
78
78
  association_name: association_name
@@ -100,7 +100,7 @@ module Gecko
100
100
  #
101
101
  # @api private
102
102
  def build_collection_proxy(target, association_name:, class_name:, embedded:)
103
- CollectionProxy.new({
103
+ CollectionProxy.new(**{
104
104
  parent: self,
105
105
  target: target,
106
106
  embedded: embedded,
@@ -11,6 +11,7 @@ module Gecko
11
11
  belongs_to :primary_location, class_name: "Location"
12
12
  belongs_to :primary_billing_location, class_name: "Location"
13
13
  belongs_to :default_currency, class_name: "Currency"
14
+ belongs_to :default_payment_method, class_name: "PaymentMethod"
14
15
  belongs_to :default_payment_term, class_name: "PaymentTerm"
15
16
  belongs_to :billing_contact, class_name: "User"
16
17
  belongs_to :default_sales_order_tax_type, class_name: "TaxType"
@@ -111,7 +111,7 @@ module Gecko
111
111
  #
112
112
  # @api public
113
113
  def where(params = {})
114
- response = @last_response = request(:get, plural_path, params: params)
114
+ response = request(:get, plural_path, params: params)
115
115
  parsed_response = response.parsed
116
116
  set_pagination(response.headers)
117
117
  parse_records(parsed_response)
@@ -203,7 +203,7 @@ module Gecko
203
203
  # @api private
204
204
  def fetch(id) # rubocop:disable Metrics/MethodLength
205
205
  verify_id_presence!(id)
206
- response = @last_response = request(:get, plural_path + '/' + id.to_s)
206
+ response = request(:get, plural_path + '/' + id.to_s)
207
207
  record_json = extract_record(response.parsed)
208
208
  instantiate_and_register_record(record_json)
209
209
  rescue OAuth2::Error => e
@@ -343,7 +343,7 @@ module Gecko
343
343
  #
344
344
  # @api private
345
345
  def create_record(record, opts = {})
346
- response = @last_response = request(:post, plural_path, {
346
+ response = request(:post, plural_path, {
347
347
  body: record.as_json,
348
348
  raise_errors: false
349
349
  }.merge(headers: headers_from_opts(opts)))
@@ -356,7 +356,7 @@ module Gecko
356
356
  #
357
357
  # @api private
358
358
  def update_record(record, opts = {})
359
- response = @last_response = request(:put, plural_path + "/" + record.id.to_s, {
359
+ response = request(:put, plural_path + "/" + record.id.to_s, {
360
360
  body: record.as_json,
361
361
  raise_errors: false
362
362
  }.merge(headers: headers_from_opts(opts)))
@@ -431,18 +431,24 @@ module Gecko
431
431
  # @return [OAuth2::Response]
432
432
  #
433
433
  # @api private
434
- def request(verb, path, options = {}) # rubocop:disable Metrics/MethodLength
434
+ def request(verb, path, options = {}) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
435
435
  ActiveSupport::Notifications.instrument('request.gecko') do |payload|
436
436
  payload[:verb] = verb
437
437
  payload[:params] = options[:params]
438
438
  payload[:body] = options[:body]
439
439
  payload[:model_class] = model_class
440
440
  payload[:request_path] = path
441
+
441
442
  options[:headers] = options.fetch(:headers, {}).tap do |headers|
442
443
  headers['Content-Type'] = 'application/json'
443
444
  end
444
- options[:body] = options[:body].to_json if options[:body]
445
- payload[:response] = @client.access_token.request(verb, path, options)
445
+
446
+ options[:body] = options[:body].to_json if options[:body]
447
+
448
+ @client.access_token.request(verb, path, options.merge(raise_errors: false)).tap do |response|
449
+ payload[:response] = @last_response = response
450
+ raise response.error if response.error && options[:raise_errors] != false
451
+ end
446
452
  end
447
453
  end
448
454
 
@@ -7,6 +7,7 @@ module Gecko
7
7
  class Company < Base
8
8
  belongs_to :assignee, class_name: "User"
9
9
  belongs_to :default_tax_type, class_name: "TaxType"
10
+ belongs_to :default_payment_method, class_name: "PaymentMethod"
10
11
  belongs_to :default_payment_term, class_name: "PaymentTerm"
11
12
  belongs_to :default_stock_location, class_name: "Location"
12
13
  # belongs_to :default_price_list, class_name: "PriceList"
@@ -6,8 +6,8 @@ module Gecko
6
6
  module Record
7
7
  class Invoice < Base
8
8
  belongs_to :order, writeable_on: :create
9
- belongs_to :shipping_address
10
- belongs_to :billing_address
9
+ belongs_to :shipping_address, class_name: 'Address'
10
+ belongs_to :billing_address, class_name: 'Address'
11
11
  belongs_to :payment_term
12
12
  belongs_to :company, readonly: true
13
13
  belongs_to :currency, readonly: true
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'gecko/record/base'
4
+
5
+ module Gecko
6
+ module Record
7
+ class PaymentMethod < Base
8
+ attribute :name, String
9
+ attribute :is_default, Boolean, readonly: true
10
+ end
11
+
12
+ class PaymentMethodAdapter < BaseAdapter
13
+ end
14
+ end
15
+ end
@@ -20,7 +20,9 @@ module Gecko
20
20
  attribute :order_number, String
21
21
  attribute :reference_number, String
22
22
  attribute :email, String
23
+
23
24
  attribute :due_at, Date
25
+ attribute :payment_due_at, Date
24
26
  attribute :received_at, Date
25
27
 
26
28
  attribute :status, String
@@ -34,9 +36,6 @@ module Gecko
34
36
  attribute :cached_quantity, BigDecimal, readonly: true
35
37
 
36
38
  attribute :tags, Array[String]
37
-
38
- # DEPRECATED
39
- # attribute :cached_total, BigDecimal, readonly: true
40
39
  end
41
40
 
42
41
  class PurchaseOrderAdapter < BaseAdapter
data/lib/gecko/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Gecko
4
- VERSION = '0.11.0'
4
+ VERSION = '0.12.2'
5
5
  end
@@ -0,0 +1,69 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://api.lvh.me:3000/payment_methods?limit=5
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Gecko/0.12.0 OAuth2/1.4.1 Faraday/0.15.4 Ruby/2.5.7
12
+ Content-Type:
13
+ - application/json
14
+ Authorization:
15
+ - Bearer <__ACCESS_TOKEN__>
16
+ Accept-Encoding:
17
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
18
+ Accept:
19
+ - "*/*"
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: OK
24
+ headers:
25
+ X-Frame-Options:
26
+ - SAMEORIGIN
27
+ X-Xss-Protection:
28
+ - 1; mode=block
29
+ X-Content-Type-Options:
30
+ - nosniff
31
+ X-Download-Options:
32
+ - noopen
33
+ X-Permitted-Cross-Domain-Policies:
34
+ - none
35
+ Referrer-Policy:
36
+ - strict-origin-when-cross-origin
37
+ X-Rate-Limit-Limit:
38
+ - '300'
39
+ X-Rate-Limit-Remaining:
40
+ - '299'
41
+ X-Rate-Limit-Reset:
42
+ - '1594871400'
43
+ Cache-Control:
44
+ - no-cache, no-store
45
+ X-Pagination:
46
+ - '{"total_records":11,"total_pages":3,"first_page":true,"last_page":false,"out_of_bounds":false,"offset":0}'
47
+ Link:
48
+ - <http://api.lvh.me:3000/ajax/payment_methods?limit=5&page=2>; rel="next",
49
+ <http://api.lvh.me:3000/ajax/payment_methods?limit=5&page=3>; rel="last"
50
+ Content-Type:
51
+ - application/json; charset=utf-8
52
+ Etag:
53
+ - W/"7462907dae56049f84e55abca4a15c5e"
54
+ X-Request-Id:
55
+ - ac553ee8-d518-404c-bd7b-215a168d164c
56
+ X-Runtime:
57
+ - '0.108324'
58
+ Connection:
59
+ - close
60
+ Server:
61
+ - thin
62
+ body:
63
+ encoding: UTF-8
64
+ string: '{"payment_methods":[{"id":32,"created_at":"2020-07-16T03:46:03.946Z","updated_at":"2020-07-16T03:46:03.946Z","name":"PayNow","is_default":false},{"id":31,"created_at":"2020-07-16T03:45:50.096Z","updated_at":"2020-07-16T03:45:50.096Z","name":"Singtel
65
+ Dash","is_default":false},{"id":30,"created_at":"2020-07-16T03:45:36.276Z","updated_at":"2020-07-16T03:45:36.276Z","name":"eNets","is_default":false},{"id":29,"created_at":"2020-07-16T03:45:21.473Z","updated_at":"2020-07-16T03:45:21.473Z","name":"Voucher","is_default":false},{"id":28,"created_at":"2020-07-16T03:45:15.160Z","updated_at":"2020-07-16T03:45:15.160Z","name":"Credit
66
+ Note","is_default":false}]}'
67
+ http_version: null
68
+ recorded_at: Thu, 16 Jul 2020 03:48:15 GMT
69
+ recorded_with: VCR 5.1.0
@@ -0,0 +1,66 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://api.lvh.me:3000/payment_methods?limit=0
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Gecko/0.12.0 OAuth2/1.4.1 Faraday/0.15.4 Ruby/2.5.7
12
+ Content-Type:
13
+ - application/json
14
+ Authorization:
15
+ - Bearer <__ACCESS_TOKEN__>
16
+ Accept-Encoding:
17
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
18
+ Accept:
19
+ - "*/*"
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: OK
24
+ headers:
25
+ X-Frame-Options:
26
+ - SAMEORIGIN
27
+ X-Xss-Protection:
28
+ - 1; mode=block
29
+ X-Content-Type-Options:
30
+ - nosniff
31
+ X-Download-Options:
32
+ - noopen
33
+ X-Permitted-Cross-Domain-Policies:
34
+ - none
35
+ Referrer-Policy:
36
+ - strict-origin-when-cross-origin
37
+ X-Rate-Limit-Limit:
38
+ - '300'
39
+ X-Rate-Limit-Remaining:
40
+ - '299'
41
+ X-Rate-Limit-Reset:
42
+ - '1594871400'
43
+ Cache-Control:
44
+ - no-cache, no-store
45
+ X-Pagination:
46
+ - '{"total_records":11,"total_pages":1,"first_page":true,"last_page":true,"out_of_bounds":false,"offset":0}'
47
+ Link:
48
+ - <http://api.lvh.me:3000/ajax/payment_methods?limit=0&page=1>; rel="last"
49
+ Content-Type:
50
+ - application/json; charset=utf-8
51
+ Etag:
52
+ - W/"98c458ef2a733afd7d9fbf88e776e5c2"
53
+ X-Request-Id:
54
+ - 89f1b27c-35d7-4b3c-a356-d87c0a1d4cc1
55
+ X-Runtime:
56
+ - '0.160860'
57
+ Connection:
58
+ - close
59
+ Server:
60
+ - thin
61
+ body:
62
+ encoding: UTF-8
63
+ string: '{"payment_methods":[]}'
64
+ http_version: null
65
+ recorded_at: Thu, 16 Jul 2020 03:48:14 GMT
66
+ recorded_with: VCR 5.1.0
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ class Gecko::Record::PaymentMethodAdapterTest < Minitest::Test
6
+ include TestingAdapter
7
+ include SharedAdapterExamples
8
+
9
+ let(:adapter) { @client.PaymentMethod }
10
+ let(:plural_name) { "payment_methods" }
11
+ let(:record_class) { Gecko::Record::PaymentMethod }
12
+
13
+ def test_initializes_adapter
14
+ assert_instance_of(Gecko::Record::PaymentMethodAdapter, @client.PaymentMethod)
15
+ end
16
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ class Gecko::PaymentMethodTest < Minitest::Test
6
+ include VCRHelper
7
+ include SharedRecordExamples
8
+
9
+ let(:plural_name) { "payment_methods" }
10
+ let(:record_class) { Gecko::Record::PaymentMethod }
11
+
12
+ def setup
13
+ @json = load_vcr_hash("payment_methods", "payment_methods").first
14
+ @record = record_class.new(client, @json)
15
+ end
16
+
17
+ def test_initializes_record
18
+ assert_instance_of(Gecko::Record::PaymentMethod, @record)
19
+ end
20
+ end
@@ -147,7 +147,7 @@ module SharedAdapterExamples # rubocop:disable Metrics/ModuleLength
147
147
  def test_saving_record_with_idempotency_key # rubocop:disable Metrics/MethodLength
148
148
  record = adapter.build
149
149
  mock_token = mock
150
- mock_response = mock(status: 200, parsed: { plural_name.singularize => { id: 123 } })
150
+ mock_response = mock(status: 200, parsed: { plural_name.singularize => { id: 123 } }, error: nil)
151
151
  mock_token.expects(:request)
152
152
  .with(:post, plural_name, {
153
153
  body: record.as_json.to_json,
@@ -165,7 +165,7 @@ private
165
165
 
166
166
  def mock_api_request(record, request, response)
167
167
  mock_token = mock
168
- mock_response = mock(status: response[0], parsed: response[1])
168
+ mock_response = mock(status: response[0], parsed: response[1], error: nil)
169
169
  mock_token.expects(:request)
170
170
  .with(request[0], request[1], {
171
171
  body: record.as_json.to_json,
data/test/test_helper.rb CHANGED
@@ -15,9 +15,19 @@ require 'support/shared_sideloaded_data_parsing_examples'
15
15
  require 'support/testing_adapter'
16
16
  require 'support/vcr_support'
17
17
 
18
+ ENV_SECRETS = %w[
19
+ OAUTH_ID
20
+ OAUTH_SECRET
21
+ ACCESS_TOKEN
22
+ REFRESH_TOKEN
23
+ ].freeze
24
+
18
25
  VCR.configure do |c|
19
26
  c.cassette_library_dir = 'test/fixtures/vcr_cassettes'
20
27
  c.hook_into :webmock
28
+ ENV_SECRETS.each do |variable|
29
+ c.filter_sensitive_data("<__#{variable}__>") { ENV[variable] }
30
+ end
21
31
  end
22
32
 
23
33
  class Minitest::Test
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gecko-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.12.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bradley Priest
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-29 00:00:00.000000000 Z
11
+ date: 2021-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -239,6 +239,7 @@ files:
239
239
  - lib/gecko/record/note.rb
240
240
  - lib/gecko/record/order.rb
241
241
  - lib/gecko/record/order_line_item.rb
242
+ - lib/gecko/record/payment_method.rb
242
243
  - lib/gecko/record/payment_term.rb
243
244
  - lib/gecko/record/product.rb
244
245
  - lib/gecko/record/purchase_order.rb
@@ -275,6 +276,8 @@ files:
275
276
  - test/fixtures/vcr_cassettes/order_line_items_specific_count.yml
276
277
  - test/fixtures/vcr_cassettes/orders.yml
277
278
  - test/fixtures/vcr_cassettes/orders_count.yml
279
+ - test/fixtures/vcr_cassettes/payment_methods.yml
280
+ - test/fixtures/vcr_cassettes/payment_methods_count.yml
278
281
  - test/fixtures/vcr_cassettes/payment_terms.yml
279
282
  - test/fixtures/vcr_cassettes/payment_terms_count.yml
280
283
  - test/fixtures/vcr_cassettes/products.yml
@@ -325,6 +328,8 @@ files:
325
328
  - test/record/order_line_item_adapter_test.rb
326
329
  - test/record/order_line_item_test.rb
327
330
  - test/record/order_test.rb
331
+ - test/record/payment_method_adapter_test.rb
332
+ - test/record/payment_method_test.rb
328
333
  - test/record/payment_term_adapter_test.rb
329
334
  - test/record/payment_term_test.rb
330
335
  - test/record/product_adapter_test.rb
@@ -366,7 +371,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
366
371
  - !ruby/object:Gem::Version
367
372
  version: '0'
368
373
  requirements: []
369
- rubygems_version: 3.1.2
374
+ rubygems_version: 3.2.25
370
375
  signing_key:
371
376
  specification_version: 4
372
377
  summary: A Ruby interface to the TradeGecko API.
@@ -398,6 +403,8 @@ test_files:
398
403
  - test/fixtures/vcr_cassettes/order_line_items_specific_count.yml
399
404
  - test/fixtures/vcr_cassettes/orders.yml
400
405
  - test/fixtures/vcr_cassettes/orders_count.yml
406
+ - test/fixtures/vcr_cassettes/payment_methods.yml
407
+ - test/fixtures/vcr_cassettes/payment_methods_count.yml
401
408
  - test/fixtures/vcr_cassettes/payment_terms.yml
402
409
  - test/fixtures/vcr_cassettes/payment_terms_count.yml
403
410
  - test/fixtures/vcr_cassettes/products.yml
@@ -448,6 +455,8 @@ test_files:
448
455
  - test/record/order_line_item_adapter_test.rb
449
456
  - test/record/order_line_item_test.rb
450
457
  - test/record/order_test.rb
458
+ - test/record/payment_method_adapter_test.rb
459
+ - test/record/payment_method_test.rb
451
460
  - test/record/payment_term_adapter_test.rb
452
461
  - test/record/payment_term_test.rb
453
462
  - test/record/product_adapter_test.rb