1
0
Fork 0
mirror of https://github.com/jnunemaker/httparty synced 2023-03-27 23:23:07 -04:00
httparty/examples/basic.rb

33 lines
872 B
Ruby
Raw Normal View History

dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
require File.join(dir, 'httparty')
require 'pp'
# You can also use post, put, delete, head, options in the same fashion
response = HTTParty.get('http://twitter.com/statuses/public_timeline.json')
2009-04-23 11:28:36 -04:00
puts response.body, response.code, response.message, response.headers.inspect
response.each do |item|
puts item['user']['screen_name']
2009-04-23 11:28:36 -04:00
end
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 = {
:body => {
:pear => { # your resource
:foo => '123', # your columns/data
:bar => 'second',
:baz => 'last thing'
}
}
}
pp Partay.post('/pears.xml', options)