Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
354 additions
and
24 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/usr/bin/env ruby -r rubygems | ||
# | ||
# ./twitter.rb --consumer-key <key> --consumer-secret <secret> <tweet_id> | ||
|
||
require 'oauth' | ||
require 'optparse' | ||
require 'json' | ||
require 'pp' | ||
|
||
options = {} | ||
|
||
option_parser = OptionParser.new do |opts| | ||
opts.banner = "Usage: #{$0} [options] <query>" | ||
|
||
opts.on("--consumer-key KEY", "Specifies the consumer key to use.") do |v| | ||
options[:consumer_key] = v | ||
end | ||
|
||
opts.on("--consumer-secret SECRET", "Specifies the consumer secret to use.") do |v| | ||
options[:consumer_secret] = v | ||
end | ||
end | ||
|
||
option_parser.parse! | ||
query = ARGV.pop | ||
query = STDIN.read if query == "-" | ||
|
||
if options[:consumer_key].nil? || options[:consumer_secret].nil? || query.nil? | ||
puts option_parser.help | ||
exit 1 | ||
end | ||
|
||
consumer = OAuth::Consumer.new \ | ||
options[:consumer_key], | ||
options[:consumer_secret], | ||
:site => "https://api.twitter.com" | ||
|
||
access_token = OAuth::AccessToken.new(consumer) | ||
|
||
response = access_token.request(:get, "/1.1/statuses/show/#{OAuth::Helper.escape(query)}.json") | ||
rsp = JSON.parse(response.body) | ||
pp rsp |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module OAuth | ||
VERSION = "0.5.4" | ||
VERSION = "0.5.5" | ||
end |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
require File.expand_path('../../test_helper', __FILE__) | ||
|
||
require 'oauth/client' | ||
|
||
class ClientHelperTest < Minitest::Test | ||
|
||
def setup | ||
@consumer=OAuth::Consumer.new( | ||
'consumer_key_86cad9', '5888bf0345e5d237', | ||
{ | ||
:site=>"http://blabla.bla", | ||
:proxy=>"http://user:password@proxy.bla:8080", | ||
:request_token_path=>"/oauth/example/request_token.php", | ||
:access_token_path=>"/oauth/example/access_token.php", | ||
:authorize_path=>"/oauth/example/authorize.php", | ||
:scheme=>:header, | ||
:http_method=>:get | ||
}) | ||
end | ||
|
||
def test_oauth_parameters_allow_empty_params_default | ||
helper = OAuth::Client::Helper.new(nil, { | ||
:consumer => @consumer | ||
}) | ||
helper.stub :timestamp, '0' do | ||
helper.stub :nonce, 'nonce' do | ||
expected = { | ||
"oauth_consumer_key"=>"consumer_key_86cad9", | ||
"oauth_signature_method"=>"HMAC-SHA1", | ||
"oauth_timestamp"=>"0", | ||
"oauth_nonce"=>"nonce", | ||
"oauth_version"=>"1.0" | ||
} | ||
assert_equal expected, helper.oauth_parameters | ||
end | ||
end | ||
end | ||
|
||
def test_oauth_parameters_allow_empty_params_true | ||
input = true | ||
helper = OAuth::Client::Helper.new(nil, { | ||
:consumer => @consumer, | ||
:allow_empty_params => input | ||
}) | ||
helper.stub :timestamp, '0' do | ||
helper.stub :nonce, 'nonce' do | ||
expected = { | ||
"oauth_body_hash"=>nil, | ||
"oauth_callback"=>nil, | ||
"oauth_consumer_key"=>"consumer_key_86cad9", | ||
"oauth_token"=>"", | ||
"oauth_signature_method"=>"HMAC-SHA1", | ||
"oauth_timestamp"=>"0", | ||
"oauth_nonce"=>"nonce", | ||
"oauth_verifier"=>nil, | ||
"oauth_version"=>"1.0", | ||
"oauth_session_handle"=>nil | ||
} | ||
assert_equal expected, helper.oauth_parameters | ||
end | ||
end | ||
end | ||
|
||
def test_oauth_parameters_allow_empty_params_false | ||
input = false | ||
helper = OAuth::Client::Helper.new(nil, { | ||
:consumer => @consumer, | ||
:allow_empty_params => input | ||
}) | ||
helper.stub :timestamp, '0' do | ||
helper.stub :nonce, 'nonce' do | ||
expected = { | ||
"oauth_consumer_key"=>"consumer_key_86cad9", | ||
"oauth_signature_method"=>"HMAC-SHA1", | ||
"oauth_timestamp"=>"0", | ||
"oauth_nonce"=>"nonce", | ||
"oauth_version"=>"1.0" | ||
} | ||
assert_equal expected, helper.oauth_parameters | ||
end | ||
end | ||
end | ||
|
||
def test_oauth_parameters_allow_empty_params_only_oauth_token_as_string | ||
input = 'oauth_token' | ||
helper = OAuth::Client::Helper.new(nil, { | ||
:consumer => @consumer, | ||
:allow_empty_params => input | ||
}) | ||
helper.stub :timestamp, '0' do | ||
helper.stub :nonce, 'nonce' do | ||
expected = { | ||
"oauth_consumer_key"=>"consumer_key_86cad9", | ||
"oauth_token"=>"", | ||
"oauth_signature_method"=>"HMAC-SHA1", | ||
"oauth_timestamp"=>"0", | ||
"oauth_nonce"=>"nonce", | ||
"oauth_version"=>"1.0", | ||
} | ||
assert_equal expected, helper.oauth_parameters | ||
end | ||
end | ||
end | ||
|
||
def test_oauth_parameters_allow_empty_params_only_oauth_token_as_array | ||
input = ['oauth_token'] | ||
helper = OAuth::Client::Helper.new(nil, { | ||
:consumer => @consumer, | ||
:allow_empty_params => input | ||
}) | ||
helper.stub :timestamp, '0' do | ||
helper.stub :nonce, 'nonce' do | ||
expected = { | ||
"oauth_consumer_key"=>"consumer_key_86cad9", | ||
"oauth_token"=>"", | ||
"oauth_signature_method"=>"HMAC-SHA1", | ||
"oauth_timestamp"=>"0", | ||
"oauth_nonce"=>"nonce", | ||
"oauth_version"=>"1.0", | ||
} | ||
assert_equal expected, helper.oauth_parameters | ||
end | ||
end | ||
end | ||
|
||
def test_oauth_parameters_allow_empty_params_oauth_token_and_oauth_session_handle | ||
input = ['oauth_token', 'oauth_session_handle'] | ||
helper = OAuth::Client::Helper.new(nil, { | ||
:consumer => @consumer, | ||
:allow_empty_params => input | ||
}) | ||
helper.stub :timestamp, '0' do | ||
helper.stub :nonce, 'nonce' do | ||
expected = { | ||
"oauth_consumer_key"=>"consumer_key_86cad9", | ||
"oauth_token"=>"", | ||
"oauth_signature_method"=>"HMAC-SHA1", | ||
"oauth_timestamp"=>"0", | ||
"oauth_nonce"=>"nonce", | ||
"oauth_version"=>"1.0", | ||
"oauth_session_handle"=>nil | ||
} | ||
assert_equal expected, helper.oauth_parameters | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.