Class: Swisspost::Auth

Inherits:
Object
  • Object
show all
Defined in:
lib/swisspost/auth.rb

Constant Summary collapse

AUTH_URL =
"https://api.post.ch/OAuth/token"

Instance Method Summary collapse

Instance Method Details

#get_access_token(api_scope) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/swisspost/auth.rb', line 7

def get_access_token(api_scope)
  response = HTTPX.with(headers: {
    "Content-Type" => "application/x-www-form-urlencoded",
  }).post(AUTH_URL, form: {
    grant_type: "client_credentials",
    client_id: "bdf1cf1f9133fcde0087c5ed95f9a488",
    client_secret: "151a4c935dd6bc83d3488a69e2e5fd02",
    scope: api_scope,
  })

  response.raise_for_status

  response.json["access_token"]
end