Class: RubyTCC::REST::Client

Inherits:
Client
  • Object
show all
Includes:
API
Defined in:
lib/rubytcc/rest/client.rb

Overview

API Client with methods for interacting with the web API

Constant Summary collapse

URL_PREFIX =
'https://rs.alarmnet.com'
URL_SUFFIX =
'/TotalConnectComfort/ws/MobileV2.asmx/'
ENDPOINT =
URL_PREFIX + URL_SUFFIX

Instance Attribute Summary collapse

Attributes inherited from Client

#application_id, #application_version, #password, #proxy, #ui_language, #user_agent, #username

Instance Method Summary collapse

Methods included from LogOff

#log_off

Methods included from KeepAlive

#keep_alive

Methods included from GetWeatherForecast

#get_weather_forecast

Methods included from GetVolatileThermostatData

#get_volatile_thermostat_data

Methods included from GetUserAddressInfo

#get_user_address_info

Methods included from GetThermostatUI

#get_thermostat_ui

Methods included from GetThermostatHumidification

#get_thermostat_humidification

Methods included from GetThermostatFan

#get_thermostat_fan

Methods included from GetThermostat

#get_thermostat

Methods included from GetSystemGeoInfo

#get_system_geo_info

Methods included from GetShortLocationInfo

#get_short_location_info

Methods included from GetSchedule

#get_schedule

Methods included from GetLocations

#get_locations

Methods included from GetCommTaskState

#get_comm_task_state

Methods included from EditLocation

#edit_location

Methods included from CreateLocation

#create_location

Methods included from ChangeThermostatUI

#change_thermostat_ui

Methods included from ChangeThermostatFan

#change_thermostat_fan

Methods included from AuthenticateUserLogin

#authenticate_user_login

Methods inherited from Client

#credentials, #initialize

Constructor Details

This class inherits a constructor from RubyTCC::Client

Instance Attribute Details

#session_idObject

Returns the value of attribute session_id.



14
15
16
# File 'lib/rubytcc/rest/client.rb', line 14

def session_id
  @session_id
end

Instance Method Details

#complete_post(method, result, options) ⇒ Object

Perform a standardized post with module information



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/rubytcc/rest/client.rb', line 63

def complete_post(method, result, options)
	response = post(URL_SUFFIX + method, options)
	result = Object.const_get("RubyTCC::" + result + "Result")
	xml = REXML::Document.new(response.body).root
	status = xml.elements["Result"].text
	if status != "Success" then
		raise RubyTCC::Error::ResultError.new(status)
	else
		result.load_from_xml(REXML::Document.new(response.body).root)
	end
end

#connection_optionsHash

Returns:

  • (Hash)


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rubytcc/rest/client.rb', line 21

def connection_options
		    	@connection_options ||= {
    :builder => middleware,
    :headers => {
      # :accept => 'application/json',
      :user_agent => user_agent,
    },
    :request => {
      :open_timeout => 10,
      :timeout => 30,
    },
    :proxy => proxy,
    :ssl => { :verify => false}
  }
end

#credentials?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/rubytcc/rest/client.rb', line 81

def credentials?
super || session_id?
end

#get(path, params = {}) ⇒ Object

Perform an HTTP GET request



51
52
53
54
# File 'lib/rubytcc/rest/client.rb', line 51

def get(path, params = {})
    headers = request_headers(:get, URL_PREFIX + path, params)
    request(:get, path, params, headers)
end

#middlewareFaraday::RackBuilder

Note:

Faraday’s middleware stack implementation is comparable to that of Rack middleware. The order of middleware is important: the first middleware on the list wraps all others, while the last middleware is the innermost one.



41
42
43
44
45
46
47
48
# File 'lib/rubytcc/rest/client.rb', line 41

def middleware
   @middleware ||= Faraday::RackBuilder.new do |faraday|
     # Encodes as "application/x-www-form-urlencoded" if not already encoded
     faraday.request :url_encoded
     # Set default HTTP adapter
     faraday.adapter :net_http
   end
end

#post(path, params = {}) ⇒ Object

Perform an HTTP POST request



57
58
59
60
# File 'lib/rubytcc/rest/client.rb', line 57

def post(path, params = {})
	headers = params.values.any? { |value| value.respond_to?(:to_io) } ? request_headers(:post, ENDPOINT + path, params, {}) : request_headers(:post, ENDPOINT + path, params)
	    		request(:post, path, params, headers)
end

#session_id?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/rubytcc/rest/client.rb', line 76

def session_id?
    !!session_id
end