Class: Pepipost::Email
- Inherits:
-
Object
- Object
- Pepipost::Email
- Defined in:
- lib/pepipost/controllers/email_controller.rb
Constant Summary collapse
- @@instance =
Email.new
Class Method Summary collapse
-
.instance ⇒ Object
Singleton instance of the controller class.
Instance Method Summary collapse
-
#create_api_web_send_json(data) ⇒ Object
‘Sending Mails` – This API is used for sending emails.
-
#get_api_web_send_rest(api_key, content, from, recipients, subject, att_name = nil, attachmentid = nil, bcc = nil, clicktrack = true, footer = true, fromname = nil, opentrack = true, replytoid = nil, tags = nil, template = nil, x_apiheader = nil) ⇒ Object
‘Sending Mails` – This API is used for sending emails.
-
#send(data) ⇒ Object
This is a common function send email using Pepipost API.
Class Method Details
.instance ⇒ Object
Singleton instance of the controller class
5 6 7 |
# File 'lib/pepipost/controllers/email_controller.rb', line 5 def self.instance @@instance end |
Instance Method Details
#create_api_web_send_json(data) ⇒ Object
‘Sending Mails` – This API is used for sending emails. Pepipost supports REST as well JSON formats for the input. This is JSON API.
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/pepipost/controllers/email_controller.rb', line 83 def create_api_web_send_json(data) # the base uri for api requests query_builder = Configuration.base_uri.dup # prepare query string for API call query_builder << '/api/web.send.json' # validate and preprocess url query_url = APIHelper.clean_url query_builder # prepare headers headers = { 'user-agent' => 'APIMATIC 2.0', 'accept' => 'application/json', 'content-type' => 'application/json; charset=utf-8' } # invoke the API call request to fetch the response response = Unirest.post query_url, headers: headers, parameters: data.to_json #Error handling using HTTP status codes if !response.code.between?(200, 206) # [200,206] = HTTP OK raise APIException.new 'HTTP Response Not OK', response.code, response.raw_body end response.body end |
#get_api_web_send_rest(api_key, content, from, recipients, subject, att_name = nil, attachmentid = nil, bcc = nil, clicktrack = true, footer = true, fromname = nil, opentrack = true, replytoid = nil, tags = nil, template = nil, x_apiheader = nil) ⇒ Object
‘Sending Mails` – This API is used for sending emails. Pepipost supports REST as well JSON formats for the input
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/pepipost/controllers/email_controller.rb', line 27 def get_api_web_send_rest(api_key, content, from, recipients, subject, att_name = nil, = nil, bcc = nil, clicktrack = true, = true, fromname = nil, opentrack = true, replytoid = nil, = nil, template = nil, x_apiheader = nil) # the base uri for api requests query_builder = Configuration.base_uri.dup # prepare query string for API call query_builder << '/api/web.send.rest' # process optional query parameters query_builder = APIHelper.append_url_with_query_parameters query_builder, { 'api_key' => api_key, 'content' => content, 'from' => from, 'recipients' => recipients, 'subject' => subject, 'ATT_NAME' => att_name, 'attachmentid' => , 'bcc' => bcc, 'clicktrack' => if clicktrack.nil? then true else clicktrack end, 'footer' => if .nil? then true else end, 'fromname' => fromname, 'opentrack' => if opentrack.nil? then true else opentrack end, 'replytoid' => replytoid, 'tags' => , 'template' => template, 'X-APIHEADER' => x_apiheader } # validate and preprocess url query_url = APIHelper.clean_url query_builder # prepare headers headers = { 'user-agent' => 'APIMATIC 2.0', 'accept' => 'application/json' } # invoke the API call request to fetch the response response = Unirest.get query_url, headers: headers #Error handling using HTTP status codes if !response.code.between?(200, 206) # [200,206] = HTTP OK raise APIException.new 'HTTP Response Not OK', response.code, response.raw_body end response.body end |
#send(data) ⇒ Object
This is a common function send email using Pepipost API
75 76 77 78 |
# File 'lib/pepipost/controllers/email_controller.rb', line 75 def send(data) response = self.create_api_web_send_json(data) return response end |