lib/lita/handlers/onewheel_election_cnn.rb in lita-onewheel-election-cnn-3.0.0 vs lib/lita/handlers/onewheel_election_cnn.rb in lita-onewheel-election-cnn-3.0.1
- old
+ new
@@ -12,17 +12,18 @@
:election_by_state,
command: true,
help: {'election AB' => 'Display the current election results in Alabama.'}
def election(response)
- Lita.logger.debug 'get_source started'
+ Lita.logger.debug 'Getting election data'
results = JSON.parse(RestClient.get('http://data.cnn.com/ELECTION/2016/full/P.full.json'))
results['candidates'].each do |candidate|
candidate_str = "#{candidate['fname']} #{candidate['lname']}: "
candidate_str += "#{candidate['pctDecimal']}%"
candidate_str += " WINNER! #{candidate['evotes']} electoral votes." if candidate['winner']
+ Lita.logger.debug "Replying with #{candidate_str}"
response.reply candidate_str
end
end
def election_by_state(response)
@@ -31,15 +32,18 @@
state = stateness(response.matches[0][0])
results['races'].each do |race|
if race['state'].downcase == state.downcase
- response.reply "#{state}, #{race['evotes']} electoral votes, #{race['pctsrep']}% reporting"
+ state_reply = "#{state}, #{race['evotes']} electoral votes, #{race['pctsrep']}% reporting"
+ response.reply state_reply
+ Lita.logger.debug "Replying with #{state_reply}"
race['candidates'].each do |candidate|
candidate_str = "#{candidate['fname']} #{candidate['lname']}: "
candidate_str += "#{candidate['pctDecimal']}%"
candidate_str += " WINNER! #{candidate['evotes']} electoral votes." if candidate['winner']
+ Lita.logger.debug "Replying with #{candidate_str}"
response.reply candidate_str
end
end
end
end
@@ -101,11 +105,13 @@
"WV" => "West Virginia",
"WY" => "Wyoming"}
search_state = gimme.upcase
if search_state.length == 2
+ Lita.logger.debug "Returning #{states[search_state.upcase]} for #{search_state}"
states[search_state.upcase]
else
+ Lita.logger.debug "Returning #{search_state}"
search_state
end
end
Lita.register_handler(self)