lib/base/db.rb in logworm-0.7.1 vs lib/base/db.rb in logworm-0.7.2

- old
+ new

@@ -7,14 +7,13 @@ class InvalidQueryException < Exception ; end class DB DEFAULT_HOST = "db.logworm.com" - URL_FORMAT = /lw:\/\/([^:]+):([^!]+)!([^:]+):([^@]+)@([^\/]+)\// - # URI: lw://<consumer_key>:<consumer_secret>!<access_token>:<access_token_secret>@db.logworm.com/ + URL_FORMAT = /logworm:\/\/([^:]+):([^@]+)@([^\/]+)\/([^\/]+)\/([^\/]+)\// + # URI: logworm://<consumer_key>:<consumer_secret>@db.logworm.com/<access_token>/<access_token_secret>/ - 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] @@ -28,11 +27,11 @@ end def self.with_tokens(token, token_secret) consumer_key = ENV["#{ENV['APP_ID']}_APPS_KEY"] consumer_secret = ENV["#{ENV['APP_ID']}_APPS_SECRET"] - DB.new("lw://#{consumer_key}:#{consumer_secret}!#{token}:#{token_secret}@#{DEFAULT_HOST}/") + DB.new(DB.url(consumer_key, consumer_secret, token, token_secret)) end def self.from_config # Try with URL from the environment return DB.new(ENV['LOGWORM_URL']) if ENV['LOGWORM_URL'] and DB.parse_url(ENV['LOGWORM_URL']) @@ -52,10 +51,22 @@ def self.from_config_or_die db = self.from_config raise "The application is not properly configured. Either use 'heroku addon:add' to add logworm to your app, or save your project's credentials into the .logworm file" unless db db end - + + def self.url(consumer_key, consumer_secret, token, token_secret, host = DEFAULT_HOST) + "logworm://#{consumer_key}:#{consumer_secret}@#{host}/#{token}/#{token_secret}/" + end + + def url() + DB.url(@consumer_key, @consumer_secret, @token, @token_secret, @host) + end + + def self.example_url + self.url("Ub5sOstT9w", "GZi0HciTVcoFHEoIZ7", "OzO71hEvWYDmncbf3C", "J7wq4X06MihhZgqDeB") + end + def tables() res = db_call(:get, "#{@host}/") end def query(table, cond)