7stud -- wrote in post #986255:
boo boo wrote in post #986241:
No requires?
Sorry here is full source in my class:
require "oauth"
require "oauth/client"
require "cgi"
require "addressable/uri"
require 'base64'
require 'cgi'
require 'openssl'
require "net/http"
require "uri
class ProxyController
def initialize
@request_token_url = "
https://api.twitter.com/oauth/request_token"
@authorize_url = "
https://api.twitter/oauth/authorize_token"
@oauth_consumer_key = "MY KEY"
@oauth_consumer_secret = "MY SECRET"
@params = Addressable::URI.new
@current_nonce = self.nonce
@current_timestamp = self.timestamp.to_s
@params.query_values = {"oauth_callback"=> "my callback url",
"oauth_consumer_key" => @oauth_consumer_key,
"oauth_nonce" => @current_nonce ,
"oauth_signature_method" => "HMAC-SHA1",
"oauth_timestamp" => @current_timestamp,
"oauth_version" => "1.0"}
@params_string = @params.to_s
@params_string[0] = ""
@encoded_params = CGI::escape(@params_string)
@concatenated_body = "POST&" + CGI::escape(@request_token_url) + "&"
+ @encoded_params
@oauth_signature =
Base64.encode64("#{OpenSSL::HMAC.digest('sha1',@oauth_consumer_key+"&",
@concatenated_body)}")
@encoded_oauth_sig = CGI::escape(@oauth_signature)
@encoded_callback = CGI::escape("My Callback url")
@headers = { 'oauth_nonce' => @current_nonce,
'oauth_callback' => @encoded_callback,
'oauth_signature_method' => "HMAC-SHA1",
'oauth_timestamp' => @current_timestamp,
'oauth_consumer_key' => @oauth_consumer_key,
'oauth_signature' => @encoded_oauth_sig,
'oauth_version' => "1.0"}
url = URI.parse("
https://api.twitter.com/oauth/request_token")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
@resp = http.post(url.path, nil, @headers)
end
def nonce
(0...43).map{ ('a'..'z').to_a[rand(26)] }.join
#rand(10 ** 43).to_s.rjust(43,'0')
end
def timestamp
t = Time.now
t.to_i
end
end