Class: Tml::Postoffice

Inherits:
Base
  • Object
show all
Defined in:
lib/tml/postoffice.rb

Constant Summary collapse

PO_HOST =
'https://postoffice.translationexchange.com'
API_VERSION =
'v1'

Instance Attribute Summary

Attributes inherited from Base

#attributes

Instance Method Summary collapse

Methods inherited from Base

attributes, belongs_to, has_many, #hash_value, hash_value, #initialize, #method_missing, #to_hash, #update_attributes

Constructor Details

This class inherits a constructor from Tml::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Tml::Base

Instance Method Details

#deliver(to, template, tokens = {}, options = {}) ⇒ Object

Postoffice API client



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/tml/postoffice.rb', line 68

def deliver(to, template, tokens = {}, options = {})
  if key.blank?
    Tml.logger.error("Failed to deliver #{template} to #{to} - PostOffice has not been configured")
    return
  end

  Tml.logger.debug("Delivering #{template} to #{to}")
  params = {
    client_id: key,
    template: template,
    tokens: tokens,
    to: to,
    via: options[:via],
    from: options[:from],
    locale: options[:locale],
    first_name: options[:first_name],
    last_name: options[:last_name],
    name: options[:name]
  }
  params = Tml::Utils.remove_nils(params)
  api_client.execute_request("#{host}/api/#{API_VERSION}/deliver", params, {:method => :post})
end

#hostObject

API host



58
59
60
# File 'lib/tml/postoffice.rb', line 58

def host
  super || PO_HOST
end

#tokenObject

API token



63
64
65
# File 'lib/tml/postoffice.rb', line 63

def token
  access_token
end