class TinCan
Attributes
id[RW]
key[RW]
name[RW]
Public Class Methods
new(app_id, app_key, app_name)
click to toggle source
# File lib/tincan.rb, line 10 def initialize(app_id, app_key, app_name) @id, @key, @name = app_id, app_key, app_name end
Public Instance Methods
validate()
click to toggle source
# File lib/tincan.rb, line 31 def validate return read_response( self.class.get( "/#{@name}/authorized", :basic_auth => {:username => @id, :password => @key} ).body ) end
Private Instance Methods
is_json?(json)
click to toggle source
# File lib/tincan.rb, line 54 def is_json?(json) return false unless json.is_a?(String) begin JSON.parse(json) return true rescue JSON::ParserError return false end end
read_response(res, has_data = false)
click to toggle source
# File lib/tincan.rb, line 49 def read_response(res, has_data = false) res = JSON.parse(res) return res["data"] || res["success"] || res["error"] end
req(type, query)
click to toggle source
# File lib/tincan.rb, line 41 def req(type, query) return self.class.post( "/#{@name}/#{type}", :body => query, :basic_auth => {:username => @id, :password => @key} ).body end