Class: Dasher::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/dasher/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, token, options = {}) ⇒ Client

Returns a new instance of Client.



8
9
10
11
12
13
# File 'lib/dasher/client.rb', line 8

def initialize(host, token, options = {})
  @host = host
  @token = token
  @port = options[:port]
  @ssl = options[:ssl]
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



6
7
8
# File 'lib/dasher/client.rb', line 6

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



6
7
8
# File 'lib/dasher/client.rb', line 6

def port
  @port
end

#sslObject (readonly)

Returns the value of attribute ssl.



6
7
8
# File 'lib/dasher/client.rb', line 6

def ssl
  @ssl
end

#tokenObject (readonly)

Returns the value of attribute token.



6
7
8
# File 'lib/dasher/client.rb', line 6

def token
  @token
end

Instance Method Details

#add_list_item(square, identifier, properties = {}) ⇒ Object



29
30
31
# File 'lib/dasher/client.rb', line 29

def add_list_item(square, identifier, properties = {})
  api.lists.add!(:square => square, :identifier => identifier, :properties => properties)
end

#insert_list_item(square, index, identifier, properties = {}) ⇒ Object



33
34
35
# File 'lib/dasher/client.rb', line 33

def insert_list_item(square, index, identifier, properties = {})
  api.lists.add!(:square => square, :index => index, :identifier => identifier, :properties => properties)
end

#replace_list(square, items = []) ⇒ Object



37
38
39
40
41
# File 'lib/dasher/client.rb', line 37

def replace_list(square, items = [])
  api.lists.replace!(:square => square, :items => items)
rescue MoonropeClient::RequestError => e
  puts e.result.data
end

#screen(id) ⇒ Object



19
20
21
# File 'lib/dasher/client.rb', line 19

def screen(id)
  api.screens.details!(:id => id).data
end

#screensObject



15
16
17
# File 'lib/dasher/client.rb', line 15

def screens
  api.screens.list!.data
end

#update_property(square, key, value) ⇒ Object



23
24
25
26
27
# File 'lib/dasher/client.rb', line 23

def update_property(square, key, value)
  api.squares.update_property!(:square => square, :key => key, :value => value).data
rescue MoonropeClient::RequestError => e
  e.result.data["code"] == "ValidationError" ? false : raise
end