processout 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -80,24 +80,30 @@ module ProcessOut
80
80
  # Initializes the Plan object
81
81
  # Params:
82
82
  # +client+:: +ProcessOut+ client instance
83
- def initialize(client)
83
+ # +data+:: data that can be used to fill the object
84
+ def initialize(client, data = {})
84
85
  @client = client
85
86
 
86
- @id = ""
87
- @project = nil
88
- @name = ""
89
- @amount = ""
90
- @currency = ""
91
- @metadata = Hash.new
92
- @interval = ""
93
- @trial_period = "0d"
94
- @return_url = ""
95
- @cancel_url = ""
96
- @sandbox = false
97
- @created_at = ""
87
+ @id = data.fetch(:id, "")
88
+ @project = data.fetch(:project, nil)
89
+ @name = data.fetch(:name, "")
90
+ @amount = data.fetch(:amount, "")
91
+ @currency = data.fetch(:currency, "")
92
+ @metadata = data.fetch(:metadata, Hash.new)
93
+ @interval = data.fetch(:interval, "")
94
+ @trial_period = data.fetch(:trial_period, "0d")
95
+ @return_url = data.fetch(:return_url, "")
96
+ @cancel_url = data.fetch(:cancel_url, "")
97
+ @sandbox = data.fetch(:sandbox, false)
98
+ @created_at = data.fetch(:created_at, "")
98
99
 
99
100
  end
100
101
 
102
+ # Create a new Plan using the current client
103
+ def new(data = {})
104
+ Plan.new(@client, data)
105
+ end
106
+
101
107
  # Fills the object with data coming from the API
102
108
  # Params:
103
109
  # +data+:: +Hash+ of data coming from the API
@@ -145,7 +151,7 @@ module ProcessOut
145
151
  # Get all the plans.
146
152
  # Params:
147
153
  # +options+:: +Hash+ of options
148
- def all(options = nil)
154
+ def all(options = {})
149
155
  request = Request.new(@client)
150
156
  path = "/plans"
