maropost-api 0.2.0 → 0.2.1
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 +4 -4
- data/README.md +120 -120
- data/lib/maropost_api/products_and_revenue.rb +91 -47
- data/lib/maropost_api/relational_tables.rb +39 -8
- data/lib/maropost_api/transactional_campaigns.rb +3 -1
- data/lib/maropost_api/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 211695842efe51cb9cad9fd34f899de04eb3e7a8
|
4
|
+
data.tar.gz: 0af58ab0257785ccf166461f399cedfe4f311e79
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0dddbf3b9edcb4d6956ed192ca00a3a0d182db059e0d09bbb75f669796988c1f41a2e5fceaf06d14a55fd8bf7c9a5d35e19fcc43f27705a94d1f5a3ad60fa5af
|
7
|
+
data.tar.gz: fa457ec6d11c2d2ab4b403eb1aefbac4093c8971861cf0eb428935df6654b72f1a9b7a90201822630760b76e739f47d5e2cf7247dde0bca37a063794f572e46a
|
data/README.md
CHANGED
@@ -15,19 +15,20 @@ service, execute:
|
|
15
15
|
|
16
16
|
reports = MaropostApi::Reports.new(account_id, auth_token)
|
17
17
|
result = reports.Get(1);
|
18
|
-
if result.success {
|
18
|
+
if (result.success) {
|
19
19
|
myReports = result.data;
|
20
20
|
}
|
21
21
|
|
22
|
-
The result object contains
|
22
|
+
The result object contains three fields:
|
23
23
|
|
24
24
|
- `success` (bool)
|
25
25
|
- `errors` (object)
|
26
|
+
- `data` (Hash|Mixed)
|
26
27
|
|
27
28
|
If `success` is `false`, then `errors` will have details about the reason for
|
28
29
|
failure. If `errors` is not `nil`, then `success` will always be `false`.
|
29
30
|
|
30
|
-
The object
|
31
|
+
The object also contains accessor, `data`, which contains whatever
|
31
32
|
data the operation itself provides. Some operations, such as `delete()`
|
32
33
|
operations, might not provide any data.
|
33
34
|
|
@@ -39,7 +40,7 @@ The specific APIs contained are:
|
|
39
40
|
- [Transactional Campaigns](#transactional-campaigns)
|
40
41
|
- [Contacts](#contacts)
|
41
42
|
- [Journeys](#journeys)
|
42
|
-
- [
|
43
|
+
- [Products and Revenue](#products-and-revenue)
|
43
44
|
- [Relational Table Rows](#relational-table-rows)
|
44
45
|
- [Reports](#reports)
|
45
46
|
|
@@ -94,26 +95,28 @@ The specific APIs contained are:
|
|
94
95
|
### Available Methods:
|
95
96
|
- `create_ab_test(name, from_email, address, language, campaign_groups_attributes,`
|
96
97
|
`commit, sendAt, brand_id: nil, suppressed_list_ids: [],`
|
97
|
-
`suppressed_journey_ids: [], suppressed_segment_ids: [],
|
98
|
+
`suppressed_journey_ids: [], suppressed_segment_ids: [], email_preview_link: nil,`
|
98
99
|
`decided_by: nil, lists: [], ctags: [], segments: [])`
|
99
100
|
* Creates an Ab Test campaign
|
100
101
|
- `name`: name of the new campaign
|
101
102
|
- `from_email`: default sender email address for campaign emails
|
102
103
|
- `address`: default physical address included on campaign emails
|
103
104
|
- `language`: ISO 639-1 language code (e.g., "en"). 2 characters
|
104
|
-
- `campaign_groups_attributes`: array of attributes. Each attribute is itself a hash with the following
|
105
|
+
- `campaign_groups_attributes`: array of attributes. Each attribute is itself a hash with the following fields (all strings):
|
105
106
|
- `name`: name of the group
|
106
107
|
- `content_id`: content ID
|
107
108
|
- `subject`: subject line of emails
|
108
109
|
- `from_name`: "from name" on emails
|
109
110
|
- `percentage`: percentage of emails that should be send with these settings
|
111
|
+
- `preheader`:
|
112
|
+
- `sendAt`: DateTime string having the format `YYYY-MM-DD HH:mm:ss`
|
110
113
|
- `commit`: allowed values: 'Save as Draft' or 'Send Test' or 'Schedule'
|
111
114
|
- `sendAt`: should be in "yyyy-mm-dd %H:%M:%S" where %H - Hour of the day, 24-hour clock (00..23), %M - Minute of the hour (00..59), %S - Second of the minute (00..60)
|
112
115
|
- `brand_id`: brand ID as a string
|
113
116
|
- `suppressed_list_ids`: array of list IDs in string format
|
114
117
|
- `suppressed_journey_ids`: array of journey IDs in string format
|
115
118
|
- `suppressed_segment_ids`: array of segment IDs in string format
|
116
|
-
- `email_preview_link`:
|
119
|
+
- `email_preview_link`: "0" for false. "1" for true.
|
117
120
|
- `decided_by`: allowed values: ('TopChoice' for Top Choices) or ('Opens' for Highest Open Rate) or ('Clicks' for Highest Click Rate) or ('Manual' for Manual Selection) or ('click_to_open' for Highest Click-to-Open Rate) or ('conversions' for Highest Conversion Rate)
|
118
121
|
- `lists`: array of list IDs in string format
|
119
122
|
- `ctags`: array of tags in string format
|
@@ -132,17 +135,17 @@ The specific APIs contained are:
|
|
132
135
|
- `create(name, subject, preheader, from_name, from_email, reply_to,`
|
133
136
|
`content_id, email_preview_link, address, language, add_ctags)`
|
134
137
|
* Creates a Transactional Campaign
|
135
|
-
- `name
|
136
|
-
- `subject
|
137
|
-
- `preheader
|
138
|
-
- `from_name
|
139
|
-
- `from_email
|
140
|
-
- `reply_to
|
141
|
-
- `content_id
|
142
|
-
- `email_preview_link`
|
143
|
-
- `address
|
144
|
-
- `language
|
145
|
-
- `add_ctags
|
138
|
+
- `name`: campaign name
|
139
|
+
- `subject`: campaign subject
|
140
|
+
- `preheader`: campaign preheader
|
141
|
+
- `from_name`: sender name in the email
|
142
|
+
- `from_email`: sender email address
|
143
|
+
- `reply_to`: reply-to email address
|
144
|
+
- `content_id`:
|
145
|
+
- `email_preview_link`: boolean. `true` to send email; `false` otherwise.
|
146
|
+
- `address`: physical address
|
147
|
+
- `language`: ISO 639-1 language code (e.g., "en"). 2 characters
|
148
|
+
- `add_ctags`: array of campaign tags
|
146
149
|
|
147
150
|
- `send_email(campaign_id,
|
148
151
|
content: {},
|
@@ -160,7 +163,7 @@ The specific APIs contained are:
|
|
160
163
|
* Sends a transactional campaign email to a recipient contact. Sender's information will be automatically fetched from the transactional campaign, unless provided in the function arguments.
|
161
164
|
- `campaign_id`: must be a campaign that already exists when you call `get()`. If you don't have one, first call `create(...)`.
|
162
165
|
- `content`: hash with the following fields: `name`, `html_part`, `text_part`
|
163
|
-
- `
|
166
|
+
- `ignore_dnm`: If true, ignores the Do Not Mail list for the recipient contact.
|
164
167
|
- `contact`: hash defining the recipient with the following fields: `email`, `first_name`, `last_name`, `custom_field`
|
165
168
|
- `custom_field`: is a hash of the custom fields.
|
166
169
|
- `send_time`: hash with the following string fields: `hour` ("1" - "12") and `minute` ("00" - "59")
|
@@ -185,7 +188,7 @@ The specific APIs contained are:
|
|
185
188
|
|
186
189
|
- `get_for_email(email)`
|
187
190
|
* Gets the contact according to email address
|
188
|
-
|
191
|
+
* `email`: email address of the contact
|
189
192
|
|
190
193
|
- `get_opens(contact_id, page)`
|
191
194
|
* Gets the list of opens for the specified contact
|
@@ -240,52 +243,43 @@ The specific APIs contained are:
|
|
240
243
|
- `remove_tags`: tags to remove from the contact. Simple array of tag names (strings).
|
241
244
|
- `remove_from_dnm`: Set this true to subscribe contact to the list, and remove it from DNM.
|
242
245
|
- `subscribe`: true to subscribe the contact to the list; false otherwise.
|
243
|
-
|
244
|
-
- `
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
- `remove_from_dnm`: set this true to subscribe contact to the list, and remove it from DNM
|
258
|
-
- `subscribe`: true to subscribe the contact to the list; false otherwise.
|
259
|
-
|
260
|
-
- `create_or_update_for_list_and_workflows(email, first_name: nil, last_name: nil, phone: nil, fax: nil, uid: nil,`
|
261
|
-
`custom_field: nil, add_tags: nil, remove_tags: nil, remove_from_dnm: false, subscribe_list_ids: nil,`
|
262
|
-
`unsubscribe_list_ids: nil, unsubscribe_workflow_ids: nil, unsubscribe_campaign: nil)`
|
246
|
+
|
247
|
+
- `create_or_update_for_lists_and_workflows(
|
248
|
+
email,
|
249
|
+
first_name,
|
250
|
+
last_name,
|
251
|
+
phone,
|
252
|
+
fax,
|
253
|
+
uid = nil,
|
254
|
+
custom_field = {},
|
255
|
+
add_tags = [],
|
256
|
+
remove_tags = [],
|
257
|
+
remove_from_dnm = true,
|
258
|
+
**options
|
259
|
+
)`
|
263
260
|
* Creates or updates Contact
|
264
261
|
- Multiple lists can be subscribed, unsubscribed.
|
265
262
|
- Multiple workflows can be unsubscribed.
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
- `unsubscribe_list_ids`: simple array of IDs of Lists to unsubscribe the contact from
|
278
|
-
- `unsubscribe_workflow_ids`: simple array of list of IDs of workflows to unsubscribe the contact from
|
279
|
-
- `unsubscribe_campaign`: campaign_id to unsubscribe the contact from
|
263
|
+
* `email`: [String] must be an email
|
264
|
+
* `first_name`: [String] Contact First Name
|
265
|
+
* `last_name`: [String] Contact Last Name
|
266
|
+
* `phone`: [String] Contact's phone number
|
267
|
+
* `fax`: [String] Contacts' fax number
|
268
|
+
* `uid`: [String] Unique identifier
|
269
|
+
* `custom_field`: [Hash] list of custom_fields addable for the new contact
|
270
|
+
* `add_tags`: [Array] list of tags to be added to the contact
|
271
|
+
* `remove_tags`: [Array] list of tags to be removed from the contact
|
272
|
+
* `remove_from_dnm`: [Boolean] decides whether to remove contact from dnm or not
|
273
|
+
* `options`: [Hash] Key value pairs containing other different properties for the new contact
|
280
274
|
|
281
275
|
- `delete_from_all_lists(email)`
|
282
276
|
* Deletes specified contact from all lists
|
283
|
-
|
277
|
+
* `email`: email address of the contact
|
284
278
|
|
285
|
-
- `delete_from_lists(contact_id,
|
279
|
+
- `delete_from_lists(contact_id, lists_to_delete_from)`
|
286
280
|
* Deletes the specified contact from the specified lists
|
287
|
-
|
288
|
-
|
281
|
+
* `contact_id`: id of the contact
|
282
|
+
* `lists_to_delete_from`: simple array of ids of the lists
|
289
283
|
|
290
284
|
- `delete_contact_for_uid(uid)`
|
291
285
|
* Deletes contact having the specified UID
|
@@ -298,8 +292,9 @@ The specific APIs contained are:
|
|
298
292
|
|
299
293
|
- `unsubscribe_all(contact_field_value, contact_field_name: "email")`
|
300
294
|
* Unsubscribes contact having the specified field name/value.
|
301
|
-
|
302
|
-
|
295
|
+
* `contact_field_value`: the value of the field for the contact(s) being unsubscribed
|
296
|
+
* `contact_field_name`: the name of the field being checked for the value. At present, the
|
297
|
+
accepted field names are: 'email' or 'uid'
|
303
298
|
|
304
299
|
## Journeys
|
305
300
|
|
@@ -323,44 +318,53 @@ The specific APIs contained are:
|
|
323
318
|
- `journey_id`: get contacts filtered with journey_id
|
324
319
|
- `page` : page # (>= 1). Up to 200 records returned per page.
|
325
320
|
|
326
|
-
- `stop_all(contact_id
|
321
|
+
- `stop_all(contact_id: nil, uid: nil, email_recipient: nil)`
|
327
322
|
* Stops all journeys, filtered for the matching parameters
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
- `page`: page # (>= 1). Up to 200 record returned per page.
|
323
|
+
* `contact_id:`: this filter ignored unless greater than 0
|
324
|
+
* `uid:`: this filter ignored if null
|
325
|
+
* `email_recipient:`: this filter ignored if null
|
332
326
|
|
333
|
-
- `
|
327
|
+
- `pause_for_contact(journey_id, contact_id)`
|
334
328
|
* Pause the specified journey for the specified contact
|
335
329
|
- `journey_id`: journey to pause
|
336
330
|
- `contact_id`: pause journey for specified contact id
|
337
331
|
|
338
|
-
- `
|
332
|
+
- `pause_for_uid(journey_id, uid)`
|
339
333
|
* Pause the specified journey for the contact having the specified UID
|
340
334
|
- `journey_id`: journey to pause
|
341
335
|
- `uid`: pause journey for specified uid
|
342
336
|
|
343
|
-
- `
|
344
|
-
* Reset the specified journey for the specified active/paused contact.
|
337
|
+
- `reset_for_contact(journey_id, contact_id)`
|
338
|
+
* Reset the specified journey for the specified active/paused contact.
|
339
|
+
Resetting a contact to the beginning of the journeys will result in
|
340
|
+
sending of the same journey campaigns as originally sent.
|
345
341
|
- `journey_id`: journey to reset
|
346
342
|
- `contact_id`: reset journey for specified contact id
|
347
343
|
|
348
|
-
- `
|
349
|
-
*
|
344
|
+
- `reset_for_uid(journey_id, uid)`
|
345
|
+
* Reset the specified journey for the active/paused contact having the
|
346
|
+
specified UID. Resetting a contact to the beginning of the journeys
|
347
|
+
will result in sending of the same journey campaigns as originally sent.
|
350
348
|
- `journey_id`: journey to reset
|
351
349
|
- `uid`: uid of contact to reset journey
|
352
350
|
|
353
|
-
- `
|
354
|
-
|
351
|
+
- `start_for_contact(journey_id, contact_id)`
|
352
|
+
* Restarts a journey for a paused contact. Adds a new contact in
|
353
|
+
journey. Retriggers the journey for a contact who has finished its
|
354
|
+
journey once. (To retrigger, *make sure* that "Retrigger Journey" option
|
355
|
+
is enabled.)
|
355
356
|
- `journey_id`: journey to start
|
356
357
|
- `contact_id`: contact id of contact to start journey
|
357
358
|
|
358
|
-
- `
|
359
|
-
|
359
|
+
- `start_for_uid(journey_id, uid)`
|
360
|
+
* Restarts a journey for a paused contact having the specified UID.
|
361
|
+
Adds a new contact in journey. Retriggers the journey for a contact
|
362
|
+
who has finished its journey once. (To retrigger, *make sure* that
|
363
|
+
"Retrigger Journey" option is enabled.)
|
360
364
|
- 'journey_id': journey to start
|
361
365
|
- 'uid': uid of contact to start journey
|
362
366
|
|
363
|
-
##
|
367
|
+
## Products and Revenue
|
364
368
|
|
365
369
|
### Instantiation:
|
366
370
|
|
@@ -398,34 +402,28 @@ The specific APIs contained are:
|
|
398
402
|
- `campaign_id`: campaign id
|
399
403
|
- `coupon_code`: coupon code
|
400
404
|
|
401
|
-
- `update_order_for_original_order_id(original_order_id
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
405
|
+
- `update_order_for_original_order_id(original_order_id, order: {})`
|
406
|
+
* Updates an existing eCommerce order using unique original_order_id if the details are changed due to partial
|
407
|
+
return or some other update.
|
408
|
+
* `original_order_id:`: [String] Orginal Order Id of the Order
|
409
|
+
* `order:`: [Hash] Contains the following fields:
|
410
|
+
- `order_date_time`: uses the format: YYYY-MM-DDTHH:MM:SS-05:00
|
411
|
+
- `order_status`: order status
|
412
|
+
- `order_items`: must contain at least one order_item.
|
413
|
+
- `campaign_id`: campaign id
|
414
|
+
- `coupon_code`: coupon code
|
415
|
+
|
416
|
+
- `update_order_for_order_id(order_id, order: {})`
|
417
|
+
* Updates an existing eCommerce order using unique order_id if the details are changed due to partial return or
|
418
|
+
* some other update.
|
419
|
+
* `original_order_id:`: [String] Original Order Id of the Order
|
420
|
+
* `order:`: [Hash] Contains the following fields:
|
421
|
+
- `order_date`: uses the format: YYYY-MM-DDTHH:MM:SS-05:00
|
422
|
+
- `order_status`: order status
|
423
|
+
- `order_items`: must contain at least one order_item.
|
424
|
+
- `campaign_id`: campaign id
|
425
|
+
- `coupon_code`: coupon code
|
414
426
|
|
415
|
-
- `update_order_for_order_id(order_id,`
|
416
|
-
`order_date_time,`
|
417
|
-
`order_status,`
|
418
|
-
`order_items,`
|
419
|
-
`campaign_id: nil,`
|
420
|
-
`coupon_code: nil)`
|
421
|
-
* Updates an existing eCommerce order using unique order_id if the details are changed due to partial return or some other update.
|
422
|
-
- `order_id`: matches the Maropost order_id field of the order
|
423
|
-
- `order_date_time`: uses the format: YYYY-MM-DDTHH:MM:SS-05:00
|
424
|
-
- `order_status`: order status
|
425
|
-
- `order_items`: must contain at least one order_item.
|
426
|
-
- `campaign_id`: campaign id
|
427
|
-
- `coupon_code`: coupon code
|
428
|
-
|
429
427
|
- `delete_for_original_order_id(original_order_id)`
|
430
428
|
* Deletes the complete eCommerce order if the order is cancelled or returned
|
431
429
|
- `original_order_id` matches the original_order_id field of the order
|
@@ -435,14 +433,16 @@ The specific APIs contained are:
|
|
435
433
|
- `id`: Maropost order_id
|
436
434
|
|
437
435
|
- `delete_products_for_original_order_id(original_order_id, product_ids)`
|
438
|
-
* Deletes the specified product(s) from a complete eCommerce order if
|
439
|
-
|
440
|
-
|
436
|
+
* Deletes the specified product(s) from a complete eCommerce order if
|
437
|
+
the product(s) is cancelled or returned
|
438
|
+
* `original_order_id`: matches the original_order_id field of the order
|
439
|
+
* `product_ids`: the product(s) to delete from the order
|
441
440
|
|
442
|
-
- `delete_products_for_order_id(
|
443
|
-
* Deletes the specified product(s) from a complete eCommerce order if
|
444
|
-
|
445
|
-
|
441
|
+
- `delete_products_for_order_id(order_id, product_ids)`
|
442
|
+
* Deletes the specified product(s) from a complete eCommerce order if
|
443
|
+
the product(s) is cancelled or returned
|
444
|
+
* `order_ids`: Maropost order_id
|
445
|
+
* `product_ids`: the product(s) to delete from the order
|
446
446
|
|
447
447
|
## Relational Table Rows
|
448
448
|
|
@@ -470,21 +470,21 @@ To switch tables, you do not need to re-instantiate the service. Simply update t
|
|
470
470
|
|
471
471
|
- `create(key_value_col, *key_value_cols)`
|
472
472
|
* Adds a record to the Relational Table
|
473
|
-
* `key_value_col`: object hash
|
474
|
-
|
475
|
-
|
473
|
+
* `key_value_col`: object hash representing the unique identifier of the record to add.
|
474
|
+
* hash key represents the column name and the hash value is the column value.
|
475
|
+
* `*key_value_cols`: other hashes representing other columns to add
|
476
476
|
|
477
477
|
- `update(key_value_col, *key_value_cols)`
|
478
478
|
* Updates a record in the Relational Table.
|
479
|
-
* `key_value_col`: object hash
|
480
|
-
|
481
|
-
|
479
|
+
* `key_value_col`: object hash representing the unique identifier of the record to add.
|
480
|
+
* hash key represents the column name and the hash value is the column value.
|
481
|
+
* `*key_value_cols`: other hashes representing other columns to add
|
482
482
|
|
483
483
|
- `upsert(key_value_col, *key_value_cols)`
|
484
484
|
* Creates or updates a record in the Relational Table.
|
485
|
-
* `key_value_col`: object hash
|
486
|
-
|
487
|
-
|
485
|
+
* `key_value_col`: object hash representing the unique identifier of the record to add.
|
486
|
+
* hash key represents the column name and the hash value is the column value.
|
487
|
+
* `*key_value_cols`: other hashes representing other columns to add
|
488
488
|
|
489
489
|
- `delete(unique_field_name, value)`
|
490
490
|
* Deletes the given record of the Relational Table
|
@@ -610,6 +610,6 @@ To switch tables, you do not need to re-instantiate the service. Simply update t
|
|
610
610
|
* `to`: end of date range filter
|
611
611
|
* `per`: gets the mentioned number of reports
|
612
612
|
|
613
|
-
- `
|
613
|
+
- `get_journeys(page)`
|
614
614
|
* returns the list of all Journeys
|
615
615
|
* `page`: page # (>= 1). Up to 200 records returned per page.
|
@@ -1,40 +1,65 @@
|
|
1
1
|
require 'maropost_api/custom_types/order_item'
|
2
2
|
|
3
3
|
module MaropostApi
|
4
|
-
|
4
|
+
|
5
|
+
##
|
6
|
+
# Contains methods that will create, update, read and delete the services
|
7
|
+
# provided in the Product and Revenue Api
|
5
8
|
class ProductsAndRevenue
|
6
|
-
|
9
|
+
##
|
10
|
+
# Creates a new instance of Reports class.
|
11
|
+
# @param account [Integer] is authentic user account id (Integer) provided by maropost.com
|
12
|
+
# @param api_key [String] is the auth token (String) that is validated on the server to authenticate the user
|
7
13
|
def initialize(account = ENV["ACCOUNT"], api_key = ENV["API_KEY"])
|
8
14
|
MaropostApi.instance_variable_set(:@api_key, api_key)
|
9
15
|
MaropostApi.instance_variable_set(:@account, account)
|
10
16
|
end
|
11
|
-
|
17
|
+
|
18
|
+
##
|
19
|
+
# Gets the order for the specified id
|
20
|
+
# @param id [Integer] unique identifier of the order
|
12
21
|
def get_order(id)
|
13
22
|
full_path = full_resource_path("/find")
|
14
23
|
query_params = MaropostApi.set_query_params({"where[id]" => id})
|
15
|
-
|
24
|
+
|
16
25
|
MaropostApi.get_result(full_path, query_params)
|
17
26
|
end
|
18
|
-
|
27
|
+
|
28
|
+
##
|
29
|
+
# gets the order for the specified original order id
|
30
|
+
# @param original_order_id [String] A unique identifier that's not changed since the creation date
|
19
31
|
def get_order_for_original_order_id(original_order_id)
|
20
32
|
full_path = full_resource_path("/#{original_order_id}")
|
21
33
|
query_params = MaropostApi.set_query_params
|
22
|
-
|
34
|
+
|
23
35
|
MaropostApi.get_result(full_path, query_params)
|
24
36
|
end
|
25
|
-
|
37
|
+
|
38
|
+
##
|
39
|
+
# Creates a new order from the given parameters
|
40
|
+
# @param require_unique [Boolean] validates that the order has a unique original_order_id for the given contact.
|
41
|
+
# @param contact [Hash] Named parameter, which if exists, must contain :email as its key
|
42
|
+
# @param order [Hash] Named parameter, which must contain :order_date, :order_status, :original_order_id, :order_items as its keys
|
43
|
+
# @param @order_items [OrderItem] Custom Type containing key value pair to reference an order item
|
44
|
+
# @param add_tags [Array] List of string tags to be added in the new order
|
45
|
+
# @param remove_tags [Array] List of string tags to be removed from the new order
|
46
|
+
# @param uid [String] Unique Identifier
|
47
|
+
# @param list_ids [String|CSV] A csv list fo list ids
|
48
|
+
# @param grand_total [Float] An amount referencing the total of the order
|
49
|
+
# @param campaing_id [Integer] ID of the Campaign the order belongs to
|
50
|
+
# @param coupon_code [String]
|
26
51
|
def create_order(
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
52
|
+
require_unique,
|
53
|
+
contact: {},
|
54
|
+
order: {},
|
55
|
+
order_items: [],
|
56
|
+
add_tags: [],
|
57
|
+
remove_tags: [],
|
58
|
+
uid: nil,
|
59
|
+
list_ids: nil,
|
60
|
+
grand_total: nil,
|
61
|
+
campaign_id: nil,
|
62
|
+
coupon_code: nil
|
38
63
|
)
|
39
64
|
# required contacts fields to check for
|
40
65
|
[:email,].each do |contact_field|
|
@@ -59,15 +84,19 @@ module MaropostApi
|
|
59
84
|
params[:grand_total] = grand_total
|
60
85
|
params[:campaign_id] = campaign_id
|
61
86
|
params[:coupon_code] = coupon_code
|
62
|
-
|
87
|
+
|
63
88
|
full_path = full_resource_path
|
64
|
-
|
89
|
+
|
65
90
|
MaropostApi.post_result(full_path, {"order" => params})
|
66
91
|
end
|
67
|
-
|
92
|
+
|
93
|
+
##
|
94
|
+
# updates an order fo the given original order id
|
95
|
+
# @param original_order_id [String] Orginal Order Id of the Order
|
96
|
+
# @param order [Hash] Key value pairs that must contain at least :order_date, :order_status and :order_items as its keys
|
68
97
|
def update_order_for_original_order_id(original_order_id, order: {})
|
69
98
|
raise ArgumentError.new('original_order_id is required') if original_order_id.nil?
|
70
|
-
|
99
|
+
|
71
100
|
[:order_date, :order_status, :order_items].each do |f|
|
72
101
|
raise ArgumentError.new("order[:#{f}] is required") unless order.has_key?(f)
|
73
102
|
end
|
@@ -75,16 +104,20 @@ module MaropostApi
|
|
75
104
|
raise TypeError.new('each order item should be a type of ' << OrderItem.class.to_s) unless oi.kind_of? OrderItem
|
76
105
|
end
|
77
106
|
order[:order_items].map! {|i| i.to_hash }
|
78
|
-
|
107
|
+
|
79
108
|
full_path = full_resource_path("/#{original_order_id}")
|
80
109
|
form_body = {order: order}
|
81
|
-
|
82
|
-
MaropostApi.put_result(full_path, form_body)
|
110
|
+
|
111
|
+
MaropostApi.put_result(full_path, form_body)
|
83
112
|
end
|
84
|
-
|
113
|
+
|
114
|
+
##
|
115
|
+
# updates an order fo the given original order id
|
116
|
+
# @param original_order_id [String] Id of the Order
|
117
|
+
# @param order [Hash] Key value pairs that must contain at least :order_date, :order_status and :order_items as its keys
|
85
118
|
def update_order_for_order_id(order_id, order: {})
|
86
119
|
raise ArgumentError.new('order_id is required') if order_id.nil?
|
87
|
-
|
120
|
+
|
88
121
|
[:order_date, :order_status, :order_items].each do |f|
|
89
122
|
raise ArgumentError.new("order[:#{f}] is required") unless order.has_key?(f)
|
90
123
|
end
|
@@ -92,50 +125,61 @@ module MaropostApi
|
|
92
125
|
raise TypeError.new('each order item should be a type of ' << OrderItem.class.to_s) unless oi.kind_of? OrderItem
|
93
126
|
end
|
94
127
|
order[:order_items].map! {|i| i.to_hash }
|
95
|
-
|
128
|
+
|
96
129
|
full_path = full_resource_path("/find")
|
97
130
|
query_params = MaropostApi.set_query_params({"where[id]" => order_id})
|
98
|
-
|
131
|
+
|
99
132
|
MaropostApi.put_result(full_path, {order: order}, query_params)
|
100
133
|
end
|
101
|
-
|
134
|
+
|
135
|
+
##
|
136
|
+
# deletes an order fo the given original order id
|
137
|
+
# @param original_order_id [String] Orginal Order Id of the Order
|
102
138
|
def delete_for_original_order_id(original_order_id)
|
103
139
|
full_path = full_resource_path("/#{original_order_id}")
|
104
140
|
query_params = MaropostApi.set_query_params
|
105
|
-
|
141
|
+
|
106
142
|
MaropostApi.delete_result(full_path, query_params)
|
107
143
|
end
|
108
|
-
|
144
|
+
|
109
145
|
def delete_for_order_id(order_id)
|
110
146
|
full_path = full_resource_path('/find')
|
111
147
|
query_params = MaropostApi.set_query_params({'where[id]' => order_id})
|
112
|
-
|
148
|
+
|
113
149
|
MaropostApi.delete_result(full_path, query_params)
|
114
150
|
end
|
115
|
-
|
151
|
+
|
152
|
+
##
|
153
|
+
# deletes products for the given original order id
|
154
|
+
# @param original_order_id [String] Orginal Order Id of the Order
|
155
|
+
# @param product_ids [Array] List of product ids to delete
|
116
156
|
def delete_products_for_original_order_id(original_order_id, product_ids)
|
117
|
-
raise TypeError.new('product_ids should be an Array')
|
157
|
+
raise TypeError.new('product_ids should be an Array') until product_ids.is_a? Array
|
118
158
|
full_path = full_resource_path("/#{original_order_id}")
|
119
159
|
query_params = MaropostApi.set_query_params({"product_ids" => product_ids.join(',')})
|
120
|
-
|
160
|
+
|
121
161
|
MaropostApi.delete_result(full_path, query_params)
|
122
162
|
end
|
123
|
-
|
163
|
+
|
164
|
+
##
|
165
|
+
# deletes products for the specified order id
|
166
|
+
# @param order_id [Integer] ID of the order
|
167
|
+
# @param product_ids [Array] List of product IDs to be deleted
|
124
168
|
def delete_products_for_order_id(order_id, product_ids)
|
125
169
|
raise TypeError.new('product_ids should be an Array') if ! product_ids.kind_of? Array
|
126
170
|
full_path = full_resource_path("/find")
|
127
171
|
query_params = MaropostApi.set_query_params({"product_ids" => product_ids.join(','), 'where[id]' => order_id})
|
128
|
-
|
172
|
+
|
129
173
|
MaropostApi.delete_result(full_path, query_params)
|
130
174
|
end
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
175
|
+
|
176
|
+
private
|
177
|
+
|
178
|
+
def full_resource_path(specifics = '', root_resource = 'orders')
|
179
|
+
account = MaropostApi.instance_variable_get(:@account)
|
180
|
+
"/accounts/#{account}/#{root_resource}" << specifics
|
181
|
+
end
|
182
|
+
|
139
183
|
end
|
140
|
-
|
184
|
+
|
141
185
|
end
|
@@ -1,8 +1,17 @@
|
|
1
|
-
module MaropostApi
|
1
|
+
module MaropostApi
|
2
|
+
|
3
|
+
##
|
4
|
+
# Contains methods to operate various operations like create, update, delete or read
|
5
|
+
# from the Relational Table Api
|
2
6
|
class RelationalTableRows
|
3
7
|
|
4
8
|
attr_accessor :table_name
|
5
|
-
|
9
|
+
|
10
|
+
##
|
11
|
+
# Creates a new instance of Reports class.
|
12
|
+
# @param account [Integer] is authentic user account id (Integer) provided by maropost.com
|
13
|
+
# @param api_key [String] is the auth token (String) that is validated on the server to authenticate the user
|
14
|
+
# @param table_name [String] sets which relational table the service's operations should act against
|
6
15
|
def initialize(account = ENV["ACCOUNT"], api_key = ENV["API_KEY"], table_name:)
|
7
16
|
MaropostApi.instance_variable_set(:@api_key, api_key)
|
8
17
|
MaropostApi.instance_variable_set(:@account, account)
|
@@ -10,14 +19,20 @@ module MaropostApi
|
|
10
19
|
|
11
20
|
MaropostApi.base_uri "https://rdb.maropost.com/#{account}"
|
12
21
|
end
|
13
|
-
|
22
|
+
|
23
|
+
##
|
24
|
+
# Gets the records of the relational table
|
14
25
|
def get
|
15
26
|
full_path = full_resource_path
|
16
27
|
query_params = MaropostApi.set_query_params
|
17
28
|
|
18
29
|
MaropostApi.get_result(full_path, query_params)
|
19
30
|
end
|
20
|
-
|
31
|
+
|
32
|
+
##
|
33
|
+
# Gets the specified record from the relational table
|
34
|
+
# @param unique_field_name [String] the name of the field to retrieve
|
35
|
+
# @param value [Mixed] Value of the unique_field_name
|
21
36
|
def show(unique_field_name, value)
|
22
37
|
raise TypeError.new("#{unique_field_name.inspect} should be a string") unless unique_field_name.is_a? String
|
23
38
|
params = {:record => {}}
|
@@ -26,7 +41,11 @@ module MaropostApi
|
|
26
41
|
|
27
42
|
MaropostApi.post_result(full_path, params)
|
28
43
|
end
|
29
|
-
|
44
|
+
|
45
|
+
##
|
46
|
+
# Adds a record to the Relational Table
|
47
|
+
# @param key_value_col [Hash] A key value pair to be added to the table
|
48
|
+
# @param key_value_cols [Hash] Other multile key value pairs that can be added at once in the table
|
30
49
|
def create(key_value_col, *key_value_cols)
|
31
50
|
raise TypeError.new("#{key_value_col.inspect} is not type of Hash") unless key_value_col.kind_of? Hash
|
32
51
|
if (key_value_cols)
|
@@ -38,7 +57,11 @@ module MaropostApi
|
|
38
57
|
|
39
58
|
MaropostApi.post_result(full_path, :record => all_key_values)
|
40
59
|
end
|
41
|
-
|
60
|
+
|
61
|
+
##
|
62
|
+
# Updates a record in the Relational Table
|
63
|
+
# @param key_value_col [Hash] A key value to be updated in the table
|
64
|
+
# @param key_value_cols [Hash] Rest of the key value pairs to be updated if there are multiple
|
42
65
|
def update(key_value_col, *key_value_cols)
|
43
66
|
raise TypeError.new("#{key_value_col.inspect} is not type of Hash") unless key_value_col.kind_of? Hash
|
44
67
|
if (key_value_cols)
|
@@ -51,7 +74,11 @@ module MaropostApi
|
|
51
74
|
|
52
75
|
MaropostApi.put_result(full_path, {:record => all_key_values}, query_params)
|
53
76
|
end
|
54
|
-
|
77
|
+
|
78
|
+
##
|
79
|
+
# Creates or updates a record in the Relational Table
|
80
|
+
# @param key_value_col [Hash] A key value to be updated inthe table
|
81
|
+
# @param key_value_cols [Hash] Rest of the key value pairs to be added/updated in case of multiple fields
|
55
82
|
def upsert(key_value_col, *key_value_cols)
|
56
83
|
raise TypeError.new("#{key_value_col.inspect} is not type of Hash") unless key_value_col.kind_of? Hash
|
57
84
|
if (key_value_cols)
|
@@ -65,7 +92,11 @@ module MaropostApi
|
|
65
92
|
|
66
93
|
MaropostApi.put_result(full_path, {:record => all_key_values}, query_params)
|
67
94
|
end
|
68
|
-
|
95
|
+
|
96
|
+
##
|
97
|
+
# Deletes the given record from the Relational Table
|
98
|
+
# @param unique_field_name [String] name of the unique identifier of the record to be deleted
|
99
|
+
# @param value [Mixed] value matching the unique identifier
|
69
100
|
def delete(unique_field_name, value)
|
70
101
|
raise TypeError.new("#{unique_field_name.inspect} is not a String") unless unique_field_name.is_a? String
|
71
102
|
record = {:record => {}}
|
@@ -57,7 +57,9 @@ module MaropostApi
|
|
57
57
|
raise ArgumentError.new('from_email must be a valid email address') until from_email.nil? or from_email.match? email_regex
|
58
58
|
raise ArgumentError.new('reply_to must be a valid email address') until reply_to.nil? or reply_to.match? email_regex
|
59
59
|
raise ArgumentError.new('add_ctags must be a valid Array of string') until add_ctags.is_a? Array and add_ctags.all?{|t| t.is_a? String }
|
60
|
-
|
60
|
+
raise ArgumentError.new('send_time must have two keys viz. :hour, :minute') until send_time.has_key?(:hour) and send_time.has_key?(:minute)
|
61
|
+
raise ArgumentError.new('send_time[:hour] must be between 1-12 and send_time[:minute] must be between 0-59') until (1..12).to_a.include?(send_time[:hour]) and (0..59).to_a.include?(send_time[:minute])
|
62
|
+
|
61
63
|
params = {}
|
62
64
|
method(__method__).parameters.each{|p| params[p[1]] = eval(p[1].to_s)}
|
63
65
|
params.reject!{|k,v| v.nil? or (v.respond_to? :empty? and v.empty?) }
|
data/lib/maropost_api/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: maropost-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ashish Acharya
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-06-
|
12
|
+
date: 2019-06-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|