rubytcc 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +37 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +118 -0
- data/Guardfile +22 -0
- data/LICENSE +22 -0
- data/Rakefile +10 -0
- data/Readme.md +107 -0
- data/lib/rubytcc.rb +9 -0
- data/lib/rubytcc/authenticate_login_result.rb +11 -0
- data/lib/rubytcc/change_request_result.rb +8 -0
- data/lib/rubytcc/change_thermostat_ui_result.rb +8 -0
- data/lib/rubytcc/client.rb +72 -0
- data/lib/rubytcc/country_info.rb +11 -0
- data/lib/rubytcc/create_location_result.rb +9 -0
- data/lib/rubytcc/current_weather.rb +13 -0
- data/lib/rubytcc/demand_response_event.rb +16 -0
- data/lib/rubytcc/edit_location_result.rb +9 -0
- data/lib/rubytcc/enumberable.rb +26 -0
- data/lib/rubytcc/error.rb +60 -0
- data/lib/rubytcc/fan.rb +12 -0
- data/lib/rubytcc/forecast_day_info.rb +13 -0
- data/lib/rubytcc/get_comm_task_state_result.rb +10 -0
- data/lib/rubytcc/get_locations_result.rb +10 -0
- data/lib/rubytcc/get_schedule_result.rb +11 -0
- data/lib/rubytcc/get_short_location_info_result.rb +10 -0
- data/lib/rubytcc/get_system_geo_info_result.rb +10 -0
- data/lib/rubytcc/get_thermostat_fan_result.rb +10 -0
- data/lib/rubytcc/get_thermostat_humidification_result.rb +10 -0
- data/lib/rubytcc/get_thermostat_result.rb +10 -0
- data/lib/rubytcc/get_thermostat_ui_result.rb +8 -0
- data/lib/rubytcc/get_user_address_info_result.rb +10 -0
- data/lib/rubytcc/get_volatile_thermostat_data_result.rb +11 -0
- data/lib/rubytcc/get_weather_forecast_result.rb +10 -0
- data/lib/rubytcc/helper.rb +14 -0
- data/lib/rubytcc/humidification.rb +17 -0
- data/lib/rubytcc/keep_alive_result.rb +7 -0
- data/lib/rubytcc/location_info.rb +18 -0
- data/lib/rubytcc/log_off_result.rb +7 -0
- data/lib/rubytcc/rest/api.rb +45 -0
- data/lib/rubytcc/rest/authenticate_user_login.rb +14 -0
- data/lib/rubytcc/rest/change_thermostat_fan.rb +14 -0
- data/lib/rubytcc/rest/change_thermostat_ui.rb +13 -0
- data/lib/rubytcc/rest/client.rb +107 -0
- data/lib/rubytcc/rest/create_location.rb +13 -0
- data/lib/rubytcc/rest/edit_location.rb +13 -0
- data/lib/rubytcc/rest/get_comm_task_state.rb +13 -0
- data/lib/rubytcc/rest/get_locations.rb +13 -0
- data/lib/rubytcc/rest/get_schedule.rb +13 -0
- data/lib/rubytcc/rest/get_short_location_info.rb +13 -0
- data/lib/rubytcc/rest/get_system_geo_info.rb +13 -0
- data/lib/rubytcc/rest/get_thermostat.rb +13 -0
- data/lib/rubytcc/rest/get_thermostat_fan.rb +13 -0
- data/lib/rubytcc/rest/get_thermostat_humidification.rb +13 -0
- data/lib/rubytcc/rest/get_thermostat_ui.rb +13 -0
- data/lib/rubytcc/rest/get_user_address_info.rb +13 -0
- data/lib/rubytcc/rest/get_volatile_thermostat_data.rb +13 -0
- data/lib/rubytcc/rest/get_weather_forecast.rb +13 -0
- data/lib/rubytcc/rest/keep_alive.rb +13 -0
- data/lib/rubytcc/rest/log_off.rb +13 -0
- data/lib/rubytcc/schedule.rb +11 -0
- data/lib/rubytcc/scheduled_period_info.rb +14 -0
- data/lib/rubytcc/short_location_info.rb +19 -0
- data/lib/rubytcc/state_info.rb +7 -0
- data/lib/rubytcc/thermostat.rb +11 -0
- data/lib/rubytcc/thermostat_alert.rb +7 -0
- data/lib/rubytcc/thermostat_info.rb +22 -0
- data/lib/rubytcc/ui.rb +38 -0
- data/lib/rubytcc/user_address_info.rb +16 -0
- data/lib/rubytcc/user_info.rb +12 -0
- data/lib/rubytcc/version.rb +4 -0
- data/rubytcc.gemspec +33 -0
- data/spec/lib/rubytcc/helper_spec.rb +28 -0
- data/spec/lib/rubytcc/rest/authenticate_user_login_spec.rb +25 -0
- data/spec/lib/rubytcc/rest/change_thermostat_fan_spec.rb +28 -0
- data/spec/lib/rubytcc/rest/change_thermostat_ui_spec.rb +44 -0
- data/spec/lib/rubytcc/rest/client_spec.rb +34 -0
- data/spec/lib/rubytcc/rest/create_location_spec.rb +39 -0
- data/spec/lib/rubytcc/rest/edit_location_spec.rb +42 -0
- data/spec/lib/rubytcc/rest/get_comm_task_state_spec.rb +28 -0
- data/spec/lib/rubytcc/rest/get_locations_spec.rb +28 -0
- data/spec/lib/rubytcc/rest/get_schedule_spec.rb +28 -0
- data/spec/lib/rubytcc/rest/get_short_location_info_spec.rb +27 -0
- data/spec/lib/rubytcc/rest/get_system_geo_info_spec.rb +27 -0
- data/spec/lib/rubytcc/rest/get_thermostat_fan_spec.rb +27 -0
- data/spec/lib/rubytcc/rest/get_thermostat_humidification_spec.rb +27 -0
- data/spec/lib/rubytcc/rest/get_thermostat_spec.rb +27 -0
- data/spec/lib/rubytcc/rest/get_thermostat_ui_spec.rb +27 -0
- data/spec/lib/rubytcc/rest/get_user_address_info_spec.rb +27 -0
- data/spec/lib/rubytcc/rest/get_volatile_thermostat_data_spec.rb +27 -0
- data/spec/lib/rubytcc/rest/get_weather_forecast_spec.rb +27 -0
- data/spec/lib/rubytcc/rest/keep_alive_spec.rb +26 -0
- data/spec/lib/rubytcc/rest/log_off_spec.rb +34 -0
- data/spec/lib/rubytcc_spec.rb +2 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/support/vcr_setup.rb +7 -0
- metadata +331 -0
@@ -0,0 +1,13 @@
|
|
1
|
+
module RubyTCC
|
2
|
+
class CurrentWeather
|
3
|
+
include XML::Mapping
|
4
|
+
|
5
|
+
boolean_node :is_defined, "IsDefined"
|
6
|
+
boolean_node :is_valid, "IsValid"
|
7
|
+
text_node :condition, "Condition"
|
8
|
+
numeric_node :temperature, "Temperature"
|
9
|
+
text_node :temp_unit, "TempUnit"
|
10
|
+
numeric_node :humidity, "Humidity"
|
11
|
+
text_node :phrase_key, "PhraseKey", :default_value => ""
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module RubyTCC
|
2
|
+
class DemandResponseEvent
|
3
|
+
include XML::Mapping
|
4
|
+
|
5
|
+
numeric_node :dr_event_id, "DREventId"
|
6
|
+
text_node :start_time, "StartTime"
|
7
|
+
text_node :end_time, "EndTime"
|
8
|
+
boolean_node :opted_out, "OptedOut"
|
9
|
+
boolean_node :optoutable, "Optoutable"
|
10
|
+
text_node :phase, "Phase"
|
11
|
+
numeric_node :heat_setpoint_limit, "HeatSetpointLimit"
|
12
|
+
numeric_node :cool_setpoint_limit, "CoolSetpointLimit"
|
13
|
+
# array_node :intervals, "Intervals", ?, ? <-- Unable to determine the contents of the interval model
|
14
|
+
boolean_node :hidden, "Hidden"
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# Credit: https://github.com/sferik/twitter/blob/master/lib/twitter/enumerable.rb
|
2
|
+
module RubyTCC
|
3
|
+
module Enumerable
|
4
|
+
include ::Enumerable
|
5
|
+
|
6
|
+
# @return [Enumerator]
|
7
|
+
def each(start = 0)
|
8
|
+
return to_enum(:each, start) unless block_given?
|
9
|
+
Array(@collection[start..-1]).each do |element|
|
10
|
+
yield(element)
|
11
|
+
end
|
12
|
+
unless last?
|
13
|
+
start = [@collection.size, start].max
|
14
|
+
fetch_next_page
|
15
|
+
each(start, &Proc.new)
|
16
|
+
end
|
17
|
+
self
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
# @return [Boolean]
|
23
|
+
def last?
|
24
|
+
true
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module RubyTCC
|
2
|
+
# Custom error class for rescuing from all RubyTCC errors
|
3
|
+
class Error < StandardError
|
4
|
+
# @return [Integer]
|
5
|
+
attr_reader :code
|
6
|
+
|
7
|
+
class << self
|
8
|
+
# Create a new error from an HTTP response
|
9
|
+
#
|
10
|
+
# @param response [RestClient::Response]
|
11
|
+
# @return [RubyTCC::Error]
|
12
|
+
def from_response(response)
|
13
|
+
message, code = parse_error(response.body)
|
14
|
+
new(message, response.response_headers, code)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def parse_error(body)
|
20
|
+
if body.nil?
|
21
|
+
['', nil]
|
22
|
+
elsif body[:error]
|
23
|
+
[body[:error], nil]
|
24
|
+
elsif body[:errors]
|
25
|
+
extract_message_from_errors(body)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def extract_message_from_errors(body)
|
30
|
+
first = Array(body[:errors]).first
|
31
|
+
if first.is_a?(Hash)
|
32
|
+
[first[:message].chomp, first[:code]]
|
33
|
+
else
|
34
|
+
[first.chomp, nil]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Initializes a new Error object
|
40
|
+
#
|
41
|
+
# @param message [Exception, String]
|
42
|
+
# @param code [Integer]
|
43
|
+
# @return [RubyTCC::Error]
|
44
|
+
def initialize(message = '', code = nil)
|
45
|
+
super(message)
|
46
|
+
@code = code
|
47
|
+
end
|
48
|
+
|
49
|
+
ConfigurationError = Class.new(::ArgumentError)
|
50
|
+
|
51
|
+
# Raised when RubyTCC returns a 4xx HTTP status code
|
52
|
+
ClientError = Class.new(self)
|
53
|
+
|
54
|
+
# Raised when RubyTCC returns the HTTP status code 408
|
55
|
+
RequestTimeout = Class.new(ClientError)
|
56
|
+
|
57
|
+
# Raised when the result is not "Success"
|
58
|
+
ResultError = Class.new(self)
|
59
|
+
end
|
60
|
+
end
|
data/lib/rubytcc/fan.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
module RubyTCC
|
2
|
+
class Fan
|
3
|
+
include XML::Mapping
|
4
|
+
|
5
|
+
boolean_node :can_control, "CanControl"
|
6
|
+
text_node :position, "Position"
|
7
|
+
boolean_node :can_set_auto, "CanSetAuto"
|
8
|
+
boolean_node :can_set_circulate, "CanSetCirculate"
|
9
|
+
boolean_node :can_follow_schedule, "CanFollowSchedule"
|
10
|
+
boolean_node :can_set_on, "CanSetOn"
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module RubyTCC
|
2
|
+
class ForecastDayInfo
|
3
|
+
include XML::Mapping
|
4
|
+
|
5
|
+
text_node :date, "Date"
|
6
|
+
text_node :condition, "Condition"
|
7
|
+
numeric_node :low, "Low"
|
8
|
+
text_node :low_unit, "LowUnit"
|
9
|
+
numeric_node :high, "High"
|
10
|
+
text_node :high_unit, "HighUnit"
|
11
|
+
text_node :phrase, "Phrase"
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module RubyTCC
|
2
|
+
module Helper
|
3
|
+
class << self
|
4
|
+
def to_period(time)
|
5
|
+
time = Time.parse(time).to_i
|
6
|
+
(time - Time.parse("00:00").to_i) / (15 * 60)
|
7
|
+
end
|
8
|
+
|
9
|
+
def camelize underscored_word
|
10
|
+
underscored_word.to_s.gsub(/(?:^|_)(.)/) { $1.upcase }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module RubyTCC
|
2
|
+
class Humidification
|
3
|
+
include XML::Mapping
|
4
|
+
|
5
|
+
boolean_node :can_control_humidification, "CanControlHumidification"
|
6
|
+
boolean_node :can_control_dehumidification, "CanControlDehumidification"
|
7
|
+
numeric_node :humidification_set_point, "HumidificationSetPoint"
|
8
|
+
numeric_node :humidification_upper_limit, "HumidificationUpperLimit"
|
9
|
+
numeric_node :humidification_lower_limit, "HumidificationLowerLimit"
|
10
|
+
text_node :humidification_mode, "HumidificationMode"
|
11
|
+
numeric_node :dehumidification_set_point, "DehumidificationSetPoint"
|
12
|
+
numeric_node :dehumidification_upper_limit, "DehumidificationUpperLimit"
|
13
|
+
numeric_node :dehumidification_lower_limit, "DehumidificationLowerLimit"
|
14
|
+
text_node :dehumidification_mode, "DehumidificationMode"
|
15
|
+
numeric_node :deadband, "Deadband"
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubytcc/current_weather'
|
2
|
+
require 'rubytcc/thermostat_info'
|
3
|
+
|
4
|
+
module RubyTCC
|
5
|
+
class LocationInfo
|
6
|
+
include XML::Mapping
|
7
|
+
|
8
|
+
numeric_node :location_id, "LocationID"
|
9
|
+
boolean_node :can_control, "CanControl"
|
10
|
+
text_node :name, "Name"
|
11
|
+
text_node :type, "Type"
|
12
|
+
text_node :country, "Country"
|
13
|
+
numeric_node :zip_code, "ZipCode"
|
14
|
+
object_node :current_weather, "CurrentWeather", :class => RubyTCC::CurrentWeather
|
15
|
+
array_node :thermostats, "Thermostats", "ThermostatInfo", :class => RubyTCC::ThermostatInfo
|
16
|
+
text_node :time_zone, "TimeZone"
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'rubytcc/rest/authenticate_user_login'
|
2
|
+
require 'rubytcc/rest/change_thermostat_fan'
|
3
|
+
require 'rubytcc/rest/change_thermostat_ui'
|
4
|
+
require 'rubytcc/rest/create_location'
|
5
|
+
require 'rubytcc/rest/edit_location'
|
6
|
+
require 'rubytcc/rest/get_comm_task_state'
|
7
|
+
require 'rubytcc/rest/get_locations'
|
8
|
+
require 'rubytcc/rest/get_schedule'
|
9
|
+
require 'rubytcc/rest/get_short_location_info'
|
10
|
+
require 'rubytcc/rest/get_system_geo_info'
|
11
|
+
require 'rubytcc/rest/get_thermostat'
|
12
|
+
require 'rubytcc/rest/get_thermostat_fan'
|
13
|
+
require 'rubytcc/rest/get_thermostat_humidification'
|
14
|
+
require 'rubytcc/rest/get_thermostat_ui'
|
15
|
+
require 'rubytcc/rest/get_user_address_info'
|
16
|
+
require 'rubytcc/rest/get_volatile_thermostat_data'
|
17
|
+
require 'rubytcc/rest/get_weather_forecast'
|
18
|
+
require 'rubytcc/rest/keep_alive'
|
19
|
+
require 'rubytcc/rest/log_off'
|
20
|
+
|
21
|
+
module RubyTCC
|
22
|
+
module REST
|
23
|
+
module API
|
24
|
+
include RubyTCC::REST::AuthenticateUserLogin
|
25
|
+
include RubyTCC::REST::ChangeThermostatFan
|
26
|
+
include RubyTCC::REST::ChangeThermostatUI
|
27
|
+
include RubyTCC::REST::CreateLocation
|
28
|
+
include RubyTCC::REST::EditLocation
|
29
|
+
include RubyTCC::REST::GetCommTaskState
|
30
|
+
include RubyTCC::REST::GetLocations
|
31
|
+
include RubyTCC::REST::GetSchedule
|
32
|
+
include RubyTCC::REST::GetShortLocationInfo
|
33
|
+
include RubyTCC::REST::GetSystemGeoInfo
|
34
|
+
include RubyTCC::REST::GetThermostat
|
35
|
+
include RubyTCC::REST::GetThermostatFan
|
36
|
+
include RubyTCC::REST::GetThermostatHumidification
|
37
|
+
include RubyTCC::REST::GetThermostatUI
|
38
|
+
include RubyTCC::REST::GetUserAddressInfo
|
39
|
+
include RubyTCC::REST::GetVolatileThermostatData
|
40
|
+
include RubyTCC::REST::GetWeatherForecast
|
41
|
+
include RubyTCC::REST::KeepAlive
|
42
|
+
include RubyTCC::REST::LogOff
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rubytcc/authenticate_login_result'
|
2
|
+
|
3
|
+
module RubyTCC
|
4
|
+
module REST
|
5
|
+
module AuthenticateUserLogin
|
6
|
+
def authenticate_user_login(options = self.credentials)
|
7
|
+
module_name = Module.nesting[0].to_s.split("::").last
|
8
|
+
result = complete_post(module_name, "AuthenticateLogin", options)
|
9
|
+
self.session_id = result.session_id
|
10
|
+
result
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|