151
157
  data = {
@@ -158,7 +164,7 @@ module ProcessOut
158
164
  a = Array.new
159
165
  body = response.body
160
166
  for v in body['plans']
161
- tmp = Plan(@client)
167
+ tmp = Plan.new(@client)
162
168
  tmp.fill_with_data(v)
163
169
  a.push(tmp)
164
170
  end
@@ -173,7 +179,7 @@ module ProcessOut
173
179
  # Create a new plan.
174
180
  # Params:
175
181
  # +options+:: +Hash+ of options
176
- def create(options = nil)
182
+ def create(options = {})
177
183
  request = Request.new(@client)
178
184
  path = "/plans"
179
185
  data = {
@@ -206,7 +212,7 @@ module ProcessOut
206
212
  # Params:
207
213
  # +plan_id+:: ID of the plan
208
214
  # +options+:: +Hash+ of options
209
- def find(plan_id, options = nil)
215
+ def find(plan_id, options = {})
210
216
  request = Request.new(@client)
211
217
  path = "/plans/" + CGI.escape(plan_id) + ""
212
218
  data = {
@@ -231,7 +237,7 @@ module ProcessOut
231
237
  # Update the plan. This action won't affect subscriptions already linked to this plan.
232
238
  # Params:
233
239
  # +options+:: +Hash+ of options
234
- def update(options = nil)
240
+ def update(options = {})
235
241
  request = Request.new(@client)
236
242
  path = "/plans/" + CGI.escape(@id) + ""
237
243
  data = {
@@ -259,7 +265,7 @@ module ProcessOut
259
265
  # Delete a plan. Subscriptions linked to this plan won't be affected.
260
266
  # Params:
261
267
  # +options+:: +Hash+ of options
262
- def end(options = nil)
268
+ def end(options = {})
263
269
  request = Request.new(@client)
264
270
  path = "/plans/" + CGI.escape(@id) + ""
265
271
  data = {
@@ -85,25 +85,31 @@ module ProcessOut
85
85
  # Initializes the Product object
86
86
  # Params:
87
87
  # +client+:: +ProcessOut+ client instance
88
- def initialize(client)
88
+ # +data+:: data that can be used to fill the object
89
+ def initialize(client, data = {})
89
90
  @client = client
90
91
 
91
- @id = ""
92
- @project = nil
93
- @url = ""
94
- @name = ""
95
- @amount = ""
96
- @currency = ""
97
- @metadata = Hash.new
98
- @request_email = false
99
- @request_shipping = false
100
- @return_url = ""
101
- @cancel_url = ""
102
- @sandbox = false
103
- @created_at = ""
92
+ @id = data.fetch(:id, "")
93
+ @project = data.fetch(:project, nil)
94
+ @url = data.fetch(:url, "")
95
+ @name = data.fetch(:name, "")
96
+ @amount = data.fetch(:amount, "")
97
+ @currency = data.fetch(:currency, "")
98
+ @metadata = data.fetch(:metadata, Hash.new)
99
+ @request_email = data.fetch(:request_email, false)
100
+ @request_shipping = data.fetch(:request_shipping, false)
101
+ @return_url = data.fetch(:return_url, "")
102
+ @cancel_url = data.fetch(:cancel_url, "")
103
+ @sandbox = data.fetch(:sandbox, false)
104
+ @created_at = data.fetch(:created_at, "")
104
105
 
105
106
  end
106
107
 
108
+ # Create a new Product using the current client
109
+ def new(data = {})
110
+ Product.new(@client, data)
111
+ end
112
+
107
113
  # Fills the object with data coming from the API
108
114
  # Params:
109
115
  # +data+:: +Hash+ of data coming from the API
@@ -154,7 +160,7 @@ module ProcessOut
154
160
  # Create a new invoice from the product.
155
161
  # Params:
156
162
  # +options+:: +Hash+ of options
157
- def invoice(options = nil)
163
+ def invoice(options = {})
158
164
  request = Request.new(@client)
159
165
  path = "/products/" + CGI.escape(@id) + "/invoices"
160
166
  data = {
@@ -166,7 +172,7 @@ module ProcessOut
166
172
 
167
173
  body = response.body
168
174
  body = body["invoice"]
169
- invoice = Invoice(self._client)
175
+ invoice = Invoice.new(@client)
170
176
  return_values.push(invoice.fill_with_data(body))
171
177
 
172
178
 
@@ -176,7 +182,7 @@ module ProcessOut
176
182
  # Get all the products.
177
183
  # Params:
178
184
  # +options+:: +Hash+ of options
179
- def all(options = nil)
185
+ def all(options = {})
180
186
  request = Request.new(@client)
181
187
  path = "/products"
182
188
  data = {
@@ -189,7 +195,7 @@ module ProcessOut
189
195
  a = Array.new
190
196
  body = response.body
191
197
  for v in body['products']
192
- tmp = Product(@client)
198
+ tmp = Product.new(@client)
193
199
  tmp.fill_with_data(v)
194
200
  a.push(tmp)
195
201
  end
@@ -204,7 +210,7 @@ module ProcessOut
204
210
  # Create a new product.
205
211
  # Params:
206
212
  # +options+:: +Hash+ of options
207
- def create(options = nil)
213
+ def create(options = {})
208
214
  request = Request.new(@client)
209
215
  path = "/products"
210
216
  data = {
@@ -236,7 +242,7 @@ module ProcessOut
236
242
  # Params:
237
243
  # +product_id+:: ID of the product
238
244
  # +options+:: +Hash+ of options
239
- def find(product_id, options = nil)
245
+ def find(product_id, options = {})
240
246
  request = Request.new(@client)
241
247
  path = "/products/" + CGI.escape(product_id) + ""
242
248
  data = {
@@ -261,7 +267,7 @@ module ProcessOut
261
267
  # Save the updated product attributes.
262
268
  # Params:
263
269
  # +options+:: +Hash+ of options
264
- def save(options = nil)
270
+ def save(options = {})
265
271
  request = Request.new(@client)
266
272
  path = "/products/" + CGI.escape(@id) + ""
267
273
  data = {
@@ -292,7 +298,7 @@ module ProcessOut
292
298
  # Delete the product.
293
299
  # Params:
294
300
  # +options+:: +Hash+ of options
295
- def delete(options = nil)
301
+ def delete(options = {})
296
302
  request = Request.new(@client)
297
303
  path = "/products/" + CGI.escape(@id) + ""
298
304
  data = {
@@ -38,17 +38,23 @@ module ProcessOut
38
38
  # Initializes the Project object
39
39
  # Params:
40
40
  # +client+:: +ProcessOut+ client instance
41
- def initialize(client)
41
+ # +data+:: data that can be used to fill the object
42
+ def initialize(client, data = {})
42
43
  @client = client
43
44
 
44
- @id = ""
45
- @name = ""
46
- @logo_url = ""
47
- @email = ""
48
- @created_at = ""
45
+ @id = data.fetch(:id, "")
46
+ @name = data.fetch(:name, "")
47
+ @logo_url = data.fetch(:logo_url, "")
48
+ @email = data.fetch(:email, "")
49
+ @created_at = data.fetch(:created_at, "")
49
50
 
50
51
  end
51
52
 
53
+ # Create a new Project using the current client
54
+ def new(data = {})
55
+ Project.new(@client, data)
56
+ end
57
+
52
58
  # Fills the object with data coming from the API
53
59
  # Params:
54
60
  # +data+:: +Hash+ of data coming from the API
@@ -75,7 +81,7 @@ module ProcessOut
75
81
  # Get all the gateway configurations of the project
76
82
  # Params:
77
83
  # +options+:: +Hash+ of options
78
- def gateway_configurations(options = nil)
84
+ def gateway_configurations(options = {})
79
85
  request = Request.new(@client)
80
86
  path = "/projects/" + CGI.escape(@id) + "/gateway-configurations"
81
87
  data = {
@@ -88,7 +94,7 @@ module ProcessOut
88
94
  a = Array.new
89
95
  body = response.body
90
96
  for v in body['gateway_configurations']
91
- tmp = GatewayConfiguration(@client)
97
+ tmp = GatewayConfiguration.new(@client)
92
98
  tmp.fill_with_data(v)
93
99
  a.push(tmp)
94
100
  end
@@ -60,20 +60,26 @@ module ProcessOut
60
60
  # Initializes the Refund object
61
61
  # Params:
62
62
  # +client+:: +ProcessOut+ client instance
63
- def initialize(client)
63
+ # +data+:: data that can be used to fill the object
64
+ def initialize(client, data = {})
64
65
  @client = client
65
66
 
66
- @id = ""
67
- @transaction = nil
68
- @reason = ""
69
- @information = ""
70
- @amount = ""
71
- @metadata = Hash.new
72
- @sandbox = false
73
- @created_at = ""
67
+ @id = data.fetch(:id, "")
68
+ @transaction = data.fetch(:transaction, nil)
69
+ @reason = data.fetch(:reason, "")
70
+ @information = data.fetch(:information, "")
71
+ @amount = data.fetch(:amount, "")
72
+ @metadata = data.fetch(:metadata, Hash.new)
73
+ @sandbox = data.fetch(:sandbox, false)
74
+ @created_at = data.fetch(:created_at, "")
74
75
 
75
76
  end
76
77
 
78
+ # Create a new Refund using the current client
79
+ def new(data = {})
80
+ Refund.new(@client, data)
81
+ end
82
+
77
83
  # Fills the object with data coming from the API
78
84
  # Params:
79
85
  # +data+:: +Hash+ of data coming from the API
@@ -111,7 +117,7 @@ module ProcessOut
111
117
  # +transaction_id+:: ID of the transaction
112
118
  # +refund_id+:: ID of the refund
113
119
  # +options+:: +Hash+ of options
114
- def find(transaction_id, refund_id, options = nil)
120
+ def find(transaction_id, refund_id, options = {})
115
121
  request = Request.new(@client)
116
122
  path = "/transactions/" + CGI.escape(transaction_id) + "/refunds/" + CGI.escape(refund_id) + ""
117
123
  data = {
@@ -137,7 +143,7 @@ module ProcessOut
137
143
  # Params:
138
144
  # +transaction_id+:: ID of the transaction
139
145
  # +options+:: +Hash+ of options
140
- def apply(transaction_id, options = nil)
146
+ def apply(transaction_id, options = {})
141
147
  request = Request.new(@client)
142
148
  path = "/transactions/" + CGI.escape(transaction_id) + "/refunds"
143
149
  data = {
@@ -161,34 +161,40 @@ module ProcessOut
161
161
  # Initializes the Subscription object
162
162
  # Params:
163
163
  # +client+:: +ProcessOut+ client instance
164
- def initialize(client)
164
+ # +data+:: data that can be used to fill the object
165
+ def initialize(client, data = {})
165
166
  @client = client
166
167
 
167
- @id = ""
168
- @project = nil
169
- @plan = nil
170
- @customer = nil
171
- @token = nil
172
- @url = ""
173
- @name = ""
174
- @amount = ""
175
- @currency = ""
176
- @metadata = Hash.new
177
- @interval = ""
178
- @trial_end_at = ""
179
- @activated = false
180
- @active = false
181
- @canceled = false
182
- @cancellation_reason = ""
183
- @pending_cancellation = false
184
- @cancel_at = ""
185
- @return_url = ""
186
- @cancel_url = ""
187
- @sandbox = false
188
- @created_at = ""
189
- @activated_at = ""
190
- @iterate_at = ""
191
-
168
+ @id = data.fetch(:id, "")
169
+ @project = data.fetch(:project, nil)
170
+ @plan = data.fetch(:plan, nil)
171
+ @customer = data.fetch(:customer, nil)
172
+ @token = data.fetch(:token, nil)
173
+ @url = data.fetch(:url, "")
174
+ @name = data.fetch(:name, "")
175
+ @amount = data.fetch(:amount, "")
176
+ @currency = data.fetch(:currency, "")
177
+ @metadata = data.fetch(:metadata, Hash.new)
178
+ @interval = data.fetch(:interval, "")
179
+ @trial_end_at = data.fetch(:trial_end_at, "")
180
+ @activated = data.fetch(:activated, false)
181
+ @active = data.fetch(:active, false)
182
+ @canceled = data.fetch(:canceled, false)
183
+ @cancellation_reason = data.fetch(:cancellation_reason, "")
184
+ @pending_cancellation = data.fetch(:pending_cancellation, false)
185
+ @cancel_at = data.fetch(:cancel_at, "")
186
+ @return_url = data.fetch(:return_url, "")
187
+ @cancel_url = data.fetch(:cancel_url, "")
188
+ @sandbox = data.fetch(:sandbox, false)
189
+ @created_at = data.fetch(:created_at, "")
190
+ @activated_at = data.fetch(:activated_at, "")
191
+ @iterate_at = data.fetch(:iterate_at, "")
192
+
193
+ end
194
+
195
+ # Create a new Subscription using the current client
196
+ def new(data = {})
197
+ Subscription.new(@client, data)
192
198
  end
193
199
 
194
200
  # Fills the object with data coming from the API
@@ -274,7 +280,7 @@ module ProcessOut
274
280
  # Get the customer owning the subscription.
275
281
  # Params:
276
282
  # +options+:: +Hash+ of options
277
- def customer(options = nil)
283
+ def customer(options = {})
278
284
  request = Request.new(@client)
279
285
  path = "/subscriptions/" + CGI.escape(@id) + "/customers"
280
286
  data = {
@@ -286,7 +292,7 @@ module ProcessOut
286
292
 
287
293
  body = response.body
288
294
  body = body["customer"]
289
- customer = Customer(self._client)
295
+ customer = Customer.new(@client)
290
296
  return_values.push(customer.fill_with_data(body))
291
297
 
292
298
 
@@ -296,7 +302,7 @@ module ProcessOut
296
302
  # Get the discounts applied to the subscription.
297
303
  # Params:
298
304
  # +options+:: +Hash+ of options
299
- def discounts(options = nil)
305
+ def discounts(options = {})
300
306
  request = Request.new(@client)
301
307
  path = "/subscriptions/" + CGI.escape(@id) + "/discounts"
302
308
  data = {
@@ -309,7 +315,7 @@ module ProcessOut
309
315
  a = Array.new
310
316
  body = response.body
311
317
  for v in body['discounts']
312
- tmp = Discount(@client)
318
+ tmp = Discount.new(@client)
313
319
  tmp.fill_with_data(v)
314
320
  a.push(tmp)
315
321
  end
@@ -325,7 +331,7 @@ module ProcessOut
325
331
  # Params:
326
332
  # +discount_id+:: ID of the discount or coupon to be removed from the subscription
327
333
  # +options+:: +Hash+ of options
328
- def remove_discount(discount_id, options = nil)
334
+ def remove_discount(discount_id, options = {})
329
335
  request = Request.new(@client)
330
336
  path = "/subscriptions/" + CGI.escape(@id) + "/discounts/" + CGI.escape(discount_id) + ""
331
337
  data = {
@@ -349,7 +355,7 @@ module ProcessOut
349
355
  # Get the subscriptions past transactions.
350
356
  # Params:
351
357
  # +options+:: +Hash+ of options
352
- def transactions(options = nil)
358
+ def transactions(options = {})
353
359
  request = Request.new(@client)
354
360
  path = "/subscriptions/" + CGI.escape(@id) + "/transactions"
355
361
  data = {
@@ -362,7 +368,7 @@ module ProcessOut
362
368
  a = Array.new
363
369
  body = response.body
364
370
  for v in body['transactions']
365
- tmp = Transaction(@client)
371
+ tmp = Transaction.new(@client)
366
372
  tmp.fill_with_data(v)
367
373
  a.push(tmp)
368
374
  end
@@ -377,7 +383,7 @@ module ProcessOut
377
383
  # Get all the subscriptions.
378
384
  # Params:
379
385
  # +options+:: +Hash+ of options
380
- def all(options = nil)
386
+ def all(options = {})
381
387
  request = Request.new(@client)
382
388
  path = "/subscriptions"
383
389
  data = {
@@ -390,7 +396,7 @@ module ProcessOut
390
396
  a = Array.new
391
397
  body = response.body
392
398
  for v in body['subscriptions']
393
- tmp = Subscription(@client)
399
+ tmp = Subscription.new(@client)
394
400
  tmp.fill_with_data(v)
395
401
  a.push(tmp)
396
402
  end
@@ -406,7 +412,7 @@ module ProcessOut
406
412
  # Params:
407
413
  # +customer_id+:: ID of the customer
408
414
  # +options+:: +Hash+ of options
409
- def create(customer_id, options = nil)
415
+ def create(customer_id, options = {})
410
416
  request = Request.new(@client)
411
417
  path = "/subscriptions"
412
418
  data = {
@@ -441,7 +447,7 @@ module ProcessOut
441
447
  # +customer_id+:: ID of the customer
442
448
  # +plan_id+:: ID of the plan
443
449
  # +options+:: +Hash+ of options
444
- def create_from_plan(customer_id, plan_id, options = nil)
450
+ def create_from_plan(customer_id, plan_id, options = {})
445
451
  request = Request.new(@client)
446
452
  path = "/subscriptions"
447
453
  data = {
@@ -476,7 +482,7 @@ module ProcessOut
476
482
  # Params:
477
483
  # +subscription_id+:: ID of the subscription
478
484
  # +options+:: +Hash+ of options
479
- def find(subscription_id, options = nil)
485
+ def find(subscription_id, options = {})
480
486
  request = Request.new(@client)
481
487
  path = "/subscriptions/" + CGI.escape(subscription_id) + ""
482
488
  data = {
@@ -502,7 +508,7 @@ module ProcessOut
502
508
  # Params:
503
509
  # +prorate+:: Define if proration should be done when updating the plan
504
510
  # +options+:: +Hash+ of options
505
- def update(prorate, options = nil)
511
+ def update(prorate, options = {})
506
512
  request = Request.new(@client)
507
513
  path = "/subscriptions/" + CGI.escape(@id) + ""
508
514
  data = {
@@ -529,7 +535,7 @@ module ProcessOut
529
535
  # +plan_id+:: ID of the new plan to be applied on the subscription
530
536
  # +prorate+:: Define if proration should be done when updating the plan
531
537
  # +options+:: +Hash+ of options
532
- def update_plan(plan_id, prorate, options = nil)
538
+ def update_plan(plan_id, prorate, options = {})
533
539
  request = Request.new(@client)
534
540
  path = "/subscriptions/" + CGI.escape(@id) + ""
535
541
  data = {
@@ -555,7 +561,7 @@ module ProcessOut
555
561
  # Params:
556
562
  # +source+:: Source to be applied on the subscription and used to pay future invoices. Can be a card, a token or a gateway request
557
563
  # +options+:: +Hash+ of options
558
- def apply_source(source, options = nil)
564
+ def apply_source(source, options = {})
559
565
  request = Request.new(@client)
560
566
  path = "/subscriptions/" + CGI.escape(@id) + ""
561
567
  data = {
@@ -580,7 +586,7 @@ module ProcessOut
580
586
  # Params:
581
587
  # +cancellation_reason+:: Cancellation reason
582
588
  # +options+:: +Hash+ of options
583
- def cancel(cancellation_reason, options = nil)
589
+ def cancel(cancellation_reason, options = {})
584
590
  request = Request.new(@client)
585
591
  path = "/subscriptions/" + CGI.escape(@id) + ""
586
592
  data = {
@@ -606,7 +612,7 @@ module ProcessOut
606
612
  # +cancel_at+:: Cancellation date, in the form of a string
607
613
  # +cancellation_reason+:: Cancellation reason
608
614
  # +options+:: +Hash+ of options
609
- def cancel_at(cancel_at, cancellation_reason, options = nil)
615
+ def cancel_at(cancel_at, cancellation_reason, options = {})
610
616
  request = Request.new(@client)
611
617
  path = "/subscriptions/" + CGI.escape(@id) + ""
612
618
  data = {