Class: Tui::Authorization::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/tui/authorization/request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#uploadObject (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

#performObject



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")

   = Base64.urlsafe_encode64("#{Tui::Config.username}:#{Tui::Config.password}")

  headers = {
    "Authorization" => "Basic #{}",
    "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