Created
March 8, 2013 06:51
-
-
Save aerith/5114677 to your computer and use it in GitHub Desktop.
Twitter の URL 短縮さんはどこにいってしまったのか…。
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
--- | |
:GET 1: | |
url: http://t.co/dvXMzvhagS | |
display_url: example.com | |
expanded_url: http://example.com/ | |
:POST 1: | |
request: /1/urls/shorten.json | |
error: This method requires a GET. | |
:GET 1.1: | |
errors: | |
- message: Could not authenticate you | |
code: 32 | |
:POST 1.1: | |
errors: | |
- message: Sorry, that page does not exist | |
code: 34 |
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
#!/usr/bin/env ruby | |
# encoding: utf-8 | |
root_dir = File.expand_path("..", File.dirname(__FILE__)) | |
$:.unshift root_dir | |
require 'yaml' | |
require 'json' | |
require 'oauth' | |
config = YAML.load_file(root_dir + '/config/twitter.yaml') | |
consumer = OAuth::Consumer.new(config[:consumer_key], config[:consumer_secret], site: 'http://api.twitter.com/') | |
access_token = OAuth::AccessToken.new(consumer, config[:access_token_key], config[:access_token_secret]) | |
responses = {} | |
responses[:'GET 1'] = access_token.get('/1/urls/shorten.json?url=http://example.com/') | |
responses[:'POST 1'] = access_token.post('/1/urls/shorten.json', url: 'http://example.com/') | |
responses[:'GET 1.1'] = access_token.get('/1.1/urls/shorten.json?url=http://example.com/') | |
responses[:'POST 1.1'] = access_token.post('/1.1/urls/shorten.json', url: 'http://example.com/') | |
puts YAML.dump(responses.inject({}) { |result, pair| | |
result[pair[0]] = JSON.parse(pair[1].body) | |
result | |
}) | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment