rubytcc 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +37 -0
  3. data/Gemfile +3 -0
  4. data/Gemfile.lock +118 -0
  5. data/Guardfile +22 -0
  6. data/LICENSE +22 -0
  7. data/Rakefile +10 -0
  8. data/Readme.md +107 -0
  9. data/lib/rubytcc.rb +9 -0
  10. data/lib/rubytcc/authenticate_login_result.rb +11 -0
  11. data/lib/rubytcc/change_request_result.rb +8 -0
  12. data/lib/rubytcc/change_thermostat_ui_result.rb +8 -0
  13. data/lib/rubytcc/client.rb +72 -0
  14. data/lib/rubytcc/country_info.rb +11 -0
  15. data/lib/rubytcc/create_location_result.rb +9 -0
  16. data/lib/rubytcc/current_weather.rb +13 -0
  17. data/lib/rubytcc/demand_response_event.rb +16 -0
  18. data/lib/rubytcc/edit_location_result.rb +9 -0
  19. data/lib/rubytcc/enumberable.rb +26 -0
  20. data/lib/rubytcc/error.rb +60 -0
  21. data/lib/rubytcc/fan.rb +12 -0
  22. data/lib/rubytcc/forecast_day_info.rb +13 -0
  23. data/lib/rubytcc/get_comm_task_state_result.rb +10 -0
  24. data/lib/rubytcc/get_locations_result.rb +10 -0
  25. data/lib/rubytcc/get_schedule_result.rb +11 -0
  26. data/lib/rubytcc/get_short_location_info_result.rb +10 -0
  27. data/lib/rubytcc/get_system_geo_info_result.rb +10 -0
  28. data/lib/rubytcc/get_thermostat_fan_result.rb +10 -0
  29. data/lib/rubytcc/get_thermostat_humidification_result.rb +10 -0
  30. data/lib/rubytcc/get_thermostat_result.rb +10 -0
  31. data/lib/rubytcc/get_thermostat_ui_result.rb +8 -0
  32. data/lib/rubytcc/get_user_address_info_result.rb +10 -0
  33. data/lib/rubytcc/get_volatile_thermostat_data_result.rb +11 -0
  34. data/lib/rubytcc/get_weather_forecast_result.rb +10 -0
  35. data/lib/rubytcc/helper.rb +14 -0
  36. data/lib/rubytcc/humidification.rb +17 -0
  37. data/lib/rubytcc/keep_alive_result.rb +7 -0
  38. data/lib/rubytcc/location_info.rb +18 -0
  39. data/lib/rubytcc/log_off_result.rb +7 -0
  40. data/lib/rubytcc/rest/api.rb +45 -0
  41. data/lib/rubytcc/rest/authenticate_user_login.rb +14 -0
  42. data/lib/rubytcc/rest/change_thermostat_fan.rb +14 -0
  43. data/lib/rubytcc/rest/change_thermostat_ui.rb +13 -0
  44. data/lib/rubytcc/rest/client.rb +107 -0
  45. data/lib/rubytcc/rest/create_location.rb +13 -0
  46. data/lib/rubytcc/rest/edit_location.rb +13 -0
  47. data/lib/rubytcc/rest/get_comm_task_state.rb +13 -0
  48. data/lib/rubytcc/rest/get_locations.rb +13 -0
  49. data/lib/rubytcc/rest/get_schedule.rb +13 -0
  50. data/lib/rubytcc/rest/get_short_location_info.rb +13 -0
  51. data/lib/rubytcc/rest/get_system_geo_info.rb +13 -0
  52. data/lib/rubytcc/rest/get_thermostat.rb +13 -0
  53. data/lib/rubytcc/rest/get_thermostat_fan.rb +13 -0
  54. data/lib/rubytcc/rest/get_thermostat_humidification.rb +13 -0
  55. data/lib/rubytcc/rest/get_thermostat_ui.rb +13 -0
  56. data/lib/rubytcc/rest/get_user_address_info.rb +13 -0
  57. data/lib/rubytcc/rest/get_volatile_thermostat_data.rb +13 -0
  58. data/lib/rubytcc/rest/get_weather_forecast.rb +13 -0
  59. data/lib/rubytcc/rest/keep_alive.rb +13 -0
  60. data/lib/rubytcc/rest/log_off.rb +13 -0
  61. data/lib/rubytcc/schedule.rb +11 -0
  62. data/lib/rubytcc/scheduled_period_info.rb +14 -0
  63. data/lib/rubytcc/short_location_info.rb +19 -0
  64. data/lib/rubytcc/state_info.rb +7 -0
  65. data/lib/rubytcc/thermostat.rb +11 -0
  66. data/lib/rubytcc/thermostat_alert.rb +7 -0
  67. data/lib/rubytcc/thermostat_info.rb +22 -0
  68. data/lib/rubytcc/ui.rb +38 -0
  69. data/lib/rubytcc/user_address_info.rb +16 -0
  70. data/lib/rubytcc/user_info.rb +12 -0
  71. data/lib/rubytcc/version.rb +4 -0
  72. data/rubytcc.gemspec +33 -0
  73. data/spec/lib/rubytcc/helper_spec.rb +28 -0
  74. data/spec/lib/rubytcc/rest/authenticate_user_login_spec.rb +25 -0
  75. data/spec/lib/rubytcc/rest/change_thermostat_fan_spec.rb +28 -0
  76. data/spec/lib/rubytcc/rest/change_thermostat_ui_spec.rb +44 -0
  77. data/spec/lib/rubytcc/rest/client_spec.rb +34 -0
  78. data/spec/lib/rubytcc/rest/create_location_spec.rb +39 -0
  79. data/spec/lib/rubytcc/rest/edit_location_spec.rb +42 -0
  80. data/spec/lib/rubytcc/rest/get_comm_task_state_spec.rb +28 -0
  81. data/spec/lib/rubytcc/rest/get_locations_spec.rb +28 -0
  82. data/spec/lib/rubytcc/rest/get_schedule_spec.rb +28 -0
  83. data/spec/lib/rubytcc/rest/get_short_location_info_spec.rb +27 -0
  84. data/spec/lib/rubytcc/rest/get_system_geo_info_spec.rb +27 -0
  85. data/spec/lib/rubytcc/rest/get_thermostat_fan_spec.rb +27 -0
  86. data/spec/lib/rubytcc/rest/get_thermostat_humidification_spec.rb +27 -0
  87. data/spec/lib/rubytcc/rest/get_thermostat_spec.rb +27 -0
  88. data/spec/lib/rubytcc/rest/get_thermostat_ui_spec.rb +27 -0
  89. data/spec/lib/rubytcc/rest/get_user_address_info_spec.rb +27 -0
  90. data/spec/lib/rubytcc/rest/get_volatile_thermostat_data_spec.rb +27 -0
  91. data/spec/lib/rubytcc/rest/get_weather_forecast_spec.rb +27 -0
  92. data/spec/lib/rubytcc/rest/keep_alive_spec.rb +26 -0
  93. data/spec/lib/rubytcc/rest/log_off_spec.rb +34 -0
  94. data/spec/lib/rubytcc_spec.rb +2 -0
  95. data/spec/spec_helper.rb +17 -0
  96. data/spec/support/vcr_setup.rb +7 -0
  97. metadata +331 -0
