Class: Dawn::Drain

Inherits:
Object
  • Object
show all
Includes:
BaseApi
Defined in:
lib/dawn/api/drain.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) ⇒ Drain

Returns a new instance of Drain.



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

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

Instance Attribute Details

#appObject



20
21
22
# File 'lib/dawn/api/drain.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/drain.rb', line 8

def data
  @data
end

Class Method Details

.all(options = {}) ⇒ Object



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

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

.find(options = {}) ⇒ Object



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

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

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

Instance Method Details

#app_idObject



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

def app_id
  data["app_id"]
end

#destroy(options = {}) ⇒ Object



50
51
52
53
54
55
56
57
# File 'lib/dawn/api/drain.rb', line 50

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

#idObject



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

def id
  data["id"]
end

#refreshObject



32
33
34
35
36
37
38
39
# File 'lib/dawn/api/drain.rb', line 32

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

#update(options = {}) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/dawn/api/drain.rb', line 41

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

#urlObject



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

def url
  data["url"]
end