2008-12-05 16:42:38 -05:00
|
|
|
dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
|
|
require File.join(dir, 'httparty')
|
|
|
|
require 'pp'
|
|
|
|
|
2009-11-22 23:18:29 -05:00
|
|
|
# You can also use post, put, delete, head, options in the same fashion
|
2014-03-11 18:31:22 -04:00
|
|
|
response = HTTParty.get('https://api.stackexchange.com/2.2/questions?site=stackoverflow')
|
2009-04-23 11:28:36 -04:00
|
|
|
puts response.body, response.code, response.message, response.headers.inspect
|
2009-01-28 16:15:06 -05:00
|
|
|
|
2010-12-23 10:20:56 -05:00
|
|
|
# An example post to a minimal rails app in the development environment
|
|
|
|
# Note that "skip_before_filter :verify_authenticity_token" must be set in the
|
|
|
|
# "pears" controller for this example
|
|
|
|
|
|
|
|
class Partay
|
|
|
|
include HTTParty
|
|
|
|
base_uri 'http://localhost:3000'
|
|
|
|
end
|
|
|
|
|
|
|
|
options = {
|
2014-05-15 16:45:32 -04:00
|
|
|
body: {
|
|
|
|
pear: { # your resource
|
|
|
|
foo: '123', # your columns/data
|
|
|
|
bar: 'second',
|
|
|
|
baz: 'last thing'
|
2010-12-23 10:20:56 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pp Partay.post('/pears.xml', options)
|