Class: SolidusMe::Account

Inherits:
ApplicationRecord
  • Object
show all
Defined in:
app/models/solidus_me/account.rb

Instance Method Summary collapse

Instance Method Details

#check_tokenObject



3
4
5
6
7
# File 'app/models/solidus_me/account.rb', line 3

def check_token
  return if client_id.blank? || client_secret.blank? || refresh_token.blank?
  return if (token_expires_in - 1.day) > DateTime.now
  refresh
end

#refreshObject



9
10
11
12
13
14
15
16
17
18
19
# File 'app/models/solidus_me/account.rb', line 9

def refresh
  refresh_json = MeApi::Client.new.refresh_token(
    client_id: client_id,
    client_secret: client_secret,
    refresh_token: refresh_token
  ).json
  access_token = refresh_json["access_token"]
  refresh_token = refresh_json["refresh_token"]
  token_expires_in = DateTime.now.utc + refresh_json["expires_in"].seconds
  update(access_token: access_token, refresh_token: refresh_token, token_expires_in: token_expires_in)
end