class Timepad::Client

Constants

API_URI
FORMAT
VERSION

Attributes

token[R]

Public Class Methods

new(token = nil) click to toggle source
# File lib/timepad/client.rb, line 8
def initialize(token = nil)
  @token = token unless token.nil?
end

Public Instance Methods

event() click to toggle source
# File lib/timepad/client.rb, line 18
def event
  @event ||= Timepad::Event.new(self)
end
order() click to toggle source
# File lib/timepad/client.rb, line 22
def order
  @order ||= Timepad::Order.new(self)
end
request(action, params = {}) click to toggle source
# File lib/timepad/client.rb, line 12
def request(action, params = {})
  uri = make_uri(action, params)
  response = Net::HTTP.get(uri)
  JSON.parse(response)
end

Private Instance Methods

make_query(params) click to toggle source
# File lib/timepad/client.rb, line 27
def make_query(params)
  params.map{|key, value| value.nil? ? "" : "#{key}=#{URI::encode value.to_s}"}.join('&')
end
make_uri(action, params = {}) click to toggle source
# File lib/timepad/client.rb, line 31
def make_uri(action, params = {})
  params.nil? ? params = {'token': @token} : params.merge!({'token': @token})
  query = make_query(params)
  URI("#{API_URI}/v#{VERSION}/#{action}.#{FORMAT}?#{query}")
end