Class: FlowcommerceSpree::Session
- Inherits:
-
Object
- Object
- FlowcommerceSpree::Session
- Defined in:
- lib/flowcommerce_spree/session.rb
Instance Attribute Summary collapse
-
#localized ⇒ Object
Returns the value of attribute localized.
-
#session ⇒ Object
Returns the value of attribute session.
-
#visitor ⇒ Object
Returns the value of attribute visitor.
Class Method Summary collapse
Instance Method Summary collapse
-
#create ⇒ Object
create session without or with experience (the latter is useful for creating a new session with the order’s experience on refreshing the checkout_token).
-
#experience ⇒ Object
get local experience or return nil.
- #expires_at ⇒ Object
- #id ⇒ Object
-
#initialize(ip:, visitor:, experience: nil) ⇒ Session
constructor
A new instance of Session.
- #local ⇒ Object
-
#update(data) ⇒ Object
if we want to manually switch to specific country or experience.
Constructor Details
#initialize(ip:, visitor:, experience: nil) ⇒ Session
Returns a new instance of Session.
14 15 16 17 18 19 20 |
# File 'lib/flowcommerce_spree/session.rb', line 14 def initialize(ip:, visitor:, experience: nil) ip = '127.0.0.1' if ip == '::1' @ip = ip @visitor = visitor @experience = experience end |
Instance Attribute Details
#localized ⇒ Object
Returns the value of attribute localized.
6 7 8 |
# File 'lib/flowcommerce_spree/session.rb', line 6 def localized @localized end |
#session ⇒ Object
Returns the value of attribute session.
6 7 8 |
# File 'lib/flowcommerce_spree/session.rb', line 6 def session @session end |
#visitor ⇒ Object
Returns the value of attribute visitor.
6 7 8 |
# File 'lib/flowcommerce_spree/session.rb', line 6 def visitor @visitor end |
Class Method Details
.create(ip:, visitor:, experience: nil) ⇒ Object
8 9 10 11 12 |
# File 'lib/flowcommerce_spree/session.rb', line 8 def self.create(ip:, visitor:, experience: nil) instance = new(ip: ip, visitor: visitor, experience: experience) instance.create instance end |
Instance Method Details
#create ⇒ Object
create session without or with experience (the latter is useful for creating a new session with the order’s experience on refreshing the checkout_token)
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/flowcommerce_spree/session.rb', line 24 def create data = { ip: @ip, visit: { id: @visitor, expires_at: (Time.now + 30.minutes).iso8601 } } data[:experience] = @experience if @experience session_model = ::Io::Flow::V0::Models::SessionForm.new data @session = FlowCommerce.instance(http_handler: LoggingHttpHandler.new) .sessions.post_organizations_by_organization(ORGANIZATION, session_model) end |
#experience ⇒ Object
get local experience or return nil
42 43 44 |
# File 'lib/flowcommerce_spree/session.rb', line 42 def experience @session.local&.experience end |
#expires_at ⇒ Object
46 47 48 |
# File 'lib/flowcommerce_spree/session.rb', line 46 def expires_at @session.visit.expires_at end |
#id ⇒ Object
54 55 56 |
# File 'lib/flowcommerce_spree/session.rb', line 54 def id @session.id end |
#local ⇒ Object
50 51 52 |
# File 'lib/flowcommerce_spree/session.rb', line 50 def local @session.local end |
#update(data) ⇒ Object
if we want to manually switch to specific country or experience
36 37 38 39 |
# File 'lib/flowcommerce_spree/session.rb', line 36 def update(data) @session = FlowCommerce.instance.sessions.put_by_session(@session.id, ::Io::Flow::V0::Models::SessionPutForm.new(data)) end |