@@ -0,0 +1,11 @@
1
+ require 'rubytcc/state_info'
2
+
3
+ module RubyTCC
4
+ class CountryInfo
5
+ include XML::Mapping
6
+
7
+ text_node :country_code, "CountryCode"
8
+ text_node :name, "Name"
9
+ array_node :states, "States", "StateInfo", :class => RubyTCC::StateInfo
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ module RubyTCC
2
+ class CreateLocationResult
3
+ include XML::Mapping
4
+
5
+ text_node :result, "Result"
6
+ text_node :location_name, "LocationName"
7
+ numeric_node :location_id, "LocationID"
8
+ end
9
+ end
@@ -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,9 @@
1
+ module RubyTCC
2
+ class EditLocationResult
3
+ include XML::Mapping
4
+
5
+ text_node :result, "Result"
6
+ text_node :location_name, "LocationName"
7
+ numeric_node :location_id, "LocationID"
8
+ end
9
+ 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
@@ -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,10 @@
1
+ module RubyTCC
2
+ class GetCommTaskStateResult
3
+ include XML::Mapping
4
+
5
+ text_node :result, "Result"
6
+ numeric_node :comm_task_id, "CommTaskID"
7
+ text_node :state, "State"
8
+ text_node :fault_reason, "FaultReason"
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubytcc/location_info'
2
+
3
+ module RubyTCC
4
+ class GetLocationsResult
5
+ include XML::Mapping
6
+
7
+ text_node :result, "Result"
8
+ array_node :locations, "Locations", "LocationInfo", :class => RubyTCC::LocationInfo
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ require 'rubytcc/schedule'
2
+
3
+ module RubyTCC
4
+ class GetScheduleResult
5
+ include XML::Mapping
6
+
7
+ text_node :result, "Result"
8
+ object_node :schedule, "Schedule", :class => RubyTCC::Schedule
9
+ boolean_node :loading, "Loading"
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubytcc/short_location_info'
2
+
3
+ module RubyTCC
4
+ class GetShortLocationInfoResult
5
+ include XML::Mapping
6
+
7
+ text_node :result, "Result"
8
+ array_node :locations, "Locations", "ShortLocationInfo", :class => RubyTCC::ShortLocationInfo
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubytcc/country_info'
2
+
3
+ module RubyTCC
4
+ class GetSystemGeoInfoResult
5
+ include XML::Mapping
6
+
7
+ text_node :result, "Result"
8
+ array_node :countries, "Countries", "CountryInfo", :class => RubyTCC::CountryInfo
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubytcc/fan'
2
+
3
+ module RubyTCC
4
+ class GetThermostatFanResult
5
+ include XML::Mapping
6
+
7
+ text_node :result, "Result"
8
+ object_node :fan, "Fan", :class => RubyTCC::Fan
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubytcc/humidification'
2
+
3
+ module RubyTCC
4
+ class GetThermostatHumidificationResult
5
+ include XML::Mapping
6
+
7
+ text_node :result, "Result"
8
+ object_node :humidification, "Humidification", :class => RubyTCC::Humidification
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubytcc/thermostat'
2
+
3
+ module RubyTCC
4
+ class GetThermostatResult
5
+ include XML::Mapping
6
+
7
+ text_node :result, "Result"
8
+ object_node :thermostat, "Thermostat", :class => RubyTCC::Thermostat
9
+ end
10
+ end
@@ -0,0 +1,8 @@
1
+ module RubyTCC
2
+ class GetThermostatUIResult
3
+ include XML::Mapping
4
+
5
+ text_node :result, "Result"
6
+ object_node :ui, "UI", :class => RubyTCC::UI
7
+ end
8
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubytcc/user_address_info'
2
+
3
+ module RubyTCC
4
+ class GetUserAddressInfoResult
5
+ include XML::Mapping
6
+
7
+ text_node :result, "Result"
8
+ object_node :user_address_info, "UserAddressInfo", :class => RubyTCC::UserAddressInfo
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ require 'rubytcc/ui'
2
+
3
+ module RubyTCC
4
+ class GetVolatileThermostatDataResult
5
+ include XML::Mapping
6
+
7
+ text_node :result, "Result"
8
+ object_node :ui, "UI", :class => RubyTCC::UI
9
+ text_node :upgrading, "Upgrading"
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubytcc/forecast_day_info'
2
+
3
+ module RubyTCC
4
+ class GetWeatherForecastResult
5
+ include XML::Mapping
6
+
7
+ text_node :result, "Result"
8
+ array_node :forecast, "Forecast", "ForecastDayInfo", :class => RubyTCC::ForecastDayInfo
9
+ end
10
+ 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,7 @@
1
+ module RubyTCC
2
+ class KeepAliveResult
3
+ include XML::Mapping
4
+
5
+ text_node :result, "Result"
6
+ end
7
+ 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,7 @@
1
+ module RubyTCC
2
+ class LogOffResult
3
+ include XML::Mapping
4
+
5
+ text_node :result, "Result"
6
+ end
7
+ 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