gecko-ruby 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.hound.yml +3 -0
- data/.rubocop.yml +4 -0
- data/.travis.yml +1 -0
- data/CHANGELOG.md +3 -0
- data/README.md +1 -1
- data/gecko-ruby.gemspec +1 -0
- data/lib/gecko/helpers/serialization_helper.rb +24 -2
- data/lib/gecko/record/account.rb +1 -1
- data/lib/gecko/record/base_adapter.rb +15 -2
- data/lib/gecko/record/company.rb +2 -3
- data/lib/gecko/record/image.rb +2 -2
- data/lib/gecko/record/product.rb +1 -1
- data/lib/gecko/record/tax_type.rb +4 -4
- data/lib/gecko/record/variant.rb +2 -0
- data/lib/gecko/version.rb +1 -1
- data/test/fixtures/vcr_cassettes/products_count.yml +1 -1
- data/test/helpers/serialization_helper_test.rb +61 -13
- data/test/record/account_adapter_test.rb +1 -0
- data/test/support/shared_adapter_examples.rb +6 -0
- data/test/test_helper.rb +1 -0
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c40754a9c277cd08ad49a2d852b695c75fe8c92
|
4
|
+
data.tar.gz: c2581aaebade775b562ea622f6cda0f3743ebed0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d8391b9645867eb544931162bdf71eb962868e94d997b2d16c9344d3f4657e1de29cc8d4de09d1392f5dc80b7d02b40111fbf59dc016ebf8bbdda5009f4266d
|
7
|
+
data.tar.gz: 6dbec0902e1e46fb6429dc6a6c194e0d4ddcbe1a6a615786cf873b71064431c92e78182ae5e1c07165db3e1fbe3c4941b710fbc5df4145dda0dac7764c3c30be
|
data/.hound.yml
ADDED
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
## Unreleased
|
2
|
+
- Add size to base adapter
|
3
|
+
- Update serialization_helper to support serializing arrays correctly
|
2
4
|
|
5
|
+
## 0.0.4 (2015-01-09)
|
3
6
|
- Renamed gem so we can publish it on RubyGems.org
|
4
7
|
- Add `Gecko::Record::TaxType`
|
5
8
|
- Add `Gecko::Record::PurchaseOrder` and `Gecko::Record::PurchaseOrderLineItem`
|
data/README.md
CHANGED
@@ -137,7 +137,7 @@ end
|
|
137
137
|
|
138
138
|
## Contributing
|
139
139
|
|
140
|
-
1. Fork it ( http://github.com/
|
140
|
+
1. Fork it ( http://github.com/tradegecko/gecko/fork )
|
141
141
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
142
142
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
143
143
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/gecko-ruby.gemspec
CHANGED
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_development_dependency "vcr"
|
25
25
|
spec.add_development_dependency "webmock"
|
26
26
|
spec.add_development_dependency "mocha"
|
27
|
+
spec.add_development_dependency "timecop"
|
27
28
|
spec.add_development_dependency "dotenv"
|
28
29
|
spec.add_development_dependency "thor"
|
29
30
|
spec.add_development_dependency "pry"
|
@@ -33,7 +33,7 @@ module Gecko
|
|
33
33
|
attribute_hash
|
34
34
|
end
|
35
35
|
|
36
|
-
#
|
36
|
+
# Store the serialized representation of a single attribute
|
37
37
|
#
|
38
38
|
# @param [Hash] attribute_hash Serialized record being iterated over
|
39
39
|
# @param [Virtus::Attribute] attribute The attribute being serialized
|
@@ -42,7 +42,29 @@ module Gecko
|
|
42
42
|
#
|
43
43
|
# @api private
|
44
44
|
def serialize_attribute(attribute_hash, attribute)
|
45
|
-
attribute_hash[attribute.name] = attributes[attribute.name]
|
45
|
+
attribute_hash[attribute.name] = _serialize(attributes[attribute.name])
|
46
|
+
end
|
47
|
+
|
48
|
+
# Serialize an attribute
|
49
|
+
#
|
50
|
+
# @param [Object] serialized The attribute to serialize
|
51
|
+
#
|
52
|
+
# @return [String]
|
53
|
+
#
|
54
|
+
# @api private
|
55
|
+
def _serialize(serialized)
|
56
|
+
if serialized.respond_to?(:serializable_hash)
|
57
|
+
serialized.serializable_hash
|
58
|
+
else
|
59
|
+
case serialized
|
60
|
+
when Array
|
61
|
+
serialized.map { |attr| _serialize(attr) }
|
62
|
+
when BigDecimal
|
63
|
+
serialized.to_s("F")
|
64
|
+
else
|
65
|
+
serialized
|
66
|
+
end
|
67
|
+
end
|
46
68
|
end
|
47
69
|
|
48
70
|
# Return JSON root key for a record
|
data/lib/gecko/record/account.rb
CHANGED
@@ -24,7 +24,6 @@ module Gecko
|
|
24
24
|
|
25
25
|
attribute :default_tax_rate, String
|
26
26
|
|
27
|
-
attribute :default_tax_type_id, Integer
|
28
27
|
|
29
28
|
attribute :tax_number_label, String
|
30
29
|
attribute :tax_label, String
|
@@ -32,6 +31,7 @@ module Gecko
|
|
32
31
|
belongs_to :billing_contact, class_name: "User"
|
33
32
|
belongs_to :primary_location, class_name: "Location"
|
34
33
|
belongs_to :primary_billing_location, class_name: "Location"
|
34
|
+
belongs_to :default_tax_type, class_name: "TaxType"
|
35
35
|
|
36
36
|
# belongs_to :default_currency, class_name: "Currency"
|
37
37
|
# belongs_to :default_payment_term, class_name: "PaymentTerm"
|
@@ -115,12 +115,12 @@ module Gecko
|
|
115
115
|
parse_records(parsed_response)
|
116
116
|
end
|
117
117
|
|
118
|
-
#
|
118
|
+
# Returns the total count for a record type via API request.
|
119
119
|
#
|
120
120
|
# @example
|
121
121
|
# client.Product.count
|
122
122
|
#
|
123
|
-
# @return [Integer] Total
|
123
|
+
# @return [Integer] Total number of available records
|
124
124
|
#
|
125
125
|
# @api public
|
126
126
|
def count
|
@@ -128,6 +128,19 @@ module Gecko
|
|
128
128
|
@pagination['total_records']
|
129
129
|
end
|
130
130
|
|
131
|
+
# Returns the total count for a record type. Reads from the last request or
|
132
|
+
# makes a new request if not available.
|
133
|
+
#
|
134
|
+
# @example
|
135
|
+
# client.Product.size
|
136
|
+
#
|
137
|
+
# @return [Integer] Total number of available records
|
138
|
+
#
|
139
|
+
# @api public
|
140
|
+
def size
|
141
|
+
(@pagination && @pagination['total_records']) || count
|
142
|
+
end
|
143
|
+
|
131
144
|
# Fetch a record via API, regardless of whether it is already in identity map.
|
132
145
|
#
|
133
146
|
# @example
|
data/lib/gecko/record/company.rb
CHANGED
@@ -3,7 +3,8 @@ require 'gecko/record/base'
|
|
3
3
|
module Gecko
|
4
4
|
module Record
|
5
5
|
class Company < Base
|
6
|
-
belongs_to :assignee,
|
6
|
+
belongs_to :assignee, class_name: "User"
|
7
|
+
belongs_to :default_tax_type, class_name: "TaxType"
|
7
8
|
|
8
9
|
has_many :addresses
|
9
10
|
has_many :contacts
|
@@ -23,8 +24,6 @@ module Gecko
|
|
23
24
|
attribute :tax_number, String
|
24
25
|
|
25
26
|
attribute :default_tax_rate, BigDecimal
|
26
|
-
attribute :default_tax_type_id, Integer
|
27
|
-
|
28
27
|
attribute :default_discount_rate, BigDecimal
|
29
28
|
|
30
29
|
# belongs_to :default_price_list, class_name: "PriceList"
|
data/lib/gecko/record/image.rb
CHANGED
@@ -16,8 +16,8 @@ module Gecko
|
|
16
16
|
|
17
17
|
# URL for image
|
18
18
|
#
|
19
|
-
# @param [Symbol] :size (:full) The image size, currently only :full
|
20
|
-
#
|
19
|
+
# @param [Symbol] :size (:full) The image size, currently only :full,
|
20
|
+
# :medium and :thumbnail supported
|
21
21
|
#
|
22
22
|
# @return [String]
|
23
23
|
#
|
data/lib/gecko/record/product.rb
CHANGED
@@ -5,11 +5,11 @@ module Gecko
|
|
5
5
|
class TaxType < Base
|
6
6
|
attribute :name, String
|
7
7
|
attribute :code, String
|
8
|
-
attribute :xero_online_id, String
|
9
|
-
attribute :imported_from, String
|
10
|
-
attribute :effective_rate, BigDecimal
|
8
|
+
attribute :xero_online_id, String, readonly: true
|
9
|
+
attribute :imported_from, String, readonly: true
|
10
|
+
attribute :effective_rate, BigDecimal, readonly: true
|
11
11
|
|
12
|
-
attribute :status, String
|
12
|
+
attribute :status, String, readonly: true
|
13
13
|
|
14
14
|
# has_many :tax_components
|
15
15
|
end
|
data/lib/gecko/record/variant.rb
CHANGED
@@ -5,6 +5,7 @@ module Gecko
|
|
5
5
|
class Variant < Base
|
6
6
|
class VariantLocation
|
7
7
|
include Virtus.model
|
8
|
+
include Gecko::Helpers::SerializationHelper
|
8
9
|
attribute :location_id, Integer
|
9
10
|
attribute :committed_stock, BigDecimal
|
10
11
|
attribute :stock_on_hand, BigDecimal
|
@@ -13,6 +14,7 @@ module Gecko
|
|
13
14
|
|
14
15
|
class VariantPrice
|
15
16
|
include Virtus.model
|
17
|
+
include Gecko::Helpers::SerializationHelper
|
16
18
|
attribute :price_list_id, String
|
17
19
|
attribute :value, BigDecimal
|
18
20
|
end
|
data/lib/gecko/version.rb
CHANGED
@@ -1,30 +1,78 @@
|
|
1
1
|
require 'gecko'
|
2
|
+
require 'test_helper'
|
2
3
|
|
3
4
|
class Gecko::Helpers::SerializationHelperTest < Minitest::Test
|
4
|
-
|
5
|
-
|
6
|
-
attribute :name, String
|
7
|
-
attribute :secret, String, readonly: true
|
5
|
+
Wodget = Class.new(Gecko::Record::Base) do
|
6
|
+
attribute :name, String
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
end
|
8
|
+
def root
|
9
|
+
:wodget
|
12
10
|
end
|
13
|
-
@client = Gecko::Client.new('ABC', 'DEF')
|
14
11
|
end
|
15
12
|
|
16
|
-
|
17
|
-
|
18
|
-
|
13
|
+
Widget = Class.new(Gecko::Record::Base) do
|
14
|
+
attribute :name, String
|
15
|
+
attribute :secret, String, readonly: true
|
16
|
+
attribute :score, BigDecimal
|
17
|
+
attribute :started_on, Date
|
18
|
+
attribute :started_at, DateTime
|
19
|
+
attribute :wodgets, Array[Wodget]
|
20
|
+
|
21
|
+
def root
|
22
|
+
:widget
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
let(:record) do
|
27
|
+
Widget.new(@client, {
|
28
|
+
name: "Gecko",
|
29
|
+
secret: "Iguana",
|
30
|
+
score: 1.234,
|
31
|
+
started_at: DateTime.now,
|
32
|
+
started_on: Date.today,
|
33
|
+
wodgets: [Wodget.new(@client, name: "Hi")]
|
34
|
+
})
|
35
|
+
end
|
36
|
+
|
37
|
+
def setup
|
38
|
+
Timecop.freeze
|
39
|
+
@client = Gecko::Client.new("ABC", "DEF")
|
40
|
+
end
|
41
|
+
|
42
|
+
def teardown
|
43
|
+
Timecop.return
|
19
44
|
end
|
20
45
|
|
21
46
|
def test_as_json
|
22
|
-
|
23
|
-
|
47
|
+
assert_equal({widget: record.serializable_hash}, record.as_json)
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_serializable_hash
|
51
|
+
assert_equal(serialized_record, record.serializable_hash)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_serializes_big_decimal_in_math_notation
|
55
|
+
assert_equal("1.234", record.serializable_hash[:score])
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_serializes_arrays
|
59
|
+
assert_equal([{name: "Hi"}], record.serializable_hash[:wodgets])
|
24
60
|
end
|
25
61
|
|
26
62
|
def test_root_key
|
27
63
|
record = Gecko::Record::OrderLineItem.new(@client, @json)
|
28
64
|
assert_equal(:order_line_item, record.root)
|
29
65
|
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def serialized_record
|
70
|
+
{
|
71
|
+
name: "Gecko",
|
72
|
+
score: "1.234",
|
73
|
+
started_on: Date.today,
|
74
|
+
started_at: DateTime.now,
|
75
|
+
wodgets: [{name: "Hi"}]
|
76
|
+
}
|
77
|
+
end
|
30
78
|
end
|
@@ -21,6 +21,12 @@ module SharedAdapterExamples
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
+
def test_adapter_size
|
25
|
+
VCR.use_cassette(plural_name + '_count') do
|
26
|
+
assert(adapter.size > 10)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
24
30
|
def test_adapter_uses_identity_map
|
25
31
|
VCR.use_cassette(plural_name) do
|
26
32
|
collection = adapter.where(limit: 5)
|
data/test/test_helper.rb
CHANGED
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.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bradley Priest
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: timecop
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: dotenv
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -186,6 +200,7 @@ extensions: []
|
|
186
200
|
extra_rdoc_files: []
|
187
201
|
files:
|
188
202
|
- ".gitignore"
|
203
|
+
- ".hound.yml"
|
189
204
|
- ".rubocop.yml"
|
190
205
|
- ".travis.yml"
|
191
206
|
- CHANGELOG.md
|