Skip to content

"Get", update and approve an email and it's content #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/mrkt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
require 'mrkt/concerns/crud_custom_objects'
require 'mrkt/concerns/crud_custom_activities'
require 'mrkt/concerns/crud_programs'
require 'mrkt/concerns/crud_emails'

module Mrkt
class Client
Expand All @@ -28,6 +29,7 @@ class Client
include CrudCustomObjects
include CrudCustomActivities
include CrudPrograms
include CrudEmails

attr_accessor :debug

Expand Down
10 changes: 10 additions & 0 deletions lib/mrkt/concerns/crud_campaigns.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,15 @@ def request_campaign(id, lead_ids, tokens = {})
}
end
end

def schedule_campaign(id, run_at = nil)
post_json("/rest/v1/campaigns/#{id}/schedule.json") do
{
input: {
runAt: run_at
}
}
end
end
end
end
23 changes: 23 additions & 0 deletions lib/mrkt/concerns/crud_emails.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module Mrkt
module CrudEmails
def get_email_by_id(id)
get("/rest/asset/v1/email/#{id}.json")
end

def approve_email_draft(id)
post("/rest/asset/v1/email/#{id}/approveDraft.json")
end

def update_email(id, subject)
post("/rest/asset/v1/email/#{id}/content.json?subject={'type':'Text','value':'#{subject}'}")
end

def update_email_content(id, html_id, content, text_value = nil)
post("/rest/asset/v1/email/#{id}/content/#{html_id}.json") do |req|
req.headers[:content_type] = 'multipart/form-data;charset=UTF-8'
req.body = {type: "Text", value: content}
end
end

end
end
1 change: 1 addition & 0 deletions lib/mrkt/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def self.create_class
610 => 'RequestedResourceNotFound',
611 => 'System',
612 => 'InvalidContentType',
702 => 'NoDataFound',
703 => 'DisabledFeature',
1001 => 'TypeMismatch',
1002 => 'MissingParamater',
Expand Down
42 changes: 42 additions & 0 deletions spec/concerns/crud_campaigns_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
value: 'Value for other token'
}]
end

subject { client.request_campaign(id, lead_ids, tokens) }

before do
Expand Down Expand Up @@ -68,4 +69,45 @@
end
end
end

describe '#schedule_campaign' do
let(:id) { 42 }

subject { client.schedule_campaign(id) }

before do
stub_request(:post, "https://#{host}/rest/v1/campaigns/#{id}/schedule.json")
.to_return(json_stub(response_stub))
end

context 'with an invalid campaign id' do
let(:response_stub) do
{
requestId: 'a2b#9a4567d34f',
success: false,
errors: [{
code: '1013',
message: 'Campaign not found'
}]
}
end

it 'should raise an Error' do
expect { subject }.to raise_error(Mrkt::Errors::ObjectNotFound)
end
end

context 'with valid campaign id' do
let(:response_stub) do
{
requestId: 'e42b#14272d07d78',
success: true,
:result=>[{:id=>1254}]
}
end

it { is_expected.to eq(response_stub) }
end
end

end
121 changes: 121 additions & 0 deletions spec/concerns/crud_emails_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
describe Mrkt::CrudCampaigns do
include_context 'initialized client'

describe '#get_email_by_id' do
let(:id) { 42 }

subject { client.get_email_by_id(id) }

before do
stub_request(:get, "https://#{host}/rest/asset/v1/email/#{id}.json")
.to_return(json_stub(response_stub))
end

context 'with invalid email id' do
let(:response_stub) do
{
requestId: '7cdc#14eb6ae8a86',
success: true,
warnings: ["No assets found for the given search criteria."]
}
end

it { is_expected.to eq(response_stub) }
end

context 'for valid email id' do
let(:response_stub) do
{
requestId: 'e42b#14272d07d78',
success: true
}
end

it { is_expected.to eq(response_stub) }
end
end



describe '#approve_email_draft' do
let(:id) { 42 }

subject { client.approve_email_draft(id) }

before do
stub_request(:post, "https://#{host}/rest/asset/v1/email/#{id}/approveDraft.json")
.to_return(json_stub(response_stub))
end

context 'with an invalid email id' do
let(:response_stub) do
{
requestId: 'a2b#9a4567d34f',
success: false,
errors: [{
code: '702',
message: 'Email not found'
}]
}
end

it 'should raise an Error' do
expect { subject }.to raise_error(Mrkt::Errors::NoDataFound)
end
end

context 'with valid email id' do
let(:response_stub) do
{
requestId: 'e42b#14272d07d78',
success: true,
:result=>[{:id=>42}]
}
end

it { is_expected.to eq(response_stub) }
end
end

describe '#update_email' do
let(:id) { 42 }
let(:email_subject) { "Test" }

subject { client.update_email(id, email_subject) }

before do
stub_request(:post, URI.encode("https://#{host}/rest/asset/v1/email/#{id}/content.json?subject={'type':'Text','value':'#{email_subject}'}"))
.to_return(json_stub(response_stub))
end

context 'with an invalid email id' do
let(:response_stub) do
{
requestId: 'a2b#9a4567d34f',
success: false,
errors: [{
code: '702',
message: 'Email not found'
}]
}
end

it 'should raise an Error' do
expect { subject }.to raise_error(Mrkt::Errors::NoDataFound)
end
end

context 'with valid email id' do
let(:response_stub) do
{
requestId: 'e42b#14272d07d78',
success: true,
:result=>[{:id=>42}]
}
end

it { is_expected.to eq(response_stub) }
end
end

end