Class: Bcli::FileClient

Inherits:
Client
  • Object
show all
Defined in:
lib/bcli/file_client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Client

#delete, #get, #patch, #post, #put

Constructor Details

#initialize(file_path = nil, options = {}) ⇒ FileClient

Returns a new instance of FileClient.



3
4
5
6
7
8
# File 'lib/bcli/file_client.rb', line 3

def initialize(file_path = nil, options = {})
  @file_path = file_path
  @file = file_contents
  @config = Bcli::Config.new
  @options = options
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



2
3
4
# File 'lib/bcli/file_client.rb', line 2

def config
  @config
end

#content_typeObject (readonly)

Returns the value of attribute content_type.



2
3
4
# File 'lib/bcli/file_client.rb', line 2

def content_type
  @content_type
end

#fileObject (readonly)

Returns the value of attribute file.



2
3
4
# File 'lib/bcli/file_client.rb', line 2

def file
  @file
end

#file_pathObject (readonly)

Returns the value of attribute file_path.



2
3
4
# File 'lib/bcli/file_client.rb', line 2

def file_path
  @file_path
end

#tokenObject (readonly)

Returns the value of attribute token.



2
3
4
# File 'lib/bcli/file_client.rb', line 2

def token
  @token
end

Instance Method Details

#file_contentsObject



29
30
31
# File 'lib/bcli/file_client.rb', line 29

def file_contents
  File.open(file_path, "r") if file_path
end

#file_headersObject



22
23
24
25
26
27
# File 'lib/bcli/file_client.rb', line 22

def file_headers
  {
    "Content-Type": "multipart/form-data",
    Authorization: "Bearer #{config.creds[:token]}"
  }
end

#uploadObject



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/bcli/file_client.rb', line 10

def upload
  HTTParty.post("#{Bcli::Client.base_uri}/uploads",
    method: :post,
    headers: file_headers,
    body: {
      upload: {
        file: file_contents,
        folder_path: @options[:folder_path]
      }
    })
end