stmpjmpr-oauth 0.2.7

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 (56) hide show
  1. data/History.txt +33 -0
  2. data/License.txt +20 -0
  3. data/Manifest.txt +55 -0
  4. data/Rakefile +4 -0
  5. data/config/hoe.rb +71 -0
  6. data/config/requirements.rb +17 -0
  7. data/lib/oauth/client/action_controller_request.rb +52 -0
  8. data/lib/oauth/client/helper.rb +74 -0
  9. data/lib/oauth/client/net_http.rb +75 -0
  10. data/lib/oauth/client.rb +4 -0
  11. data/lib/oauth/consumer.rb +218 -0
  12. data/lib/oauth/helper.rb +14 -0
  13. data/lib/oauth/request_proxy/action_controller_request.rb +64 -0
  14. data/lib/oauth/request_proxy/base.rb +76 -0
  15. data/lib/oauth/request_proxy/net_http.rb +67 -0
  16. data/lib/oauth/request_proxy/rack_request.rb +42 -0
  17. data/lib/oauth/request_proxy.rb +24 -0
  18. data/lib/oauth/server.rb +68 -0
  19. data/lib/oauth/signature/base.rb +76 -0
  20. data/lib/oauth/signature/hmac/base.rb +12 -0
  21. data/lib/oauth/signature/hmac/md5.rb +9 -0
  22. data/lib/oauth/signature/hmac/rmd160.rb +9 -0
  23. data/lib/oauth/signature/hmac/sha1.rb +10 -0
  24. data/lib/oauth/signature/hmac/sha2.rb +9 -0
  25. data/lib/oauth/signature/md5.rb +13 -0
  26. data/lib/oauth/signature/plaintext.rb +23 -0
  27. data/lib/oauth/signature/rsa/sha1.rb +44 -0
  28. data/lib/oauth/signature/sha1.rb +13 -0
  29. data/lib/oauth/signature.rb +28 -0
  30. data/lib/oauth/token.rb +137 -0
  31. data/lib/oauth/version.rb +9 -0
  32. data/lib/oauth.rb +3 -0
  33. data/script/destroy +14 -0
  34. data/script/generate +14 -0
  35. data/script/txt2html +74 -0
  36. data/setup.rb +1585 -0
  37. data/tasks/deployment.rake +34 -0
  38. data/tasks/environment.rake +7 -0
  39. data/tasks/website.rake +17 -0
  40. data/test/test_action_controller_request_proxy.rb +28 -0
  41. data/test/test_consumer.rb +284 -0
  42. data/test/test_helper.rb +7 -0
  43. data/test/test_hmac_sha1.rb +21 -0
  44. data/test/test_net_http_client.rb +169 -0
  45. data/test/test_net_http_request_proxy.rb +38 -0
  46. data/test/test_rack_request_proxy.rb +40 -0
  47. data/test/test_server.rb +40 -0
  48. data/test/test_signature.rb +11 -0
  49. data/test/test_signature_base.rb +32 -0
  50. data/test/test_token.rb +14 -0
  51. data/website/index.html +87 -0
  52. data/website/index.txt +73 -0
  53. data/website/javascripts/rounded_corners_lite.inc.js +285 -0
  54. data/website/stylesheets/screen.css +138 -0
  55. data/website/template.rhtml +48 -0
  56. metadata +137 -0
