Class: RubyTCC::REST::Client
- 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
-
#session_id ⇒ Object
Returns the value of attribute session_id.
Attributes inherited from Client
#application_id, #application_version, #password, #proxy, #ui_language, #user_agent, #username
Instance Method Summary collapse
-
#complete_post(method, result, options) ⇒ Object
Perform a standardized post with module information.
- #connection_options ⇒ Hash
- #credentials? ⇒ Boolean
-
#get(path, params = {}) ⇒ Object
Perform an HTTP GET request.
- #middleware ⇒ Faraday::RackBuilder
-
#post(path, params = {}) ⇒ Object
Perform an HTTP POST request.
- #session_id? ⇒ Boolean
Methods included from LogOff
Methods included from KeepAlive
Methods included from GetWeatherForecast
Methods included from GetVolatileThermostatData
Methods included from GetUserAddressInfo
Methods included from GetThermostatUI
Methods included from GetThermostatHumidification
#get_thermostat_humidification
Methods included from GetThermostatFan
Methods included from GetThermostat
Methods included from GetSystemGeoInfo
Methods included from GetShortLocationInfo
Methods included from GetSchedule
Methods included from GetLocations
Methods included from GetCommTaskState
Methods included from EditLocation
Methods included from CreateLocation
Methods included from ChangeThermostatUI
Methods included from ChangeThermostatFan
Methods included from AuthenticateUserLogin
Methods inherited from Client
Constructor Details
This class inherits a constructor from RubyTCC::Client
Instance Attribute Details
#session_id ⇒ Object
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, ) response = post(URL_SUFFIX + method, ) 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_options ⇒ 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 ||= { :builder => middleware, :headers => { # :accept => 'application/json', :user_agent => user_agent, }, :request => { :open_timeout => 10, :timeout => 30, }, :proxy => proxy, :ssl => { :verify => false} } end |
#credentials? ⇒ 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 |
#middleware ⇒ Faraday::RackBuilder
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
76 77 78 |
# File 'lib/rubytcc/rest/client.rb', line 76 def session_id? !!session_id end |