Sha256: d197ae36ac331b48d33b0876b182061eec61c71c43bbb4a002818a1b3f4f2d08
Contents?: true
Size: 981 Bytes
Versions: 7
Compression:
Stored size: 981 Bytes
Contents
module SolidusMe class Preferences attr_reader :preferences def initialize store @store = store @preferences = store.preferences[:melhor_envio] check end def check return if @preferences[:client_id].nil? || @preferences[:client_secret].nil? || @preferences[:refresh_token].nil? return if (@preferences[:token_expires_in]&.to_datetime - 1.day) > DateTime.now refresh end def refresh refresh_json = MeApi::Client.new.refresh_token( client_id: @preferences[:client_id], client_secret: @preferences[:client_secret], refresh_token: @preferences[:refresh_token] ).json @preferences[:access_token] = refresh_json["access_token"] @preferences[:refresh_token] = refresh_json["refresh_token"] @preferences[:token_expires_in] = (DateTime.now.utc + refresh_json["expires_in"].seconds).to_s @store.update(preferences: { melhor_envio: @preferences }) end end end
Version data entries
7 entries across 7 versions & 1 rubygems