require 'washbullet' require 'pokeplot/helpers/time' module Pokeplot class Pushbullet def initialize(api_key, pokemon = []) @pokemon = pokemon @client = Washbullet::Client.new(api_key) end def started(event) if event.command.has_key?('insert') if event.command.fetch('insert') == 'encounters' if @pokemon.include?(event.command.fetch('documents')[0][:pokemon]) text = "Found a #{event.command.fetch('documents')[0][:pokemon]}! " time = Helpers::Time.to_s(Time.now.to_i - ((event.command.fetch('documents')[0][:current_timestamp_ms].to_i / 1000) -(event.command.fetch('documents')[0][:time_till_hidden_ms].to_i / 1000))) text += "It expires in #{time}. " text += "Google maps: http://www.google.com/maps/place/#{event.command.fetch('documents')[0][:latitude]},#{event.command.fetch('documents')[0][:longitude]}" @client.devices.each do |device| @client.push_note( receiver: :device, identifier: device.body['iden'], params: { title: 'Pokeplot', body: text } ) end end end end end def failed(_); end def succeeded(_); end end end