gecko-ruby 0.0.4 → 0.0.5

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
  SHA1:
3
- metadata.gz: c3e9fd6fed6c04a1519102f2148126d4afce428a
4
- data.tar.gz: 6f9df328f522933a00cc2153b1bdc0ddf3b21478
3
+ metadata.gz: 9c40754a9c277cd08ad49a2d852b695c75fe8c92
4
+ data.tar.gz: c2581aaebade775b562ea622f6cda0f3743ebed0
5
5
  SHA512:
6
- metadata.gz: f2fd067297069ac22a4f11fe40690317c217b121c2eed07d286c386702c98105ba1546a30cc0a5ab9eb060742b159eea01bdfba6d314775f59968bd079d37039
7
- data.tar.gz: 11fe376aeafdbbce26989aad6f7ff9d604bdf89b0e295907f0baf07e6baaf07a07d54e29f1f99d1db24982447afdcc210e5d04893a8d05d12ede80a42200a0df
6
+ metadata.gz: 3d8391b9645867eb544931162bdf71eb962868e94d997b2d16c9344d3f4657e1de29cc8d4de09d1392f5dc80b7d02b40111fbf59dc016ebf8bbdda5009f4266d
7
+ data.tar.gz: 6dbec0902e1e46fb6429dc6a6c194e0d4ddcbe1a6a615786cf873b71064431c92e78182ae5e1c07165db3e1fbe3c4941b710fbc5df4145dda0dac7764c3c30be
@@ -0,0 +1,3 @@
1
+ ruby:
2
+ enabled: true
3
+ config_file: .rubocop.yml
@@ -7,3 +7,7 @@ SpaceAroundEqualsInParameterDefault:
7
7
 
8
8
  IndentHash:
9
9
  Enabled: false
10
+
11
+ # We like to line up the attribute definitions
12
+ ExtraSpacing:
13
+ Enabled: false
@@ -3,3 +3,4 @@ rvm:
3
3
  - 1.9.3
4
4
  - 2.0
5
5
  - 2.1
6
+ - 2.2
@@ -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/[my-github-username]/gecko/fork )
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`)
@@ -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
- # Serialize a single attribute
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
@@ -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
- # Return total count for a record type. Fetched from the metadata
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 record count
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
@@ -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, class_name: 'User'
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"
@@ -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
- # and :thumbnail supported
19
+ # @param [Symbol] :size (:full) The image size, currently only :full,
20
+ # :medium and :thumbnail supported
21
21
  #
22
22
  # @return [String]
23
23
  #
@@ -16,7 +16,7 @@ module Gecko
16
16
 
17
17
  attribute :status, String
18
18
 
19
- # attribute :image_url, String, readonly: true
19
+ attribute :image_url, String, readonly: true
20
20
  # attribute :quantity, Integer, readonly: true
21
21
  # attribute :search_cache, String, readonly: true
22
22
  end
@@ -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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Gecko
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
@@ -53,6 +53,6 @@ http_interactions:
53
53
  body:
54
54
  encoding: UTF-8
55
55
  string: '{"products":[],"meta":{"total":247}}'
56
- http_version:
56
+ http_version:
57
57
  recorded_at: Sat, 08 Mar 2014 04:18:46 GMT
58
58
  recorded_with: VCR 2.8.0
@@ -1,30 +1,78 @@
1
1
  require 'gecko'
2
+ require 'test_helper'
2
3
 
3
4
  class Gecko::Helpers::SerializationHelperTest < Minitest::Test
4
- def setup
5
- @klass = Class.new(Gecko::Record::Base) do
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
- def root
10
- :widget
11
- end
8
+ def root
9
+ :wodget
12
10
  end
13
- @client = Gecko::Client.new('ABC', 'DEF')
14
11
  end
15
12
 
16
- def test_serializable_hash
17
- record = @klass.new(@client, name: "Gecko", secret: "Iguana")
18
- assert_equal({name: "Gecko"}, record.serializable_hash)
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
- record = @klass.new(@client, name: "Gecko", secret: "Iguana")
23
- assert_equal({widget: {name: "Gecko"}}, record.as_json)
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
@@ -3,6 +3,7 @@ class Gecko::Record::AccountAdapterTest < Minitest::Test
3
3
  include TestingAdapter
4
4
  include SharedAdapterExamples
5
5
  undef :test_adapter_count
6
+ undef :test_adapter_size
6
7
 
7
8
  # Can't build accounts via API
8
9
  undef :test_build
@@ -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)
@@ -4,6 +4,7 @@ require 'minitest/pride'
4
4
  require 'mocha/mini_test'
5
5
  require 'vcr'
6
6
  require 'webmock/minitest'
7
+ require 'timecop'
7
8
 
8
9
  require 'support/let'
9
10
  require 'support/shared_adapter_examples'
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
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-01-09 00:00:00.000000000 Z
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