Class: Mautic::Connections::Oauth2
Instance Method Summary
collapse
#contacts, receive_webhook, #tags
Instance Method Details
#authorize(context) ⇒ Object
14
15
16
|
# File 'app/models/mautic/connections/oauth2.rb', line 14
def authorize(context)
client.auth_code.authorize_url(redirect_uri: callback_url(context))
end
|
#client ⇒ Object
5
6
7
8
9
10
11
12
|
# File 'app/models/mautic/connections/oauth2.rb', line 5
def client
@client ||= OAuth2::Client.new(client_id, secret, {
site: url,
authorize_url: 'oauth/v2/authorize',
token_url: 'oauth/v2/token',
raise_errors: false
})
end
|
#connection ⇒ Object
22
23
24
|
# File 'app/models/mautic/connections/oauth2.rb', line 22
def connection
@connection ||= OAuth2::AccessToken.new(client, token, { refresh_token: refresh_token })
end
|
#get_code(code, context) ⇒ Object
18
19
20
|
# File 'app/models/mautic/connections/oauth2.rb', line 18
def get_code(code, context)
client.auth_code.get_token(code, redirect_uri: callback_url(context))
end
|
#refresh! ⇒ Object
26
27
28
29
30
|
# File 'app/models/mautic/connections/oauth2.rb', line 26
def refresh!
@connection = connection.refresh!
update(token: @connection.token, refresh_token: @connection.refresh_token)
@connection
end
|
#request(type, path, params = {}) ⇒ Object
32
33
34
35
36
|
# File 'app/models/mautic/connections/oauth2.rb', line 32
def request(type, path, params = {})
@last_request = [type, path, params]
response = connection.request(type, path, params)
parse_response(response)
end
|