lib/targetdata/api/auth.rb in targetdata-0.3.1 vs lib/targetdata/api/auth.rb in targetdata-0.4.0

- old
+ new

@@ -1,12 +1,10 @@ module Targetdata module Api module Auth def token - response = HTTP.headers(auth_headers).post(Targetdata::BASE_URL + '/token', form: auth_body) - parsed = JSON.parse(response.body.to_s) - parsed["access_token"] + ENV.fetch('TARGET_DATA_ACCESS_TOKEN') || generate_access_token end private def auth_body { @@ -23,8 +21,14 @@ { 'Content-Type':'application/x-www-form-urlencoded', 'Accept': 'application/json' } end + + def generate_access_token + response = HTTP.headers(auth_headers).post(Targetdata::BASE_URL + '/token', form: auth_body) + parsed = JSON.parse(response.body.to_s) + parsed["access_token"] + end end end -end \ No newline at end of file +end