class EmailOpened

Constants

VERSION

Public Class Methods

new(api_key, version = 1, sandbox = false) click to toggle source
# File lib/email-opened.rb, line 4
def initialize(api_key, version = 1, sandbox = false)
  @eo_api_key = api_key
  @eo_version = version
  @eo_sandbox = sandbox
end

Public Instance Methods

add_contact(contacts = {}) click to toggle source
# File lib/email-opened.rb, line 31
def add_contact(contacts = {})
  contacts = contacts[:contacts]

  response = RestClient.post api_path + "contacts", { "contacts[]" => contacts }, headers
  puts response
end
api_path() click to toggle source
# File lib/email-opened.rb, line 38
def api_path
  if @eo_sandbox == "development"
    "http://localhost:3000/api/"
  elsif @eo_sandbox == "edge"
    "http://edge.emailopened.com/api/"
  elsif @eo_sandbox == "staging"
    "http://staging.emailopened.com/api/"
  else
    "https://app.emailopened.com/api/"
  end
end
headers() click to toggle source
# File lib/email-opened.rb, line 10
def headers
  {
    "Authorization" => "Token token=\"#{@eo_api_key}\"",
    "Content-Type" => "application/json",
    "Accept" => "application/vnd.email-opened.v#{@eo_version}"
  }
end
messages() click to toggle source
# File lib/email-opened.rb, line 26
def messages
  response = RestClient.get api_path + "messages", headers
  puts response
end
send(message = {}) click to toggle source
# File lib/email-opened.rb, line 18
def send(message = {})
  to = message[:to]
  token = message[:message_token]

  response = RestClient.post api_path + "messages", { "to[]" => to, token: token }, headers
  puts response
end