Class: TryPaper::Mailer
- Inherits:
-
Object
- Object
- TryPaper::Mailer
- Defined in:
- lib/TryPaper/mailer.rb
Overview
the Mailer class takes an instance of the document class and sends it to the TryPaper API
Constant Summary collapse
- API_URL =
"https://api.trypaper.com/Mailing"
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#document ⇒ Object
Returns the value of attribute document.
-
#recipient ⇒ Object
Returns the value of attribute recipient.
-
#return_address_id ⇒ Object
readonly
Returns the value of attribute return_address_id.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
Instance Method Summary collapse
-
#initialize(api_key, return_address_id, tags = []) ⇒ Mailer
constructor
instantiate client and then add document and recipient.
- #send_data ⇒ Object
- #submit ⇒ Object
Constructor Details
#initialize(api_key, return_address_id, tags = []) ⇒ Mailer
instantiate client and then add document and recipient
16 17 18 19 20 21 22 |
# File 'lib/TryPaper/mailer.rb', line 16 def initialize(api_key, return_address_id, = []) @recipient = TryPaper::Recipient.new @document = nil @api_key = api_key @return_address_id = return_address_id = end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
13 14 15 |
# File 'lib/TryPaper/mailer.rb', line 13 def api_key @api_key end |
#document ⇒ Object
Returns the value of attribute document.
12 13 14 |
# File 'lib/TryPaper/mailer.rb', line 12 def document @document end |
#recipient ⇒ Object
Returns the value of attribute recipient.
12 13 14 |
# File 'lib/TryPaper/mailer.rb', line 12 def recipient @recipient end |
#return_address_id ⇒ Object (readonly)
Returns the value of attribute return_address_id.
13 14 15 |
# File 'lib/TryPaper/mailer.rb', line 13 def return_address_id @return_address_id end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
13 14 15 |
# File 'lib/TryPaper/mailer.rb', line 13 def end |
Instance Method Details
#send_data ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/TryPaper/mailer.rb', line 24 def send_data { "ReturnAddressId" => return_address_id, "Tags" => , "Content" => document.base64format, "Recipient" => recipient.formatted_address } end |
#submit ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/TryPaper/mailer.rb', line 33 def submit uri = URI.parse(API_URL) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true request = Net::HTTP::Post.new(uri.request_uri) #headers request['Authorization'] = api_key request['Content-Type'] = "application/json" request.body = send_data.to_json response = http.request(request) end |