Class: HttpHelper

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

Instance Method Summary collapse

Constructor Details

#initializeHttpHelper

Constructor method for HttpHelper. Initialize local data.



14
15
16
17
18
# File 'lib/httpHelper.rb', line 14

def initialize()
  @uri = URI.parse 'https://api.thingdom.io'
  @path = '/1.1'
  @request_counter = 0;
end

Instance Method Details

#get_data(requestPath) ⇒ Hash

Perform a HTTP GET request.

Parameters:

  • requestPath (String)

    Contains path and optional query parameters (e.g. path/to/somewhere?param1=1&param2=2)

Returns:

  • (Hash)

    The request response.



26
27
28
# File 'lib/httpHelper.rb', line 26

def get_data( requestPath )
  do_request( requestPath )
end

#post_data(requestPath, data) ⇒ Hash

Perform a HTTP Post request.

Parameters:

  • requestPath (String)

    Contains path to where data will be posted (e.g. path/to/post/endpoint)

  • data (Hash)

    The data to be posted.

Returns:

  • (Hash)

    The request response.



37
38
39
40
41
42
# File 'lib/httpHelper.rb', line 37

def post_data( requestPath, data )
  @request_counter += 1
  data[:counter] = @request_counter
  data[:time] = Time.now.strftime( '%Y/%m/%d %H:%M:%S' )
  do_request( requestPath, data )
end