Class: ChaskiqRubyClient::Auth

Inherits:
Object
  • Object
show all
Defined in:
lib/chaskiqRubyClient/auth.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uid:, secret:, site:) ⇒ Auth

Returns a new instance of Auth.



7
8
9
10
11
# File 'lib/chaskiqRubyClient/auth.rb', line 7

def initialize(uid:, secret:, site:)
  self.uid = uid
  self.secret = secret
  self.site = site
end

Instance Attribute Details

#secretObject

Returns the value of attribute secret.



5
6
7
# File 'lib/chaskiqRubyClient/auth.rb', line 5

def secret
  @secret
end

#siteObject

Returns the value of attribute site.



5
6
7
# File 'lib/chaskiqRubyClient/auth.rb', line 5

def site
  @site
end

#uidObject

Returns the value of attribute uid.



5
6
7
# File 'lib/chaskiqRubyClient/auth.rb', line 5

def uid
  @uid
end

Instance Method Details

#authorize_urlObject



21
22
23
24
25
26
27
28
# File 'lib/chaskiqRubyClient/auth.rb', line 21

def authorize_url
  client = OAuth2::Client.new(uid, secret, site: site)
  client.authorize_url(
    redirect_uri: site , 
    client_id: uid,
    response_type: "code"
  )
end

#get_token(user, password) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/chaskiqRubyClient/auth.rb', line 13

def get_token(user, password)
  client = OAuth2::Client.new(uid, secret, site: site)
  access_token =  client.password.get_token(
    user, 
    password
  ).token
end