Skip to content

Commit 27f4d5c

Browse files
committed
PvQuery.search uses wrapper gem for request WIP.
1 parent 828c09b commit 27f4d5c

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

app/models/pv_output.rb

+9-3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def initialize(similar_system)
4040
@efficiency = nil
4141
end
4242

43+
# TODO: fix me!
4344
# @return output_pa divided by system_watts (Wh).
4445
def output_per_system_watts
4546
output = self.output_pa / self.system_watts.to_i
@@ -92,6 +93,7 @@ def self.find_similar_system(pvo_search_params)
9293
top5.each do |system|
9394
# get rid of systems with secondary panels
9495
if system['entries'].to_i >= 100 && system['panel_count'] == 'NaN'
96+
# returning nil here in spec
9597
system_info = self.get_system(system['id'])
9698
if system_info['shade'] == 'No'
9799
similar_system = system_info.merge(system)
@@ -111,9 +113,12 @@ def self.find_similar_system(pvo_search_params)
111113
# @return [Array<Hash>] of systems [{name: 'some_name', size: 'size,...}, {...}]
112114
# or empty array.
113115
def self.search(query)
114-
params = { 'q' => query,
115-
'country' => 'Australia' }
116-
response = self.request('search', params)
116+
params = { :q => query,
117+
:country => 'Australia' }
118+
request = PvOutputWrapper::Request.new(Rails.application.secrets.pvo_api_key,
119+
Rails.application.secrets.pvo_system_id)
120+
response = request.search(params).body
121+
# response = self.request('search', params)
117122
response.chomp!
118123
results = []
119124
keys = ['name', 'system_watts', 'postcode', 'orientation', 'entries', 'last_entry', 'id', 'panel', 'inverter', 'distance', 'latitude', 'longitude']
@@ -133,6 +138,7 @@ def self.search(query)
133138
end
134139

135140
# @param [Fixnum]
141+
# TODO handle nil/empty resultset
136142
# @return [Hash] of system info data.
137143
def self.get_system(id)
138144
response = self.request('getsystem', {:sid1 => id})

0 commit comments

Comments
 (0)