Class: Io::Flow::V0::Models::OrganizationSession

Inherits:
Session
  • Object
show all
Defined in:
lib/flow_commerce/flow_api_v0_client.rb

Overview

Represents a session created for an organization. Primary method to select an experience for a given user session and ensure that experience does not change throughout the user’s activity. Provides authentication to objects created during this session (e.g. order).

Instance Attribute Summary collapse

Attributes inherited from Session

#discriminator

Instance Method Summary collapse

Methods inherited from Session

from_json, #to_hash

Constructor Details

#initialize(incoming = {}) ⇒ OrganizationSession

Returns a new instance of OrganizationSession.



21946
21947
21948
21949
21950
21951
21952
21953
21954
21955
21956
21957
21958
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 21946

def initialize(incoming={})
  super(:discriminator => Session::Types::ORGANIZATION_SESSION)
  opts = HttpClient::Helper.symbolize_keys(incoming)
  HttpClient::Preconditions.require_keys(opts, [:id, :organization, :visitor, :visit, :environment, :attributes], 'OrganizationSession')
  @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), String)
  @organization = HttpClient::Preconditions.assert_class('organization', opts.delete(:organization), String)
  @visitor = (x = opts.delete(:visitor); x.is_a?(::Io::Flow::V0::Models::SessionVisitor) ? x : ::Io::Flow::V0::Models::SessionVisitor.new(x))
  @visit = (x = opts.delete(:visit); x.is_a?(::Io::Flow::V0::Models::SessionVisit) ? x : ::Io::Flow::V0::Models::SessionVisit.new(x))
  @environment = (x = opts.delete(:environment); x.is_a?(::Io::Flow::V0::Models::Environment) ? x : ::Io::Flow::V0::Models::Environment.apply(x))
  @attributes = HttpClient::Preconditions.assert_class('attributes', opts.delete(:attributes), Hash).inject({}) { |h, d| h[d[0]] = HttpClient::Preconditions.assert_class('attributes', d[1], String); h }
  @ip = (x = opts.delete(:ip); x.nil? ? nil : HttpClient::Preconditions.assert_class('ip', x, String))
  @local = (x = opts.delete(:local); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::V0::Models::LocalSession) ? x : ::Io::Flow::V0::Models::LocalSession.new(x)))
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



21944
21945
21946
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 21944

def attributes
  @attributes
end

#environmentObject (readonly)

Returns the value of attribute environment.



21944
21945
21946
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 21944

def environment
  @environment
end

#idObject (readonly)

Returns the value of attribute id.



21944
21945
21946
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 21944

def id
  @id
end

#ipObject (readonly)

Returns the value of attribute ip.



21944
21945
21946
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 21944

def ip
  @ip
end

#localObject (readonly)

Returns the value of attribute local.



21944
21945
21946
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 21944

def local
  @local
end

#organizationObject (readonly)

Returns the value of attribute organization.



21944
21945
21946
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 21944

def organization
  @organization
end

#visitObject (readonly)

Returns the value of attribute visit.



21944
21945
21946
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 21944

def visit
  @visit
end

#visitorObject (readonly)

Returns the value of attribute visitor.



21944
21945
21946
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 21944

def visitor
  @visitor
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



21964
21965
21966
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 21964

def copy(incoming={})
  OrganizationSession.new(subtype_to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
end

#subtype_to_hashObject



21968
21969
21970
21971
21972
21973
21974
21975
21976
21977
21978
21979
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 21968

def subtype_to_hash
  {
    :id => id,
    :organization => organization,
    :visitor => visitor.to_hash,
    :visit => visit.to_hash,
    :environment => environment.value,
    :attributes => attributes,
    :ip => ip,
    :local => local.nil? ? nil : local.to_hash
  }
end

#to_jsonObject



21960
21961
21962
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 21960

def to_json
  JSON.dump(to_hash)
end