From 16d62d9b0ca0a7b310eb94e86c533b0a9c4d6d51 Mon Sep 17 00:00:00 2001 From: Benjamin Darcet Date: Sat, 18 Dec 2021 22:51:49 +0100 Subject: [PATCH] Adding examples for the new marketing campaigns --- examples/new_marketing_campaigns/contacts.rb | 29 +++++++++++ .../new_marketing_campaigns/customfields.rb | 49 +++++++++++++++++++ examples/new_marketing_campaigns/lists.rb | 35 +++++++++++++ .../new_marketing_campaigns/singlesends.rb | 28 +++++++++++ 4 files changed, 141 insertions(+) create mode 100644 examples/new_marketing_campaigns/contacts.rb create mode 100644 examples/new_marketing_campaigns/customfields.rb create mode 100644 examples/new_marketing_campaigns/lists.rb create mode 100644 examples/new_marketing_campaigns/singlesends.rb diff --git a/examples/new_marketing_campaigns/contacts.rb b/examples/new_marketing_campaigns/contacts.rb new file mode 100644 index 00000000..b41b4bb0 --- /dev/null +++ b/examples/new_marketing_campaigns/contacts.rb @@ -0,0 +1,29 @@ +require 'sendgrid-ruby' + +sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY']) + +################################################## +# Add or Update a Contact # +# POST /marketing/contacts # + +data = JSON.parse('{ + "list_ids": [ + "ca7a3796-e8a8-4029-9ccb-df8937940562" + ], + "contacts": [ + { + "address_line_1": "123 Elm St.", + "address_line_2": "Apt. 456", + "city": "Denver", + "country": "United States", + "email": "example@example.com", + "first_name": "User", + "last_name": "Example" + } + ] +}') + +response = sg.client.marketing.contacts.put(request_body: data) +puts response.status_code +puts response.body +puts response.headers diff --git a/examples/new_marketing_campaigns/customfields.rb b/examples/new_marketing_campaigns/customfields.rb new file mode 100644 index 00000000..4ec8c548 --- /dev/null +++ b/examples/new_marketing_campaigns/customfields.rb @@ -0,0 +1,49 @@ +require 'sendgrid-ruby' + +sg = SendGrid::API.new(api_key: ENV["SENDGRID_API_KEY"]) + +################################################## +# Create Custom Field Definition # +# POST /marketing/field_definitions # + +data = JSON.parse('{ + "name": "pet", + "field_type": "Text" +}') + +response = sg.client.marketing.field_definitions.post(request_body: data) +puts response.status_code +puts response.body +puts response.headers + +################################################## +# Get All Field Definitions # +# GET /marketing/field_definitions # + +response = sg.client.marketing.field_definitions.get +puts response.status_code +puts response.body +puts response.headers + +################################################## +# Update Custom Field Definition # +# PATCH /marketing/field_definitions/{custom_field_id} # + +data = JSON.parse('{ + "name": "new_custom_field_name" +}') +custom_field_id = 'e1_T' +response = sg.client.marketing.field_definitions._(custom_field_id).patch(request_body: data) +puts response.status_code +puts response.body +puts response.headers + +################################################## +# Delete Custom Field Definition # +# DELETE /marketing/field_definitions/{custom_field_id} # + +custom_field_id = 'e1_T' +response = sg.client.marketing.field_definitions._(custom_field_id).delete +puts response.status_code +puts response.body +puts response.headers diff --git a/examples/new_marketing_campaigns/lists.rb b/examples/new_marketing_campaigns/lists.rb new file mode 100644 index 00000000..f0d9873a --- /dev/null +++ b/examples/new_marketing_campaigns/lists.rb @@ -0,0 +1,35 @@ +require 'sendgrid-ruby' + +sg = SendGrid::API.new(api_key: ENV["SENDGRID_API_KEY"]) + +################################################## +# Create List # +# GET /marketing/lists # + +data = JSON.parse('{ + "name": "list-name" +}') + +response = sg.client.marketing.lists.post(request_body: data) +puts response.status_code +puts response.body +puts response.headers + +################################################## +# Get All Lists # +# GET /marketing/lists # + +response = sg.client.marketing.lists.get +puts response.status_code +puts response.body +puts response.headers + +################################################## +# Get a List by ID # +# GET /marketing/lists/{id} # + +list_id = 'ca7a3796-e8a8-4029-9ccb-df8937940562' +response = sg.client.marketing.lists._(list_id).get +puts response.status_code +puts response.body +puts response.headers diff --git a/examples/new_marketing_campaigns/singlesends.rb b/examples/new_marketing_campaigns/singlesends.rb new file mode 100644 index 00000000..796e5233 --- /dev/null +++ b/examples/new_marketing_campaigns/singlesends.rb @@ -0,0 +1,28 @@ +require 'sendgrid-ruby' + +sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY']) + +################################################## +# Create Single Send # +# POST /marketing/singlesends # + +data = JSON.parse('{ + "name": "Example API Created Single Send", + "categories": [ + "unique opens" + ], + "send_to": { + "all": true + }, + "email_config": { + "design_id": "", + "editor": "design", + "suppression_group_id": 12, + "sender_id": 10 + } +}') + +response = sg.client.marketing.singlesends.post(request_body: data) +puts response.status_code +puts response.body +puts response.headers