Class: Simplify::AccessToken

Inherits:
Hash
  • Object
show all
Defined in:
lib/simplify/accesstoken.rb

Overview

An OAuth access token.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ AccessToken

Construct a AccessToken from a hash.



38
39
40
# File 'lib/simplify/accesstoken.rb', line 38

def initialize(options = {})
    self.merge!(options)
end

Class Method Details

.create(auth_code, redirect_uri, *auth) ⇒ Object

Creates an OAuth access token object.

auth_code: The OAuth authentication code. redirect_uri: The OAuth redirection URI.

auth

Authentication information used for the API call. If no value is passed the global keys Simplify::public_key and Simplify::private_key are used.



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/simplify/accesstoken.rb', line 49

def self.create(auth_code, redirect_uri, *auth)

    props = {
            'grant_type' => 'authorization_code',
            'code' => auth_code,
            'redirect_uri' => redirect_uri
    }

    h = Simplify::PaymentsApi.send_auth_request(props, 'token', Simplify::PaymentsApi.create_auth_object(auth))

    obj = AccessToken.new()
    obj = obj.merge!(h)

    obj

end

Instance Method Details

#refresh(*auth) ⇒ Object

Refreshes the OAuth access token

auth

Authentication information used for the API call. If no value is passed the global keys Simplify::public_key and Simplify::private_key are used.



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/simplify/accesstoken.rb', line 71

def refresh(*auth)

    rt = self['refresh_token']
    if rt == nil || rt.empty?
        raise ArgumentError.new("Cannot refresh access token; refresh token is invalid.")
    end

    props = {
            'grant_type' => 'refresh_token',
            'refresh_token' => rt
    }

    h = Simplify::PaymentsApi.send_auth_request(props, 'token', Simplify::PaymentsApi.create_auth_object(auth))

    self.merge!(h)
    self
end

#revoke(*auth) ⇒ Object

Revokes the access token.

auth

Authentication information used for the API call. If no value is passed the global keys Simplify::public_key and Simplify::private_key are used.



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/simplify/accesstoken.rb', line 94

def revoke(*auth)

    token = self['access_token']
    if token == nil || token.empty?
        raise ArgumentError.new("Cannot revoke access token; access token is invalid.")
    end

    props = {
            'token' => token
    }

    h = Simplify::PaymentsApi.send_auth_request(props, 'revoke', Simplify::PaymentsApi.create_auth_object(auth))
    self.clear
    self
end