newgistics 1.1.0 → 2.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9e4beb6b736d1470b531b46cac3356b06405e5bd
4
- data.tar.gz: c6743453796386f18b6a7f1b35472e67f491190f
3
+ metadata.gz: 71568ff5b6f4a81cfe913095bc14707e6e76867e
4
+ data.tar.gz: 003a16e6b4cbc982e1bf366db97590237c0f0448
5
5
  SHA512:
6
- metadata.gz: 6991c8ec582649313e5c5575a2644d16ea4df560208cbaec6b01218513fea8273b79c22032af7fc85156c96eba0ae98b188776f6d6e87fbebeea0a9746d2ef7e
7
- data.tar.gz: 472593db28710abbafceb6bd491f38de105919eedd6e27c05586e0bce7618a775d9f9dc9cd13abb12f042bfc7ed86c08509f49d86732649cfdaca4807125ab2f
6
+ metadata.gz: 45ff8b1f9cf39885b897d198bedd54a526ca81f960ef7ee4ebe7dbfab527c71f68dbbcee36510a2ba325dc3eeadb742a30db9b9c10c908cc0f263e1fa93a1ab4
7
+ data.tar.gz: 90c502e5be3d5458dc1687752c84085f46ece2a4f729535bbc6ef85386debae1b4707986729fff9a871424d800e422983739cfcccc77b5936308ed1bcccc91dd
data/.codeclimate.yml CHANGED
@@ -1,13 +1,6 @@
1
1
  engines:
2
2
  rubocop:
3
3
  enabled: true
4
- checks:
5
- Rubocop/Style/Documentation:
6
- enabled: false
7
- Rubocop/Style/FrozenStringLiteralComment:
8
- enabled: false
9
- Rubocop/Style/StringLiterals:
10
- enabled: false
11
4
  duplication:
12
5
  enabled: true
13
6
  config:
data/.rubocop.yml ADDED
@@ -0,0 +1,14 @@
1
+ Style/Alias:
2
+ EnforcedStyle: prefer_alias_method
3
+
4
+ Style/Documentation:
5
+ Enabled: false
6
+
7
+ Style/FrozenStringLiteralComment:
8
+ Enabled: false
9
+
10
+ Style/StringLiterals:
11
+ Enabled: false
12
+
13
+ Layout/DotPosition:
14
+ EnforcedStyle: trailing
@@ -1,6 +1,6 @@
1
1
  module Newgistics
2
2
  class Customer
3
- include Virtus.model
3
+ include Newgistics::Model
4
4
 
5
5
  attribute :company, String
6
6
  attribute :first_name, String
@@ -1,6 +1,6 @@
1
1
  module Newgistics
2
2
  class Fee
3
- include Virtus.model
3
+ include Newgistics::Model
4
4
 
5
5
  attribute :type, String
6
6
  attribute :amount, Float
@@ -1,6 +1,6 @@
1
1
  module Newgistics
2
2
  class InboundReturn
3
- include Virtus.model
3
+ include Newgistics::Model
4
4
 
5
5
  attribute :id, String
6
6
  attribute :shipment_id, String
@@ -15,7 +15,6 @@ module Newgistics
15
15
  def self.where(conditions)
16
16
  Query.build(
17
17
  endpoint: '/inbound_returns.aspx',
18
- element_selector: 'InboundReturns InboundReturn',
19
18
  model_class: self
20
19
  ).where(conditions)
21
20
  end
@@ -1,6 +1,6 @@
1
1
  module Newgistics
2
2
  class Inventory
3
- include Virtus.model
3
+ include Newgistics::Model
4
4
 
5
5
  attribute :manifest_id, String
6
6
  attribute :manifest_po, String
@@ -14,9 +14,12 @@ module Newgistics
14
14
  def self.where(conditions)
15
15
  Query.build(
16
16
  endpoint: '/inventory_details.aspx',
17
- element_selector: 'inventories inventory',
18
17
  model_class: self
19
18
  ).where(conditions)
