Permalink
Browse files

refactoring

default api port is given by URI.parse
  • Loading branch information...
1 parent 05fe0eb commit 1d0f09070ac3fdb51f933941cf0c239dc376c678 @vivienschilis vivienschilis committed Feb 24, 2012
Showing with 11 additions and 27 deletions.
  1. +1 −14 lib/panda/config.rb
  2. +9 −12 lib/panda/connection.rb
  3. +1 −1 spec/heroku_spec.rb
View
15 lib/panda/config.rb
@@ -11,7 +11,7 @@ def self.from_panda_url(panda_url)
config.secret_key = panda_uri.password
config.cloud_id = panda_uri.path[1..-1]
config.api_host = panda_uri.host
- config.api_port = API_PORT
+ config.api_port = panda_uri.port
config
end
@@ -50,19 +50,6 @@ def adapter(adapter_name)
def adapter=(adapter_name)
Panda.adapter = adapter_name
end
-
- # Setup connection for Heroku
- # @deprecated: use Config.from_panda_url(panda_url)
- def parse_panda_url(panda_url)
- panda_uri = URI.parse(panda_url)
-
- config['access_key'] = panda_uri.user
- config['secret_key'] = panda_uri.password
- config['cloud_id'] = panda_uri.path[1..-1]
- config['api_host'] = panda_uri.host
- config['api_port'] = API_PORT
- config
- end
# Set the correct api_host for US/EU
def region(region)
View
21 lib/panda/connection.rb
@@ -7,9 +7,16 @@ module Panda
class Connection
attr_accessor :api_host, :api_port, :access_key, :secret_key, :api_version, :cloud_id
- def initialize(auth_params={})
+ def initialize(auth_params={})
+ params = { :api_host => US_API_HOST, :api_port => API_PORT }.merge!(auth_params)
@api_version = 2
- init_from_hash(auth_params)
+
+ @cloud_id = params["cloud_id"] || params[:cloud_id]
+ @access_key = params["access_key"] || params[:access_key]
+ @secret_key = params["secret_key"] || params[:secret_key]
+ @api_host = params["api_host"] || params[:api_host]
+ @api_port = params["api_port"] || params[:api_port]
+ @prefix = params["prefix_url"] || "v#{api_version}"
end
def adapter
@@ -89,16 +96,6 @@ def stringify_keys(params)
end
end
- def init_from_hash(hash_params)
- params = { :api_host => US_API_HOST, :api_port => API_PORT }.merge!(hash_params)
-
- @cloud_id = params["cloud_id"] || params[:cloud_id]
- @access_key = params["access_key"] || params[:access_key]
- @secret_key = params["secret_key"] || params[:secret_key]
- @api_host = params["api_host"] || params[:api_host]
- @api_port = params["api_port"] || params[:api_port]
- @prefix = params["prefix_url"] || "v#{api_version}"
- end
end
end
View
2 spec/heroku_spec.rb
@@ -6,7 +6,7 @@
stub_http_request(:get, /api.example.com:443\/v2\/clouds\/my_cloud_id.json/).
to_return(:body => cloud_json)
- my_heroku_url = "http://access_key:secret_key@api.example.com:85/my_cloud_id"
+ my_heroku_url = "http://access_key:secret_key@api.example.com:443/my_cloud_id"
ENV['PANDASTREAM_URL']= my_heroku_url
end

0 comments on commit 1d0f090

Please sign in to comment.