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(country:, 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(country:, visitor:, experience: nil) ⇒ Session
Returns a new instance of Session.
14 15 16 17 18 |
# File 'lib/flowcommerce_spree/session.rb', line 14 def initialize(country:, visitor:, experience: nil) @country = country @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(country:, visitor:, experience: nil) ⇒ Object
8 9 10 11 12 |
# File 'lib/flowcommerce_spree/session.rb', line 8 def self.create(country:, visitor:, experience: nil) instance = new(country: country, 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)
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/flowcommerce_spree/session.rb', line 22 def create data = { country: @country, 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
40 41 42 |
# File 'lib/flowcommerce_spree/session.rb', line 40 def experience @session.local&.experience end |
#expires_at ⇒ Object
44 45 46 |
# File 'lib/flowcommerce_spree/session.rb', line 44 def expires_at @session.visit.expires_at end |
#id ⇒ Object
52 53 54 |
# File 'lib/flowcommerce_spree/session.rb', line 52 def id @session.id end |
#local ⇒ Object
48 49 50 |
# File 'lib/flowcommerce_spree/session.rb', line 48 def local @session.local end |
#update(data) ⇒ Object
if we want to manually switch to specific country or experience
34 35 36 37 |
# File 'lib/flowcommerce_spree/session.rb', line 34 def update(data) @session = FlowCommerce.instance.sessions.put_by_session(@session.id, ::Io::Flow::V0::Models::SessionPutForm.new(data)) end |