Skip to content

Instantly share code, notes, and snippets.

@brntbeer
Created February 12, 2011 21:22
Show Gist options
  • Save brntbeer/824140 to your computer and use it in GitHub Desktop.
Save brntbeer/824140 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'net/http'
require 'json'
uri = URI.parse("http://fluttrly.com/bouverdafs") #=> should be a valid task ID
http = Net::HTTP.new(uri.host, uri.port)
response = http.request(Net::HTTP::Get.new(uri.request_uri))
# Use the get response above to get an auth token and cookie
auth_token = $1 if response.body =~ /"authenticity_token".*value="(.+)"/ or nil
raise "No authenticity token found :(" if auth_token.nil?
#COOKIE COOKIE COOKIE COOKIE COOKIE COOKIE
cookie = response['set-cookie'].split('; ')[0]
uri = URI.parse('http://fluttrly.com/tasks')
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Put.new(uri.request_uri)
params = JSON.generate("completed" => "true", "authenticity_token" => auth_token)
request["Cookie"] = cookie
##THEN WHAT???????????????
#maybe?
response = http.request_put("/1135", params)
#results in a 422, and im not even using the request["Cookie"] at all, just sending
# auth_token and the completed => true field
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment