sayso-oauth 0.4.4.001

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. data/.gitignore +3 -0
  2. data/Gemfile +14 -0
  3. data/Gemfile.lock +45 -0
  4. data/HISTORY +150 -0
  5. data/LICENSE +20 -0
  6. data/README.rdoc +74 -0
  7. data/Rakefile +37 -0
  8. data/TODO +32 -0
  9. data/bin/oauth +5 -0
  10. data/examples/yql.rb +44 -0
  11. data/lib/digest/hmac.rb +104 -0
  12. data/lib/oauth.rb +13 -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 +65 -0
  16. data/lib/oauth/client/em_http.rb +120 -0
  17. data/lib/oauth/client/helper.rb +91 -0
  18. data/lib/oauth/client/net_http.rb +119 -0
  19. data/lib/oauth/consumer.rb +385 -0
  20. data/lib/oauth/core_ext.rb +31 -0
  21. data/lib/oauth/errors.rb +3 -0
  22. data/lib/oauth/errors/error.rb +4 -0
  23. data/lib/oauth/errors/problem.rb +14 -0
  24. data/lib/oauth/errors/unauthorized.rb +12 -0
  25. data/lib/oauth/helper.rb +93 -0
  26. data/lib/oauth/oauth.rb +13 -0
  27. data/lib/oauth/oauth_test_helper.rb +25 -0
  28. data/lib/oauth/request_proxy.rb +24 -0
  29. data/lib/oauth/request_proxy/action_controller_request.rb +62 -0
  30. data/lib/oauth/request_proxy/base.rb +174 -0
  31. data/lib/oauth/request_proxy/curb_request.rb +55 -0
  32. data/lib/oauth/request_proxy/em_http_request.rb +66 -0
  33. data/lib/oauth/request_proxy/jabber_request.rb +41 -0
  34. data/lib/oauth/request_proxy/mock_request.rb +44 -0
  35. data/lib/oauth/request_proxy/net_http.rb +72 -0
  36. data/lib/oauth/request_proxy/rack_request.rb +48 -0
  37. data/lib/oauth/request_proxy/typhoeus_request.rb +53 -0
  38. data/lib/oauth/server.rb +66 -0
  39. data/lib/oauth/signature.rb +45 -0
  40. data/lib/oauth/signature/base.rb +110 -0
  41. data/lib/oauth/signature/hmac/base.rb +15 -0
  42. data/lib/oauth/signature/hmac/md5.rb +8 -0
  43. data/lib/oauth/signature/hmac/rmd160.rb +8 -0
  44. data/lib/oauth/signature/hmac/sha1.rb +9 -0
  45. data/lib/oauth/signature/hmac/sha2.rb +8 -0
  46. data/lib/oauth/signature/md5.rb +13 -0
  47. data/lib/oauth/signature/plaintext.rb +23 -0
  48. data/lib/oauth/signature/rsa/sha1.rb +46 -0
  49. data/lib/oauth/signature/sha1.rb +13 -0
  50. data/lib/oauth/token.rb +7 -0
  51. data/lib/oauth/tokens/access_token.rb +71 -0
  52. data/lib/oauth/tokens/consumer_token.rb +33 -0
  53. data/lib/oauth/tokens/request_token.rb +32 -0
  54. data/lib/oauth/tokens/server_token.rb +9 -0
  55. data/lib/oauth/tokens/token.rb +17 -0
  56. data/oauth.gemspec +173 -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 +307 -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 +171 -0
  71. data/test/test_curb_request_proxy.rb +77 -0
  72. data/test/test_em_http_client.rb +80 -0
  73. data/test/test_em_http_request_proxy.rb +115 -0
  74. data/test/test_helper.rb +26 -0
  75. data/test/test_hmac_sha1.rb +20 -0
  76. data/test/test_net_http_client.rb +280 -0
  77. data/test/test_net_http_request_proxy.rb +72 -0
  78. data/test/test_oauth_helper.rb +71 -0
  79. data/test/test_rack_request_proxy.rb +40 -0
  80. data/test/test_request_token.rb +51 -0
  81. data/test/test_rsa_sha1.rb +59 -0
  82. data/test/test_server.rb +40 -0
  83. data/test/test_signature.rb +22 -0
  84. data/test/test_signature_base.rb +32 -0
  85. data/test/test_signature_plain_text.rb +31 -0
  86. data/test/test_token.rb +14 -0
  87. data/test/test_typhoeus_request_proxy.rb +81 -0
  88. metadata +235 -0
