Class: Signnow::Authentications::Oauth

Inherits:
Base
  • Object
show all
Includes:
Operations::Create
Defined in:
lib/signnow/authentications/oauth.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Operations::Create

included

Methods inherited from Base

authenticate

Constructor Details

#initialize(attributes = {}) ⇒ Oauth

Initializes the object using the given attributes

Parameters:

  • attributes (Hash) (defaults to: {})

    The attributes to use for initialization



46
47
48
49
# File 'lib/signnow/authentications/oauth.rb', line 46

def initialize(attributes = {})
  set_attributes(attributes)
  parse_timestamps
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



6
7
8
# File 'lib/signnow/authentications/oauth.rb', line 6

def access_token
  @access_token
end

#createdObject

Returns the value of attribute created.



6
7
8
# File 'lib/signnow/authentications/oauth.rb', line 6

def created
  @created
end

#expires_inObject

Returns the value of attribute expires_in.



6
7
8
# File 'lib/signnow/authentications/oauth.rb', line 6

def expires_in
  @expires_in
end

#last_loginObject

Returns the value of attribute last_login.



6
7
8
# File 'lib/signnow/authentications/oauth.rb', line 6

def 
  @last_login
end

#refresh_tokenObject

Returns the value of attribute refresh_token.



6
7
8
# File 'lib/signnow/authentications/oauth.rb', line 6

def refresh_token
  @refresh_token
end

#scopeObject

Returns the value of attribute scope.



6
7
8
# File 'lib/signnow/authentications/oauth.rb', line 6

def scope
  @scope
end

#token_typeObject

Returns the value of attribute token_type.



6
7
8
# File 'lib/signnow/authentications/oauth.rb', line 6

def token_type
  @token_type
end

Class Method Details

.authorize_url(options = {}) ⇒ Object

Returns the redirect url to authorize

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • redirect_url (String)

    () redirect url to receive the code param



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/signnow/authentications/oauth.rb', line 14

def authorize_url(options = {})
  protocol = "https"
  base_url = "#{protocol}://#{domain}.#{API_BASE}"
  path = "/proxy/index.php/authorize"
  params = {
    client_id: Signnow.configuration[:app_id],
    redirect_uri: options[:redirect_uri],
    response_type: 'code'
  }

  "#{base_url}#{path}?#{URI.encode_www_form(params)}"
end

Instance Method Details

#parse_timestampsObject

Parses UNIX timestamps and creates Time objects.



61
62
63
64
65
# File 'lib/signnow/authentications/oauth.rb', line 61

def parse_timestamps
  @created = Time.at(created.to_i) if created
  @expires_in = Time.at(expires_in.to_i) if expires_in
  @last_login = Time.at(.to_i) if 
end

#set_attributes(attributes) ⇒ Object

Sets the attributes

Parameters:

  • attributes (Hash)

    The attributes to initialize



54
55
56
57
58
# File 'lib/signnow/authentications/oauth.rb', line 54

def set_attributes(attributes)
  attributes.each_pair do |key, value|
    instance_variable_set("@#{key}", value)
  end
end