From 781a7affe91df19ef92f740cbc07f6c2014b20a3 Mon Sep 17 00:00:00 2001 From: Murray Summers Date: Sun, 2 Sep 2012 00:13:03 +0100 Subject: [PATCH] Create wrapper methods for oauth flow to prevent users directly accessing client and to make code cleaner in applications. --- lib/freeagent.rb | 16 ++++++++++++++++ lib/freeagent/client.rb | 8 ++++++++ 2 files changed, 24 insertions(+) diff --git a/lib/freeagent.rb b/lib/freeagent.rb index f5ce9e3..b8cc5fa 100644 --- a/lib/freeagent.rb +++ b/lib/freeagent.rb @@ -28,5 +28,21 @@ def access_details(client_id, client_secret, access_token=nil) @client = Client.new(client_id, client_secret) @client.access_token = access_token if access_token end + + def authorize(options) + @client.authorize(options) + end + + def fetch_access_token(auth_token, options) + @client.fetch_access_token(auth_token, options) + end + + def access_token=(access_token) + @client.access_token = access_token + end + + def access_token + @client.access_token.token + end end end diff --git a/lib/freeagent/client.rb b/lib/freeagent/client.rb index 05e2291..aa199c4 100644 --- a/lib/freeagent/client.rb +++ b/lib/freeagent/client.rb @@ -41,6 +41,14 @@ def self.token_url def self.connection_opts { :headers => { :user_agent => "freeagent-api-rb", :accept => "application/json", :content_type => "application/json" } } end + + def authorize(options) + if options[:redirect_uri] + @client.auth_code.authorize_url(options) + else + raise FreeAgent::ClientError.new('Redirect uri not specified') + end + end def fetch_access_token(auth_code, options) if options[:redirect_uri]