Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/panda/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def config

[:api_host, :api_port,
:access_key, :secret_key,
:api_version, :cloud_id].each do |attr|
:api_version, :cloud_id, :token].each do |attr|
define_method "#{attr}" do |value|
config["#{attr.to_s}"] = value
end
Expand Down Expand Up @@ -74,6 +74,9 @@ def valid?

def validation_errors
err = []
unless config["token"].to_s.empty?
return err
end
if config["access_key"].to_s.empty?
err << "access_key is missing"
end
Expand Down
11 changes: 8 additions & 3 deletions lib/panda/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Panda
EU_API_HOST="api-eu.pandastream.com"

class Connection
attr_accessor :api_host, :api_port, :access_key, :secret_key, :api_version, :cloud_id
attr_accessor :api_host, :api_port, :access_key, :secret_key, :api_version, :cloud_id, :token

def initialize(auth_params={})
params = { :api_host => US_API_HOST, :api_port => API_PORT }.merge!(auth_params)
Expand All @@ -17,12 +17,13 @@ def initialize(auth_params={})
@api_host = params["api_host"] || params[:api_host]
@api_port = params["api_port"] || params[:api_port]
@prefix = params["prefix_url"] || "v#{api_version}"
@token = params["token"] || params[:token]
end

def http_client
Panda::HttpClient::Faraday.new(api_url)
end

# Authenticated requests
def get(request_uri, params={})
sp = signed_params("GET", request_uri, params)
Expand Down Expand Up @@ -52,6 +53,10 @@ def signed_query(*args)
def signed_params(verb, request_uri, params = {}, timestamp_str = nil)
auth_params = stringify_keys(params)
auth_params['cloud_id'] = cloud_id unless request_uri =~ /^\/clouds/
if token
auth_params['token'] = token
return auth_params
end
auth_params['access_key'] = access_key
auth_params['timestamp'] = timestamp_str || Time.now.utc.iso8601(6)

Expand Down Expand Up @@ -81,7 +86,7 @@ def setup_bucket(params={})

def to_hash
hash = {}
[:api_host, :api_port, :access_key, :secret_key, :api_version, :cloud_id].each do |a|
[:api_host, :api_port, :access_key, :secret_key, :api_version, :cloud_id, :token].each do |a|
hash[a] = send(a)
end
hash
Expand Down
2 changes: 1 addition & 1 deletion lib/panda/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Panda
VERSION = "1.6.2"
VERSION = "1.6.3"
end