class Intelipost::Client

Constants

API_VERSION
HOST
SERVICE

Attributes

api_key[R]
connection[R]
options[R]
platform[R]
uri[R]

Public Class Methods

new(options) click to toggle source
# File lib/intelipost/client.rb, line 10
def initialize(options)
  @options = { ssl: true }
  @options.merge! options
  uri = @options[:ssl] ? 'https://' : 'http://'
  uri.concat HOST

  @uri = URI.join uri, SERVICE, API_VERSION
  @api_key = @options[:api_key]
  @platform = @options[:platform]

  @connection = connection
end

Public Instance Methods

camelize(term) click to toggle source
# File lib/intelipost/client.rb, line 57
def camelize(term)
  string = term.to_s
  string = string.sub(/^[a-z\d]*/) { $&.capitalize }
  string.gsub!(/(?:_|(\/))([a-z\d]*)/i) { "#{$1}#{$2.capitalize}" }
  string.gsub!("/", "::")
  string
end
get(endpoint, args={}) click to toggle source
# File lib/intelipost/client.rb, line 40
def get(endpoint, args={})
  connection.get(endpoint, args).body
end
method_missing(method, *args, &block) click to toggle source
Calls superclass method
# File lib/intelipost/client.rb, line 48
def method_missing(method, *args, &block)
  method = camelize method
  if Intelipost.const_defined? method
    return Intelipost.const_get(method).new self
  else
    super
  end
end
post(endpoint, args = {}) click to toggle source
# File lib/intelipost/client.rb, line 44
def post(endpoint, args = {})
  connection.post(endpoint, args).body
end