Class: WebService
- Inherits:
-
Object
- Object
- WebService
- Defined in:
- lib/webService.rb
Instance Method Summary collapse
-
#add_feed(thing, category, message, feedOptions) ⇒ Object
Add a feed message to a thing.
-
#add_status(thing, statusArray) ⇒ Object
Add or update a status item for a thing.
-
#add_thing(thing) ⇒ Object
Retrieve a thing.
-
#get_authorization ⇒ Hash
Authorize this application by sending the application secret to Thingdom.
-
#initialize(secret) ⇒ WebService
constructor
Constructor method for WebService.
-
#ping_server ⇒ Object
Ping Thingdom.
Constructor Details
#initialize(secret) ⇒ WebService
Constructor method for WebService.
14 15 16 17 18 19 |
# File 'lib/webService.rb', line 14 def initialize( secret ) @httpHelper = HttpHelper.new() @apiSecret = secret @applicationToken = '' @deviceSecret = 'none' end |
Instance Method Details
#add_feed(thing, category, message, feedOptions) ⇒ Object
Add a feed message to a thing.
91 92 93 94 95 96 97 98 99 100 |
# File 'lib/webService.rb', line 91 def add_feed( thing, category, , feedOptions ) data = { token: @applicationToken, thing_id: thing.id, feed_category: category, message: , options: feedOptions } @httpHelper.post_data( 'feed', data ) end |
#add_status(thing, statusArray) ⇒ Object
Add or update a status item for a thing.
73 74 75 76 77 78 79 80 81 |
# File 'lib/webService.rb', line 73 def add_status( thing, statusArray ) data = { token: @applicationToken, thing_id: thing.id, id: 'null', status_array: statusArray } @httpHelper.post_data( 'status', data ) end |
#add_thing(thing) ⇒ Object
Retrieve a thing. If it doesn’t exist, then add it.
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/webService.rb', line 54 def add_thing( thing ) data = { token: @applicationToken, name: thing.name, display_name: thing.display_name } if( thing.product_type.length > 0 ) data[:product_type] = thing.product_type end @httpHelper.post_data( 'thing', data ) end |
#get_authorization ⇒ Hash
Authorize this application by sending the application secret to Thingdom. If valid, Thingdom will send back a token which must be used in subsequent communications.
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/webService.rb', line 38 def () data = { api_secret: @apiSecret, device_secret: @deviceSecret } response = @httpHelper.post_data( 'token', data ) response[:device_secret] ||= ''; @applicationToken = response[:application_token] return response end |
#ping_server ⇒ Object
Ping Thingdom.
24 25 26 |
# File 'lib/webService.rb', line 24 def ping_server() @httpHelper.get_data( 'ping' ) end |