janio_api 0.3.4 → 0.3.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
  SHA256:
3
- metadata.gz: ec588d4ddedcb71c4d1038732fe2db5864cacc915b2d4f0e257feedafd5916d7
4
- data.tar.gz: ccb59b3ec045bcd86029fbd301e909a2919a94c000f1e098f780a9e99ccf53f2
3
+ metadata.gz: 91d85f8a1ab6814c4c4b8eb6ec69b436330384f45b788ff833387fb11d44d174
4
+ data.tar.gz: e098b9a86980679c69d5a697b9e0978cdf20c129dc00b6cc7228a9d222144523
5
5
  SHA512:
6
- metadata.gz: 868e7843a0cfdfa019f48fc2eaf0df991e2aeb0369e012aa2cb2407c53cc3865b1fc5f83f6fae8ac6b42e00ee945edf8014be90b00a5ada8f41adc9740549857
7
- data.tar.gz: d946eca197b5186140ba4741cd90cbdbd15b44b66da94d2ceb54edf4be9d7a5a2013551a8d476d3f5cd55e1db87e572781e19bbb443ac37e44eb672dd23d3fe9
6
+ metadata.gz: c25cb39853f1566b4abdc8570e6f534dbd77157eeae20479de9ce62d1b77022dd5759aedd0e4c6db644ba8ed4b30a504d787ab03ba19920fd83d77eff37b7ad8
7
+ data.tar.gz: 93a94c79dd8f34efb86fc9bffed84915455028161ca06deb1401131d40e6e95212b5291b88d6e18a0731e8ee2cac90f6e890bda7320ab55d22dec67d09ff56cd
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- janio_api (0.3.4)
4
+ janio_api (0.3.5)
5
5
  activeresource
6
6
  countries
7
7
  phonelib
@@ -17,6 +17,7 @@ module JanioAPI
17
17
 
18
18
  SUPPORTED_PICKUP_COUNTRIES = SERVICES.map { |s| s[:pickup_country] }.uniq.freeze
19
19
  SUPPORTED_CONSIGNEE_COUNTRIES = SERVICES.map { |s| s[:consignee_country] }.uniq.freeze
20
+ PICKUP_DATE_ACCEPTED_COUNTRIES = ["Singapore"]
20
21
 
21
22
  POSTAL_EXCLUDED_COUNTRIES = ["Hong Kong", "Vietnam", "Brunei"].freeze
22
23
  VALID_PAYMENT_TYPES = ["cod", "prepaid"].freeze
@@ -59,7 +60,10 @@ module JanioAPI
59
60
 
60
61
  validates :service_id, :order_length, :order_width, :order_height, :order_weight,
61
62
  :consignee_name, :consignee_country, :consignee_address, :consignee_state, :consignee_email,
62
- :pickup_contact_name, :pickup_country, :pickup_address, :pickup_state, :pickup_date, presence: true
63
+ :pickup_contact_name, :pickup_country, :pickup_address, :pickup_state, presence: true
64
+
65
+ validates :pickup_date, presence: true, if: -> { PICKUP_DATE_ACCEPTED_COUNTRIES.include?(pickup_country) }
66
+ validates :pickup_date, absence: true, if: -> { !PICKUP_DATE_ACCEPTED_COUNTRIES.include?(pickup_country) }
63
67
 
64
68
  validates :pickup_country, inclusion: {
65
69
  in: SUPPORTED_PICKUP_COUNTRIES,
@@ -129,11 +133,22 @@ module JanioAPI
129
133
  end
130
134
 
131
135
  def initialize(attributes = {}, persisted = false)
136
+ if attributes[:pickup_date].is_a?(ActiveSupport::TimeWithZone)
137
+ attributes[:pickup_date] = attributes[:pickup_date].strftime("%Y-%-m-%-d")
138
+ end
132
139
  attributes = DEFAULT_ATTRS.merge(attributes)
133
140
  super
134
141
  set_service_id
135
142
  end
136
143
 
144
+ def pickup_date=(date)
145
+ @attributes[:pickup_date] = if date.is_a?(ActiveSupport::TimeWithZone)
146
+ date.strftime("%Y-%-m-%-d")
147
+ else
148
+ date
149
+ end
150
+ end
151
+
137
152
  def get_service_id(service_category = "pickup")
138
153
  # only check with services offering pickup by default
139
154
  SERVICES.find do |s|
@@ -234,7 +249,7 @@ module JanioAPI
234
249
  elsif JanioAPI.config.api_token
235
250
  JanioAPI.config.api_token
236
251
  else
237
- throw ArgumentError.new("JanioAPI api_token is missing, please set it in the config.")
252
+ raise ArgumentError, "JanioAPI api_token is missing, please set it in the config."
238
253
  end
239
254
  end
240
255
 
@@ -1,3 +1,3 @@
1
1
  module JanioAPI
2
- VERSION = "0.3.4"
2
+ VERSION = "0.3.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: janio_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Chong
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-15 00:00:00.000000000 Z
11
+ date: 2020-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activeresource