Class: Ey::Core::Client::ApplicationArchive

Inherits:
Model
  • Object
show all
Extended by:
Associations
Defined in:
lib/ey-core/models/application_archive.rb

Instance Method Summary collapse

Methods included from Associations

assoc_accessor, assoc_coverage, assoc_reader, assoc_writer, associations, collection_reader

Methods inherited from Model

#destroy, range_parser, #save, #to_s, #update!, #url

Instance Method Details

#downloadObject



58
59
60
61
62
63
64
65
66
# File 'lib/ey-core/models/application_archive.rb', line 58

def download
  requires :url

  params = {
    "url" => self.url,
  }

  self.connection.download_file(params)
end

#mime_typeObject

FIXME: hard coded in core, not exposed via api



15
16
17
# File 'lib/ey-core/models/application_archive.rb', line 15

def mime_type
  "text/plain"
end

#save!Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ey-core/models/application_archive.rb', line 19

def save!
  if new_record?
    requires :filename
    params = {
      "url" => self.collection.url,
      "application" => self.application_id,
      "application_archive" => {
        "filename" => filename,
        "sha256"   => sha256,
      },
    }
    merge_attributes(self.connection.create_application_archive(params).body["application_archive"])
  else
    params = {
      "id" => id,
      "application" => self.application_id,
      "application_archive" => {
        "upload_successful" => upload_successful,
      }
    }
    merge_attributes(self.connection.update_application_archive(params).body["application_archive"])
  end
end

#upload(options) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/ey-core/models/application_archive.rb', line 43

def upload(options)
  requires :upload_url

  params = {
    "body"       => options[:body] || File.read(options[:file]),
    "mime_type"  => self.mime_type,
    "upload_url" => self.upload_url,
  }

  self.connection.upload_file(params)

  self.upload_successful = true
  self.save
end