Class: Cocupu::File

Inherits:
Object
  • Object
show all
Defined in:
lib/cocupu/file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node, file_name, file) ⇒ File

Returns a new instance of File.



5
6
7
8
9
10
# File 'lib/cocupu/file.rb', line 5

def initialize(node, file_name, file)
  self.node = node
  self.file_name = file_name
  self.file = file
  @conn = Thread.current[:cocupu_connection] 
end

Instance Attribute Details

#connObject (readonly)

Returns the value of attribute conn.



4
5
6
# File 'lib/cocupu/file.rb', line 4

def conn
  @conn
end

#fileObject

Returns the value of attribute file.



3
4
5
# File 'lib/cocupu/file.rb', line 3

def file
  @file
end

#file_nameObject

Returns the value of attribute file_name.



3
4
5
# File 'lib/cocupu/file.rb', line 3

def file_name
  @file_name
end

#nodeObject

Returns the value of attribute node.



3
4
5
# File 'lib/cocupu/file.rb', line 3

def node
  @node
end

Instance Method Details

#saveObject



16
17
18
19
# File 'lib/cocupu/file.rb', line 16

def save
  response = conn.post("#{url}.json")#, query: {file_name: file_name, file: file})
  raise "Error saving file: #{response.inspect}" unless response.code >= 200 and response.code < 300
end

#urlObject



12
13
14
# File 'lib/cocupu/file.rb', line 12

def url
  node.url + "/files"
end