Class: Dawn::App

Inherits:
Object
  • Object
show all
Includes:
BaseApi
Defined in:
lib/dawn/api/app.rb,
lib/dawn/api/app/env.rb,
lib/dawn/api/app/gears.rb,
lib/dawn/api/app/drains.rb,
lib/dawn/api/app/domains.rb

Defined Under Namespace

Classes: Domains, Drains, Env, Gears

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from BaseApi

included

Methods included from BaseApi::Extension

#json_request, #request

Constructor Details

#initialize(hsh) ⇒ App

Returns a new instance of App.



16
17
18
19
# File 'lib/dawn/api/app.rb', line 16

def initialize(hsh)
  @data = hsh
  @env = Env.new(self, @data.delete("env"))
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



13
14
15
# File 'lib/dawn/api/app.rb', line 13

def data
  @data
end

#envObject (readonly)

Returns the value of attribute env.



14
15
16
# File 'lib/dawn/api/app.rb', line 14

def env
  @env
end

Class Method Details

.all(options = {}) ⇒ Object



95
96
97
98
99
100
101
102
# File 'lib/dawn/api/app.rb', line 95

def self.all(options={})
  json_request(
    expects: 200,
    method: :get,
    path: "/apps",
    query: options
  ).map { |hsh| new(hsh["app"]) }
end

.create(options) ⇒ Object



104
105
106
107
108
109
110
111
# File 'lib/dawn/api/app.rb', line 104

def self.create(options)
  new json_request(
    expects: 200,
    method: :post,
    path: '/apps',
    body: options.to_json
  )["app"]
end

.destroy(options) ⇒ Object



125
126
127
128
# File 'lib/dawn/api/app.rb', line 125

def self.destroy(options)
  app = find options
  app.destroy if app
end

.find(options) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
# File 'lib/dawn/api/app.rb', line 113

def self.find(options)
  path = options[:id] ? "/apps/#{options.delete(:id)}" : "/apps"
  hsh = json_request(
    expects: 200,
    method: :get,
    path: path,
    query: options
  )
  hsh = hsh.first if hsh.is_a?(Array)
  hsh && new(hsh["app"])
end

Instance Method Details

#destroy(options = {}) ⇒ Object



86
87
88
89
90
91
92
93
# File 'lib/dawn/api/app.rb', line 86

def destroy(options={})
  request(
    expects: 200,
    method: :delete,
    path: "/apps/#{id}",
    query: options
  )
end

#domainsObject



54
55
56
# File 'lib/dawn/api/app.rb', line 54

def domains
  @domains ||= Domains.new self
end

#drainsObject



50
51
52
# File 'lib/dawn/api/app.rb', line 50

def drains
  @drains ||= Drains.new self
end

#formationObject



29
30
31
# File 'lib/dawn/api/app.rb', line 29

def formation
  data["formation"]
end

#gearsObject



46
47
48
# File 'lib/dawn/api/app.rb', line 46

def gears
  @gears ||= Gears.new self
end

#gitObject



33
34
35
# File 'lib/dawn/api/app.rb', line 33

def git
  data["git"]
end

#idObject



25
26
27
# File 'lib/dawn/api/app.rb', line 25

def id
  data["id"]
end

#logs(options = {}) ⇒ Object



58
59
60
61
62
63
64
65
66
# File 'lib/dawn/api/app.rb', line 58

def logs(options={})
  url = json_request(
    expects: 200,
    method: :get,
    path: "/apps/#{id}/logs",
    query: options
  )["logs"]
  "http://#{Dawn.log_host}#{url}"
end

#nameObject



21
22
23
# File 'lib/dawn/api/app.rb', line 21

def name
  data["name"]
end

#restart(options = {}) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/dawn/api/app.rb', line 37

def restart(options={})
  request(
    expects: 200,
    method: :delete,
    path: "/apps/#{id}/gears",
    query: options
  )
end

#scale(options = {}) ⇒ Object



77
78
79
80
81
82
83
84
# File 'lib/dawn/api/app.rb', line 77

def scale(options={})
  request(
    expects: 200,
    method: :post,
    path: "/apps/#{id}/scale",
    body: options.to_json
  )
end

#update(options = {}) ⇒ Object



68
69
70
71
72
73
74
75
# File 'lib/dawn/api/app.rb', line 68

def update(options={})
  data.merge!(json_request(
    expects: 200,
    method: :patch,
    path: "/apps/#{id}",
    body: { name: name }.merge(options).to_json
  )["app"])
end