Module: Astrotrain::Transports::HttpPost
- Defined in:
- lib/astrotrain/transports/http_post.rb
Class Attribute Summary collapse
Class Method Summary collapse
-
.create_hash(message, recipient) ⇒ Object
Creates a param hash for RestClient.
-
.deliver(message, url, options = {}) ⇒ Object
Public: Sends the message to the given address.
-
.process(url, message, recipient = nil, extra = nil) ⇒ Object
kept for backwards compatibility.
Class Attribute Details
.connection ⇒ Object
12 13 14 |
# File 'lib/astrotrain/transports/http_post.rb', line 12 def self.connection @connection ||= Faraday.default_connection end |
Class Method Details
.create_hash(message, recipient) ⇒ Object
Creates a param hash for RestClient.
message - Astrotrain::Message instance recipient - String email of the main recipient.
Returns a Hash for RestClient.post
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/astrotrain/transports/http_post.rb', line 43 def self.create_hash(, recipient) h = {:subject => .subject, :to => {}, :from => {}, :cc => {}, :body => .body, :emails => .recipients.join(", "), :html => .html, :headers => .headers, :attachments => {}} [:to, :from, :cc].each do |key| .send(key).each_with_index do |addr, i| h[key][i] = {:name => addr.display_name, :address => addr.address} end end ..each_with_index do |a, i| h[:attachments][i] = a end [:attachments, :to, :from, :cc].each do |key| h.delete(key) if h[key].empty? end h end |
.deliver(message, url, options = {}) ⇒ Object
Public: Sends the message to the given address.
message - Astrotrain::Message instance url - String address of the recipient service options - Optional Hash:
:recipient - String email of the main recipient
:extra - Hash to be merged with the payload
Returns a RestClient::Response object for responses between 200..206 Raises RestClient::Exception for any code not between 200..206 or 301..302
27 28 29 30 31 32 33 34 |
# File 'lib/astrotrain/transports/http_post.rb', line 27 def self.deliver(, url, = {}) recipient = [:recipient] || .recipients.first payload = create_hash(, recipient) if extra = [:extra] payload.update(extra) end connection.post(url, payload) end |
.process(url, message, recipient = nil, extra = nil) ⇒ Object
kept for backwards compatibility
62 63 64 |
# File 'lib/astrotrain/transports/http_post.rb', line 62 def self.process(url, , recipient = nil, extra = nil) deliver(, url, :recipient => recipient, :extra => extra) end |