Module: SocketLabs
- Defined in:
- lib/socketlabs.rb
Defined Under Namespace
Classes: EmailMessage
Class Attribute Summary collapse
-
.max_attempts ⇒ Object
Returns the value of attribute max_attempts.
-
.serverToken ⇒ Object
Returns the value of attribute serverToken.
-
.ssl ⇒ Object
Returns the value of attribute ssl.
-
.url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
- .port ⇒ Object
- .SendQuickMessage(from, to, subject, textBody, options = {}) ⇒ Object
- .SendRawHashMessage(msgHash) ⇒ Object
- .SendRawJsonMessage(msgJson) ⇒ Object
Class Attribute Details
.max_attempts ⇒ Object
Returns the value of attribute max_attempts.
9 10 11 |
# File 'lib/socketlabs.rb', line 9 def max_attempts @max_attempts end |
.serverToken ⇒ Object
Returns the value of attribute serverToken.
9 10 11 |
# File 'lib/socketlabs.rb', line 9 def serverToken @serverToken end |
.ssl ⇒ Object
Returns the value of attribute ssl.
9 10 11 |
# File 'lib/socketlabs.rb', line 9 def ssl @ssl end |
.url ⇒ Object
Returns the value of attribute url.
9 10 11 |
# File 'lib/socketlabs.rb', line 9 def url @url end |
Class Method Details
.port ⇒ Object
16 17 18 |
# File 'lib/socketlabs.rb', line 16 def port @port || (ssl ? 443 : 80) end |
.SendQuickMessage(from, to, subject, textBody, options = {}) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/socketlabs.rb', line 43 def self.SendQuickMessage(from, to, subject, textBody, ={}) msg = Hash.new msg['From']=from msg['To']=to msg['Subject']=subject msg['TextBody']=textBody .each do | k, v | msg['Bcc']=v if k=="bcc" msg['Cc']=cc if k=="cc" msg['Template']=template if k=="template" msg['HtmlBody']=htmlBody if k=="htmlBody" msg['ReplyTo']=replyTo if k=="replyTo" msg['Headers'] = headers if k=="headers" end SocketLabs::SendRawHashMessage(msg); end |
.SendRawHashMessage(msgHash) ⇒ Object
60 61 62 |
# File 'lib/socketlabs.rb', line 60 def self.SendRawHashMessage(msgHash) SocketLabs::SendRawJsonMessage(msgHash.to_json) end |
.SendRawJsonMessage(msgJson) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/socketlabs.rb', line 64 def self.SendRawJsonMessage(msgJson) @attempt = 1 begin api_url = URI.parse(url) req = Net::HTTP::Post.new(api_url.path) #req.basic_auth user, pw req.body=msgJson req.set_content_type('application/x-www-form-urlencoded') req.delete("Accept") req.add_field("Accept", "application/json") req.add_field("Content-Type", "application/json; charset=utf-8") req.add_field("User-Agent", "SocketLabs Ruby Gem") req.add_field("X-Server-Token", serverToken) http = Net::HTTP.new(api_url.host, @port) http.use_ssl= @ssl res = http.start {|http| http.request(req) } rescue Exception => e if @attempt < max_attempts @attempt += 1 retry else raise end end res.body end |