Class: Ibanity::PontoConnect::Token

Inherits:
OAuthResource show all
Defined in:
lib/ibanity/api/ponto_connect/token.rb

Class Method Summary collapse

Methods inherited from OAuthResource

create_by_uri, find_by_uri, #initialize

Constructor Details

This class inherits a constructor from Ibanity::OAuthResource

Class Method Details

.create(refresh_token: nil, authorization_code: nil, redirect_uri: nil, idempotency_key: nil, code_verifier: nil) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ibanity/api/ponto_connect/token.rb', line 4

def self.create(refresh_token: nil, authorization_code: nil, redirect_uri: nil, idempotency_key: nil, code_verifier: nil)
  arguments =
    if refresh_token
      [
        ["grant_type", "refresh_token"],
        ["client_id", Ibanity.client.ponto_connect_client_id],
        ["refresh_token", refresh_token]
      ]
    elsif authorization_code
      [
        ["grant_type", "authorization_code"],
        ["client_id", Ibanity.client.ponto_connect_client_id],
        ["code", authorization_code],
        ["code_verifier", code_verifier],
        ["redirect_uri", redirect_uri]
      ]
    else
      [
        ["grant_type", "client_credentials"]
      ]
    end

  create_by_uri(
    uri: Ibanity.ponto_connect_api_schema["oauth2"]["token"],
    payload: URI.encode_www_form(arguments),
    idempotency_key: idempotency_key,
    headers: self.headers
  )
end

.delete(refresh_token:) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/ibanity/api/ponto_connect/token.rb', line 34

def self.delete(refresh_token:)
  uri = Ibanity.ponto_connect_api_schema["oauth2"]["revoke"]
  arguments = [
    ["token", refresh_token]
  ]
  payload = URI.encode_www_form(arguments)
  create_by_uri(uri: uri, payload: payload, headers: self.headers)
end