gecko-ruby 0.8.0 → 0.9.0

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: eb9de08507d0105e06a6d879856fa389834a6854e27947f24ed4ffd9fb84a64e
4
- data.tar.gz: f869506161aa22431c4eed00e71b326678a45d612e4d15754bfaba831b954784
3
+ metadata.gz: b82efcf479bde2b049bfd09f55185e8c4c5fd29377ca35a8865dc2816c6cba0c
4
+ data.tar.gz: 838ba153b885dcbca0accf42143733b4e9d79478bcd1d26d57001c3cfda9f4ca
5
5
  SHA512:
6
- metadata.gz: 2b6eef606da5df282eba8fa943a73a6460d3a5a51cbd824158a6b76bdcef7cc2d817124735839b4ca0af866df6cb1075d348016c626a700767bd7445c4b6733a
7
- data.tar.gz: 901d13594b029897e6de3033fa0f153b7ba9d1f0654fa233f5ec5580b9499a0f33c29680a21d4e90a2af30902ba77db12c652f7b74bda58ef3629db0e19a08ad
6
+ metadata.gz: 607951bf8f6958c8b11814dcaa5c9f8d3d24517dcf0ae2f34e2b443358abdf1f27354a53f227baba505a1bfebae42891519b17cdadecde23c5fd696d0a9ff087
7
+ data.tar.gz: da203fe38e4d22f35de38d56217489338a5319de2f6cdd82fb8a67d9533a5f97969e2397010323f53598c19203c0e63b422211cf2b296d2db4ca67877ab9d7ee
@@ -1,6 +1,12 @@
1
+ ## 0.9.0 (2019-07-24)
2
+ - Added an optional `ActiveSupport::LogSubscriber` class for easy logging,
3
+ can be enabled via `Gecko.enable_logging`.
4
+ - Added an optional compatibility shim for the Liquid templating language,
5
+ can be enabled via `Gecko.install_liquid_shim`.
6
+
1
7
  ## 0.8.0 (2019-07-01)
2
- - Add `discount_amount` attribute and `discounted_price` helper to `OrderLineItem`'s
3
- - Drop support for Ruby 2.3
8
+ - Add `discount_amount` attribute and `discounted_price` helper to `OrderLineItem`'s.
9
+ - Drop support for EOL Ruby 2.3 as well.
4
10
 
5
11
  ## 0.7.1 (2019-03-19)
6
12
  - Add `Gecko::Record::Note` model.
@@ -8,7 +14,7 @@
8
14
 
9
15
  ## 0.7.0 (2019-02-19)
10
16
  - Add new `country_code` attribute to Address model.
11
- - Stop testing on Ruby 2.1 and 2.2
17
+ - Stop testing on Ruby 2.1 and 2.2.
12
18
 
13
19
  ## 0.6.0 (2018-11-13)
14
20
  - Add `Gecko::Record::Webhook` model.
@@ -26,51 +32,51 @@
26
32
  - Add minimum `oauth2` gem dependency
27
33
 
28
34
  ## 0.2.5 (2018-01-15)
29
- - Add `User#account_name`
35
+ - Add `User#account_name`.
30
36
 
31
37
  ## 0.2.4 (2017-08-28)
32
- - Add `Company#tags`
38
+ - Add `Company#tags`.
33
39
 
34
40
  ## 0.2.3 (2017-08-14)
35
- - Add support for API idempotency `@client.Record.save(idempotency_key: 'ABCDEF123456')`
36
- - Marked a couple of fields as readonly that weren't correctly marked so
41
+ - Add support for API idempotency `@client.Record.save(idempotency_key: 'ABCDEF123456')`.
42
+ - Marked a couple of fields as readonly that weren't correctly marked so.
37
43
 
38
44
  ## 0.2.2 (2016-06-06)
39
- - Add `@client.Record.peek_all` to return all items currently in identity map
45
+ - Add `@client.Record.peek_all` to return all items currently in identity map.
40
46
 
41
47
  ## 0.2.1 (2016-06-06) (Yanked)
42
48
  ## 0.2.0 (2016-06-06)
