Permalink
Browse files

authenticate and access_token methods updated

  • Loading branch information...
1 parent 6d1b4bb commit 79a58c32d3a9b31d0b579fc6b32611cf2f3991fd @ana-ci ana-ci committed Dec 29, 2010
Showing with 15 additions and 12 deletions.
  1. +12 −9 lib/codaset/codaset-api.rb
  2. +3 −3 lib/provider/codaset.rb
View
21 lib/codaset/codaset-api.rb
@@ -14,9 +14,9 @@ module CodasetAPI
class Error < StandardError; end
class << self
- attr_accessor :username, :password, :host_format, :domain_format, :protocol
+ attr_accessor :username, :password, :host_format, :domain_format, :protocol, :site, :token, :client_id, :client_secret
- def authenticate(username, password)
+ def authenticate(username, password, client_id, client_secret)
@username = username
@password = password
@site = 'https://api.codaset.com'
@@ -25,26 +25,29 @@ def authenticate(username, password)
self::Base.password = password
self::Base.site = @site
+ self.client_id = client_id
+ self.client_secret = client_secret
+
self.token = access_token(self)
end
def access_token(master)
- consumer = OAuth2::Client.new('07f16ec71c324ab053885212ad65a6cc8f34ac6e57ecb8412235ad406fc2c49c',
- '442fe0b16ff1143602e89ea923cbabc50342ab949a4b9c337905b9231236bdef',
- {:site =>
+ consumer = OAuth2::Client.new(master.client_id,
+ master.client_secret,
+ {:site =>
{:url => master.site,
:ssl => {:verify => OpenSSL::SSL::VERIFY_NONE,
:ca_file => nil
},
:adapter => :NetHttp
},
- :authorize_url => '/authorization/token',
- :parse_json => true})
+ :authorize_url => '/authorization/token',
+ :parse_json => true})
response = consumer.request(:post, auth_url, {:grant_type => 'password',
- :client_id => '07f16ec71c324ab053885212ad65a6cc8f34ac6e57ecb8412235ad406fc2c49c',
- :client_secret => '442fe0b16ff1143602e89ea923cbabc50342ab949a4b9c337905b9231236bdef',
+ :client_id => master.client_id,
+ :client_secret => master.client_secret,
:username => master.user,
:password => master.password},
'Content-Type' => 'application/x-www-form-urlencoded')
View
6 lib/provider/codaset.rb
@@ -15,11 +15,11 @@ def self.new(auth = {})
def authorize(auth = {})
@authentication ||= TicketMaster::Authenticator.new(auth)
auth = @authentication
- if auth.username.nil? or auth.password.nil?
- raise "Please provide username and password"
+ if auth.username.nil? or auth.password.nil? or auth.client_id.nil? or auth.client_secret.nil?
+ raise "Please provide username, password, client_id and client_secret"
end
CodasetAPI.protocol = auth.protocol if auth.protocol?
- CodasetAPI.authenticate(auth.username, auth.password)
+ CodasetAPI.authenticate(auth.username, auth.password, auth.client_id, auth.client_secret)
end
# declare needed overloaded methods here

0 comments on commit 79a58c3

Please sign in to comment.