Class: ShopifyAPI::Auth::Session
- Inherits:
-
Object
- Object
- ShopifyAPI::Auth::Session
- Extended by:
- T::Sig
- Defined in:
- lib/shopify_api/auth/session.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#associated_user ⇒ Object
Returns the value of attribute associated_user.
-
#associated_user_scope ⇒ Object
Returns the value of attribute associated_user_scope.
-
#expires ⇒ Object
Returns the value of attribute expires.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#refresh_token ⇒ Object
Returns the value of attribute refresh_token.
-
#refresh_token_expires ⇒ Object
Returns the value of attribute refresh_token_expires.
-
#scope ⇒ Object
Returns the value of attribute scope.
-
#shop ⇒ Object
Returns the value of attribute shop.
-
#shopify_session_id ⇒ Object
Returns the value of attribute shopify_session_id.
-
#state ⇒ Object
Returns the value of attribute state.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #copy_attributes_from(other) ⇒ Object
- #eql? ⇒ Object
- #expired? ⇒ Boolean
-
#initialize(shop:, id: nil, state: nil, access_token: "", scope: [], associated_user_scope: nil, expires: nil, is_online: nil, associated_user: nil, shopify_session_id: nil, refresh_token: nil, refresh_token_expires: nil) ⇒ Session
constructor
A new instance of Session.
- #online? ⇒ Boolean
- #refresh_token_expired? ⇒ Boolean
Constructor Details
#initialize(shop:, id: nil, state: nil, access_token: "", scope: [], associated_user_scope: nil, expires: nil, is_online: nil, associated_user: nil, shopify_session_id: nil, refresh_token: nil, refresh_token_expires: nil) ⇒ Session
Returns a new instance of Session.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/shopify_api/auth/session.rb', line 70 def initialize(shop:, id: nil, state: nil, access_token: "", scope: [], associated_user_scope: nil, expires: nil, is_online: nil, associated_user: nil, shopify_session_id: nil, refresh_token: nil, refresh_token_expires: nil) @id = T.let(id || SecureRandom.uuid, String) @shop = shop @state = state @access_token = access_token @scope = T.let(AuthScopes.new(scope), AuthScopes) @associated_user_scope = T.let( associated_user_scope.nil? ? nil : AuthScopes.new(associated_user_scope), T.nilable(AuthScopes) ) @expires = expires @associated_user = associated_user @is_online = T.let(is_online || !associated_user.nil?, T::Boolean) @shopify_session_id = shopify_session_id @refresh_token = refresh_token @refresh_token_expires = refresh_token_expires end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
13 14 15 |
# File 'lib/shopify_api/auth/session.rb', line 13 def access_token @access_token end |
#associated_user ⇒ Object
Returns the value of attribute associated_user.
28 29 30 |
# File 'lib/shopify_api/auth/session.rb', line 28 def associated_user @associated_user end |
#associated_user_scope ⇒ Object
Returns the value of attribute associated_user_scope.
22 23 24 |
# File 'lib/shopify_api/auth/session.rb', line 22 def associated_user_scope @associated_user_scope end |
#expires ⇒ Object
Returns the value of attribute expires.
25 26 27 |
# File 'lib/shopify_api/auth/session.rb', line 25 def expires @expires end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
10 11 12 |
# File 'lib/shopify_api/auth/session.rb', line 10 def id @id end |
#refresh_token ⇒ Object
Returns the value of attribute refresh_token.
34 35 36 |
# File 'lib/shopify_api/auth/session.rb', line 34 def refresh_token @refresh_token end |
#refresh_token_expires ⇒ Object
Returns the value of attribute refresh_token_expires.
37 38 39 |
# File 'lib/shopify_api/auth/session.rb', line 37 def refresh_token_expires @refresh_token_expires end |
#scope ⇒ Object
Returns the value of attribute scope.
19 20 21 |
# File 'lib/shopify_api/auth/session.rb', line 19 def scope @scope end |
#shop ⇒ Object
Returns the value of attribute shop.
16 17 18 |
# File 'lib/shopify_api/auth/session.rb', line 16 def shop @shop end |
#shopify_session_id ⇒ Object
Returns the value of attribute shopify_session_id.
31 32 33 |
# File 'lib/shopify_api/auth/session.rb', line 31 def shopify_session_id @shopify_session_id end |
#state ⇒ Object
Returns the value of attribute state.
13 14 15 |
# File 'lib/shopify_api/auth/session.rb', line 13 def state @state end |
Class Method Details
.from(shop:, access_token_response:) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/shopify_api/auth/session.rb', line 108 def from(shop:, access_token_response:) is_online = access_token_response.online_token? if is_online associated_user = T.must(access_token_response.associated_user) associated_user_scope = access_token_response.associated_user_scope id = "#{shop}_#{associated_user.id}" else id = "offline_#{shop}" end if access_token_response.expires_in expires = Time.now + access_token_response.expires_in.to_i end if access_token_response.refresh_token_expires_in refresh_token_expires = Time.now + access_token_response.refresh_token_expires_in.to_i end new( id: id, shop: shop, access_token: access_token_response.access_token, scope: access_token_response.scope, is_online: is_online, associated_user_scope: associated_user_scope, associated_user: associated_user, expires: expires, shopify_session_id: access_token_response.session, refresh_token: access_token_response.refresh_token, refresh_token_expires: refresh_token_expires, ) end |
.temp(shop:, access_token:, &blk) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/shopify_api/auth/session.rb', line 95 def temp(shop:, access_token:, &blk) original_session = Context.active_session temp_session = Session.new(shop: shop, access_token: access_token) begin Context.activate_session(temp_session) yield temp_session ensure Context.activate_session(original_session) end end |
Instance Method Details
#==(other) ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/shopify_api/auth/session.rb', line 161 def ==(other) if other id == other.id && shop == other.shop && state == other.state && scope == other.scope && associated_user_scope == other.associated_user_scope && (!(expires.nil? ^ other.expires.nil?) && (expires.nil? || expires.to_i == other.expires.to_i)) && online? == other.online? && associated_user == other.associated_user && shopify_session_id == other.shopify_session_id && refresh_token == other.refresh_token && refresh_token_expires&.to_i == other.refresh_token_expires&.to_i else false end end |
#copy_attributes_from(other) ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/shopify_api/auth/session.rb', line 144 def copy_attributes_from(other) @shop = other.shop @state = other.state @access_token = other.access_token @scope = other.scope @associated_user_scope = other.associated_user_scope @expires = other.expires @associated_user = other.associated_user @is_online = other.online? @shopify_session_id = other.shopify_session_id @refresh_token = other.refresh_token @refresh_token_expires = other.refresh_token_expires self end |
#eql? ⇒ Object
159 |
# File 'lib/shopify_api/auth/session.rb', line 159 alias_method :eql?, :== |
#expired? ⇒ Boolean
45 46 47 |
# File 'lib/shopify_api/auth/session.rb', line 45 def expired? @expires ? @expires < Time.now : false end |
#online? ⇒ Boolean
40 41 42 |
# File 'lib/shopify_api/auth/session.rb', line 40 def online? @is_online end |
#refresh_token_expired? ⇒ Boolean
50 51 52 |
# File 'lib/shopify_api/auth/session.rb', line 50 def refresh_token_expired? @refresh_token_expires ? @refresh_token_expires < Time.now + 60 : false end |