Class: Tui::Authorization::Request
- Inherits:
-
Object
- Object
- Tui::Authorization::Request
- Defined in:
- lib/tui/authorization/request.rb
Instance Attribute Summary collapse
-
#upload ⇒ Object
readonly
Returns the value of attribute upload.
Instance Method Summary collapse
-
#initialize(upload) ⇒ Request
constructor
A new instance of Request.
- #perform ⇒ Object
Constructor Details
#initialize(upload) ⇒ Request
Returns a new instance of Request.
8 9 10 |
# File 'lib/tui/authorization/request.rb', line 8 def initialize(upload) @upload = upload end |
Instance Attribute Details
#upload ⇒ Object (readonly)
Returns the value of attribute upload.
12 13 14 |
# File 'lib/tui/authorization/request.rb', line 12 def upload @upload end |
Instance Method Details
#perform ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/tui/authorization/request.rb', line 14 def perform json_request = upload.as_json.to_json connection = Excon.new("http://#{Tui::Config.host}/files") login = Base64.urlsafe_encode64("#{Tui::Config.username}:#{Tui::Config.password}") headers = { "Authorization" => "Basic #{login}", "Accept" => "application/json", "Content-Type" => "application/json", } response = connection.request({ :method => "POST", :headers => headers, :expects => 200, :body => json_request, }) json_response = JSON.parse(response.body) Response.new(json_response) end |