Skip to content

Commit

Permalink
Added !sandycam
Browse files Browse the repository at this point in the history
  • Loading branch information
onewheelskyward committed Dec 9, 2016
1 parent cde8cba commit 536409e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
15 changes: 13 additions & 2 deletions lib/lita/handlers/onewheel_odot_tripcheck_web_hack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class OnewheelOdotTripcheckWebHack < Handler
route(/^tripcheck$/i, :handle_tripcheck_list, command: true,
help: { 'tripcheck': 'Display a list of tripcheck cameras covered.'})

route(/^sandycam$/i, :handle_sandycam, command: true)

def get_cameras
uri_base = 'https://tripcheck.com/RoadCams/cams/'

Expand All @@ -25,19 +27,28 @@ def get_cameras
}
end

def handle_sandycam(response)
Lita.logger.debug "SANDYCAM"
response.reply get_camera_url('sandy')
end

def handle_tripcheck(response)
input = response.matches[0][0]
Lita.logger.debug "Looking for '#{input}'"

response.reply get_camera_url(input)
end

def get_camera_url(input)
get_cameras.keys.each do |camera_key|
Lita.logger.debug "Trying to match '#{input.downcase}' to '#{camera_key.downcase}'"
if camera_key.to_s.downcase.include? input.downcase
image = get_cameras[camera_key]
unless camera_key.to_s == 'Sandy Blvd in Hollywood'
image += "?rand=#{Time.now.to_i}123"
end
response.reply image
return # Quick exit.

return image
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lita-onewheel-odot-tripcheck-web-hack.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |spec|
spec.name = 'lita-onewheel-odot-tripcheck-web-hack'
spec.version = '0.1.2'
spec.version = '0.2.0'
spec.authors = ['Andrew Kreps']
spec.email = ['andrew.kreps@gmail.com']
spec.description = %q{ODOT Tripcheck Cameras}
Expand Down
6 changes: 6 additions & 0 deletions spec/lita/handlers/onewheel_odot_tripcheck_web_hack_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

it { is_expected.to route_command('tripcheck blue') }
it { is_expected.to route_command('tripcheck') }
it { is_expected.to route_command('sandycam') }

it 'will respond to tripcheck' do
send_command 'tripcheck govy'
Expand All @@ -21,4 +22,9 @@
send_command 'tripcheck sandy'
expect(replies.last).to_not include('rand=')
end

it 'sandycam' do
send_command 'sandycam'
expect(replies.last).to eq('https://launchpad.pin13.net/cam/sandy.jpg')
end
end

0 comments on commit 536409e

Please sign in to comment.