Class: ShopifyAPI::Auth::Session

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/shopify_api/auth/session.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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) ⇒ Session

Returns a new instance of Session.



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/shopify_api/auth/session.rb', line 52

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

Instance Attribute Details

#access_tokenObject

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_userObject

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_scopeObject

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

#expiresObject

Returns the value of attribute expires.



25
26
27
# File 'lib/shopify_api/auth/session.rb', line 25

def expires
  @expires
end

#idObject (readonly)

Returns the value of attribute id.



10
11
12
# File 'lib/shopify_api/auth/session.rb', line 10

def id
  @id
end

#scopeObject

Returns the value of attribute scope.



19
20
21
# File 'lib/shopify_api/auth/session.rb', line 19

def scope
  @scope
end

#shopObject

Returns the value of attribute shop.



16
17
18
# File 'lib/shopify_api/auth/session.rb', line 16

def shop
  @shop
end

#shopify_session_idObject

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

#stateObject

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

.deserialize(str) ⇒ Object



88
89
90
# File 'lib/shopify_api/auth/session.rb', line 88

def deserialize(str)
  Oj.load(str)
end

.temp(shop:, access_token:, &blk) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
# File 'lib/shopify_api/auth/session.rb', line 75

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



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/shopify_api/auth/session.rb', line 100

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
    )
  else
    false
  end
end

#eql?Object



98
# File 'lib/shopify_api/auth/session.rb', line 98

alias_method :eql?, :==

#online?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/shopify_api/auth/session.rb', line 34

def online?
  @is_online
end

#serializeObject



94
95
96
# File 'lib/shopify_api/auth/session.rb', line 94

def serialize
  Oj.dump(self)
end