ingram_micro 0.1.2 → 0.1.3

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: 1f0d867b8114f0777ecb1cac2bf499dd51f2b463
4
- data.tar.gz: 773e12a0d083e12509836d96feea1a8e0bb2e63d
3
+ metadata.gz: ced56ce6b64dcb31798c34be03efc8e9637738b8
4
+ data.tar.gz: bef3a1e41d54ebcbc42ca13a90b61c19d64ca433
5
5
  SHA512:
6
- metadata.gz: deb441feb192fd6f202007fcee5fdb24b4d9d10d2f2414e591bc74e86166ca64a1e39a96b26918eb1d57e0add9a6a33c79940ca42d097e4a3f8eed4aac414eaf
7
- data.tar.gz: f631420bdde8cf9634e52973001c8715d0dec06bd40b5f198e46d7ddfb981c60863951338e44a565629ba91414e57403c1035448e73f7119679f85b64c5ceaa6
6
+ metadata.gz: 3591785159a554ca1837e4af5cc0e73541d3220e3d18bfbee23303d9c44763609c02ef1b5b6484f00453a0092b78e9ad54ef0c4d24999cb2fc5ce07e806c684e
7
+ data.tar.gz: a097e58b06d3ad2cde84e3feb02d79d4b739bf749340327d084e22dbbf31e4d5e1dfe2b8b93da64e94161054eaa917fe16485f728ddeb0cc07021b585dcc29bd
data/.gitignore CHANGED
@@ -10,3 +10,5 @@
10
10
  /tmp/
11
11
  lib/config/defaults.yml
12
12
  .DS_STORE
13
+ *.gem
14
+
@@ -1,5 +1,4 @@
1
1
  class IngramMicro::BaseElement
2
-
3
2
  attr_accessor :element
4
3
 
5
4
  def initialize(options={})
@@ -14,7 +13,7 @@ class IngramMicro::BaseElement
14
13
  def build(builder)
15
14
  self.defaults.keys.each do |field|
16
15
  element_name = field.to_s.gsub('_', '-')
17
- element_value = @element[field]
16
+ element_value = formatted_value_of(field)
18
17
  builder.send(element_name, element_value)
19
18
  end
20
19
  end
@@ -26,6 +25,25 @@ class IngramMicro::BaseElement
26
25
  end
27
26
  end
28
27
 
28
+ def self.format(field, formatter)
29
+ @formatters ||= {}
30
+ @formatters[field] = formatter
31
+ end
32
+
33
+ private
34
+
35
+ def self.formatter_for(field)
36
+ if @formatters && @formatters[field]
37
+ @formatters[field]
38
+ else
39
+ IngramMicro::NullFormatter.new
40
+ end
41
+ end
42
+
43
+ def formatted_value_of(field)
44
+ self.class.formatter_for(field).format(@element[field])
45
+ end
46
+
29
47
  def integer?(string)
30
48
  Integer(string) != nil rescue false
31
49
  end
@@ -0,0 +1,9 @@
1
+ class IngramMicro::DateFormatter
2
+ def format(date)
3
+ if date.respond_to?(:strftime)
4
+ date.strftime('%Y%m%d')
5
+ else
6
+ date
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ class IngramMicro::DateTimeFormatter
2
+ def format(datetime)
3
+ if datetime.respond_to?(:strftime)
4
+ datetime.strftime('%Y%m%d%H%M%S')
5
+ else
6
+ datetime
7
+ end
8
+ end
9
+ end
@@ -9,6 +9,8 @@ class IngramMicro::MessageHeaderNoPW < IngramMicro::BaseElement
9
9
  response_request: 1
10
10
  }
11
11
 
12
+ format :create_timestamp, IngramMicro::DateTimeFormatter.new
13
+
12
14
  def defaults
13
15
  DEFAULTS
14
16
  end
@@ -10,6 +10,8 @@ class IngramMicro::MessageHeaderPW < IngramMicro::BaseElement
10
10
  response_request: 1
11
11
  }
12
12
 
13
+ format :create_timestamp, IngramMicro::DateTimeFormatter.new
14
+
13
15
  def defaults
14
16
  DEFAULTS
15
17
  end
@@ -20,10 +20,4 @@ class IngramMicro::ReturnAuthorizationOrderHeader < IngramMicro::BaseElement
20
20
  def defaults
21
21
  DEFAULTS
22
22
  end
23
-
24
- def use_current_date?
25
- if @element[:customer_order_date].nil?
26
- @element[:customer_order_date] = DateTime.now.strftime("%Y%m%d")
27
- end
28
- end
29
23
  end
@@ -15,13 +15,9 @@ class IngramMicro::SalesOrderHeader < IngramMicro::BaseElement
15
15
  gift_flag: nil
16
16
  }
17
17
 
18
+ format :customer_order_date, IngramMicro::DateFormatter.new
19
+
18
20
  def defaults
19
21
  DEFAULTS
20
22
  end
21
-
22
- def use_current_date?
23
- if @element[:customer_order_date].nil?
24
- @element[:customer_order_date] = DateTime.now.strftime('%Y%m%d')
25
- end
26
- end
27
23
  end
@@ -0,0 +1,5 @@
1
+ class IngramMicro::NullFormatter
2
+ def format(value)
3
+ value
4
+ end
5
+ end
@@ -7,7 +7,7 @@ class IngramMicro::SalesOrder < IngramMicro::Transmission
7
7
  super(options)
8
8
  @transaction_name = 'sales-order-submission'
9
9
  @customer = options[:customer]
10
- @shipment_information = options[:sales_order_shipment_information]
10
+ @sales_order_shipment_information = options[:sales_order_shipment_information]
11
11
  @credit_card_information = options[:credit_card_information]
12
12
  @order_header = options[:order_header]
13
13
  @detail = options[:detail]
@@ -1,3 +1,3 @@
1
1
  module IngramMicro
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ingram_micro
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Christel
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: exe
13
13
  cert_chain: []
14
- date: 2016-06-28 00:00:00.000000000 Z
14
+ date: 2016-06-29 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: faraday
@@ -176,6 +176,8 @@ files:
176
176
  - lib/ingram_micro/base_element.rb
177
177
  - lib/ingram_micro/client.rb
178
178
  - lib/ingram_micro/configuration.rb
179
+ - lib/ingram_micro/date_formatter.rb
180
+ - lib/ingram_micro/date_time_formatter.rb
179
181
  - lib/ingram_micro/elements/credit_card_information.rb
180
182
  - lib/ingram_micro/elements/customer.rb
181
183
  - lib/ingram_micro/elements/detail.rb
@@ -195,6 +197,7 @@ files:
195
197
  - lib/ingram_micro/elements/shipment_status_line_item.rb
196
198
  - lib/ingram_micro/errors/invalid_type.rb
197
199
  - lib/ingram_micro/errors/missing_field.rb
200
+ - lib/ingram_micro/null_formatter.rb
198
201
  - lib/ingram_micro/request_processor.rb
199
202
  - lib/ingram_micro/transmission.rb
200
203
  - lib/ingram_micro/transmissions/check_shipment_status.rb