Class: Fluxiom::Asset

Inherits:
Fluxiom show all
Defined in:
lib/fluxapi/asset.rb

Instance Attribute Summary

Attributes inherited from Fluxiom

#base_url

Instance Method Summary collapse

Methods inherited from Fluxiom

#account, #assets, call, post_call, #tags, #users

Constructor Details

#initialize(data) ⇒ Asset

Returns a new instance of Asset.



2
3
4
5
6
7
8
# File 'lib/fluxapi/asset.rb', line 2

def initialize(data)
  data.each do |k, v|
    self.instance_variable_set("@#{k}", v)
    self.class.send(:define_method, k, proc{self.instance_variable_get("@#{k}")})
    self.class.send(:define_method, "#{k}=", proc{|v| self.instance_variable_set("@#{k}", v)})
  end
end

Instance Method Details

#download(path_to_file) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/fluxapi/asset.rb', line 15

def download(path_to_file)
  session = Net::HTTP.new(@@base_url.gsub('https://', ''), 443)
  session.use_ssl = true
  session.start {|http|
    req = Net::HTTP::Get.new("/api/assets/#{self.id}/download")
    req.basic_auth @@user, @@password
    resp = http.request(req)
    open(File.join(path_to_file, self.filename), 'wb') do |file|
      file.write(resp.body)
    end
  }
end

#tag(t) ⇒ Object



10
11
12
13
# File 'lib/fluxapi/asset.rb', line 10

def tag(t)
  res = self.class.post_call("/api/assets/#{self.id}/tag", :body => {:tags => t.api_name})
  self.tags = self.tags.to_s + ' ' + t.api_name
end