@@ -0,0 +1,3 @@
1
+ pkg/*
2
+ _site
3
+ .bundle
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source :gemcutter
2
+
3
+ group :development do
4
+ gem 'jeweler'
5
+ end
6
+
7
+ group :test do
8
+ gem 'actionpack', '~>2.3.8'
9
+ gem 'mocha', '>=0.9.8'
10
+ gem 'typhoeus', '>=0.1.13'
11
+ gem 'em-http-request', "0.2.11"
12
+ gem 'curb', ">= 0.6.6.0"
13
+ gem 'webmock'
14
+ end
@@ -0,0 +1,45 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ actionpack (2.3.8)
5
+ activesupport (= 2.3.8)
6
+ rack (~> 1.1.0)
7
+ activesupport (2.3.8)
8
+ addressable (2.2.0)
9
+ crack (0.1.8)
10
+ curb (0.7.7.1)
11
+ em-http-request (0.2.11)
12
+ addressable (>= 2.0.0)
13
+ eventmachine (>= 0.12.9)
14
+ eventmachine (0.12.10)
15
+ gemcutter (0.4.1)
16
+ json_pure
17
+ git (1.2.5)
18
+ jeweler (1.4.0)
19
+ gemcutter (>= 0.1.0)
20
+ git (>= 1.2.5)
21
+ rubyforge (>= 2.0.0)
22
+ json_pure (1.4.3)
23
+ mocha (0.9.8)
24
+ rake
25
+ rack (1.1.0)
26
+ rake (0.8.7)
27
+ rubyforge (2.0.4)
28
+ json_pure (>= 1.1.7)
29
+ typhoeus (0.1.31)
30
+ rack
31
+ webmock (1.3.5)
32
+ addressable (>= 2.1.1)
33
+ crack (>= 0.1.7)
34
+
35
+ PLATFORMS
36
+ ruby
37
+
38
+ DEPENDENCIES
39
+ actionpack (~> 2.3.8)
40
+ curb (>= 0.6.6.0)
41
+ em-http-request (= 0.2.11)
42
+ jeweler
43
+ mocha (>= 0.9.8)
44
+ typhoeus (>= 0.1.13)
45
+ webmock
data/HISTORY ADDED
@@ -0,0 +1,150 @@
1
+ === 0.4.4 2010-10-31
2
+
3
+ * Fix LoadError rescue in tests: return can't be used in this context (Hans de Graaff)
4
+ * HTTP headers should be strings. (seancribbs)
5
+ * ensure consumer uri gets set back to original config even if an error occurs (Brian Finney)
6
+ * Yahoo uses & to split records in OAuth headers (Brian Finney)
7
+ * Added support for Rails 3 in client/action_controller_request (Pelle)
8
+
9
+ == 0.4.3 2010-09-01
10
+
11
+ * Fix for em-http proxy (ichverstehe)
12
+
13
+ == 0.4.2 2010-08-13
14
+
15
+ * Fixed compatibility with Ruby 1.9.2 (ecavazos)
16
+ * Fixed the em-http request proxy (Joshua Hull)
17
+ * Fix for oauth proxy string manipulation (Jakub Suder)
18
+ * Added Bundler (rc) Gemfile for easier dev/testing
19
+
20
+ == 0.4.1 2010-06-16
21
+
22
+ * Added support for using OAuth with proxies (Marsh Gardiner)
23
+ * Rails 3 Compatibility fixes (Pelle Braendgaard)
24
+ * Fixed load errors on tests for missing (non-required) libraries
25
+
26
+ == 0.4.0 2010-04-22
27
+
28
+ * Added computation of oauth_body_hash as per OAuth Request Body Hash 1.0
29
+ Draft 4 (Michael Reinsch)
30
+ * Added the optional `oauth_session_handle` parameter for the Yahoo implementation (Will Bailey)
31
+ * Better marshalling implementation (Yoan Blanc)
32
+ * Added optional block to OAuth::Consumer.get_*_token (Neill Pearman)
33
+ * Exclude `oauth_callback` with :exclude_callback (Neill Pearman)
34
+ * Strip extraneous spaces and line breaks from access_token responses
35
+ (observed in the wild with Yahoo!'s OAuth+OpenID hybrid) (Eric Hartmann)
36
+ * Stop double-escaping PLAINTEXT signatures (Jimmy Zimmerman)
37
+ * OAuth::Client::Helper won't override the specified `oauth_version`
38
+ (Philip Kromer)
39
+ * Support for Ruby 1.9 (Aaron Quint, Corey Donahoe, et al)
40
+ * Fixed an encoding / multibyte issue (成田 一生)
41
+ * Replaced hoe with Jeweler (Aaron Quint)
42
+ * Support for Typhoeus (Bill Kocik)
43
+ * Support for em-http (EventMachine) (Darcy Laycock)
44
+ * Support for curb (André Luis Leal Cardoso Junior)
45
+ * New website (Aaron Quint)
46
+
47
+ == 0.3.6 2009-09-14
48
+
49
+ * Added -B CLI option to use the :body authentication scheme (Seth)
50
+ * Respect `--method` in `authorize` CLI command (Seth)
51
+ * Support POST and PUT with raw bodies (Yu-Shan Fung et al)
52
+ * Test clean-up (Xavier Shay, Hannes Tydén)
53
+ * Added :ca_file consumer option to allow consumer specific certificate
54
+ override. (Pelle)
55
+
56
+ == 0.3.5 2009-06-03
57
+
58
+ * `query` CLI command to access protected resources (Seth)
59
+ * Added -H, -Q CLI options for specifying the authentication scheme (Seth)
60
+ * Added -O CLI option for specifying a file containing options (Seth)
61
+ * Support streamable body contents for large request bodies (Seth Cousins)
62
+ * Support for OAuth 1.0a (Seth)
63
+ * Added proxy support to OAuth::Consumer (Marshall Huss)
64
+ * Added --scope CLI option for Google's 'scope' parameter (Seth)
65
+
66
+ == 0.3.4 2009-05-06
67
+
68
+ * OAuth::Client::Helper uses OAuth::VERSION (chadisfaction)
69
+ * Fix OAuth::RequestProxy::ActionControllerRequest's handling of params
70
+ (Tristan Groléat)
71
+
72
+ == 0.3.3 2009-05-04
73
+
74
+ * Corrected OAuth XMPP namespace (Seth)
75
+ * Improved error handling for invalid Authorization headers (Matt Sanford)
76
+ * Fixed signatures for non-ASCII under $KCODE other than 'u' (Matt Sanford)
77
+ * Fixed edge cases in ActionControllerRequestProxy where params were being
78
+ incorrectly signed (Marcos Wright Kuhns)
79
+ * Support for arguments in OAuth::Consumer#get_access_token (Matt Sanford)
80
+ * Add gem version to user-agent header (Matt Sanford)
81
+ * Handle input from aggressive form encoding libraries (Matt Wood)
82
+
83
+ == 0.3.2 2009-03-23
84
+
85
+ * 2xx statuses should be treated as success (Anders Conbere)
86
+ * Support applications using the MethodOverride Rack middleware (László Bácsi)
87
+ * `authorize` command for `oauth` CLI (Seth)
88
+ * Initial support for Problem Reporting extension (Seth)
89
+ * Verify SSL certificates if CA certificates are available (Seth)
90
+ * Fixed ActionController parameter escaping behavior (Thiago Arrais, László
91
+ Bácsi, Brett Gibson, et al)
92
+ * Fixed signature calculation when both options and a block were provided to
93
+ OAuth::Signature::Base#initialize (Seth)
94
+ * Added help to the 'oauth' CLI (Seth)
95
+ * Fixed a problem when attempting to normalize MockRequest URIs (Seth)
96
+
97
+ == 0.3.1 2009-1-26
98
+
99
+ * Fixed a problem with relative and absolute token request paths. (Michael
100
+ Wood)
101
+
102
+ == 0.3.0 2009-1-25
103
+
104
+ * Support ActionController::Request from Edge Rails (László Bácsi)
105
+ * Correctly handle multi-valued parameters (Seth)
106
+ * Added #normalized_parameters to OAuth::RequestProxy::Base (Pelle)
107
+ * OAuth::Signature.sign and friends now yield the RequestProxy instead of the
108
+ token when the passed block's arity is 1. (Seth)
109
+ * Token requests are made to the configured URL rather than generating a
110
+ potentially incorrect one. (Kellan Elliott-McCrea)
111
+ * Command-line app for generating signatures. (Seth)
112
+ * Improved test-cases and compatibility for encoding issues. (Pelle)
113
+
114
+ == 0.2.7 2008-9-10 The lets fix the last release release
115
+
116
+ * Fixed plain text signatures (Andrew Arrow)
117
+ * Fixed RSA requests using OAuthTokens. (Philip Lipu Tsai)
118
+
119
+ == 0.2.6 2008-9-9 The lets RSA release
120
+
121
+ * Improved support for Ruby 1.8.7 (Bill Kocik)
122
+ * Fixed RSA verification to support RSA providers
123
+ now using Ruby and RSA
124
+ * Improved RSA testing
125
+ * Omit token when signing with RSA
126
+ * Added support for 'private_key_file' option for RSA signatures (Chris Mear)
127
+ * Fixed several edge cases where params were being incorrectly signed (Scott
128
+ Hill)
129
+ * Fixed RSA signing (choonkeat)
130
+
131
+ == 0.2.2 2008-2-22 Lets actually support SSL release
132
+
133
+ * Use HTTPS when required.
134
+
135
+ == 0.2 2008-1-19 All together now release
136
+
137
+ This is a big release, where we have merged the efforts of various parties into one common library.
138
+ This means there are definitely some API changes you should be aware of. They should be minimal
139
+ but please have a look at the unit tests.
140
+
141
+ == 0.1.2 2007-12-1
142
+
143
+ * Fixed checks for missing OAuth params to improve performance
144
+ * Includes Pat's fix for getting the realm out.
145
+
146
+ == 0.1.1 2007-11-26
147
+
148
+ * First release as a GEM
149
+ * Moved all non-Rails functionality from the Rails plugin:
150
+ 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,74 @@
1
+ = Ruby OAuth
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
+ The source code is now hosted on the OAuth GitHub Project http://github.com/oauth/oauth-ruby
14
+
15
+ == The basics
16
+
17
+ 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.
18
+
19
+ 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.
20
+
21
+ == Demonstration of usage
22
+
23
+ We need to specify the oauth_callback url explicitly, otherwise it defaults to "oob" (Out of Band)
24
+
25
+ @callback_url = "http://127.0.0.1:3000/oauth/callback"
26
+
27
+ Create a new consumer instance by passing it a configuration hash:
28
+
29
+ @consumer = OAuth::Consumer.new("key","secret", :site => "https://agree2")
30
+
31
+ Start the process by requesting a token
32
+
33
+ @request_token = @consumer.get_request_token(:oauth_callback => @callback_url)
34
+ session[:request_token] = @request_token
35
+ redirect_to @request_token.authorize_url(:oauth_callback => @callback_url)
36
+
37
+ When user returns create an access_token
38
+
39
+ @access_token = @request_token.get_access_token
40
+ @photos = @access_token.get('/photos.xml')
41
+
42
+ Now that you have an access token, you can use Typhoeus to interact with the OAuth provider if you choose.
43
+
44
+ oauth_params = {:consumer => oauth_consumer, :token => access_token}
45
+ hydra = Typhoeus::Hydra.new
46
+ req = Typhoeus::Request.new(uri, options)
47
+ oauth_helper = OAuth::Client::Helper.new(req, oauth_params.merge(:request_uri => uri))
48
+ req.headers.merge!({"Authorization" => oauth_helper.header}) # Signs the request
49
+ hydra.queue(req)
50
+ hydra.run
51
+ @response = req.response
52
+
53
+
54
+ == More Information
55
+
56
+ * RDoc: http://rdoc.info/projects/oauth/oauth-ruby/
57
+ * Mailing List/Google Group: http://groups.google.com/group/oauth-ruby
58
+
59
+ == How to submit patches
60
+
61
+ The source code is now hosted on the OAuth GitHub Project http://github.com/oauth/oauth-ruby
62
+
63
+ 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.
64
+
65
+ == License
66
+
67
+ This code is free to use under the terms of the MIT license.
68
+
69
+ == Contact
70
+
71
+ OAuth Ruby has been created and maintained by a large number of talented individuals.
72
+ The current maintainer is Aaron Quint (quirkey).
73
+
74
+ Comments are welcome. Send an email to via the OAuth Ruby mailing list http://groups.google.com/group/oauth-ruby
@@ -0,0 +1,37 @@
1
+ %w[rubygems rake rake/clean rake/testtask fileutils].each { |f| require f }
2
+ $LOAD_PATH << File.dirname(__FILE__) + '/lib'
3
+ require 'oauth'
4
+
5
+ begin
6
+ require 'jeweler'
7
+ Jeweler::Tasks.new do |s|
8
+ s.name = %q{oauth}
9
+ s.version = OAuth::VERSION
10
+ s.authors = ["Pelle Braendgaard", "Blaine Cook", "Larry Halff", "Jesse Clark", "Jon Crosby", "Seth Fitzsimmons", "Matt Sanford", "Aaron Quint"]
11
+ s.email = "oauth-ruby@googlegroups.com"
12
+ s.description = "OAuth Core Ruby implementation"
13
+ s.summary = s.description
14
+ s.rubyforge_project = %q{oauth}
15
+ s.add_development_dependency(%q<actionpack>, [">=2.3.5"])
16
+ s.add_development_dependency(%q<rack>, [">= 1.0.0"])
17
+ s.add_development_dependency(%q<mocha>, [">= 0.9.8"])
18
+ s.add_development_dependency(%q<typhoeus>, [">= 0.1.13"])
19
+ s.add_development_dependency(%q<em-http-request>, [">= 0.2.10"])
20
+ s.add_development_dependency(%q<curb>, [">= 0.6.6.0"])
21
+
22
+ s.files.include '.gemtest'
23
+ end
24
+ Jeweler::GemcutterTasks.new
25
+ rescue LoadError
26
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
27
+ end
28
+
29
+ Rake::TestTask.new do |t|
30
+ t.libs << "test"
31
+ t.test_files = FileList['test/**/*test*.rb']
32
+ t.verbose = true
33
+ end
34
+
35
+ Dir['tasks/**/*.rake'].each { |t| load t }
36
+
37
+ task :default => :test
data/TODO ADDED
@@ -0,0 +1,32 @@
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
32
+ * Take a look at Curb HTTP Verbs
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
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
@@ -0,0 +1,104 @@
1
+ # = digest/hmac.rb
2
+ #
3
+ # An implementation of HMAC keyed-hashing algorithm
4
+ #
5
+ # == Overview
6
+ #
7
+ # This library adds a method named hmac() to Digest classes, which
8
+ # creates a Digest class for calculating HMAC digests.
9
+ #
10
+ # == Examples
11
+ #
12
+ # require 'digest/hmac'
13
+ #
14
+ # # one-liner example
15
+ # puts Digest::HMAC.hexdigest("data", "hash key", Digest::SHA1)
16
+ #
17
+ # # rather longer one
18
+ # hmac = Digest::HMAC.new("foo", Digest::RMD160)
19
+ #
20
+ # buf = ""
21
+ # while stream.read(16384, buf)
22
+ # hmac.update(buf)
23
+ # end
24
+ #
25
+ # puts hmac.bubblebabble
26
+ #
27
+ # == License
28
+ #
29
+ # Copyright (c) 2006 Akinori MUSHA <knu@iDaemons.org>
30
+ #
31
+ # Documentation by Akinori MUSHA
32
+ #
33
+ # All rights reserved. You can redistribute and/or modify it under
34
+ # the same terms as Ruby.
35
+ #
36
+ # $Id: hmac.rb 14881 2008-01-04 07:26:14Z akr $
37
+ #
38
+
39
+ require 'digest'
40
+
41
+ unless defined?(Digest::HMAC)
42
+ module Digest
43
+ class HMAC < Digest::Class
44
+ def initialize(key, digester)
45
+ @md = digester.new
46
+
47
+ block_len = @md.block_length
48
+
49
+ if key.bytesize > block_len
50
+ key = @md.digest(key)
51
+ end
52
+
53
+ ipad = Array.new(block_len).fill(0x36)
54
+ opad = Array.new(block_len).fill(0x5c)
55
+
56
+ key.bytes.each_with_index { |c, i|
57
+ ipad[i] ^= c
58
+ opad[i] ^= c
59
+ }
60
+
61
+ @key = key.freeze
62
+ @ipad = ipad.inject('') { |s, c| s << c.chr }.freeze
63
+ @opad = opad.inject('') { |s, c| s << c.chr }.freeze
64
+ @md.update(@ipad)
65
+ end
66
+
67
+ def initialize_copy(other)
68
+ @md = other.instance_eval { @md.clone }
69
+ end
70
+
71
+ def update(text)
72
+ @md.update(text)
73
+ self
74
+ end
75
+ alias << update
76
+
77
+ def reset
78
+ @md.reset
79
+ @md.update(@ipad)
80
+ self
81
+ end
82
+
83
+ def finish
84
+ d = @md.digest!
85
+ @md.update(@opad)
86
+ @md.update(d)
87
+ @md.digest!
88
+ end
89
+ private :finish
90
+
91
+ def digest_length
92
+ @md.digest_length
93
+ end
94
+
95
+ def block_length
96
+ @md.block_length
97
+ end
98
+
99
+ def inspect
100
+ sprintf('#<%s: key=%s, digest=%s>', self.class.name, @key.inspect, @md.inspect.sub(/^\#<(.*)>$/) { $1 });
101
+ end
102
+ end
103
+ end
104
+ end