Class: RedboothRuby::Request::Connection
- Inherits:
-
Object
- Object
- RedboothRuby::Request::Connection
- Includes:
- Helpers
- Defined in:
- lib/redbooth-ruby/request/connection.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
-
#request_data ⇒ Object
readonly
Returns the value of attribute request_data.
Instance Method Summary collapse
-
#download_file_with_redirect ⇒ Object
Downloads the desired file following redirects to amazon s3 without authentication headers.
-
#initialize(request_info) ⇒ Connection
constructor
A new instance of Connection.
- #request ⇒ Object
- #set_request_data ⇒ Object
Methods included from Helpers
#flatten_hash_keys, #normalize_params
Constructor Details
#initialize(request_info) ⇒ Connection
Returns a new instance of Connection.
9 10 11 12 13 |
# File 'lib/redbooth-ruby/request/connection.rb', line 9 def initialize(request_info) @info = request_info @session = @info.session if @info @access_token = @info.session.access_token if @session end |
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
7 8 9 |
# File 'lib/redbooth-ruby/request/connection.rb', line 7 def access_token @access_token end |
#request_data ⇒ Object (readonly)
Returns the value of attribute request_data.
7 8 9 |
# File 'lib/redbooth-ruby/request/connection.rb', line 7 def request_data @request_data end |
Instance Method Details
#download_file_with_redirect ⇒ Object
Downloads the desired file following redirects to amazon s3 without authentication headers
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/redbooth-ruby/request/connection.rb', line 30 def download_file_with_redirect max_redirects = access_token..fetch(:max_redirects, 20) response = access_token.send(:get, URI.encode(api_url), { redirect_count: max_redirects + 1 }) if [302, 301].include? response.status url = response.headers['Location'] uri = URI.parse(url) req = Net::HTTP::Get.new(uri) http = Net::HTTP.new(uri.host , Net::HTTP.https_default_port) http.verify_mode = OpenSSL::SSL::VERIFY_NONE http.use_ssl = RedboothRuby.configuration[:use_ssl] http.start do |inner_http| inner_http.request(req) end else response end end |
#request ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/redbooth-ruby/request/connection.rb', line 15 def request return unless access_token case when use_body_file? multipart_request when download_file? download_file_with_redirect else access_token.send(*request_data) end end |
#set_request_data ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/redbooth-ruby/request/connection.rb', line 48 def set_request_data @request_data = [] @request_data << @info.http_method if @info @request_data << api_url unless use_url_params? @request_data << { body: body_hash } end end |