expressly 2.0.32.rc1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,480 @@
1
+ module Expressly
2
+ class CustomerImport
3
+ attr_accessor :metadata, :primary_email, :customer, :cart
4
+ def initialize(attribute_value_map = {})
5
+ attribute_value_map.map { |(k, v)| public_send("#{k}=", v) }
6
+ self.freeze
7
+ end
8
+
9
+ def ==(object)
10
+ ObjectHelper.equals(self,object)
11
+ end
12
+
13
+ def self.from_json(json)
14
+ CustomerImport.new({
15
+ :metadata => json['migration']['meta'],
16
+ :primary_email => json['migration']['data']['email'],
17
+ :customer => Customer.from_json(json['migration']['data']['customerData']),
18
+ :cart => Cart.from_json(json['cart'])})
19
+ end
20
+ end
21
+
22
+ class CustomerExport
23
+ attr_accessor :metadata, :primary_email, :customer
24
+
25
+ def initialize(attribute_value_map = {})
26
+ attribute_value_map.map { |(k, v)| public_send("#{k}=", v) }
27
+ self.freeze
28
+ end
29
+
30
+ def ==(object)
31
+ ObjectHelper.equals(self,object)
32
+ end
33
+
34
+ def to_json(state = nil)
35
+ JSON.generate({
36
+ :meta => @metadata,
37
+ :data => {
38
+ :email => @primary_email,
39
+ :customerData => customer
40
+ }
41
+ })
42
+ end
43
+ end
44
+
45
+ class Cart
46
+ attr_accessor :coupon_code, :product_id
47
+ def initialize(attribute_value_map = {})
48
+ attribute_value_map.map { |(k, v)| public_send("#{k}=", v) }
49
+ self.freeze
50
+ end
51
+
52
+ def ==(object)
53
+ ObjectHelper.equals(self,object)
54
+ end
55
+
56
+ def self.from_json(json)
57
+ if json.nil? then return nil end
58
+ Cart.new({
59
+ :coupon_code => json['couponCode'],
60
+ :product_id => json['productId']})
61
+ end
62
+ end
63
+
64
+ class Customer
65
+ include Expressly::Helper
66
+ attr_accessor :first_name, :last_name, :gender, :billing_address_index, :shipping_address_index,
67
+ :company_name, :date_of_birth, :tax_number, :last_updated,
68
+ :online_identity_list, :phone_list, :email_list, :address_list,
69
+ :last_order_date, :number_of_orders
70
+ def initialize(attribute_value_map = {})
71
+ attribute_value_map.map { |(k, v)| public_send("#{k}=", v) }
72
+ self.freeze
73
+ end
74
+
75
+ def gender=(gender)
76
+ Gender::assertValidValue(gender)
77
+ @gender = gender
78
+ end
79
+
80
+ def date_of_birth=(date_of_birth)
81
+ if blank?(date_of_birth) then return end
82
+ @date_of_birth = if date_of_birth.is_a? Date then date_of_birth else Date.parse(date_of_birth) end
83
+ end
84
+
85
+ def last_updated=(last_updated)
86
+ if blank?(last_updated) then return end
87
+ @last_updated = if last_updated.is_a? DateTime then last_updated else DateTime.parse(last_updated) end
88
+ end
89
+
90
+ def last_order_date=(last_order_date)
91
+ if blank?(last_order_date) then return end
92
+ @last_order_date = if last_order_date.is_a? Date then last_order_date else Date.parse(last_order_date) end
93
+ end
94
+
95
+ def ==(object)
96
+ ObjectHelper.equals(self,object)
97
+ end
98
+
99
+ def self.from_json(json)
100
+ Customer.new({
101
+ :first_name => json['firstName'],
102
+ :last_name => json['lastName'],
103
+ :gender => json['gender'],
104
+ :billing_address_index => json['billingAddress'].to_i,
105
+ :shipping_address_index => json['shippingAddress'].to_i,
106
+ :company_name => json['company'],
107
+ :date_of_birth => safe_date_parse(json['dob']),
108
+ :tax_number => json['taxNumber'],
109
+ :last_updated => safe_datetime_parse(json['dateUpdated']),
110
+
111
+ :online_identity_list => OnlineIdentity.from_json_list(json['onlinePresence']),
112
+ :phone_list => Phone.from_json_list(json['phones']),
113
+ :email_list => EmailAddress.from_json_list(json['emails']),
114
+ :address_list => Address.from_json_list(json['addresses']),
115
+
116
+ :last_order_date => safe_date_parse(json['dateLastOrder']),
117
+ :number_of_orders => json['numberOrdered'].to_i
118
+ })
119
+ end
120
+
121
+ def self.safe_date_parse(date)
122
+ date.nil? ? nil : Date.parse(date)
123
+ end
124
+
125
+ def self.safe_datetime_parse(datetime)
126
+ datetime.nil? ? nil : DateTime.parse(datetime)
127
+ end
128
+
129
+ def to_json(state = nil)
130
+ JSON.generate({
131
+ :firstName => @first_name,
132
+ :lastName => @last_name,
133
+ :gender => @gender,
134
+ :billingAddress => @billing_address_index,
135
+ :shippingAddress => @shipping_address_index,
136
+ :company => @company_name,
137
+ :dob => @date_of_birth,
138
+ :taxNumber => @tax_number,
139
+ :onlinePresence => @online_identity_list,
140
+ :dateUpdated => @last_updated,
141
+ :dateLastOrder => @last_order_date,
142
+ :numberOrdered => @number_of_orders,
143
+ :emails => @email_list,
144
+ :phones => @phone_list,
145
+ :addresses => @address_list
146
+ })
147
+ end
148
+ end
149
+
150
+ class Address
151
+ include Expressly::Helper
152
+
153
+ attr_accessor :first_name, :last_name, :address_1, :address_2, :city,
154
+ :company_name, :zip, :phone_index, :address_alias, :state_province, :country
155
+ def initialize(attribute_value_map = {})
156
+ attribute_value_map.map { |(k, v)| public_send("#{k}=", v) }
157
+ self.freeze
158
+ end
159
+
160
+ def phone_index=(phone_index)
161
+ if !blank?(phone_index) && !phone_index.is_a?(Integer) then
162
+ throw("phone_index should be an integer [#{phone_index}]")
163
+ end
164
+ @phone_index = phone_index
165
+ end
166
+
167
+ def ==(object)
168
+ ObjectHelper.equals(self,object)
169
+ end
170
+
171
+ def self.from_json(json)
172
+ Address.new({
173
+ :first_name => json['firstName'],
174
+ :last_name => json['lastName'],
175
+ :address_1 => json['address1'],
176
+ :address_2 => json['address2'],
177
+ :city => json['city'],
178
+ :company_name => json['companyName'],
179
+ :zip => json['zip'],
180
+ :phone_index => json['phone'],
181
+ :address_alias => json['alias'],
182
+ :state_province => json['stateProvince'],
183
+ :country => json['country']
184
+ })
185
+ end
186
+
187
+ def self.from_json_list(json)
188
+ if json.nil? then return [] end
189
+
190
+ list = []
191
+ json.each do |entity|
192
+ list << Address.from_json(entity)
193
+ end
194
+ return list
195
+ end
196
+
197
+ def to_json(state = nil)
198
+ JSON.generate({
199
+ :firstName => @first_name,
200
+ :lastName => @last_name,
201
+ :address1 => @address_1,
202
+ :address2 => @address_2,
203
+ :city => @city,
204
+ :companyName => @company_name,
205
+ :zip => @zip,
206
+ :phone => @phone_index,
207
+ :alias => @address_alias,
208
+ :stateProvince => @state_province,
209
+ :country => @country
210
+ })
211
+ end
212
+ end
213
+
214
+ class Phone
215
+ include Expressly::Helper
216
+ attr_accessor :type, :number, :country_code
217
+ def initialize(attribute_value_map = {})
218
+ attribute_value_map.map { |(k, v)| public_send("#{k}=", v) }
219
+ self.freeze
220
+ end
221
+
222
+ def type=(type)
223
+ PhoneType::assertValidValue(type)
224
+ @type = type
225
+ end
226
+
227
+ def country_code=(country_code)
228
+ if !blank?(country_code) && !country_code.is_a?(Integer) then
229
+ throw("country_code should be an integer [#{country_code}]")
230
+ end
231
+ @country_code = country_code
232
+ end
233
+
234
+ def ==(object)
235
+ ObjectHelper.equals(self,object)
236
+ end
237
+
238
+ def self.from_json(json)
239
+ Phone.new({
240
+ :type => json['type'],
241
+ :number => json['number'],
242
+ :country_code => json['countryCode'].to_i
243
+ })
244
+ end
245
+
246
+ def self.from_json_list(json)
247
+ if json.nil? then return [] end
248
+
249
+ list = []
250
+ json.each do |entity|
251
+ list << Phone.from_json(entity)
252
+ end
253
+ return list
254
+ end
255
+
256
+ def to_json(state = nil)
257
+ JSON.generate({
258
+ :type => @type.to_s,
259
+ :number => @number,
260
+ :countryCode => @country_code
261
+ })
262
+ end
263
+ end
264
+
265
+ class PhoneType < Enumeration
266
+ self.add_item(:Mobile, "M")
267
+ self.add_item(:Home, "H")
268
+ self.add_item(:Work, "W")
269
+ self.add_item(:Landline, "L")
270
+ self.add_item(:Personal, "P")
271
+ end
272
+
273
+ class EmailAddress
274
+ attr_accessor :email, :alias
275
+ def initialize(attribute_value_map = {})
276
+ attribute_value_map.map { |(k, v)| public_send("#{k}=", v) }
277
+ self.freeze
278
+ end
279
+
280
+ def ==(object)
281
+ ObjectHelper.equals(self,object)
282
+ end
283
+
284
+ def self.from_json(json)
285
+ EmailAddress.new({
286
+ :email => json['email'],
287
+ :alias => json['alias']
288
+ })
289
+ end
290
+
291
+ def self.from_json_list(json)
292
+ if json.nil? then return [] end
293
+
294
+ list = []
295
+ json.each do |entity|
296
+ list << EmailAddress.from_json(entity)
297
+ end
298
+ return list
299
+ end
300
+
301
+ def to_json(state = nil)
302
+ JSON.generate({
303
+ :email => @email,
304
+ :alias => @alias
305
+ })
306
+ end
307
+ end
308
+
309
+ class OnlineIdentity
310
+ attr_accessor :type, :identity
311
+ def initialize(attribute_value_map = {})
312
+ attribute_value_map.map { |(k, v)| public_send("#{k}=", v) }
313
+ self.freeze
314
+ end
315
+
316
+ def type=(type)
317
+ OnlineIdentityType::assertValidValue(type)
318
+ @type = type
319
+ end
320
+
321
+ def ==(object)
322
+ ObjectHelper.equals(self,object)
323
+ end
324
+
325
+ def self.from_json(json)
326
+ OnlineIdentity.new({
327
+ :type => json['field'],
328
+ :identity => json['value']
329
+ })
330
+ end
331
+
332
+ def self.from_json_list(json)
333
+ if json.nil? then return [] end
334
+
335
+ list = []
336
+ json.each do |entity|
337
+ list << OnlineIdentity.from_json(entity)
338
+ end
339
+ return list
340
+ end
341
+
342
+ def to_json(state = nil)
343
+ JSON.generate({
344
+ :field => @type.to_s,
345
+ :value => @identity
346
+ })
347
+ end
348
+
349
+ end
350
+
351
+ class OnlineIdentityType < Enumeration
352
+ self.add_item(:PersonalWebsite, 'website')
353
+ self.add_item(:CompanyWebsite, 'company_website')
354
+ self.add_item(:Twitter, 'twitter')
355
+ self.add_item(:Facebook, 'facebook')
356
+ self.add_item(:LinkedIn, 'linkedin')
357
+ self.add_item(:Pintrest, 'pintrest')
358
+ self.add_item(:Instagram, 'instagram')
359
+ end
360
+
361
+ ##
362
+ # Gender valid values
363
+ #
364
+ class Gender < Enumeration
365
+ self.add_item(:Male, "M")
366
+ self.add_item(:Female, "F")
367
+ self.add_item(:Other, "O")
368
+ self.add_item(:NotAvailable, "N")
369
+ end
370
+
371
+ class CustomerStatuses
372
+ attr_reader :existing, :pending, :deleted
373
+ def initialize()
374
+ @existing = []
375
+ @pending = []
376
+ @deleted = []
377
+ end
378
+
379
+ def add_existing(email)
380
+ @existing << email
381
+ end
382
+
383
+ def add_pending(email)
384
+ @pending << email
385
+ end
386
+
387
+ def add_deleted(email)
388
+ @deleted << email
389
+ end
390
+ end
391
+
392
+ class CustomerInvoiceRequest
393
+ attr_reader :email, :from, :to
394
+ def initialize(email, from, to)
395
+ @email = email
396
+ @from = if from.is_a? Date then from else Date.parse(from) end
397
+ @to = if to.is_a? Date then to else Date.parse(to) end
398
+ end
399
+
400
+ def self.from_json(json)
401
+ CustomerInvoiceRequest.new(
402
+ json['email'],
403
+ Date.parse(json['from']),
404
+ Date.parse(json['to']))
405
+ end
406
+
407
+ def self.from_json_list(json)
408
+ if json.nil? then return [] end
409
+ list = []
410
+ json.each do |entity|
411
+ list << CustomerInvoiceRequest.from_json(entity)
412
+ end
413
+ return list
414
+ end
415
+ end
416
+
417
+ class CustomerInvoice
418
+ attr_reader :email
419
+ def initialize(email)
420
+ @email = email
421
+ @orders = []
422
+ @pre_tax_total = 0.0
423
+ @tax = 0.0
424
+ @post_tax_total = 0.0
425
+ end
426
+
427
+ def add_order(order)
428
+ order.freeze
429
+ @orders << order
430
+ @pre_tax_total += order.pre_tax_total.to_f
431
+ @post_tax_total += order.post_tax_total.to_f
432
+ @tax += order.tax.to_f
433
+ end
434
+
435
+ def to_json(state = nil)
436
+ JSON.generate(json_attribute_map)
437
+ end
438
+
439
+ def self.to_json_from_list(invoice_list)
440
+ json_invoices = []
441
+ invoice_list.each do |invoice|
442
+ json_invoices << invoice.json_attribute_map
443
+ end
444
+ JSON.generate({:invoices => json_invoices })
445
+ end
446
+
447
+ def json_attribute_map()
448
+ { :email => @email,
449
+ :orderCount => @orders.length,
450
+ :preTaxTotal => @pre_tax_total,
451
+ :postTaxTotal => @post_tax_total,
452
+ :tax => @tax,
453
+ :orders => @orders}
454
+ end
455
+ end
456
+
457
+ class CustomerOrder
458
+ attr_accessor :order_id, :order_date, :item_count, :coupon_code, :currency, :pre_tax_total, :post_tax_total, :tax
459
+ def initialize(attribute_value_map = {})
460
+ attribute_value_map.map { |(k, v)| public_send("#{k}=", v) }
461
+ end
462
+
463
+ def order_date=(order_date)
464
+ @order_date = if order_date.is_a? Date then order_date else Date.parse(order_date) end
465
+ end
466
+
467
+ def to_json(state = nil)
468
+ JSON.generate({
469
+ :id => @order_id,
470
+ :date => @order_date,
471
+ :itemCount => @item_count.to_i,
472
+ :coupon => @coupon_code,
473
+ :currency => @currency,
474
+ :preTaxTotal => @pre_tax_total.to_f,
475
+ :postTaxTotal => @post_tax_total.to_f,
476
+ :tax => @tax.to_f})
477
+ end
478
+ end
479
+
480
+ end