class KeyholeIO::Entity
Attributes
apikey[RW]
channel_name[RW]
id[RW]
name[RW]
token[RW]
Public Class Methods
get_info(name, apikey, options = {})
click to toggle source
Class Methods
# File lib/keyholeio.rb, line 295 def self.get_info name, apikey, options = {} # options: password response = Net::HTTP.get(URI.parse("#{APIURL}/entity?#{self.paramshash_string(name, apikey, options)}")) Response.new response end
new(name, apikey, options = {})
click to toggle source
Entity
Methods
# File lib/keyholeio.rb, line 118 def initialize name, apikey, options = {} # options: desc, password, public @apikey = apikey @name = name response = Net::HTTP.post_form URI.parse("#{APIURL}/entity"), paramshash(name, options) r = Response.new response.body if r.successful? @token = r.data["token"] end end
paramshash(name, apikey, options)
click to toggle source
# File lib/keyholeio.rb, line 317 def self.paramshash name, apikey, options params = { apikey: apikey, id: name } options.collect { |k,v| params[k] = v } params end
paramshash_string(name, apikey, options)
click to toggle source
# File lib/keyholeio.rb, line 331 def self.paramshash_string name, apikey, options self.paramshash(name, apikey, options).collect { |k, v| "#{k}=#{v}" }.join("&") end
Public Instance Methods
add_apns_client(id)
click to toggle source
# File lib/keyholeio.rb, line 216 def add_apns_client id add_client id, "apns" end
add_client(id, type)
click to toggle source
Messaging Client Methods
# File lib/keyholeio.rb, line 207 def add_client id, type response = Net::HTTP.post_form URI.parse("#{APIURL}/entity/messaging/#{type}"), tokenparams(id: id) Response.new response.body end
add_email_client(id)
click to toggle source
# File lib/keyholeio.rb, line 212 def add_email_client id add_client id, "email" end
apns_client_exists?(id)
click to toggle source
# File lib/keyholeio.rb, line 234 def apns_client_exists? id check_client id, "apns" end
change_password(old_pass, new_pass)
click to toggle source
# File lib/keyholeio.rb, line 153 def change_password old_pass, new_pass response = Net::HTTP.post_form URI.parse("#{APIURL}/entity/password"), tokenparams(old: old_pass, new: new_pass) Response.new response.body end
channel()
click to toggle source
Channel Methods
# File lib/keyholeio.rb, line 168 def channel response = Net::HTTP.post_form URI.parse("#{APIURL}/entity/channel"), tokenparams(nil) r = Response.new response.body if r.successful? @channel_name = r.data["name"] end end
channel_connected()
click to toggle source
# File lib/keyholeio.rb, line 176 def channel_connected response = Net::HTTP.get URI.parse("#{APIURL}/entity/channel?token=#{@token}") Response.new response end
channel_destroy()
click to toggle source
# File lib/keyholeio.rb, line 192 def channel_destroy http = Net::HTTP.new("api.keyhole.io") req = Net::HTTP::Delete.new("/v1/entity/channel?token=#{@token}") r = Response.new http.request(req).body if r.successful? @channel_name = nil end r end
channel_rename()
click to toggle source
# File lib/keyholeio.rb, line 181 def channel_rename http = Net::HTTP.new("api.keyhole.io") req = Net::HTTP::Put.new("/v1/entity/channel") req.set_form_data token: @token r = Response.new http.request(req).body if r.successful? @channel_name = r.data["name"] end end
check_client(id, type)
click to toggle source
# File lib/keyholeio.rb, line 220 def check_client id, type response = Net::HTTP.get URI.parse("#{APIURL}/entity/messaging/#{type}?token=#{@token}&id=#{id}") r = Response.new response if r.successful? r.meta["status"] == 200 else false end end
datastores(options = {})
click to toggle source
# File lib/keyholeio.rb, line 275 def datastores options = {} response = Net::HTTP.get URI.parse("#{APIURL}/datastore?#{tokenparams_string(options)}") Response.new response end
delete(key)
click to toggle source
# File lib/keyholeio.rb, line 158 def delete key http = Net::HTTP.new("api.keyhole.io") req = Net::HTTP::Delete.new("/v1/datastore/#{key}?token=#{@token}") Response.new http.request(req).body end
delete_client(id, type)
click to toggle source
# File lib/keyholeio.rb, line 238 def delete_client id, type http = Net::HTTP.new("api.keyhole.io") req = Net::HTTP::Delete.new("/v1/entity/messaging/#{type}?token=#{@token}&id=#{id}") r = Response.new http.request(req).body end
destroy()
click to toggle source
# File lib/keyholeio.rb, line 134 def destroy http = Net::HTTP.new("api.keyhole.io") req = Net::HTTP::Delete.new("/v1/entity?token=#{@token}&apikey=#{@apikey}&id=#{@name}") Response.new http.request(req).body end
email_client_exists?(id)
click to toggle source
# File lib/keyholeio.rb, line 230 def email_client_exists? id check_client id, "email" end
get(key)
click to toggle source
# File lib/keyholeio.rb, line 280 def get key response = Net::HTTP.get URI.parse("#{APIURL}/datastore/#{key}?#{tokenparams_string(nil)}") KVPair.new response end
info(options = {})
click to toggle source
# File lib/keyholeio.rb, line 130 def info options = {} self.class.get_info @name, @apikey, options end
nullify_token()
click to toggle source
# File lib/keyholeio.rb, line 140 def nullify_token http = Net::HTTP.new("api.keyhole.io") req = Net::HTTP::Put.new("/v1/entity") req.set_form_data token: @token Response.new http.request(req).body end
paramshash(name, options = {})
click to toggle source
# File lib/keyholeio.rb, line 313 def paramshash name, options = {} self.class.paramshash name, @apikey, options end
paramshash_string(name, options = {})
click to toggle source
# File lib/keyholeio.rb, line 327 def paramshash_string name, options = {} self.class.paramshash_string name, options, @apikey end
remove(key)
click to toggle source
# File lib/keyholeio.rb, line 285 def remove key http = Net::HTTP.new("api.keyhole.io") req = Net::HTTP::Delete.new("/v1/datastore/#{key}?token=#{@token}") r = Response.new http.request(req).body end
remove_apns_client(id)
click to toggle source
# File lib/keyholeio.rb, line 248 def remove_apns_client id delete_client id, "apns" end
remove_email_client(id)
click to toggle source
# File lib/keyholeio.rb, line 244 def remove_email_client id delete_client id, "email" end
set(kvpair)
click to toggle source
Datastore Methods
# File lib/keyholeio.rb, line 256 def set kvpair tparams = {} unless kvpair.empty? tparams[:k] = kvpair.keys.first if (kvpair.values.first.class == Array or kvpair.values.first.class == Hash) tparams[:v] = kvpair.values.first.to_json else tparams[:v] = kvpair.values.first end end if kvpair.size > 1 tparams[:meta] = kvpair.values.last.to_json end response = Net::HTTP.post_form URI.parse("#{APIURL}/datastore"), tokenparams(tparams) Response.new response.body end
set_password(new_pass)
click to toggle source
# File lib/keyholeio.rb, line 148 def set_password new_pass response = Net::HTTP.post_form URI.parse("#{APIURL}/entity/password"), tokenparams(new: new_pass) Response.new response.body end
tokenparams(options = {})
click to toggle source
private
# File lib/keyholeio.rb, line 303 def tokenparams options = {} params = { token: @token } options.collect { |k,v| params[k] = v } unless options.nil? params end
tokenparams_string(options)
click to toggle source
# File lib/keyholeio.rb, line 309 def tokenparams_string options tokenparams(options).collect { |k, v| "#{k}=#{v}" }.join("&") end