20
19
  end
20
+
21
+ def self.element_selector
22
+ 'inventory'
23
+ end
21
24
  end
22
25
  end
@@ -1,6 +1,6 @@
1
1
  module Newgistics
2
2
  class Item
3
- include Virtus.model
3
+ include Newgistics::Model
4
4
 
5
5
  attribute :id, String
6
6
 
@@ -1,29 +1,36 @@
1
1
  module Newgistics
2
2
  class Manifest
3
- include Virtus.model
3
+ include Newgistics::Model
4
4
 
5
- attribute :id, String
6
- attribute :manifest_po, String
7
- attribute :manifest_name, String
8
- attribute :warehouse_id, String
9
- attribute :status, String
10
- attribute :ship_date, Date
11
- attribute :shipped_via, String
12
- attribute :tracking_no, String
13
- attribute :created_date, Timestamp
14
- attribute :estimated_arrival_date, Date
15
- attribute :pallet_count, Integer
16
- attribute :carton_count, Integer
17
- attribute :weight, Float
18
- attribute :notes, String
5
+ attribute :manifest_slip, ManifestSlip
19
6
  attribute :contents, Array[ManifestItem], default: []
20
7
 
21
8
  attribute :errors, Array[String], default: []
22
9
  attribute :warnings, Array[String], default: []
23
10
 
11
+ def id
12
+ manifest_slip&.manifest_id
13
+ end
14
+
15
+ def id=(id)
16
+ self.manifest_slip ||= ManifestSlip.new
17
+ manifest_slip.manifest_id = id
18
+ end
19
+
24
20
  def save
25
21
  Requests::PostManifest.new(self).perform
26
22
  errors.empty?
27
23
  end
24
+
25
+ def self.where(conditions)
26
+ Query.build(
27
+ endpoint: '/manifests.aspx',
28
+ model_class: self
29
+ ).where(conditions)
30
+ end
31
+
32
+ def self.element_selector
33
+ 'manifest'
34
+ end
28
35
  end
29
36
  end
@@ -1,10 +1,17 @@
1
1
  module Newgistics
2
2
  class ManifestItem
3
- include Virtus.model
3
+ include Newgistics::Model
4
4
 
5
- attribute :sku, String
5
+ attribute :damaged_qty, Integer
6
6
  attribute :description, String
7
7
  attribute :original_qty, Integer
8
8
  attribute :received_qty, Integer
9
+ attribute :sku, String
10
+ attribute :upc, String
11
+ attribute :variance, Integer
12
+
13
+ def self.element_selector
14
+ "item"
15
+ end
9
16
  end
10
17
  end
@@ -0,0 +1,49 @@
1
+ module Newgistics
2
+ class ManifestSlip
3
+ include Newgistics::Model
4
+
5
+ attribute :actual_arrival_date, Timestamp
6
+ attribute :actual_received_date, Timestamp
7
+ attribute :carton_count, Integer
8
+ attribute :created_date, Timestamp
9
+ attribute :estimated_arrival_date, Date
10
+ attribute :manifest_id, String
11
+ attribute :manifest_name, String
12
+ attribute :manifest_po, String
13
+ attribute :notes, String
14
+ attribute :pallet_count, Integer
15
+ attribute :ship_date, Timestamp
16
+ attribute :shipped_via, String
17
+ attribute :status, String
18
+ attribute :total_weight, Float
19
+ attribute :tracking_no, String
20
+ attribute :warehouse_id, String
21
+ attribute :weight, Float
22
+
23
+ alias_method :no_pallets, :pallet_count
24
+ alias_method :no_pallets=, :pallet_count=
25
+ alias_method :no_cartons, :carton_count
26
+ alias_method :no_cartons=, :carton_count=
27
+ alias_method :shipped_date, :ship_date
28
+ alias_method :shipped_date=, :ship_date=
29
+ alias_method :total_weight, :weight
30
+ alias_method :total_weight=, :weight=
31
+
32
+ def estimated_arrival_date=(date)
33
+ date = parse_date(date) if should_parse_date?(date)
34
+ super(date)
35
+ end
36
+
37
+ private
38
+
39
+ def should_parse_date?(date)
40
+ date.is_a?(String) && date =~ %r{[01]\d/[0123]\d/\d{4}}
41
+ end
42
+
43
+ def parse_date(date)
44
+ Date.strptime(date, '%m/%d/%Y')
45
+ rescue ArgumentError
46
+ date
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,14 @@
1
+ module Newgistics
2
+ module Model
3
+ def self.included(base)
4
+ base.include(Virtus.model)
5
+ base.extend(ClassMethods)
6
+ end
7
+
8
+ module ClassMethods
9
+ def element_selector
10
+ name.split('::').last
11
+ end
12
+ end
13
+ end
14
+ end
@@ -1,6 +1,6 @@
1
1
  module Newgistics
