Skip to content

Commit

Permalink
Merge pull request #171 from galois17/feature-add-examples
Browse files Browse the repository at this point in the history
Add another example
  • Loading branch information
pboling authored Jan 20, 2021
2 parents 048c121 + 783e34d commit 6385e03
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
42 changes: 42 additions & 0 deletions examples/twitter.rb
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
2 changes: 1 addition & 1 deletion examples/yql.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env ruby -rubygems
#!/usr/bin/env ruby -r rubygems

# Sample queries:
# ./yql.rb --consumer-key <key> --consumer-secret <secret> "show tables"
Expand Down

0 comments on commit 6385e03

Please sign in to comment.