Permalink
Browse files

Refactor: don't need DI container, plus stepdown rule.

  • Loading branch information...
1 parent 3898c96 commit 30eb8d5a55bb6778865778c4e36c35dcdaa1fd5d @ben-biddington ben-biddington committed with Jan 28, 2012
Showing with 19 additions and 32 deletions.
  1. +19 −32 Rakefile
View
@@ -1,41 +1,15 @@
-
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new
task :default => [:spec]
-class Container
- class << self
- def set(parent, name, value)
- parent.send :remove_const, name
- parent.const_set name, value
- end
- end
-end
-
namespace :example do
require "addressable/uri"
require "trello"
include Trello
include Trello::Authorization
- def ensure_consumer_credentials
- %w{PUBLIC_KEY SECRET}.each do |name|
- fullname = "DEVELOPER_#{name}"
- unless ENV[fullname]
- puts "ERROR: Missing <#{fullname}> environment variable."
- exit 1
- end
- end
- end
-
- def parse_token(text)
- matchdata = /oauth_token=([^&]+)&oauth_token_secret=(.+)/.match text
-
- the_request_token = OAuthCredential.new *matchdata[1..2]
- end
-
desc "get a new request token"
task :get_request_token do
ensure_consumer_credentials
@@ -46,9 +20,8 @@ namespace :example do
OAuthPolicy.consumer_credential = OAuthCredential.new @developer_public_key, @developer_secret
OAuthPolicy.token = nil
- Container.set Trello::Authorization, "AuthPolicy", OAuthPolicy
request = Request.new :get, URI.parse("https://trello.com/1/OAuthGetRequestToken")
- response = TInternet.get AuthPolicy.authorize(request)
+ response = TInternet.execute OAuthPolicy.authorize(request)
the_request_token = parse_token(response.body)
@@ -64,13 +37,27 @@ namespace :example do
OAuthPolicy.consumer_credential = OAuthCredential.new @developer_public_key, @developer_secret
OAuthPolicy.token = OAuthCredential.new args.request_token_key, args.request_token_secret
- Container.set Trello::Authorization, "AuthPolicy", OAuthPolicy
-
access_token_request = Request.new :get, URI.parse("https://trello.com/1/OAuthGetAccessToken?oauth_verifier=#{args.oauth_verifier}")
- response = TInternet.get AuthPolicy.authorize(access_token_request)
+ response = TInternet.execute OAuthPolicy.authorize(access_token_request)
the_access_token = parse_token response.body
puts "key => #{the_access_token.key}, secret => #{the_access_token.secret}"
end
-end
+
+ def ensure_consumer_credentials
+ %w{PUBLIC_KEY SECRET}.each do |name|
+ fullname = "DEVELOPER_#{name}"
+ unless ENV[fullname]
+ puts "ERROR: Missing <#{fullname}> environment variable."
+ exit 1
+ end
+ end
+ end
+
+ def parse_token(text)
+ matchdata = /oauth_token=([^&]+)&oauth_token_secret=(.+)/.match text
+
+ the_request_token = OAuthCredential.new *matchdata[1..2]
+ end
+end

0 comments on commit 30eb8d5

Please sign in to comment.