Class: ADN::File

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_file) ⇒ File

Returns a new instance of File.



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/adn/file.rb', line 22

def initialize(raw_file)
  if raw_file.respond_to?(:each_pair)
    set_values(raw_file)
    file_id = id
  else
    file_id = raw_file
    file_details = details
    if file_details.has_key? "data"
      set_values(file_details["data"])
    end
  end
end

Instance Attribute Details

#completeObject

Returns the value of attribute complete.



5
6
7
# File 'lib/adn/file.rb', line 5

def complete
  @complete
end

#created_atObject



46
47
48
# File 'lib/adn/file.rb', line 46

def created_at
  DateTime.parse(@created_at)
end

#file_idObject

Returns the value of attribute file_id.



5
6
7
# File 'lib/adn/file.rb', line 5

def file_id
  @file_id
end

#file_tokenObject

Returns the value of attribute file_token.



5
6
7
# File 'lib/adn/file.rb', line 5

def file_token
  @file_token
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/adn/file.rb', line 5

def id
  @id
end

#kindObject

Returns the value of attribute kind.



5
6
7
# File 'lib/adn/file.rb', line 5

def kind
  @kind
end

#mime_typeObject

Returns the value of attribute mime_type.



5
6
7
# File 'lib/adn/file.rb', line 5

def mime_type
  @mime_type
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/adn/file.rb', line 5

def name
  @name
end

#publicObject

Returns the value of attribute public.



5
6
7
# File 'lib/adn/file.rb', line 5

def public
  @public
end

#sha1Object

Returns the value of attribute sha1.



5
6
7
# File 'lib/adn/file.rb', line 5

def sha1
  @sha1
end

#sizeObject

Returns the value of attribute size.



5
6
7
# File 'lib/adn/file.rb', line 5

def size
  @size
end

#sourceObject

Returns the value of attribute source.



5
6
7
# File 'lib/adn/file.rb', line 5

def source
  @source
end

#total_sizeObject

Returns the value of attribute total_size.



5
6
7
# File 'lib/adn/file.rb', line 5

def total_size
  @total_size
end

#typeObject

Returns the value of attribute type.



5
6
7
# File 'lib/adn/file.rb', line 5

def type
  @type
end

#urlObject

Returns the value of attribute url.



5
6
7
# File 'lib/adn/file.rb', line 5

def url
  @url
end

#url_expiresObject

Returns the value of attribute url_expires.



5
6
7
# File 'lib/adn/file.rb', line 5

def url_expires
  @url_expires
end

#userObject



50
51
52
# File 'lib/adn/file.rb', line 50

def user
  ADN::User.new(@user)
end

Class Method Details

.by_id(id) ⇒ Object



17
18
19
20
# File 'lib/adn/file.rb', line 17

def self.by_id(id)
  result = ADN::API::File.by_id(id)
  File.new(result["data"])
end

.upload_file(filename, params) ⇒ Object



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

def self.upload_file(filename, params)
  result = ADN::API::File.create(filename, params)
  File.new(result["data"])
end

Instance Method Details

#deleteObject



54
55
56
57
# File 'lib/adn/file.rb', line 54

def delete
  result = ADN::API::File.delete(id)
  ADN.create_instance(result["data"], File)
end

#detailsObject



35
36
37
38
39
40
41
42
43
44
# File 'lib/adn/file.rb', line 35

def details
  if id
    value = self.instance_variables.map do |i|
      [i.to_s.slice(1..-1), self.instance_variable_get(i)]
    end
    Hash[value]
  else
    ADN::API::File.by_id(file_id)
  end
end

#set_values(values) ⇒ Object



59
60
61
# File 'lib/adn/file.rb', line 59

def set_values(values)
  values.each_pair { |k, v| send("#{k}=", v) if respond_to?("#{k}=") }
end