2
2
  class Order
3
- include Virtus.model
3
+ include Newgistics::Model
4
4
 
5
5
  attribute :id, String
6
6
  attribute :warehouse_id, String
@@ -1,6 +1,6 @@
1
1
  module Newgistics
2
2
  class Product
3
- include Virtus.model
3
+ include Newgistics::Model
4
4
 
5
5
  attribute :id, String
6
6
  attribute :sku, String
@@ -22,9 +22,12 @@ module Newgistics
22
22
  def self.where(conditions)
23
23
  Query.build(
24
24
  endpoint: '/inventory.aspx',
25
- element_selector: 'products product',
26
25
  model_class: self
27
26
  ).where(conditions)
28
27
  end
28
+
29
+ def self.element_selector
30
+ 'product'
31
+ end
29
32
  end
30
33
  end
@@ -10,12 +10,9 @@ module Newgistics
10
10
  @conditions = {}
11
11
  end
12
12
 
13
- def self.build(endpoint:, element_selector:, model_class:)
13
+ def self.build(endpoint:, model_class:)
14
14
  request = Requests::Search.new(endpoint)
15
- response_handler = ResponseHandlers::Search.new(
16
- element_selector: element_selector,
17
- model_class: model_class
18
- )
15
+ response_handler = ResponseHandlers::Search.new(model_class: model_class)
19
16
 
20
17
  new(request, response_handler)
21
18
  end
@@ -44,7 +44,7 @@ module Newgistics
44
44
  end
45
45
 
46
46
  def mandatory_params
