class Sqwiggle::Api::Client

Attributes

token[RW]

Public Class Methods

new(token=nil) click to toggle source
# File lib/sqwiggle/api/client.rb, line 8
def initialize(token=nil)
  unless @token = token || Sqwiggle.token
    raise NoTokenError 
  end
end
service(key, klass) click to toggle source
# File lib/sqwiggle/api/client.rb, line 14
def self.service(key, klass)
  define_method key, -> {
    instance_eval('Service').new instance_eval(klass), self
  }
end

Public Instance Methods

==(val) click to toggle source
# File lib/sqwiggle/api/client.rb, line 28
def ==(val)
  self.class == val.class && val.token == token
end
delete(endpoint) click to toggle source
# File lib/sqwiggle/api/client.rb, line 44
def delete(endpoint)
  connection.delete endpoint
end
get(endpoint, params={}) click to toggle source
# File lib/sqwiggle/api/client.rb, line 32
def get(endpoint, params={})
  connection.get endpoint, params
end
inspect() click to toggle source
# File lib/sqwiggle/api/client.rb, line 48
def inspect
  #This is purely to stop huge console output when inspecting resource
  #objects as they contain a reference to the loading client
  "#<Sqwiggle::Api::Client # (#{object_id})>"
end
post(endpoint, params) click to toggle source
# File lib/sqwiggle/api/client.rb, line 40
def post(endpoint, params)
  connection.post endpoint, params
end
put(endpoint, params) click to toggle source
# File lib/sqwiggle/api/client.rb, line 36
def put(endpoint, params)
  connection.put endpoint, params
end

Private Instance Methods

connection() click to toggle source
# File lib/sqwiggle/api/client.rb, line 56
def connection
  @connection ||= Faraday.new(url:Sqwiggle::Api.url) do |f|
    f.request  :url_encoded             # form-encode POST params
    f.adapter  Faraday.default_adapter  # make requests with Net::HTTP
    f.basic_auth token, 'X'
    f.headers['User-Agent'] = "sqwiggle-ruby #{Sqwiggle::VERSION}"
    f.use ErrorHandler
  end
end