Class: TelestreamCloud::Connection
- Inherits:
-
Object
- Object
- TelestreamCloud::Connection
- Defined in:
- lib/telestream_cloud/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.
-
#factory_id ⇒ Object
Returns the value of attribute factory_id.
-
#secret_key ⇒ Object
Returns the value of attribute secret_key.
Instance Method Summary collapse
- #api_scheme ⇒ Object
- #api_url ⇒ Object
- #delete(request_uri, params = {}) ⇒ Object
-
#get(request_uri, params = {}) ⇒ Object
Authenticated requests.
- #http_client ⇒ Object
-
#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.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/telestream_cloud/connection.rb', line 11 def initialize(auth_params={}) params = { :api_host => US_API_HOST, :api_port => API_PORT }.merge!(auth_params) @api_version = '3.0' @factory_id = params["factory_id"] || params[:factory_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 |
Instance Attribute Details
#access_key ⇒ Object
Returns the value of attribute access_key.
9 10 11 |
# File 'lib/telestream_cloud/connection.rb', line 9 def access_key @access_key end |
#api_host ⇒ Object
Returns the value of attribute api_host.
9 10 11 |
# File 'lib/telestream_cloud/connection.rb', line 9 def api_host @api_host end |
#api_port ⇒ Object
Returns the value of attribute api_port.
9 10 11 |
# File 'lib/telestream_cloud/connection.rb', line 9 def api_port @api_port end |
#api_version ⇒ Object
Returns the value of attribute api_version.
9 10 11 |
# File 'lib/telestream_cloud/connection.rb', line 9 def api_version @api_version end |
#factory_id ⇒ Object
Returns the value of attribute factory_id.
9 10 11 |
# File 'lib/telestream_cloud/connection.rb', line 9 def factory_id @factory_id end |
#secret_key ⇒ Object
Returns the value of attribute secret_key.
9 10 11 |
# File 'lib/telestream_cloud/connection.rb', line 9 def secret_key @secret_key end |
Instance Method Details
#api_scheme ⇒ Object
68 69 70 |
# File 'lib/telestream_cloud/connection.rb', line 68 def api_scheme api_port.to_i == 443 ? 'https' : 'http' end |
#api_url ⇒ Object
64 65 66 |
# File 'lib/telestream_cloud/connection.rb', line 64 def api_url "#{api_scheme}://#{api_host}:#{api_port}/#{@prefix}" end |
#delete(request_uri, params = {}) ⇒ Object
43 44 45 46 |
# File 'lib/telestream_cloud/connection.rb', line 43 def delete(request_uri, params={}) sp = signed_params("DELETE", request_uri, params) http_client.delete(request_uri, sp) end |
#get(request_uri, params = {}) ⇒ Object
Authenticated requests
28 29 30 31 |
# File 'lib/telestream_cloud/connection.rb', line 28 def get(request_uri, params={}) sp = signed_params("GET", request_uri, params) http_client.get(request_uri, sp) end |
#http_client ⇒ Object
23 24 25 |
# File 'lib/telestream_cloud/connection.rb', line 23 def http_client TelestreamCloud::HttpClient::Faraday.new(api_url) end |
#post(request_uri, params = {}) ⇒ Object
33 34 35 36 |
# File 'lib/telestream_cloud/connection.rb', line 33 def post(request_uri, params={}) sp = signed_params("POST", request_uri, params) http_client.post(request_uri, sp) end |
#put(request_uri, params = {}) ⇒ Object
38 39 40 41 |
# File 'lib/telestream_cloud/connection.rb', line 38 def put(request_uri, params={}) sp = signed_params("PUT", request_uri, params) http_client.put(request_uri, sp) end |
#setup_bucket(params = {}) ⇒ Object
Shortcut to setup your bucket
73 74 75 76 77 78 79 80 81 |
# File 'lib/telestream_cloud/connection.rb', line 73 def setup_bucket(params={}) granting_params = { :s3_videos_bucket => params[:bucket], :aws_access_key => params[:access_key], :aws_secret_key => params[:secret_key] } put("/factories/#{@factory_id}.json", granting_params) end |
#signed_params(verb, request_uri, params = {}, timestamp_str = nil) ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/telestream_cloud/connection.rb', line 53 def signed_params(verb, request_uri, params = {}, = nil) auth_params = stringify_keys(params) auth_params['factory_id'] = factory_id unless request_uri =~ /^\/factories/ 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
49 50 51 |
# File 'lib/telestream_cloud/connection.rb', line 49 def signed_query(*args) ApiAuthentication.hash_to_query(signed_params(*args)) end |
#to_hash ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/telestream_cloud/connection.rb', line 83 def to_hash hash = {} [:api_host, :api_port, :access_key, :secret_key, :api_version, :factory_id].each do |a| hash[a] = send(a) end hash end |