drogus-oauth 0.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. data/.document +5 -0
  2. data/.gitignore +21 -0
  3. data/History.txt +114 -0
  4. data/LICENSE +20 -0
  5. data/Manifest.txt +84 -0
  6. data/README.rdoc +71 -0
  7. data/Rakefile +56 -0
  8. data/TODO +31 -0
  9. data/VERSION +1 -0
  10. data/bin/oauth +5 -0
  11. data/examples/yql.rb +44 -0
  12. data/lib/oauth.rb +4 -0
  13. data/lib/oauth/cli.rb +378 -0
  14. data/lib/oauth/client.rb +4 -0
  15. data/lib/oauth/client/action_controller_request.rb +54 -0
  16. data/lib/oauth/client/helper.rb +85 -0
  17. data/lib/oauth/client/net_http.rb +106 -0
  18. data/lib/oauth/consumer.rb +370 -0
  19. data/lib/oauth/errors.rb +3 -0
  20. data/lib/oauth/errors/error.rb +4 -0
  21. data/lib/oauth/errors/problem.rb +14 -0
  22. data/lib/oauth/errors/unauthorized.rb +12 -0
  23. data/lib/oauth/helper.rb +78 -0
  24. data/lib/oauth/oauth.rb +11 -0
  25. data/lib/oauth/oauth_test_helper.rb +25 -0
  26. data/lib/oauth/request_proxy.rb +24 -0
  27. data/lib/oauth/request_proxy/action_controller_request.rb +61 -0
  28. data/lib/oauth/request_proxy/base.rb +166 -0
  29. data/lib/oauth/request_proxy/jabber_request.rb +41 -0
  30. data/lib/oauth/request_proxy/mock_request.rb +44 -0
  31. data/lib/oauth/request_proxy/net_http.rb +65 -0
  32. data/lib/oauth/request_proxy/rack_request.rb +40 -0
  33. data/lib/oauth/request_proxy/typhoeus_request.rb +53 -0
  34. data/lib/oauth/server.rb +66 -0
  35. data/lib/oauth/signature.rb +40 -0
  36. data/lib/oauth/signature/base.rb +87 -0
  37. data/lib/oauth/signature/hmac/md5.rb +21 -0
  38. data/lib/oauth/signature/hmac/rmd160.rb +21 -0
  39. data/lib/oauth/signature/hmac/sha1.rb +22 -0
  40. data/lib/oauth/signature/hmac/sha2.rb +21 -0
  41. data/lib/oauth/signature/md5.rb +13 -0
  42. data/lib/oauth/signature/plaintext.rb +23 -0
  43. data/lib/oauth/signature/rsa/sha1.rb +45 -0
  44. data/lib/oauth/signature/sha1.rb +13 -0
  45. data/lib/oauth/token.rb +7 -0
  46. data/lib/oauth/tokens/access_token.rb +68 -0
  47. data/lib/oauth/tokens/consumer_token.rb +33 -0
  48. data/lib/oauth/tokens/request_token.rb +32 -0
  49. data/lib/oauth/tokens/server_token.rb +9 -0
  50. data/lib/oauth/tokens/token.rb +17 -0
  51. data/lib/oauth/version.rb +3 -0
  52. data/oauth.gemspec +167 -0
  53. data/script/destroy +14 -0
  54. data/script/generate +14 -0
  55. data/script/txt2html +74 -0
  56. data/setup.rb +1585 -0
  57. data/tasks/deployment.rake +34 -0
  58. data/tasks/environment.rake +7 -0
  59. data/tasks/website.rake +17 -0
  60. data/test/cases/oauth_case.rb +19 -0
  61. data/test/cases/spec/1_0-final/test_construct_request_url.rb +62 -0
  62. data/test/cases/spec/1_0-final/test_normalize_request_parameters.rb +88 -0
  63. data/test/cases/spec/1_0-final/test_parameter_encodings.rb +86 -0
  64. data/test/cases/spec/1_0-final/test_signature_base_strings.rb +77 -0
  65. data/test/integration/consumer_test.rb +304 -0
  66. data/test/keys/rsa.cert +11 -0
  67. data/test/keys/rsa.pem +16 -0
  68. data/test/test_access_token.rb +26 -0
  69. data/test/test_action_controller_request_proxy.rb +133 -0
  70. data/test/test_consumer.rb +159 -0
  71. data/test/test_helper.rb +14 -0
  72. data/test/test_hmac_sha1.rb +20 -0
  73. data/test/test_net_http_client.rb +224 -0
  74. data/test/test_net_http_request_proxy.rb +72 -0
  75. data/test/test_oauth_helper.rb +49 -0
  76. data/test/test_rack_request_proxy.rb +40 -0
  77. data/test/test_request_token.rb +51 -0
  78. data/test/test_rsa_sha1.rb +59 -0
  79. data/test/test_server.rb +40 -0
  80. data/test/test_signature.rb +21 -0
  81. data/test/test_signature_base.rb +32 -0
  82. data/test/test_signature_plain_text.rb +26 -0
  83. data/test/test_token.rb +14 -0
  84. data/test/test_typhoeus_request_proxy.rb +72 -0
  85. data/website/index.html +87 -0
  86. data/website/index.txt +73 -0
  87. data/website/javascripts/rounded_corners_lite.inc.js +285 -0
  88. data/website/stylesheets/screen.css +138 -0
  89. data/website/template.rhtml +48 -0
  90. metadata +207 -0
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
@@ -0,0 +1,114 @@
1
+ == 0.3.7
2
+ * Better marshalling implementation (Yoan Blanc)
3
+ * Added optional block to OAuth::Consumer.get_*_token (Neill Pearman)
4
+ * Exclude `oauth_callback` with :exclude_callback (Neill Pearman)
5
+ * Strip extraneous spaces and line breaks from access_token responses
6
+ (observed in the wild with Yahoo!'s OAuth+OpenID hybrid) (Eric Hartmann)
7
+ * Stop double-escaping PLAINTEXT signatures (Jimmy Zimmerman)
8
+ * OAuth::Client::Helper won't override the specified `oauth_version`
9
+ (Philip Kromer)
10
+ * Added OAuth::RequestProxy::Typhoeus as an alternative to Net::HTTP
11
+ (Bill Kocik)
12
+
13
+ == 0.3.6 2009-09-14
14
+
15
+ * Added -B CLI option to use the :body authentication scheme (Seth)
16
+ * Respect `--method` in `authorize` CLI command (Seth)
17
+ * Support POST and PUT with raw bodies (Yu-Shan Fung et al)
18
+ * Test clean-up (Xavier Shay, Hannes Tydén)
19
+ * Added :ca_file consumer option to allow consumer specific certificate
20
+ override. (Pelle)
21
+
22
+ == 0.3.5 2009-06-03
23
+
24
+ * `query` CLI command to access protected resources (Seth)
25
+ * Added -H, -Q CLI options for specifying the authentication scheme (Seth)
26
+ * Added -O CLI option for specifying a file containing options (Seth)
27
+ * Support streamable body contents for large request bodies (Seth Cousins)
28
+ * Support for OAuth 1.0a (Seth)
29
+ * Added proxy support to OAuth::Consumer (Marshall Huss)
30
+ * Added --scope CLI option for Google's 'scope' parameter (Seth)
31
+
32
+ == 0.3.4 2009-05-06
33
+
34
+ * OAuth::Client::Helper uses OAuth::VERSION (chadisfaction)
35
+ * Fix OAuth::RequestProxy::ActionControllerRequest's handling of params
36
+ (Tristan Groléat)
37
+
38
+ == 0.3.3 2009-05-04
39
+
40
+ * Corrected OAuth XMPP namespace (Seth)
41
+ * Improved error handling for invalid Authorization headers (Matt Sanford)
42
+ * Fixed signatures for non-ASCII under $KCODE other than 'u' (Matt Sanford)
43
+ * Fixed edge cases in ActionControllerRequestProxy where params were being
44
+ incorrectly signed (Marcos Wright Kuhns)
45
+ * Support for arguments in OAuth::Consumer#get_access_token (Matt Sanford)
46
+ * Add gem version to user-agent header (Matt Sanford)
47
+ * Handle input from aggressive form encoding libraries (Matt Wood)
48
+
49
+ == 0.3.2 2009-03-23
50
+
51
+ * 2xx statuses should be treated as success (Anders Conbere)
52
+ * Support applications using the MethodOverride Rack middleware (László Bácsi)
53
+ * `authorize` command for `oauth` CLI (Seth)
54
+ * Initial support for Problem Reporting extension (Seth)
55
+ * Verify SSL certificates if CA certificates are available (Seth)
56
+ * Fixed ActionController parameter escaping behavior (Thiago Arrais, László
57
+ Bácsi, Brett Gibson, et al)
58
+ * Fixed signature calculation when both options and a block were provided to
59
+ OAuth::Signature::Base#initialize (Seth)
60
+ * Added help to the 'oauth' CLI (Seth)
61
+ * Fixed a problem when attempting to normalize MockRequest URIs (Seth)
62
+
63
+ == 0.3.1 2009-1-26
64
+
65
+ * Fixed a problem with relative and absolute token request paths. (Michael
66
+ Wood)
67
+
68
+ == 0.3.0 2009-1-25
69
+
70
+ * Support ActionController::Request from Edge Rails (László Bácsi)
71
+ * Correctly handle multi-valued parameters (Seth)
72
+ * Added #normalized_parameters to OAuth::RequestProxy::Base (Pelle)
73
+ * OAuth::Signature.sign and friends now yield the RequestProxy instead of the
74
+ token when the passed block's arity is 1. (Seth)
75
+ * Token requests are made to the configured URL rather than generating a
76
+ potentially incorrect one. (Kellan Elliott-McCrea)
77
+ * Command-line app for generating signatures. (Seth)
78
+ * Improved test-cases and compatibility for encoding issues. (Pelle)
79
+
80
+ == 0.2.7 2008-9-10 The lets fix the last release release
81
+
82
+ * Fixed plain text signatures (Andrew Arrow)
83
+ * Fixed RSA requests using OAuthTokens. (Philip Lipu Tsai)
84
+
85
+ == 0.2.6 2008-9-9 The lets RSA release
86
+
87
+ * Improved support for Ruby 1.8.7 (Bill Kocik)
88
+ * Fixed RSA verification to support RSA providers
89
+ now using Ruby and RSA
90
+ * Improved RSA testing
91
+ * Omit token when signing with RSA
92
+ * Added support for 'private_key_file' option for RSA signatures (Chris Mear)
93
+ * Fixed several edge cases where params were being incorrectly signed (Scott
94
+ Hill)
95
+ * Fixed RSA signing (choonkeat)
96
+
97
+ == 0.2.2 2008-2-22 Lets actually support SSL release
98
+
99
+ * Use HTTPS when required.
100
+
101
+ == 0.2 2008-1-19 All together now release
102
+
103
+ This is a big release, where we have merged the efforts of various parties into one common library. This means there are definitely some API changes you should be aware of. They should be minimal but please have a look at the unit tests.
104
+
105
+ == 0.1.2 2007-12-1
106
+
107
+ * Fixed checks for missing OAuth params to improve performance
108
+ * Includes Pat's fix for getting the realm out.
109
+
110
+ == 0.1.1 2007-11-26
111
+
112
+ * First release as a GEM
113
+ * Moved all non-Rails functionality from the Rails plugin:
114
+ http://code.google.com/p/oauth-plugin/
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2007 Blaine Cook, Larry Halff, Pelle Braendgaard
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,84 @@
1
+ History.txt
2
+ License.txt
3
+ Manifest.txt
4
+ README.rdoc
5
+ Rakefile
6
+ TODO
7
+ bin/oauth
8
+ examples/yql.rb
9
+ lib/oauth.rb
10
+ lib/oauth/oauth.rb
11
+ lib/oauth/cli.rb
12
+ lib/oauth/client.rb
13
+ lib/oauth/client/action_controller_request.rb
14
+ lib/oauth/client/helper.rb
15
+ lib/oauth/client/net_http.rb
16
+ lib/oauth/consumer.rb
17
+ lib/oauth/errors.rb
18
+ lib/oauth/errors/error.rb
19
+ lib/oauth/errors/problem.rb
20
+ lib/oauth/errors/unauthorized.rb
21
+ lib/oauth/helper.rb
22
+ lib/oauth/oauth_test_helper.rb
23
+ lib/oauth/request_proxy.rb
24
+ lib/oauth/request_proxy/action_controller_request.rb
25
+ lib/oauth/request_proxy/base.rb
26
+ lib/oauth/request_proxy/jabber_request.rb
27
+ lib/oauth/request_proxy/mock_request.rb
28
+ lib/oauth/request_proxy/net_http.rb
29
+ lib/oauth/request_proxy/rack_request.rb
30
+ lib/oauth/server.rb
31
+ lib/oauth/signature.rb
32
+ lib/oauth/signature/base.rb
33
+ lib/oauth/signature/hmac/base.rb
34
+ lib/oauth/signature/hmac/md5.rb
35
+ lib/oauth/signature/hmac/rmd160.rb
36
+ lib/oauth/signature/hmac/sha1.rb
37
+ lib/oauth/signature/hmac/sha2.rb
38
+ lib/oauth/signature/md5.rb
39
+ lib/oauth/signature/plaintext.rb
40
+ lib/oauth/signature/rsa/sha1.rb
41
+ lib/oauth/signature/sha1.rb
42
+ lib/oauth/token.rb
43
+ lib/oauth/tokens/access_token.rb
44
+ lib/oauth/tokens/consumer_token.rb
45
+ lib/oauth/tokens/request_token.rb
46
+ lib/oauth/tokens/server_token.rb
47
+ lib/oauth/tokens/token.rb
48
+ lib/oauth/version.rb
49
+ oauth.gemspec
50
+ script/destroy
51
+ script/generate
52
+ script/txt2html
53
+ setup.rb
54
+ tasks/deployment.rake
55
+ tasks/environment.rake
56
+ tasks/website.rake
57
+ test/cases/oauth_case.rb
58
+ test/cases/spec/1_0-final/test_construct_request_url.rb
59
+ test/cases/spec/1_0-final/test_normalize_request_parameters.rb
60
+ test/cases/spec/1_0-final/test_parameter_encodings.rb
61
+ test/cases/spec/1_0-final/test_signature_base_strings.rb
62
+ test/keys/rsa.cert
63
+ test/keys/rsa.pem
64
+ test/test_access_token.rb
65
+ test/test_action_controller_request_proxy.rb
66
+ test/test_consumer.rb
67
+ test/test_helper.rb
68
+ test/test_hmac_sha1.rb
69
+ test/test_net_http_client.rb
70
+ test/test_net_http_request_proxy.rb
71
+ test/test_oauth_helper.rb
72
+ test/test_rack_request_proxy.rb
73
+ test/test_request_token.rb
74
+ test/test_rsa_sha1.rb
75
+ test/test_server.rb
76
+ test/test_signature.rb
77
+ test/test_signature_base.rb
78
+ test/test_signature_plain_text.rb
79
+ test/test_token.rb
80
+ website/index.html
81
+ website/index.txt
82
+ website/javascripts/rounded_corners_lite.inc.js
83
+ website/stylesheets/screen.css
84
+ website/template.rhtml
@@ -0,0 +1,71 @@
1
+ = Ruby OAuth GEM
2
+
3
+ == What
4
+
5
+ This is a RubyGem for implementing both OAuth clients and servers in Ruby applications.
6
+
7
+ See the OAuth specs http://oauth.net/core/1.0/
8
+
9
+ == Installing
10
+
11
+ sudo gem install oauth
12
+
13
+ You can also install it from the oauth rubyforge project http://rubyforge.org/projects/oauth/.
14
+
15
+ The source code is now hosted on the OAuth GitHub Project http://github.com/mojodna/oauth
16
+
17
+ == The basics
18
+
19
+ This is a ruby library which is intended to be used in creating Ruby Consumer and Service Provider applications. It is NOT a Rails plugin, but could easily be used for the foundation for such a Rails plugin.
20
+
21
+ As a matter of fact it has been pulled out from an OAuth Rails Plugin http://code.google.com/p/oauth-plugin/ which now requires this GEM.
22
+
23
+ == Demonstration of usage
24
+
25
+ Create a new consumer instance by passing it a configuration hash:
26
+
27
+ @consumer = OAuth::Consumer.new("key","secret", :site => "https://agree2")
28
+
29
+ Start the process by requesting a token
30
+
31
+ @request_token = @consumer.get_request_token
32
+ session[:request_token] = @request_token
33
+ redirect_to @request_token.authorize_url
34
+
35
+ When user returns create an access_token
36
+
37
+ @access_token = @request_token.get_access_token
38
+ @photos = @access_token.get('/photos.xml')
39
+
40
+ For more detailed instructions I have written this OAuth Client Tutorial http://stakeventures.com/articles/2008/02/23/developing-oauth-clients-in-ruby and "How to turn your rails site into an OAuth Provider ":http://stakeventures.com/articles/2007/11/26/how-to-turn-your-rails-site-into-an-oauth-provider .
41
+
42
+ Finally be sure to check out the OAuth RDoc Manual http://oauth.rubyforge.org/rdoc/ .
43
+
44
+ == Documentation Wiki
45
+
46
+ There is some documentation on the Google Code project for the "OAuth Rails Plugin":http://code.google.com/p/oauth-plugin/ :
47
+
48
+ * RequestToken http://code.google.com/p/oauth-plugin/wiki/RequestToken
49
+ * AccessToken http://code.google.com/p/oauth-plugin/wiki/AccessToken
50
+
51
+ == Forum
52
+
53
+ http://groups.google.com/group/oauth-ruby
54
+
55
+
56
+ == How to submit patches
57
+
58
+ Read the "8 steps for fixing other people's code" http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/.
59
+
60
+ The source code is now hosted on the OAuth GitHub Project http://github.com/mojodna/oauth
61
+
62
+ To submit a patch, please fork the oauth project and create a patch with tests. Once you're happy with it send a pull request and post a message to the google group.
63
+
64
+ == License
65
+
66
+ This code is free to use under the terms of the MIT license.
67
+
68
+ == Contact
69
+
70
+ Comments are welcome. Send an email to "Pelle Braendgaard" pelleb@gmail.com email via the OAuth Ruby mailing list http://groups.google.com/group/oauth-ruby
71
+
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "oauth"
8
+ gem.summary = %Q{OAuth Core Ruby implementation}
9
+ gem.description = %Q{OAuth Core Ruby implementation}
10
+ gem.email = "drogus@gmail.com"
11
+ gem.homepage = "http://github.com/drogus/oauth"
12
+ gem.authors = ["Piotr Sarnacki"]
13
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
14
+ gem.add_dependency('ruby-hmac', '>= 0.3.1')
15
+ gem.add_development_dependency('actionpack')
16
+ gem.add_development_dependency('rack')
17
+ gem.add_development_dependency('mocha')
18
+ end
19
+ Jeweler::GemcutterTasks.new
20
+ rescue LoadError
21
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
22
+ end
23
+
24
+ require 'rake/testtask'
25
+ Rake::TestTask.new(:test) do |test|
26
+ test.libs << 'lib' << 'test'
27
+ test.pattern = 'test/**/test_*.rb'
28
+ test.verbose = true
29
+ end
30
+
31
+ begin
32
+ require 'rcov/rcovtask'
33
+ Rcov::RcovTask.new do |test|
34
+ test.libs << 'test'
35
+ test.pattern = 'test/**/test_*.rb'
36
+ test.verbose = true
37
+ end
38
+ rescue LoadError
39
+ task :rcov do
40
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
41
+ end
42
+ end
43
+
44
+ task :test => :check_dependencies
45
+
46
+ task :default => :test
47
+
48
+ require 'rake/rdoctask'
49
+ Rake::RDocTask.new do |rdoc|
50
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
51
+
52
+ rdoc.rdoc_dir = 'rdoc'
53
+ rdoc.title = "oauth #{version}"
54
+ rdoc.rdoc_files.include('README*')
55
+ rdoc.rdoc_files.include('lib/**/*.rb')
56
+ end
data/TODO ADDED
@@ -0,0 +1,31 @@
1
+ Common use-cases should be streamlined:
2
+
3
+ * I have a URL that I want to sign (given consumer key/secret, optional
4
+ token/secret, optional nonce/timestamp).
5
+ * I have a URL that I want to sign AND I want to see what the components
6
+ (e.g. signature base string, etc.) are while it's being signed (i.e. verbose
7
+ signing).
8
+ * I have a URL that I want to sign and I only want the signature.
9
+ * I have a URL that I want to sign and I want something suitable to put in
10
+ {the header, the querystring, XMPP}.
11
+ * I want to make a query to an OAuth-enabled web service (with sensible
12
+ errors, if available).
13
+ * I want to host an OAuth-enabled web service.
14
+ * I want to test my OAuth-enabled web service (i.e. test helpers)
15
+
16
+ Example applications for:
17
+ * Ning
18
+ * Fire Eagle
19
+ * Google (blogger, contacts)
20
+ * Twitter
21
+ * YOS / YQL
22
+ * Netflix
23
+
24
+ In addition to providing best practices of use, these can also be part of
25
+ the pre-release checks to make sure that there have been no regressions.
26
+
27
+ Random TODOs:
28
+ * finish CLI
29
+ * sensible Exception hierarchy
30
+ * Tokens as Modules
31
+ * don't tie to Net::HTTP
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.3.6
@@ -0,0 +1,5 @@
1
+ #! /home/kuba/.rvm/rubies/ruby-1.9.1-p378/bin/ruby -w -rubygems
2
+
3
+ require "oauth/cli"
4
+
5
+ OAuth::CLI.execute(STDOUT, STDIN, STDERR, ARGV)
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env ruby -rubygems
2
+
3
+ # Sample queries:
4
+ # ./yql.rb --consumer-key <key> --consumer-secret <secret> "show tables"
5
+ # ./yql.rb --consumer-key <key> --consumer-secret <secret> "select * from flickr.photos.search where text='Cat' limit 10"
6
+
7
+ require 'oauth'
8
+ require 'optparse'
9
+ require 'json'
10
+ require 'pp'
11
+
12
+ options = {}
13
+
14
+ option_parser = OptionParser.new do |opts|
15
+ opts.banner = "Usage: #{$0} [options] <query>"
16
+
17
+ opts.on("--consumer-key KEY", "Specifies the consumer key to use.") do |v|
18
+ options[:consumer_key] = v
19
+ end
20
+
21
+ opts.on("--consumer-secret SECRET", "Specifies the consumer secret to use.") do |v|
22
+ options[:consumer_secret] = v
23
+ end
24
+ end
25
+
26
+ option_parser.parse!
27
+ query = ARGV.pop
28
+ query = STDIN.read if query == "-"
29
+
30
+ if options[:consumer_key].nil? || options[:consumer_secret].nil? || query.nil?
31
+ puts option_parser.help
32
+ exit 1
33
+ end
34
+
35
+ consumer = OAuth::Consumer.new \
36
+ options[:consumer_key],
37
+ options[:consumer_secret],
38
+ :site => "http://query.yahooapis.com"
39
+
40
+ access_token = OAuth::AccessToken.new(consumer)
41
+
42
+ response = access_token.request(:get, "/v1/yql?q=#{OAuth::Helper.escape(query)}&format=json")
43
+ rsp = JSON.parse(response.body)
44
+ pp rsp