Created
July 11, 2011 04:50
-
-
Save ichiban/1075327 to your computer and use it in GitHub Desktop.
How to post multipart/form-data with OAuth in Ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'oauth/consumer' | |
require 'net/http/post/multipart' | |
OAuth::VERSION = 1.0 | |
consumer = OAuth::Consumer.new('consumer_key', 'consumer_secret', | |
:site => 'http://provider.example.com', | |
:request_token_path => '/request_token', | |
:authorize_path => '/authorize', | |
:access_token_path => '/access.token') | |
request_token = consumer.get_request_token(:oauth_callback => 'http://consumer.example.com/callback') | |
puts request_token.authorize_url # put the url displayed in your browser then authorize it. | |
access_token = request_token.get_access_token | |
File.open("./image.jpg") do |image| | |
req = Net::HTTP::Post::Multipart.new(url.path, | |
'text' => 'hi, there', | |
'image' => UploadIO.new(image, "image/jpeg", "image.jpg")) | |
access_token.sign! req | |
res = Net::HTTP.start('provider.example.com', 80) do |http| | |
http.request(req) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment