Class: Panda::Connection
- Inherits:
-
Object
- Object
- Panda::Connection
- Defined in:
- lib/panda/connection.rb
Instance Attribute Summary collapse
-
#access_key ⇒ Object
Returns the value of attribute access_key.
-
#api_host ⇒ Object
Returns the value of attribute api_host.
-
#api_port ⇒ Object
Returns the value of attribute api_port.
-
#api_version ⇒ Object
Returns the value of attribute api_version.
-
#cloud_id ⇒ Object
Returns the value of attribute cloud_id.
-
#secret_key ⇒ Object
Returns the value of attribute secret_key.
Instance Method Summary collapse
- #adapter ⇒ Object
- #api_scheme ⇒ Object
- #api_url ⇒ Object
- #delete(request_uri, params = {}) ⇒ Object
-
#get(request_uri, params = {}) ⇒ Object
Authenticated requests.
-
#initialize(auth_params = {}) ⇒ Connection
constructor
A new instance of Connection.
- #post(request_uri, params = {}) ⇒ Object
- #put(request_uri, params = {}) ⇒ Object
-
#setup_bucket(params = {}) ⇒ Object
Shortcut to setup your bucket.
- #signed_params(verb, request_uri, params = {}, timestamp_str = nil) ⇒ Object
-
#signed_query(*args) ⇒ Object
Signing methods.
- #to_hash ⇒ Object
Constructor Details
#initialize(auth_params = {}) ⇒ Connection
Returns a new instance of Connection.
10 11 12 13 |
# File 'lib/panda/connection.rb', line 10 def initialize(auth_params={}) @api_version = 2 init_from_hash(auth_params) end |
Instance Attribute Details
#access_key ⇒ Object
Returns the value of attribute access_key.
8 9 10 |
# File 'lib/panda/connection.rb', line 8 def access_key @access_key end |
#api_host ⇒ Object
Returns the value of attribute api_host.
8 9 10 |
# File 'lib/panda/connection.rb', line 8 def api_host @api_host end |
#api_port ⇒ Object
Returns the value of attribute api_port.
8 9 10 |
# File 'lib/panda/connection.rb', line 8 def api_port @api_port end |
#api_version ⇒ Object
Returns the value of attribute api_version.
8 9 10 |
# File 'lib/panda/connection.rb', line 8 def api_version @api_version end |
#cloud_id ⇒ Object
Returns the value of attribute cloud_id.
8 9 10 |
# File 'lib/panda/connection.rb', line 8 def cloud_id @cloud_id end |
#secret_key ⇒ Object
Returns the value of attribute secret_key.
8 9 10 |
# File 'lib/panda/connection.rb', line 8 def secret_key @secret_key end |
Instance Method Details
#adapter ⇒ Object
15 16 17 |
# File 'lib/panda/connection.rb', line 15 def adapter @adapter ||= Panda.adapter.new(api_url) end |
#api_scheme ⇒ Object
60 61 62 |
# File 'lib/panda/connection.rb', line 60 def api_scheme api_port == 443 ? 'https' : 'http' end |
#api_url ⇒ Object
56 57 58 |
# File 'lib/panda/connection.rb', line 56 def api_url "#{api_scheme}://#{api_host}:#{api_port}/#{@prefix}" end |
#delete(request_uri, params = {}) ⇒ Object
35 36 37 38 |
# File 'lib/panda/connection.rb', line 35 def delete(request_uri, params={}) sp = signed_params("DELETE", request_uri, params) adapter.delete(request_uri, sp) end |
#get(request_uri, params = {}) ⇒ Object
Authenticated requests
20 21 22 23 |
# File 'lib/panda/connection.rb', line 20 def get(request_uri, params={}) sp = signed_params("GET", request_uri, params) adapter.get(request_uri, sp) end |
#post(request_uri, params = {}) ⇒ Object
25 26 27 28 |
# File 'lib/panda/connection.rb', line 25 def post(request_uri, params={}) sp = signed_params("POST", request_uri, params) adapter.post(request_uri, sp) end |
#put(request_uri, params = {}) ⇒ Object
30 31 32 33 |
# File 'lib/panda/connection.rb', line 30 def put(request_uri, params={}) sp = signed_params("PUT", request_uri, params) adapter.put(request_uri, sp) end |
#setup_bucket(params = {}) ⇒ Object
Shortcut to setup your bucket
65 66 67 68 69 70 71 72 73 |
# File 'lib/panda/connection.rb', line 65 def setup_bucket(params={}) granting_params = { :s3_videos_bucket => params[:bucket], :aws_access_key => params[:access_key], :aws_secret_key => params[:secret_key] } put("/clouds/#{@cloud_id}.json", granting_params) end |
#signed_params(verb, request_uri, params = {}, timestamp_str = nil) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/panda/connection.rb', line 45 def signed_params(verb, request_uri, params = {}, = nil) auth_params = stringify_keys(params) auth_params['cloud_id'] = cloud_id unless request_uri =~ /^\/clouds/ auth_params['access_key'] = access_key auth_params['timestamp'] = || Time.now.utc.iso8601(6) params_to_sign = auth_params.reject{|k,v| ['file'].include?(k.to_s)} auth_params['signature'] = ApiAuthentication.generate_signature(verb, request_uri, api_host, secret_key, params_to_sign) auth_params end |
#signed_query(*args) ⇒ Object
Signing methods
41 42 43 |
# File 'lib/panda/connection.rb', line 41 def signed_query(*args) ApiAuthentication.hash_to_query(signed_params(*args)) end |
#to_hash ⇒ Object
75 76 77 78 79 80 81 |
# File 'lib/panda/connection.rb', line 75 def to_hash hash = {} [:api_host, :api_port, :access_key, :secret_key, :api_version, :cloud_id].each do |a| hash[a] = send(a) end hash end |