Class: Dawn::Gear

Inherits:
Object
  • Object
show all
Includes:
BaseApi
Defined in:
lib/dawn/api/gear.rb

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(data) ⇒ Gear

Returns a new instance of Gear.



11
12
13
14
# File 'lib/dawn/api/gear.rb', line 11

def initialize(data)
  @app = nil
  @data = data
end

Instance Attribute Details

#appObject



20
21
22
# File 'lib/dawn/api/gear.rb', line 20

def app
  @app ||= App.find(id: app_id)
end

#dataObject (readonly)

Returns the value of attribute data.



8
9
10
# File 'lib/dawn/api/gear.rb', line 8

def data
  @data
end

Class Method Details

.all(options = {}) ⇒ Object



80
81
82
83
84
85
86
87
# File 'lib/dawn/api/gear.rb', line 80

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

.find(options) ⇒ Object



89
90
91
92
93
94
95
96
97
98
# File 'lib/dawn/api/gear.rb', line 89

def self.find(options)
  id = options.delete(:id)

  new json_request(
    expects: 200,
    method: :get,
    path: "/gears/#{id}",
    query: options
  )["gear"]
end

Instance Method Details

#app_idObject



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

def app_id
  data["app_id"]
end

#destroy(options = {}) ⇒ Object



71
72
73
74
75
76
77
78
# File 'lib/dawn/api/gear.rb', line 71

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

#idObject



24
25
26
# File 'lib/dawn/api/gear.rb', line 24

def id
  data["id"]
end

#nameObject



28
29
30
# File 'lib/dawn/api/gear.rb', line 28

def name
  data["name"]
end

#numberObject



40
41
42
# File 'lib/dawn/api/gear.rb', line 40

def number
  data["number"]
end

#refreshObject



44
45
46
47
48
49
50
51
# File 'lib/dawn/api/gear.rb', line 44

def refresh
  @data = json_request(
    expects: 200,
    method: :get,
    path: "/gears/#{id}",
    query: options
  )["gear"]
end

#restart(options = {}) ⇒ Object



53
54
55
56
57
58
59
60
# File 'lib/dawn/api/gear.rb', line 53

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

#typeObject



36
37
38
# File 'lib/dawn/api/gear.rb', line 36

def type
  data["type"]
end

#update(options = {}) ⇒ Object



62
63
64
65
66
67
68
69
# File 'lib/dawn/api/gear.rb', line 62

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

#uptimeObject



32
33
34
# File 'lib/dawn/api/gear.rb', line 32

def uptime
  data["uptime"]
end