class MailUp::API
Attributes
access_token[RW]
credentials[RW]
debug[RW]
host[RW]
path[RW]
Public Class Methods
new(credentials=nil, debug=false)
click to toggle source
Initialize a new (thread-safe) API
instance.
@param [Hash] credentials for connecting to the MailUp
API
.
* client_id [String] * client_secret [String] * oauth [Hash] * token [String] * refresh_token [String] * expires_at [Integer]
@param [Boolean] debug whether or not to raise errors.
@example
credentials = { client_id: "1324567890", client_secret: "123abc456def", oauth: { token: "1324567890", refresh_token: "1324567890", expires_at: 123456789, } } mailup = MailUp::API.new(credentials)
# File lib/mailup.rb, line 51 def initialize(credentials=nil, debug=false) @debug = debug @host = 'https://services.mailup.com' @path = '' @credentials = credentials # Validate the credentials raise Error.new, 'MailUp credentials missing' if credentials.nil? or !credentials.is_a?(Hash) [:client_id, :client_secret, :oauth].each do |key| raise Error.new, "MailUp credentials must include a #{key.to_s} key" unless credentials.has_key?(key) end raise Error.new, 'MailUp credentials :oauth must be a hash' unless credentials[:oauth].is_a?(Hash) [:token, :refresh_token, :expires_at].each do |key| raise Error.new, "MailUp credentials :oauth hash must include a #{key.to_s} key" unless credentials[:oauth].has_key?(key) end # Create a OAuth2 client instance client = OAuth2::Client.new( credentials[:client_id], credentials[:client_secret], site: @host, authorize_url: "/Authorization/OAuth/LogOn", token_url: "/Authorization/OAuth/Token", raise_errors: @debug ) # Create an access_token instance @access_token = OAuth2::AccessToken.new( client, credentials[:oauth][:token], { refresh_token: credentials[:oauth][:refresh_token], expires_at: credentials[:oauth][:expires_at] } ) end
Public Instance Methods
console()
click to toggle source
Access the console API
methods
@example
lists = mailup.console.user.lists
# File lib/mailup.rb, line 204 def console Console::Base.new self end
public()
click to toggle source
Access the public API
methods
@example
activation = mailup.public.activation.new(...)
# File lib/mailup.rb, line 214 def public Public::Base.new self end
stats()
click to toggle source
Access the email statistics API
methods
@example
views = mailup.stats.message.views_count(1)
# File lib/mailup.rb, line 224 def stats Stats::Base.new self end