lib/base/db.rb in logworm-0.7.2 vs lib/base/db.rb in logworm-0.7.3
- old
+ new
@@ -14,18 +14,14 @@
def initialize(url)
match = DB.parse_url(url)
raise ForbiddenAccessException.new("Incorrect URL Format #{url}") unless match and match.size == 6
- keys = match[1..4]
- raise ForbiddenAccessException.new("Incorrect Keys") unless keys.is_a? Array and keys.size == 4
- @consumer_key, @consumer_secret, @token, @token_secret = keys
+ @consumer_key, @consumer_secret, @host, @token, @token_secret = match[1..5]
raise ForbiddenAccessException.new("Missing consumer keys") if @consumer_key.nil? or @consumer_secret.nil?
raise ForbiddenAccessException.new("Missing tokens") if @token.nil? or @token_secret.nil?
@connection = OAuth::AccessToken.new(OAuth::Consumer.new(@consumer_key, @consumer_secret), @token, @token_secret)
-
- @host = "http://" + match[5]
end
def self.with_tokens(token, token_secret)
consumer_key = ENV["#{ENV['APP_ID']}_APPS_KEY"]
consumer_secret = ENV["#{ENV['APP_ID']}_APPS_SECRET"]
@@ -65,26 +61,26 @@
def self.example_url
self.url("Ub5sOstT9w", "GZi0HciTVcoFHEoIZ7", "OzO71hEvWYDmncbf3C", "J7wq4X06MihhZgqDeB")
end
def tables()
- res = db_call(:get, "#{@host}/")
+ res = db_call(:get, "#{host_with_protocol}/")
end
def query(table, cond)
- res = db_call(:post, "#{@host}/queries", {:table => table, :query => cond})
+ res = db_call(:post, "#{host_with_protocol}/queries", {:table => table, :query => cond})
end
def results(uri)
res = db_call(:get, uri)
raise InvalidQueryException.new("#{res['error']}") if res['error']
res["results"] = JSON.parse(res["results"])
res
end
def batch_log(entries)
- db_call(:post, "#{@host}/log", {:entries => $lr_queue.to_json})
+ db_call(:post, "#{host_with_protocol}/log", {:entries => $lr_queue.to_json})
end
private
def db_call(method, uri, params = {})
begin
@@ -105,9 +101,12 @@
def self.parse_url(url)
url.match(URL_FORMAT)
end
+ def host_with_protocol
+ "http://#{@host}"
+ end
end
end