47
- {
47
+ {
48
48
  apiKey: api_key,
49
49
  shipmentID: shipment_cancellation.shipment_id,
50
50
  orderID: shipment_cancellation.order_id
@@ -46,25 +46,27 @@ module Newgistics
46
46
  end
47
47
 
48
48
  def manifest_slip_xml(xml)
49
- xml.manifest_slip do
50
- xml.manifest_po manifest.manifest_po
51
- xml.manifest_name manifest.manifest_name
52
- xml.warehouse_id manifest.warehouse_id
53
- xml.status manifest.status
54
- xml.tracking_no manifest.tracking_no
55
- xml.pallet_count manifest.pallet_count
56
- xml.carton_count manifest.carton_count
57
- xml.weight manifest.weight
58
- xml.notes manifest.notes
49
+ manifest_slip = manifest.manifest_slip || ManifestSlip.new
59
50
 
60
- date_xml(xml, :ship_date)
61
- date_xml(xml, :estimated_arrival_date)
51
+ xml.manifest_slip do
52
+ xml.manifest_po manifest_slip.manifest_po
53
+ xml.manifest_name manifest_slip.manifest_name
54
+ xml.warehouse_id manifest_slip.warehouse_id
55
+ xml.status manifest_slip.status
56
+ xml.tracking_no manifest_slip.tracking_no
57
+ xml.pallet_count manifest_slip.pallet_count
58
+ xml.carton_count manifest_slip.carton_count
59
+ xml.weight manifest_slip.weight
60
+ xml.notes manifest_slip.notes
61
+ xml.ship_date format_date(manifest_slip.ship_date)
62
+ xml.estimated_arrival_date format_date(
63
+ manifest_slip.estimated_arrival_date
64
+ )
62
65
  end
63
66
  end
64
67
 
65
- def date_xml(xml, attribute)
66
- date = manifest.send(attribute)
67
- xml.send(attribute, date.strftime("%m/%d/%Y")) unless date.nil?
68
+ def format_date(date)
69
+ date.strftime("%m/%d/%Y") if date.respond_to?(:strftime)
68
70
  end
69
71
 
70
72
  def contents_xml(xml)
@@ -13,7 +13,7 @@ module Newgistics
13
13
 
14
14
  def body
15
15
  params.
16
- map { |k,v| [StringHelper.camelize(k, upcase_first: false), v] }.
16
+ map { |k, v| [StringHelper.camelize(k, upcase_first: false), v] }.
17
17
  to_h
18
18
  end
19
19
  end
@@ -1,10 +1,9 @@
1
1
  module Newgistics
2
2
  module ResponseHandlers
3
3
  class Search
4
- attr_reader :element_selector, :model_class
4
+ attr_reader :model_class
5
5
 
6
- def initialize(element_selector:, model_class:)
7
- @element_selector = element_selector
6
+ def initialize(model_class:)
8
7
  @model_class = model_class
9
8
  end
10
9
 
@@ -34,7 +33,7 @@ module Newgistics
34
33
  end
35
34
 
36
35
  def build_models(xml)
37
- xml.css(element_selector).map do |model_xml|
36
+ xml.css(model_class.element_selector).map do |model_xml|
38
37
  build_model(model_xml)
39
38
  end
40
39
  end
@@ -50,7 +49,7 @@ module Newgistics
50
49
  end
51
50
 
52
51
  def raise_error(message)
53
- raise QueryError.new(message)
52
+ raise QueryError, message
54
53
  end
55
54
  end
56
55
  end
@@ -1,6 +1,6 @@
1
1
  module Newgistics
2
2
  class Return
3
- include Virtus.model
3
+ include Newgistics::Model
4
4
 
5
5
  attribute :warehouse_id, String
6
6
  attribute :shipment_id, String
@@ -32,7 +32,6 @@ module Newgistics
32
32
  def self.where(conditions)
33
33
  Query.build(
34
34
  endpoint: '/returns.aspx',
35
- element_selector: 'Returns Return',
36
35
  model_class: self
37
36
  ).where(conditions)
38
37
  end
@@ -1,6 +1,6 @@
1
1
  module Newgistics
2
2
  class Shipment
3
- include Virtus.model
3
+ include Newgistics::Model
4
4
 
5
5
  attribute :id, String
6
6
  attribute :client_name, String
@@ -71,7 +71,6 @@ module Newgistics
71
71
  def self.where(conditions)
72
72
  Query.build(
73
73
  endpoint: '/shipments.aspx',
74
- element_selector: 'Shipments Shipment',
75
74
  model_class: self
76
75
  ).where(conditions)
77
76
  end
@@ -1,6 +1,6 @@
1
1
  module Newgistics
2
2
  class ShipmentCancellation
3
- include Virtus.model
3
+ include Newgistics::Model
4
4
 
5
5
  attribute :shipment_id, String
6
6
  attribute :order_id, String
@@ -1,6 +1,6 @@
1
1
  module Newgistics
2
2
  class ShipmentUpdate
3
- include Virtus.model
3
+ include Newgistics::Model
4
4
 
5
5
  attribute :id, String
6
6
  attribute :order_id, String
@@ -1,13 +1,21 @@
1
1
  module Newgistics
2
2
  class StringHelper
3
+ CAMEL_CASED_STRING_REGEX = /([a-z])([A-Z])/
4
+ UNDERSCORED_STRING_REGEX = /([A-Za-z\d]+)(_|\z)/
5
+ CAPITALIZED_STRING_REGEX = /\A[A-Z]/
6
+
3
7
  def self.camelize(string, upcase_first: true)
4
- result = string.to_s.gsub(/([a-z\d]+)(_|\z)/) { $1.capitalize }
5
- result = result.gsub(/\A[A-Z]/) { $&.downcase } unless upcase_first
6
- result
8
+ string.dup.to_s.tap do |s|
9
+ s.gsub!(UNDERSCORED_STRING_REGEX) { $1.capitalize! || $1 }
10
+ s.gsub!(CAPITALIZED_STRING_REGEX) { $&.downcase! } unless upcase_first
11
+ end
7
12
  end
8
13
 
9
14
  def self.underscore(string)
10
- string.to_s.gsub(/([a-z])([A-Z])/) { "#{$1}_#{$2}" }.downcase
15
+ string.dup.to_s.tap do |s|
16
+ s.gsub!(CAMEL_CASED_STRING_REGEX) { "#{$1}_#{$2}" }
17
+ s.downcase!
18
+ end
11
19
  end
12
20
  end
13
21
  end
@@ -1,3 +1,3 @@
1
1
  module Newgistics
2
- VERSION = "1.1.0"
2
+ VERSION = "2.0.0"
3
3
  end
@@ -1,6 +1,6 @@
1
1
  module Newgistics
2
2
  class Warehouse
3
- include Virtus.model
3
+ include Newgistics::Model
4
4
 
5
5
  attribute :id, String
6
6
 
@@ -37,8 +37,7 @@ module Newgistics
37
37
  end
38
38
 
39
39
  def build_list(item_class, element)
40
- item_selector = get_list_item_selector(item_class)
41
- element.css(item_selector).map do |child|
40
+ element.css(item_class.element_selector).map do |child|
42
41
  build_object(item_class, child)
43
42
  end
44
43
  end
@@ -49,10 +48,6 @@ module Newgistics
49
48
  end
50
49
  end
51
50
 
52
- def get_list_item_selector(item_class)
53
- item_class.to_s.split('::').last
54
- end
55
-
56
51
  def assign_simple_attribute(object, element)
57
52
  attribute = attribute_name(element)
58
53
  assign_attribute(object, attribute, element.text)
data/lib/newgistics.rb CHANGED
@@ -8,6 +8,7 @@ require "newgistics/default_logger"
8
8
  require "newgistics/configuration"
9
9
  require "newgistics/time_zone"
10
10
  require "newgistics/timestamp"
11
+ require "newgistics/model"
11
12
  require "newgistics/customer"
12
13
  require "newgistics/item"
13
14
  require "newgistics/order"
@@ -35,6 +36,7 @@ require "newgistics/response_handlers/search"
35
36
  require "newgistics/response_handlers/update_shipment_contents"
36
37
  require "newgistics/response_handlers/post_manifest"
37
38
  require "newgistics/manifest_item"
39
+ require "newgistics/manifest_slip"
38
40
  require "newgistics/manifest"
39
41
  require "newgistics/fee"
40
42
  require "newgistics/shipment"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: newgistics
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Manuel Martinez
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2018-09-04 00:00:00.000000000 Z
12
+ date: 2018-09-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: virtus
@@ -191,6 +191,7 @@ files:
191
191
  - ".env.sample"
192
192
  - ".gitignore"
193
193
  - ".rspec"
194
+ - ".rubocop.yml"
194
195
  - ".ruby-version"
195
196
  - ".simplecov"
196
197
  - CODE_OF_CONDUCT.md
@@ -212,6 +213,8 @@ files:
212
213
  - lib/newgistics/item.rb
213
214
  - lib/newgistics/manifest.rb
214
215
  - lib/newgistics/manifest_item.rb
216
+ - lib/newgistics/manifest_slip.rb
217
+ - lib/newgistics/model.rb
215
218
  - lib/newgistics/order.rb
216
219
  - lib/newgistics/product.rb
217
220
  - lib/newgistics/query.rb