43
- - Support `writeable_on :create` for attributes
44
- - Allow passing query parameters to `Adapter#count`
45
- - Add `@client.Record.first` and `@client.Record.forty_two` as helpers
46
- - Store the last API response at `@client.Record.last_response`
47
- - Make sure to set Content-Type to `application/json`
48
- - Clean up some deprecated fields leading up to API release (See [https://developer.tradegecko.com](https://developer.tradegecko.com) for up-to-date attribute list)
49
+ - Support `writeable_on :create` for attributes.
50
+ - Allow passing query parameters to `Adapter#count`.
51
+ - Add `@client.Record.first` and `@client.Record.forty_two` as helpers.
52
+ - Store the last API response at `@client.Record.last_response`.
53
+ - Make sure to set Content-Type to `application/json`.
54
+ - Clean up some deprecated fields leading up to API release (See [https://developer.tradegecko.com](https://developer.tradegecko.com) for up-to-date attribute list).
49
55
 
50
56
  ## 0.1.0 (2015-11-25)
51
- - Move default headers to the adapter base class to make it easier to merge them when overriding
52
- - Clean up old attributes
57
+ - Move default headers to the adapter base class to make it easier to merge them when overriding.
58
+ - Clean up old attributes.
53
59
 
54
60
  ## 0.0.10 (2015-10-21)
55
- - Add `first_name`/`last_name` to addresses
61
+ - Add `first_name`/`last_name` to addresses.
56
62
 
57
63
  ## 0.0.9 (2015-10-02)
58
- - Add tags to order
64
+ - Add tags to order.
59
65
 
60
66
  ## 0.0.8 (2015-09-10)
61
- - Fetch `VariantLocation#committed_stock` as committed
62
- - Make image uploading work
67
+ - Fetch `VariantLocation#committed_stock` as committed.
68
+ - Make image uploading work.
63
69
 
64
70
  ## 0.0.7 (2015-03-17)
65
- - Fix issue with `Order#tax_override`
66
- - Support sideloaded records without a hack
71
+ - Fix issue with `Order#tax_override`.
72
+ - Support sideloaded records without a hack.
67
73
 
68
74
  ## 0.0.6 (2015-03-17)
69
- - Add `Gecko::Record::PaymentTerm`
75
+ - Add `Gecko::Record::PaymentTerm`.
70
76
 
71
77
  ## 0.0.5 (2015-03-04)
72
- - Add size to base adapter
73
- - Update serialization_helper to support serializing arrays correctly
78
+ - Add `size` to base adapter.
79
+ - Update serialization_helper to support serializing arrays correctly.
74
80
 
75
81
  ## 0.0.4 (2015-01-09)
76
82
  - Renamed gem so we can publish it on RubyGems.org
data/README.md CHANGED
@@ -189,6 +189,9 @@ ActiveSupport::Notifications.subscribe('request.gecko') do |name, start, finish,
189
189
  end
190
190
  ```
191
191
 
192
+ The gem comes with a default `LogSubscriber` that outputs API requests in an ActiveRecord style.
193
+ This is disabled by default and can be included by calling `Gecko.enable_logging`.
194
+
192
195
  ## Checking API limits
193
196
 
194
197
  The Gecko gem stores a copy of the last API response per adapter.
@@ -204,6 +207,10 @@ client.Product.last_response.headers['X-Rate-Limit-Reset']
204
207
  #=> '1412079600'
205
208
  ```
206
209
 
210
+ ## Liquid Compatibility
211
+ A compatibility shim for the Liquid templating language is distributed, but not loaded by default.
212
+ This can be enabled via `Gecko.install_liquid_shim`
213
+
207
214
  ## TODO
208
215
  - Deleting records
209
216
  - Complete record collection
@@ -32,3 +32,13 @@ require 'gecko/record/purchase_order_line_item'
32
32
  require 'gecko/record/tax_type'
33
33
  require 'gecko/record/payment_term'
34
34
  require 'gecko/record/webhook'
35
+
36
+ module Gecko
37
+ def self.enable_logging
38
+ require 'gecko/ext/log_subscriber'
39
+ end
40
+
41
+ def self.install_liquid_shim
42
+ require 'gecko/ext/liquid_compat'
43
+ end
44
+ end
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Including this file enhances every Gecko::Record object to support the Liquid::Drop API.
4
+ #
5
+ # @example
6
+ # template = Liquid::Template.parse("{{variant.sku}}")
7
+ # rendered = template.render('variant' => client.Variant.find(123))
8
+ module Gecko
9
+ # Monkey-patches the base record class with a `to_liquid` method
10
+ module LiquidCompatibility
11
+ # The Liquid templating library automatically uses a `to_liquid` method if found.
12
+ def to_liquid
13
+ liquid_decorator.new(self)
14
+ end
15
+
16
+ private
17
+
18
+ # If you'd like to add custom behviour per-record-type,
19
+ # override this method and return a subclass.
20
+ #
21
+ # @example
22
+ #
23
+ # module MyLiquidCompat
24
+ # def liquid_decorator
25
+ # "#{self.class.demodulized_name}Decorator".safe_constantize || BaseDecorator
26
+ # end
27
+ # end
28
+ #
29
+ # Gecko::Record::Base.include(MyLiquidCompat)
30
+ def liquid_decorator
31
+ Gecko::BaseDecorator
32
+ end
33
+ end
34
+
35
+ Gecko::Record::Base.include(LiquidCompatibility)
36
+ Gecko::Helpers::CollectionProxy.delegate(:to_liquid, to: :@target)
37
+
38
+ class BaseDecorator < Liquid::Drop
39
+ def initialize(delegate)
40
+ raise 'Turtles all the way down' if delegate.is_a?(BaseDecorator)
41
+
42
+ @delegate = delegate
43
+ end
44
+
45
+ def method_missing(method_name, *args, &block)
46
+ if @delegate.respond_to?(method_name)
47
+ @delegate.public_send(method_name, *args, &block)
48
+ else
49
+ super
50
+ end
51
+ end
52
+
53
+ def respond_to_missing?(method_name, include_private = false)
54
+ @delegate.respond_to?(method_name) || super
55
+ end
56
+
57
+ ## Override Liquid::Drop#invoke_drop to also check method arity
58
+ def invoke_drop(method_or_key)
59
+ if self.invokable_methods.include?(method_or_key.to_s) && self.method_arity(method_or_key.to_sym) <= 0
60
+ self.public_send(method_or_key)
61
+ end
62
+ end
63
+
64
+ ## Override Liquid::Drop#invokable_methods to add extra checks
65
+ def invokable_methods
66
+ @invokable_methods ||= begin
67
+ blacklist = Gecko::Record::Base.public_instance_methods + Liquid::Drop.public_instance_methods
68
+ blacklist -= [:to_liquid, :id, :created_at, :updated_at]
69
+ whitelist = self.public_methods + @delegate.public_methods
70
+ available_methods = (whitelist - blacklist).map(&:to_s)
71
+ available_methods.reject! { |method_name| method_name.ends_with?("=") }
72
+ Set.new(available_methods)
73
+ end
74
+ end
75
+
76
+ protected
77
+
78
+ def method_arity(method_name)
79
+ if self.methods.include?(method_name)
80
+ self.method(method_name).arity
81
+ else
82
+ @delegate.method(method_name).arity
83
+ end
84
+ end
85
+
86
+ def client
87
+ @delegate.instance_variable_get(:@client)
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'request_store'
4
+
5
+ # Requiring this file, or calling `Gecko.enable_logging` will hook into the provided
6
+ # ActiveSupport::Notification hooks on requests and log ActiveRecord-style messages
7
+ # on API requests.
8
+ class GeckoLogSubscriber < ActiveSupport::LogSubscriber
9
+ ENV_KEY = :"gecko-logger"
10
+
11
+ def initialize
12
+ super
13
+ @odd = false
14
+ end
15
+
16
+ def request(event)
17
+ RequestStore.store[ENV_KEY] = []
18
+ payload = event.payload
19
+
20
+ request_path = payload[:request_path]
21
+
22
+ if payload[:params] && payload[:verb] == :get
23
+ request_path = request_path + "?" + payload[:params].to_param
24
+ RequestStore.store[ENV_KEY] << request_path
25
+ end
26
+
27
+ name = "#{payload[:model_class]} Load (#{event.duration.round(1)}ms)"
28
+ query = "#{payload[:verb].to_s.upcase} /#{request_path}"
29
+
30
+ if odd?
31
+ name = color(name, CYAN, true)
32
+ else
33
+ name = color(name, MAGENTA, true)
34
+ end
35
+
36
+ query = color(query, nil, true)
37
+
38
+ debug(" #{name} #{query}")
39
+ end
40
+
41
+ def odd?
42
+ @odd = !@odd
43
+ end
44
+ end
45
+
46
+ GeckoLogSubscriber.attach_to :gecko
@@ -1,3 +1,3 @@
1
1
  module Gecko
2
- VERSION = '0.8.0'
2
+ VERSION = '0.9.0'
3
3
  end
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.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bradley Priest
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-01 00:00:00.000000000 Z
11
+ date: 2019-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -214,6 +214,8 @@ files:
214
214
  - lib/gecko-ruby.rb
215
215
  - lib/gecko.rb
216
216
  - lib/gecko/client.rb
217
+ - lib/gecko/ext/liquid_compat.rb
218
+ - lib/gecko/ext/log_subscriber.rb
217
219
  - lib/gecko/helpers/association_helper.rb
218
220
  - lib/gecko/helpers/inspection_helper.rb
219
221
  - lib/gecko/helpers/record_helper.rb