@@ -0,0 +1,137 @@
1
+ require 'oauth/helper'
2
+ module OAuth
3
+
4
+ # Superclass for the various tokens used by OAuth
5
+
6
+ class Token
7
+ include OAuth::Helper
8
+
9
+ attr_accessor :token, :secret
10
+
11
+ def initialize(token, secret)
12
+ @token = token
13
+ @secret = secret
14
+ end
15
+
16
+ def to_query
17
+ "oauth_token=#{escape(token)}&oauth_secret=#{escape(secret)}"
18
+ end
19
+
20
+ end
21
+
22
+ # Used on the server for generating tokens
23
+ class ServerToken<Token
24
+
25
+ def initialize
26
+ super generate_key(16),generate_key
27
+ end
28
+ end
29
+ # Superclass for tokens used by OAuth Clients
30
+ class ConsumerToken<Token
31
+ attr_accessor :consumer
32
+
33
+ def initialize(consumer,token="",secret="")
34
+ super token,secret
35
+ @consumer=consumer
36
+ end
37
+
38
+ # Make a signed request using given http_method to the path
39
+ #
40
+ # @token.request(:get,'/people')
41
+ # @token.request(:post,'/people',@person.to_xml,{ 'Content-Type' => 'application/xml' })
42
+ #
43
+ def request(http_method,path,*arguments)
44
+ response=consumer.request(http_method,path,self,{},*arguments)
45
+ end
46
+
47
+ # Sign a request generated elsewhere using Net:HTTP::Post.new or friends
48
+ def sign!(request,options = {})
49
+ consumer.sign!(request,self,options)
50
+ end
51
+
52
+ end
53
+
54
+ # The RequestToken is used for the initial Request.
55
+ # This is normally created by the Consumer object.
56
+ class RequestToken<ConsumerToken
57
+
58
+ # Returns the authorization url that you need to use for redirecting the user
59
+ def authorize_url
60
+ consumer.authorize_url+"?oauth_token="+CGI.escape(token)
61
+ end
62
+
63
+ # exchange for AccessToken on server
64
+ def get_access_token(options={})
65
+ response=consumer.token_request(consumer.http_method,consumer.access_token_path,self,options)
66
+ OAuth::AccessToken.new(consumer,response[:oauth_token],response[:oauth_token_secret])
67
+ end
68
+ end
69
+
70
+ # The Access Token is used for the actual "real" web service calls thatyou perform against the server
71
+ class AccessToken<ConsumerToken
72
+
73
+ # The less intrusive way. Otherwise, if we are to do it correctly inside consumer,
74
+ # we need to restructure and touch more methods: request(), sign!(), etc.
75
+ def request(http_method, path, *arguments)
76
+ request_uri = URI.parse(path)
77
+ site_uri = consumer.uri
78
+ is_service_uri_different = (request_uri.absolute? && request_uri != site_uri)
79
+ consumer.uri(request_uri) if is_service_uri_different
80
+ resp = super(http_method, path, *arguments)
81
+ # NOTE: reset for wholesomeness? meaning that we admit only AccessToken service calls may use different URIs?
82
+ # so reset in case consumer is still used for other token-management tasks subsequently?
83
+ consumer.uri(site_uri) if is_service_uri_different
84
+ resp
85
+ end
86
+
87
+ # Make a regular get request using AccessToken
88
+ #
89
+ # @response=@token.get('/people')
90
+ # @response=@token.get('/people',{'Accept'=>'application/xml'})
91
+ #
92
+ def get(path,headers={})
93
+ request(:get,path,headers)
94
+ end
95
+
96
+ # Make a regular head request using AccessToken
97
+ #
98
+ # @response=@token.head('/people')
99
+ #
100
+ def head(path,headers={})
101
+ request(:head,path,headers)
102
+ end
103
+
104
+ # Make a regular post request using AccessToken
105
+ #
106
+ # @response=@token.post('/people')
107
+ # @response=@token.post('/people',{:name=>'Bob',:email=>'bob@mailinator.com'})
108
+ # @response=@token.post('/people',{:name=>'Bob',:email=>'bob@mailinator.com'},{'Accept'=>'application/xml'})
109
+ # @response=@token.post('/people',nil,{'Accept'=>'application/xml'})
110
+ # @response=@token.post('/people',@person.to_xml,{'Accept'=>'application/xml','Content-Type' => 'application/xml'})
111
+ #
112
+ def post(path, body = '',headers={})
113
+ request(:post,path,body,headers)
114
+ end
115
+
116
+ # Make a regular put request using AccessToken
117
+ #
118
+ # @response=@token.put('/people/123')
119
+ # @response=@token.put('/people/123',{:name=>'Bob',:email=>'bob@mailinator.com'})
120
+ # @response=@token.put('/people/123',{:name=>'Bob',:email=>'bob@mailinator.com'},{'Accept'=>'application/xml'})
121
+ # @response=@token.put('/people/123',nil,{'Accept'=>'application/xml'})
122
+ # @response=@token.put('/people/123',@person.to_xml,{'Accept'=>'application/xml','Content-Type' => 'application/xml'})
123
+ #
124
+ def put(path, body = '', headers={})
125
+ request(:put,path,body,headers)
126
+ end
127
+
128
+ # Make a regular delete request using AccessToken
129
+ #
130
+ # @response=@token.delete('/people/123')
131
+ # @response=@token.delete('/people/123',{'Accept'=>'application/xml'})
132
+ #
133
+ def delete(path,headers={})
134
+ request(:delete,path,headers)
135
+ end
136
+ end
137
+ end
@@ -0,0 +1,9 @@
1
+ module Oauth #:nodoc:
2
+ module VERSION #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 2
5
+ TINY = 7
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end
data/lib/oauth.rb ADDED
@@ -0,0 +1,3 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+
3
+ module OAuth; end
data/script/destroy ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.join(File.dirname(__FILE__), '..')
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
data/script/generate ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.join(File.dirname(__FILE__), '..')
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
data/script/txt2html ADDED
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ begin
5
+ require 'newgem'
6
+ rescue LoadError
7
+ puts "\n\nGenerating the website requires the newgem RubyGem"
8
+ puts "Install: gem install newgem\n\n"
9
+ exit(1)
10
+ end
11
+ require 'redcloth'
12
+ require 'syntax/convertors/html'
13
+ require 'erb'
14
+ require File.dirname(__FILE__) + '/../lib/oauth/version.rb'
15
+
16
+ version = Oauth::VERSION::STRING
17
+ download = 'http://rubyforge.org/projects/oauth'
18
+
19
+ class Fixnum
20
+ def ordinal
21
+ # teens
22
+ return 'th' if (10..19).include?(self % 100)
23
+ # others
24
+ case self % 10
25
+ when 1: return 'st'
26
+ when 2: return 'nd'
27
+ when 3: return 'rd'
28
+ else return 'th'
29
+ end
30
+ end
31
+ end
32
+
33
+ class Time
34
+ def pretty
35
+ return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
36
+ end
37
+ end
38
+
39
+ def convert_syntax(syntax, source)
40
+ return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
41
+ end
42
+
43
+ if ARGV.length >= 1
44
+ src, template = ARGV
45
+ template ||= File.join(File.dirname(__FILE__), '/../website/template.rhtml')
46
+
47
+ else
48
+ puts("Usage: #{File.split($0).last} source.txt [template.rhtml] > output.html")
49
+ exit!
50
+ end
51
+
52
+ template = ERB.new(File.open(template).read)
53
+
54
+ title = nil
55
+ body = nil
56
+ File.open(src) do |fsrc|
57
+ title_text = fsrc.readline
58
+ body_text = fsrc.read
59
+ syntax_items = []
60
+ body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</\1>!m){
61
+ ident = syntax_items.length
62
+ element, syntax, source = $1, $2, $3
63
+ syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
64
+ "syntax-temp-#{ident}"
65
+ }
66
+ title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
67
+ body = RedCloth.new(body_text).to_html
68
+ body.gsub!(%r!(?:<pre><code>)?syntax-temp-(\d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
69
+ end
70
+ stat = File.stat(src)
71
+ created = stat.ctime
72
+ modified = stat.mtime
73
+
74
+ $stdout << template.result(binding)