Class: WebService

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

Instance Method Summary collapse

Constructor Details

#initialize(secret) ⇒ WebService

Constructor method for WebService.

Parameters:

  • secret (String)

    A secret identifier for an application obtained by the user during the registration process. Without this, the app will not have access to Thingdom.



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.

Parameters:

  • thing (Thing)

    The thing to which the feed message is applied.

  • category (String)

    The feed category.

  • message (String)

    The feed message.

  • feedOptions (FeedOption)

    Additional feed options (icon, progress bar, etc)



91
92
93
94
95
96
97
98
99
100
# File 'lib/webService.rb', line 91

def add_feed( thing, category, message, feedOptions  )
  data = {
              token: @applicationToken,
           thing_id: thing.id,
      feed_category: category,
            message: message,
            options: feedOptions
  }
  @httpHelper.post_data( 'feed', data )
end

#add_status(thing, statusArray) ⇒ Object

Add or update a status item for a thing.

Parameters:

  • thing (Thing)

    The thing to which the status item is attached.

  • statusArray (Array)

    An array of status item updates (name, value, unit).



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.

Parameters:

  • thing (Thing)

    The thing to get or add.



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_authorizationHash

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.

Returns:

  • (Hash)

    A hash containing the authorization response: application_token - The token used in subsequent communications with Thingdom expires_in - The number of seconds remaining before above token expires. device_secret - A unique identifier for device running this application

    (always "none" for the Ruby wrapper)
    


38
39
40
41
42
43
44
45
46
47
# File 'lib/webService.rb', line 38

def get_authorization()
  data = {
      api_secret: @apiSecret,
      device_secret: @deviceSecret
  }
  response = @httpHelper.post_data( 'token', data )
  response[:device_secret] ||= '';
  @applicationToken = response[:application_token]
  return response
end

#ping_serverObject

Ping Thingdom.



24
25
26
# File 'lib/webService.rb', line 24

def ping_server()
  @httpHelper.get_data( 'ping' )
end