gecko-ruby 0.1.0 → 0.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 +60 -7
- data/CHANGELOG.md +8 -0
- data/README.md +15 -0
- data/generate.thor +4 -2
- data/lib/gecko/helpers/serialization_helper.rb +19 -1
- data/lib/gecko/record/account.rb +1 -3
- data/lib/gecko/record/address.rb +1 -1
- data/lib/gecko/record/base_adapter.rb +44 -7
- data/lib/gecko/record/contact.rb +2 -2
- data/lib/gecko/record/fulfillment.rb +3 -2
- data/lib/gecko/record/fulfillment_line_item.rb +2 -2
- data/lib/gecko/record/invoice.rb +5 -3
- data/lib/gecko/record/invoice_line_item.rb +1 -1
- data/lib/gecko/record/location.rb +0 -1
- data/lib/gecko/record/order.rb +5 -1
- data/lib/gecko/record/order_line_item.rb +2 -2
- data/lib/gecko/record/product.rb +0 -2
- data/lib/gecko/record/purchase_order.rb +6 -2
- data/lib/gecko/record/purchase_order_line_item.rb +2 -2
- data/lib/gecko/record/tax_type.rb +1 -1
- data/lib/gecko/record/user.rb +0 -5
- data/lib/gecko/record/variant.rb +7 -2
- data/lib/gecko/version.rb +1 -1
- data/test/helpers/serialization_helper_test.rb +17 -0
- data/test/record/fulfillment_test.rb +1 -1
- data/test/support/shared_adapter_examples.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd4c6e56d2678d03d389be05ba3e141724089e76
|
4
|
+
data.tar.gz: b7395c6ceab56b95dc79db04cfb0891564fb1b7a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bea2e880324d48b95e68289b5a41c0a21c7a42f55c62db2ac4233c8a81f29dbae606b381aa597733722e3bbb3ca5eac5e320a84a4c2f2b90b85ebc10cc483d28
|
7
|
+
data.tar.gz: c9e4065f15a4b4b15e05b50984f6403e811ce86311d1342f0f0eb6b19c56bed3d1572736a9ec6d7d1de8ff9c9651461692f1265167e7cc499b4a6ea6f13cc65c
|
data/.rubocop.yml
CHANGED
@@ -1,13 +1,66 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
AllCops:
|
2
|
+
DisplayCopNames: true
|
3
|
+
|
4
|
+
# class Example
|
5
|
+
# ...
|
6
|
+
# private
|
7
|
+
# ...
|
8
|
+
# end
|
9
|
+
Style/AccessModifierIndentation:
|
3
10
|
EnforcedStyle: outdent
|
4
11
|
|
5
|
-
|
6
|
-
|
12
|
+
Style/Blocks:
|
13
|
+
Enabled: false
|
14
|
+
|
15
|
+
# Allows foo(bar: baz)
|
16
|
+
Style/BracesAroundHashParameters:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
Style/DotPosition:
|
20
|
+
EnforcedStyle: leading
|
21
|
+
|
22
|
+
Style/IndentHash:
|
23
|
+
EnforcedStyle: consistent
|
24
|
+
|
25
|
+
Style/LineLength:
|
26
|
+
Max: 120
|
27
|
+
|
28
|
+
Style/RedundantSelf:
|
29
|
+
Enabled: false
|
30
|
+
|
31
|
+
# We like neatly-aligned code
|
32
|
+
Style/SingleSpaceBeforeFirstArg:
|
33
|
+
Enabled: false
|
34
|
+
|
35
|
+
Style/SpaceAroundEqualsInParameterDefault:
|
36
|
+
Enabled: false
|
37
|
+
|
38
|
+
Style/SpaceInsideHashLiteralBraces:
|
39
|
+
Enabled: false
|
40
|
+
|
41
|
+
# Allow single or double quotes
|
42
|
+
Style/StringLiterals:
|
43
|
+
Enabled: false
|
7
44
|
|
8
|
-
|
45
|
+
# Disable this until we can work out how to allow aligning of assignments
|
46
|
+
# https://github.com/bbatsov/rubocop/blob/master/spec/rubocop/cop/style/extra_spacing_spec.rb#L23
|
47
|
+
Style/ExtraSpacing:
|
9
48
|
Enabled: false
|
10
49
|
|
11
|
-
|
12
|
-
ExtraSpacing:
|
50
|
+
Style/WordArray:
|
13
51
|
Enabled: false
|
52
|
+
|
53
|
+
Style/NumericLiterals:
|
54
|
+
Enabled: false
|
55
|
+
|
56
|
+
Style/SignalException:
|
57
|
+
Enabled: false
|
58
|
+
|
59
|
+
Metrics/ClassLength:
|
60
|
+
Enabled: false
|
61
|
+
|
62
|
+
Style/MultilineOperationIndentation:
|
63
|
+
Enabled: false
|
64
|
+
|
65
|
+
Style/ClassAndModuleChildren:
|
66
|
+
EnforcedStyle: compact
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
## 0.2.0 (2016-06-06)
|
2
|
+
- Support `writeable_on :create` for attributes
|
3
|
+
- Allow passing query parameters to `Adapter#count`
|
4
|
+
- Add `@client.Record.first` and `@client.Record.forty_two` as helpers
|
5
|
+
- Store the last API response at `@client.Record.last_response`
|
6
|
+
- Make sure to set Content-Type to `application/json`
|
7
|
+
- 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)
|
8
|
+
|
1
9
|
## 0.1.0 (2015-11-25)
|
2
10
|
- Move default headers to the adapter base class to make it easier to merge them when overriding
|
3
11
|
- Clean up old attributes
|
data/README.md
CHANGED
@@ -139,6 +139,21 @@ ActiveSupport::Notifications.subscribe('request.gecko') do |name, start, finish,
|
|
139
139
|
end
|
140
140
|
```
|
141
141
|
|
142
|
+
## Checking API limits
|
143
|
+
|
144
|
+
The Gecko gem stores a copy of the last API response per adapter.
|
145
|
+
You can use this to access headers such as cache controls or current API limit usages.
|
146
|
+
|
147
|
+
```ruby
|
148
|
+
client.Product.find(124)
|
149
|
+
client.Product.last_response.headers['X-Rate-Limit-Limit']
|
150
|
+
#=> '300'
|
151
|
+
client.Product.last_response.headers['X-Rate-Limit-Remaining']
|
152
|
+
#=> '290'
|
153
|
+
client.Product.last_response.headers['X-Rate-Limit-Reset']
|
154
|
+
#=> '1412079600'
|
155
|
+
```
|
156
|
+
|
142
157
|
## TODO
|
143
158
|
- Deleting records
|
144
159
|
- Complete record collection
|
data/generate.thor
CHANGED
@@ -59,7 +59,8 @@ class Gecko::#{@model_name}Test < Minitest::Test
|
|
59
59
|
def test_initializes_record
|
60
60
|
assert_instance_of(Gecko::Record::#{@model_name}, @record)
|
61
61
|
end
|
62
|
-
end
|
62
|
+
end
|
63
|
+
}
|
63
64
|
end
|
64
65
|
|
65
66
|
def test_adapter_template
|
@@ -76,6 +77,7 @@ class Gecko::Record::#{@model_name}AdapterTest < Minitest::Test
|
|
76
77
|
def test_initializes_adapter
|
77
78
|
assert_instance_of(Gecko::Record::#{@model_name}Adapter, @client.#{@model_name})
|
78
79
|
end
|
79
|
-
end
|
80
|
+
end
|
81
|
+
}
|
80
82
|
end
|
81
83
|
end
|
@@ -27,12 +27,30 @@ module Gecko
|
|
27
27
|
def serializable_hash
|
28
28
|
attribute_hash = {}
|
29
29
|
attribute_set.each do |attribute|
|
30
|
-
next
|
30
|
+
next unless writeable?(attribute)
|
31
31
|
serialize_attribute(attribute_hash, attribute)
|
32
32
|
end
|
33
33
|
attribute_hash
|
34
34
|
end
|
35
35
|
|
36
|
+
# Returns true if an attribute can be serialized
|
37
|
+
#
|
38
|
+
# @return [Boolean]
|
39
|
+
#
|
40
|
+
# @api private
|
41
|
+
def writeable?(attribute)
|
42
|
+
return if attribute.options[:readonly]
|
43
|
+
return true unless attribute.options[:writeable_on]
|
44
|
+
case attribute.options[:writeable_on]
|
45
|
+
when :update
|
46
|
+
persisted?
|
47
|
+
when :create
|
48
|
+
!persisted?
|
49
|
+
else
|
50
|
+
raise ArgumentError
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
36
54
|
# Store the serialized representation of a single attribute
|
37
55
|
#
|
38
56
|
# @param [Hash] attribute_hash Serialized record being iterated over
|
data/lib/gecko/record/account.rb
CHANGED
@@ -37,10 +37,8 @@ module Gecko
|
|
37
37
|
attribute :tax_label, String
|
38
38
|
attribute :tax_number_label, String
|
39
39
|
|
40
|
-
# attribute :stock_level_warn, String
|
41
|
-
|
42
40
|
## DEPRECATED
|
43
|
-
attribute :default_tax_rate, String
|
41
|
+
# attribute :default_tax_rate, String
|
44
42
|
# attribute :default_tax_type, String
|
45
43
|
end
|
46
44
|
|
data/lib/gecko/record/address.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Gecko
|
2
2
|
module Record
|
3
3
|
class BaseAdapter
|
4
|
-
attr_reader :client
|
4
|
+
attr_reader :client, :last_response
|
5
5
|
# Instantiates a new Record Adapter
|
6
6
|
#
|
7
7
|
# @param [Gecko::Client] client
|
@@ -84,10 +84,10 @@ module Gecko
|
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
87
|
-
#
|
87
|
+
# Fetch a record collection via the API. Parameters vary via Record Type
|
88
88
|
#
|
89
89
|
# @example Fetch via ID
|
90
|
-
# client.Product.where(ids: [1,2]
|
90
|
+
# client.Product.where(ids: [1,2])
|
91
91
|
#
|
92
92
|
# @example Fetch via date
|
93
93
|
# client.Product.where(updated_at_min: "2014-03-03T21:09:00")
|
@@ -109,22 +109,57 @@ module Gecko
|
|
109
109
|
#
|
110
110
|
# @api public
|
111
111
|
def where(params={})
|
112
|
-
response
|
112
|
+
response = @last_response = request(:get, plural_path, params: params)
|
113
113
|
parsed_response = response.parsed
|
114
114
|
set_pagination(response.headers)
|
115
115
|
parse_records(parsed_response)
|
116
116
|
end
|
117
117
|
|
118
|
+
# Fetch the first record for the given parameters
|
119
|
+
#
|
120
|
+
# @example Fetch via ID
|
121
|
+
# client.Product.first
|
122
|
+
#
|
123
|
+
# @example Fetch via date
|
124
|
+
# client.Product.first(updated_at_min: "2014-03-03T21:09:00")
|
125
|
+
#
|
126
|
+
# @example Search
|
127
|
+
# client.Product.first(q: "gecko")
|
128
|
+
#
|
129
|
+
# @param [#to_hash] params
|
130
|
+
# @option params [String] :q Search query
|
131
|
+
# @option params [Array<Integer>] :ids IDs to search for
|
132
|
+
# @option params [String] :updated_at_min Last updated_at minimum
|
133
|
+
# @option params [String] :updated_at_max Last updated_at maximum
|
134
|
+
# @option params [String] :order Sort order i.e 'name asc'
|
135
|
+
# @option params [String, Array<String>] :status Record status/es
|
136
|
+
#
|
137
|
+
# @return <Gecko::Record::Base> A record instance
|
138
|
+
#
|
139
|
+
# @api public
|
140
|
+
def first(params={})
|
141
|
+
where(params.merge(limit: 1)).first
|
142
|
+
end
|
143
|
+
|
144
|
+
# Fetch the forty-second record for the given parameters
|
145
|
+
#
|
146
|
+
# @api public
|
147
|
+
def forty_two(params={})
|
148
|
+
where(params.merge(limit: 1, page: 42)).first
|
149
|
+
end
|
150
|
+
|
118
151
|
# Returns the total count for a record type via API request.
|
119
152
|
#
|
120
153
|
# @example
|
121
154
|
# client.Product.count
|
122
155
|
#
|
156
|
+
# @param [#to_hash] params
|
157
|
+
#
|
123
158
|
# @return [Integer] Total number of available records
|
124
159
|
#
|
125
160
|
# @api public
|
126
|
-
def count
|
127
|
-
self.where(limit: 0)
|
161
|
+
def count(params = {})
|
162
|
+
self.where(params.merge(limit: 0))
|
128
163
|
@pagination['total_records']
|
129
164
|
end
|
130
165
|
|
@@ -154,7 +189,7 @@ module Gecko
|
|
154
189
|
# @api private
|
155
190
|
def fetch(id)
|
156
191
|
verify_id_presence!(id)
|
157
|
-
response
|
192
|
+
response = @last_response = request(:get, plural_path + '/' + id.to_s)
|
158
193
|
record_json = extract_record(response.parsed)
|
159
194
|
instantiate_and_register_record(record_json)
|
160
195
|
rescue OAuth2::Error => ex
|
@@ -377,6 +412,8 @@ module Gecko
|
|
377
412
|
payload[:body] = options[:body]
|
378
413
|
payload[:model_class] = model_class
|
379
414
|
payload[:request_path] = path
|
415
|
+
options[:headers] = options.fetch(:headers, {}).tap { |headers| headers['Content-Type'] = 'application/json' }
|
416
|
+
options[:body] = options[:body].to_json if options[:body]
|
380
417
|
payload[:response] = @client.access_token.request(verb, path, options)
|
381
418
|
end
|
382
419
|
end
|
data/lib/gecko/record/contact.rb
CHANGED
@@ -3,7 +3,7 @@ require 'gecko/record/base'
|
|
3
3
|
module Gecko
|
4
4
|
module Record
|
5
5
|
class Contact < Base
|
6
|
-
belongs_to :company
|
6
|
+
belongs_to :company, writeable_on: :create
|
7
7
|
|
8
8
|
attribute :email, String
|
9
9
|
attribute :first_name, String
|
@@ -18,7 +18,7 @@ module Gecko
|
|
18
18
|
attribute :status, String, readonly: true
|
19
19
|
|
20
20
|
## DEPRECATED
|
21
|
-
attribute :phone, String
|
21
|
+
# attribute :phone, String
|
22
22
|
end
|
23
23
|
|
24
24
|
class ContactAdapter < BaseAdapter
|
@@ -4,9 +4,11 @@ require 'gecko/record/fulfillment_line_item'
|
|
4
4
|
module Gecko
|
5
5
|
module Record
|
6
6
|
class Fulfillment < Base
|
7
|
-
belongs_to :order
|
7
|
+
belongs_to :order, writeable_on: :create
|
8
8
|
belongs_to :shipping_address, class_name: 'Address'
|
9
9
|
belongs_to :billing_address, class_name: 'Address'
|
10
|
+
belongs_to :stock_location, class_name: 'Location'
|
11
|
+
|
10
12
|
has_many :fulfillment_line_items
|
11
13
|
|
12
14
|
attribute :status, String
|
@@ -16,7 +18,6 @@ module Gecko
|
|
16
18
|
attribute :notes, String
|
17
19
|
attribute :tracking_url, String
|
18
20
|
attribute :tracking_company, String
|
19
|
-
attribute :destination_url, String, readonly: true
|
20
21
|
|
21
22
|
attribute :packed_at, Date
|
22
23
|
attribute :shipped_at, DateTime
|
@@ -3,8 +3,8 @@ require 'gecko/record/base'
|
|
3
3
|
module Gecko
|
4
4
|
module Record
|
5
5
|
class FulfillmentLineItem < Base
|
6
|
-
belongs_to :fulfillment
|
7
|
-
belongs_to :order_line_item
|
6
|
+
belongs_to :fulfillment, writeable_on: :create
|
7
|
+
belongs_to :order_line_item, writeable_on: :create
|
8
8
|
|
9
9
|
attribute :quantity, BigDecimal
|
10
10
|
attribute :base_price, BigDecimal, readonly: true
|
data/lib/gecko/record/invoice.rb
CHANGED
@@ -3,7 +3,7 @@ require 'gecko/record/base'
|
|
3
3
|
module Gecko
|
4
4
|
module Record
|
5
5
|
class Invoice < Base
|
6
|
-
belongs_to :order
|
6
|
+
belongs_to :order, writeable_on: :create
|
7
7
|
belongs_to :shipping_address
|
8
8
|
belongs_to :billing_address
|
9
9
|
belongs_to :payment_term
|
@@ -16,8 +16,10 @@ module Gecko
|
|
16
16
|
attribute :notes, String
|
17
17
|
attribute :exchange_rate, BigDecimal
|
18
18
|
|
19
|
-
attribute :
|
20
|
-
attribute :
|
19
|
+
attribute :status, String, readonly: true
|
20
|
+
attribute :payment_status, String, readonly: true
|
21
|
+
attribute :total, BigDecimal, readonly: true
|
22
|
+
attribute :document_url, String, readonly: true
|
21
23
|
end
|
22
24
|
|
23
25
|
class InvoiceAdapter < BaseAdapter
|
data/lib/gecko/record/order.rb
CHANGED
@@ -28,7 +28,11 @@ module Gecko
|
|
28
28
|
attribute :packed_status, String, readonly: true
|
29
29
|
attribute :fulfillment_status, String, readonly: true
|
30
30
|
attribute :invoice_status, String, readonly: true
|
31
|
-
attribute :payment_status, String
|
31
|
+
attribute :payment_status, String, readonly: true
|
32
|
+
attribute :return_status, String, readonly: true
|
33
|
+
attribute :returning_status, String, readonly: true
|
34
|
+
attribute :shippability_status, String, readonly: true
|
35
|
+
attribute :backordering_status, String, readonly: true
|
32
36
|
attribute :tax_treatment, String
|
33
37
|
attribute :issued_at, Date
|
34
38
|
attribute :ship_at, Date
|
@@ -3,8 +3,8 @@ require 'gecko/record/base'
|
|
3
3
|
module Gecko
|
4
4
|
module Record
|
5
5
|
class OrderLineItem < Base
|
6
|
-
belongs_to :order
|
7
|
-
belongs_to :variant
|
6
|
+
belongs_to :order, writeable_on: :create
|
7
|
+
belongs_to :variant, writeable_on: :create
|
8
8
|
belongs_to :tax_type
|
9
9
|
|
10
10
|
has_many :fulfillment_line_items
|
data/lib/gecko/record/product.rb
CHANGED
@@ -19,18 +19,22 @@ module Gecko
|
|
19
19
|
attribute :reference_number, String
|
20
20
|
attribute :email, String
|
21
21
|
attribute :due_at, Date
|
22
|
+
attribute :received_at, Date
|
22
23
|
|
23
24
|
attribute :status, String
|
24
25
|
attribute :procurement_status, String, readonly: true
|
25
26
|
attribute :notes, String
|
26
27
|
attribute :tax_treatment, String
|
27
28
|
|
28
|
-
attribute :destination_url, String, readonly: true
|
29
29
|
attribute :document_url, String, readonly: true
|
30
30
|
|
31
31
|
attribute :total, BigDecimal, readonly: true
|
32
32
|
attribute :cached_quantity, BigDecimal, readonly: true
|
33
|
-
|
33
|
+
|
34
|
+
attribute :tags, Array[String]
|
35
|
+
|
36
|
+
# DEPRECATED
|
37
|
+
# attribute :cached_total, BigDecimal, readonly: true
|
34
38
|
end
|
35
39
|
|
36
40
|
class PurchaseOrderAdapter < BaseAdapter
|
@@ -3,8 +3,8 @@ require 'gecko/record/base'
|
|
3
3
|
module Gecko
|
4
4
|
module Record
|
5
5
|
class PurchaseOrderLineItem < Base
|
6
|
-
belongs_to :purchase_order
|
7
|
-
belongs_to :variant
|
6
|
+
belongs_to :purchase_order, writeable_on: :create
|
7
|
+
belongs_to :variant, writeable_on: :create
|
8
8
|
belongs_to :procurement
|
9
9
|
belongs_to :tax_type
|
10
10
|
|
data/lib/gecko/record/user.rb
CHANGED
@@ -16,11 +16,6 @@ module Gecko
|
|
16
16
|
attribute :status, String, readonly: true
|
17
17
|
attribute :billing_contact, Boolean, readonly: true
|
18
18
|
|
19
|
-
# attribute :sales_report_email, Boolean
|
20
|
-
# attribute :action_items_email, String
|
21
|
-
|
22
|
-
# attribute :notification_email, Boolean
|
23
|
-
# attribute :permissions, Array[String]
|
24
19
|
# attribute :account_id, Integer
|
25
20
|
|
26
21
|
## DEPRECATED
|
data/lib/gecko/record/variant.rb
CHANGED
@@ -21,7 +21,7 @@ module Gecko
|
|
21
21
|
attribute :value, BigDecimal
|
22
22
|
end
|
23
23
|
|
24
|
-
belongs_to :product
|
24
|
+
belongs_to :product, writeable_on: :create
|
25
25
|
has_many :images
|
26
26
|
|
27
27
|
attribute :name, String
|
@@ -36,6 +36,7 @@ module Gecko
|
|
36
36
|
attribute :opt3, String
|
37
37
|
|
38
38
|
attribute :weight, String
|
39
|
+
attribute :weight_unit, String
|
39
40
|
|
40
41
|
attribute :status, String, readonly: true
|
41
42
|
|
@@ -54,7 +55,6 @@ module Gecko
|
|
54
55
|
attribute :reorder_point, Integer
|
55
56
|
attribute :max_online, Integer
|
56
57
|
|
57
|
-
attribute :composite, Boolean
|
58
58
|
attribute :keep_selling, Boolean
|
59
59
|
attribute :taxable, Boolean
|
60
60
|
attribute :sellable, Boolean
|
@@ -63,11 +63,16 @@ module Gecko
|
|
63
63
|
attribute :position, Integer
|
64
64
|
|
65
65
|
attribute :stock_on_hand, BigDecimal, readonly: true
|
66
|
+
attribute :incoming_stock, BigDecimal, readonly: true
|
66
67
|
attribute :committed_stock, BigDecimal, readonly: true
|
67
68
|
|
68
69
|
attribute :locations, Array[VariantLocation]
|
69
70
|
attribute :variant_prices, Array[VariantPrice]
|
70
71
|
|
72
|
+
attribute :composite, Boolean, writeable_on: :create
|
73
|
+
attribute :initial_stock_level, BigDecimal, writeable_on: :create
|
74
|
+
attribute :initial_cost_price, BigDecimal, writeable_on: :create
|
75
|
+
|
71
76
|
# Returns a display name for a variant
|
72
77
|
#
|
73
78
|
# @example
|
data/lib/gecko/version.rb
CHANGED
@@ -13,6 +13,8 @@ class Gecko::Helpers::SerializationHelperTest < Minitest::Test
|
|
13
13
|
Widget = Class.new(Gecko::Record::Base) do
|
14
14
|
attribute :name, String
|
15
15
|
attribute :secret, String, readonly: true
|
16
|
+
attribute :initial_stock, BigDecimal, writeable_on: :create
|
17
|
+
attribute :update_stock, BigDecimal, writeable_on: :update
|
16
18
|
attribute :score, BigDecimal
|
17
19
|
attribute :started_on, Date
|
18
20
|
attribute :started_at, DateTime
|
@@ -27,6 +29,8 @@ class Gecko::Helpers::SerializationHelperTest < Minitest::Test
|
|
27
29
|
Widget.new(@client, {
|
28
30
|
name: "Gecko",
|
29
31
|
secret: "Iguana",
|
32
|
+
initial_stock: 10.0,
|
33
|
+
update_stock: 10.0,
|
30
34
|
score: 1.234,
|
31
35
|
started_at: DateTime.now,
|
32
36
|
started_on: Date.today,
|
@@ -47,6 +51,18 @@ class Gecko::Helpers::SerializationHelperTest < Minitest::Test
|
|
47
51
|
assert_equal({widget: record.serializable_hash}, record.as_json)
|
48
52
|
end
|
49
53
|
|
54
|
+
def test_writeable_on_create
|
55
|
+
assert_equal(serialized_record, record.serializable_hash)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_writeable_on_update
|
59
|
+
cleaned_record = serialized_record
|
60
|
+
cleaned_record.delete(:initial_stock)
|
61
|
+
cleaned_record[:update_stock] = "10.0"
|
62
|
+
record.id = 1
|
63
|
+
assert_equal(cleaned_record, record.serializable_hash)
|
64
|
+
end
|
65
|
+
|
50
66
|
def test_serializable_hash
|
51
67
|
assert_equal(serialized_record, record.serializable_hash)
|
52
68
|
end
|
@@ -69,6 +85,7 @@ private
|
|
69
85
|
def serialized_record
|
70
86
|
{
|
71
87
|
name: "Gecko",
|
88
|
+
initial_stock: "10.0",
|
72
89
|
score: "1.234",
|
73
90
|
started_on: Date.today,
|
74
91
|
started_at: DateTime.now,
|
@@ -18,7 +18,7 @@ class Gecko::FulfillmentTest < Minitest::Test
|
|
18
18
|
|
19
19
|
def test_serialization
|
20
20
|
json_keys = %w(
|
21
|
-
order_id shipping_address_id billing_address_id status exchange_rate
|
21
|
+
order_id shipping_address_id billing_address_id status stock_location_id exchange_rate
|
22
22
|
delivery_type tracking_number notes tracking_url tracking_company packed_at
|
23
23
|
service shipped_at received_at receipt
|
24
24
|
).map(&:to_sym)
|
@@ -150,7 +150,7 @@ private
|
|
150
150
|
mock_token = mock
|
151
151
|
mock_response = mock(status: response[0], parsed: response[1])
|
152
152
|
mock_token.expects(:request)
|
153
|
-
.with(request[0], request[1], body: record.as_json, raise_errors: false)
|
153
|
+
.with(request[0], request[1], body: record.as_json.to_json, raise_errors: false, headers: {'Content-Type' => 'application/json'})
|
154
154
|
.returns(mock_response)
|
155
155
|
adapter.client.access_token = mock_token
|
156
156
|
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.
|
4
|
+
version: 0.2.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:
|
11
|
+
date: 2016-06-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -357,7 +357,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
357
357
|
version: '0'
|
358
358
|
requirements: []
|
359
359
|
rubyforge_project:
|
360
|
-
rubygems_version: 2.4
|
360
|
+
rubygems_version: 2.6.4
|
361
361
|
signing_key:
|
362
362
|
specification_version: 4
|
363
363
|
summary: A Ruby interface to the TradeGecko API.
|