Class: Bkblz::V1::Session
- Inherits:
-
Object
- Object
- Bkblz::V1::Session
- Defined in:
- lib/bkblz/v1/session.rb
Instance Attribute Summary collapse
-
#auth_response ⇒ Object
Returns the value of attribute auth_response.
-
#config ⇒ Object
Returns the value of attribute config.
Class Method Summary collapse
Instance Method Summary collapse
- #account_id ⇒ Object
- #authorized? ⇒ Boolean
- #create_download_url(url_suffix) ⇒ Object
- #create_get(url, addl_headers = {}) ⇒ Object
- #create_post(url, body = nil, addl_headers = {}) ⇒ Object
- #create_url(url_suffix) ⇒ Object
-
#initialize(config) ⇒ Session
constructor
A new instance of Session.
- #send(request) ⇒ Object
Constructor Details
#initialize(config) ⇒ Session
Returns a new instance of Session.
23 24 25 |
# File 'lib/bkblz/v1/session.rb', line 23 def initialize(config) @config = config end |
Instance Attribute Details
#auth_response ⇒ Object
Returns the value of attribute auth_response.
21 22 23 |
# File 'lib/bkblz/v1/session.rb', line 21 def auth_response @auth_response end |
#config ⇒ Object
Returns the value of attribute config.
21 22 23 |
# File 'lib/bkblz/v1/session.rb', line 21 def config @config end |
Class Method Details
.authorize(config) {|session| ... } ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/bkblz/v1/session.rb', line 11 def (config, &block) session = Session.new config session.auth_response = session.send Bkblz::V1::AuthorizeAccountRequest.new yield(session) if block_given? session end |
Instance Method Details
#account_id ⇒ Object
31 32 33 34 |
# File 'lib/bkblz/v1/session.rb', line 31 def account_id auth_response.account_id end |
#authorized? ⇒ Boolean
36 37 38 |
# File 'lib/bkblz/v1/session.rb', line 36 def !!auth_response && !!auth_response. end |
#create_download_url(url_suffix) ⇒ Object
40 41 42 43 |
# File 'lib/bkblz/v1/session.rb', line 40 def create_download_url(url_suffix) URI.join auth_response.download_url, url_suffix end |
#create_get(url, addl_headers = {}) ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/bkblz/v1/session.rb', line 50 def create_get(url, addl_headers={}) Bkblz.log.debug { "creating GET for request => #{url}" } request = Net::HTTP::Get.new uri_from_url(url) add_request_headers request, addl_headers request end |
#create_post(url, body = nil, addl_headers = {}) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/bkblz/v1/session.rb', line 59 def create_post(url, body=nil, addl_headers={}) Bkblz.log.debug { "creating POST for request => #{url}" } request = Net::HTTP::Post.new uri_from_url(url) if body.is_a? Hash body = Bkblz::MapKeyFormatter.camelcase_keys(body).to_json end request.body = body if body add_request_headers request, addl_headers request end |
#create_url(url_suffix) ⇒ Object
45 46 47 48 |
# File 'lib/bkblz/v1/session.rb', line 45 def create_url(url_suffix) URI.join auth_response.api_url, url_suffix end |
#send(request) ⇒ Object
27 28 29 |
# File 'lib/bkblz/v1/session.rb', line 27 def send(request) request.send self end |