Sha256: a0e28ac2dcb7a39b908fdc4d81b111cc1b450b50e6a125cd097bdaa8dca2420e

Contents?: true

Size: 729 Bytes

Versions: 11

Compression:

Stored size: 729 Bytes

Contents

module SolidusMe
  class Account < ApplicationRecord
    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

    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
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
solidus_me-3.2.0 app/models/solidus_me/account.rb
solidus_me-3.1.0 app/models/solidus_me/account.rb
solidus_me-3.0.2 app/models/solidus_me/account.rb
solidus_me-3.0.1 app/models/solidus_me/account.rb
solidus_me-3.0.0 app/models/solidus_me/account.rb
solidus_me-2.3.1 app/models/solidus_me/account.rb
solidus_me-2.3.0 app/models/solidus_me/account.rb
solidus_me-2.2.0 app/models/solidus_me/account.rb
solidus_me-2.1.1 app/models/solidus_me/account.rb
solidus_me-2.1.0 app/models/solidus_me/account.rb
solidus_me-2.0.3 app/models/solidus_me/account.rb