-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
52 changed files
with
4,906 additions
and
2,813 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require 'responsys_api' | ||
module Api | ||
module V1 | ||
class ListController < ApplicationController | ||
before_action :validate_params, only: [:create] | ||
|
||
def create | ||
list = Responsys::Api::Object::InteractObject.new(params[:folder], params[:list]) | ||
record_data = Responsys::Api::Object::RecordData.new(params[:record_data]) | ||
if params[:record_data].size > 150 | ||
render(status: :bad_request, json: { 'error_message': 'Maximum of 150 records exceeded.' }) | ||
else | ||
response = Responsys::Api::Client.new.merge_list_members(list, record_data, Responsys::Api::Object::ListMergeRule.new(insertOnNoMatch: true)) | ||
|
||
if response[:status] == 'ok' | ||
render json: json(response[:data][0][:result]) | ||
else | ||
render json: json(response) | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def validate_params | ||
# rubocop:disable Lint/NonLocalExitFromIterator | ||
required_params.each { |param| validate_param_exists(param) && return } | ||
# rubocop:enable Lint/NonLocalExitFromIterator | ||
end | ||
|
||
def required_params | ||
[:list, :folder, :record_data] | ||
end | ||
end | ||
end | ||
end |
52 changes: 52 additions & 0 deletions
52
app/controllers/api/v1/trigger_campaign_message_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
require 'responsys_api' | ||
module Api | ||
module V1 | ||
class TriggerCampaignMessageController < ApplicationController | ||
before_action :validate_params, only: [:create] | ||
|
||
def create | ||
list = Responsys::Api::Object::InteractObject.new(params[:folder], params[:list]) | ||
campaign = Responsys::Api::Object::InteractObject.new(params[:folder], params[:campaign]) | ||
|
||
recipients = [] | ||
|
||
if params[:recipients].size > 150 | ||
logger.error "recipients size = #{params[:recipients].size}" | ||
render(status: :bad_request, json: json(error_message: 'Maximum of 150 recipients')) | ||
return | ||
end | ||
|
||
params[:recipients].each do |r| | ||
recipient_data = Responsys::Api::Object::RecipientData.new(Responsys::Api::Object::Recipient.new(emailAddress: r[:email], listName: list)) | ||
r[:optional_data].each do |k, v| | ||
recipient_data.optional_data << Responsys::Api::Object::OptionalData.new(k, v) | ||
end if r[:optional_data] | ||
recipients << recipient_data | ||
end | ||
|
||
response = Responsys::Api::Client.new.trigger_message(campaign, recipients) | ||
if (response[:status] == 'ok') | ||
if response[:result] | ||
render(json: json(response[:result])) | ||
else | ||
render(json: json(response[:data].map { |entry| entry[:result] })) | ||
end | ||
else | ||
render(status: 500, json: json(error_code: response[:error][:code], error_message: response[:error][:message])) | ||
end | ||
end | ||
|
||
private | ||
|
||
def validate_params | ||
# rubocop:disable Lint/NonLocalExitFromIterator | ||
required_params.each { |param| validate_param_exists(param) && return } | ||
# rubocop:enable Lint/NonLocalExitFromIterator | ||
end | ||
|
||
def required_params | ||
[:list, :folder, :campaign, :recipients] | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.