I have this script to pull data out of the Filepicker API internal. It's mostly reverse-engineering and the code seems to be ugly to me. How can this be improved?
yesterday = (Time.now - 1.day).to_i
start_date = "08/08/2013".to_time.to_i
url = URI.parse("https://developers.inkfilepicker.com/login/")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = (url.scheme == "https")
request = Net::HTTP::Post.new(url.request_uri)
request.set_form_data({"email" => "[email protected]", "password" => "123456"})
response = http.request(request)
cookie = response.response['set-cookie'].split('; ')[0]
uri = URI("https://developers.inkfilepicker.com/apps/XXX/stats/file?startdate=#{start_date}&enddate=#{yesterday}")
req = Net::HTTP::Get.new(uri.request_uri)
req['Cookie'] = cookie
res = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => uri.scheme == 'https') {|http|
http.request(req)
}
stats = JSON.parse res.body
stats = stats['data']['links.created']
In case of some of you are against reverse engineering, I asked for a 'real' API to pull this data and they suggested me to do this until they provide an API.