Class: Sredder::WrikeAuth

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/sredder/wrike_auth.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sredderc = Sredderc.new) ⇒ WrikeAuth

Returns a new instance of WrikeAuth.



22
23
24
25
# File 'lib/sredder/wrike_auth.rb', line 22

def initialize(sredderc = Sredderc.new)
  @sredderc = sredderc
  @sredderc.load
end

Instance Attribute Details

#consumer=(value) ⇒ Object

Sets the attribute consumer

Parameters:

  • value

    the value to set the attribute consumer to.



18
19
20
# File 'lib/sredder/wrike_auth.rb', line 18

def consumer=(value)
  @consumer = value
end

#sreddercObject

Returns the value of attribute sredderc.



17
18
19
# File 'lib/sredder/wrike_auth.rb', line 17

def sredderc
  @sredderc
end

Instance Method Details

#authorized?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/sredder/wrike_auth.rb', line 41

def authorized?
  !!credentials[:wrike_token] && !!credentials[:wrike_secret]
end

#oauth_access_tokenObject



45
46
47
48
49
# File 'lib/sredder/wrike_auth.rb', line 45

def oauth_access_token
  if @access_token || authorized?
    @access_token ||= OAuth::AccessToken.new(consumer, credentials[:wrike_token], credentials[:wrike_secret])
  end
end

#run_oauth_procedureObject



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/sredder/wrike_auth.rb', line 27

def run_oauth_procedure
  @request_token = consumer.get_request_token
  puts 'Sredder is about to open your browser to complete the oauth protocol.'
  puts 'Please return to the terminal after you authenticate with Wrike.'

  Util.wait_for_input

  `open #{@request_token.authorize_url}`

  Util.wait_for_input

  store_tokens(@request_token.get_access_token)
end