Skip to content

Instantly share code, notes, and snippets.

@makoto
Created February 28, 2009 20:02
Show Gist options
  • Select an option

  • Save makoto/72082 to your computer and use it in GitHub Desktop.

Select an option

Save makoto/72082 to your computer and use it in GitHub Desktop.
require 'json'
class GeoTimeline < SourceAdapter
include RestAPIHelpers
def initialize(source, credential = nil)
super(source)
end
def login
#TODO: Write some code here
# use the variable @source.login and @source.password
# raise "Please provide some code to perform an authenticated login to the backend application"
end
def ask(question)
latitude, longtitude = question.split(',')
range = "25km"
url = "/search.json?geocode=#{latitude}%2C#{longtitude}%2C#{range}"
p "url"
p url
# http://search.twitter.com/search.atom?geocode=-1067548169.0%2C-1067548169.0%2C25km
res = Net::HTTP.get('search.twitter.com', url)
json_data = JSON.parse(res)
data = json_data["results"]
p "data class #{data.class}"
header_id = "header_#{question}"
data_id = "data_#{question}"
# return array of objects that correspond
result = [
ObjectValue.new(:source_id=>@source.id, :object => header_id,
:attrib => "section", :value => "header"),
ObjectValue.new(:source_id=>@source.id, :object => header_id,
:attrib => "created_at", :value => DateTime.now.to_s),
ObjectValue.new(:source_id=>@source.id, :object => header_id,
:attrib => "question", :value => question),
ObjectValue.new(:source_id=>@source.id, :object => header_id,
:attrib => "data_id", :value => data_id),
#########
ObjectValue.new(:source_id=>@source.id, :object => data_id,
:attrib => "section", :value => "data"),
ObjectValue.new(:source_id=>@source.id, :object => data_id,
:attrib => "data_length", :value => data.length.to_s),
ObjectValue.new(:source_id=>@source.id, :object => data_id,
:attrib => "data", :value => data),
]
p result
result
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment