Class: SolarEdge::Client
- Inherits:
-
Object
- Object
- SolarEdge::Client
- Defined in:
- lib/solar_edge/client.rb
Instance Method Summary collapse
-
#initialize(api_key) ⇒ Client
constructor
A new instance of Client.
- #sites(search_text: nil, sort_by: nil, sort_order: nil) ⇒ Object
Constructor Details
#initialize(api_key) ⇒ Client
Returns a new instance of Client.
10 11 12 13 14 15 16 |
# File 'lib/solar_edge/client.rb', line 10 def initialize(api_key) @api_key = api_key @host = URI.parse('https://monitoringapi.solaredge.com/') @http = Net::HTTP.new(@host.host, @host.port) @http.use_ssl = (@host.scheme == 'https') @http.verify_mode = OpenSSL::SSL::VERIFY_PEER end |
Instance Method Details
#sites(search_text: nil, sort_by: nil, sort_order: nil) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/solar_edge/client.rb', line 18 def sites(search_text: nil, sort_by: nil, sort_order: nil) raise ArgumentError, "invalid sort_by" if sort_by && !VALID_SORT_PROPERTIES.include?(sort_by) raise ArgumentError, "sort_order must be specific with sort_by" if sort_order && !sort_by raise ArgumentError, "sort_order must be :asc or :desc" if sort_order && !%i{asc desc}.include?(sort_order) params = {} params[:search_text] = search_text if search_text params[:sort_property] = sort_by if sort_by params[:sort_order] = sort_order if sort_order # we cache the "all sites" query if params.empty? @sites ||= Sites.new(self, params) else Sites.new(self, params) end end |