Class: Parse::Session

Inherits:
Object show all
Defined in:
lib/parse/model/classes/session.rb,
lib/parse/stack/generators/templates/model_session.rb

Overview

This class represents the data and columns contained in the standard Parse `_Session` collection. The Session class maintains per-device (or website) authentication information for a particular user. Whenever a User object is logged in, a new Session record, with a session token is generated. You may use a known active session token to find the corresponding user for that session. Deleting a Session record (and session token), effectively logs out the user, when making Parse requests on behalf of the user using the session token.

The default schema for the Session class is as follows:

class Parse::Session < Parse::Object
   # See Parse::Object for inherited properties...

   property :session_token
   property :created_with, :object
   property :expires_at, :date
   property :installation_id
   property :restricted, :boolean

   belongs_to :user

   # Installation where the installation_id matches.
   has_one :installation, ->{ where(installation_id: i.installation_id) }, scope_only: true
end

See Also:

Constant Summary

Constants included from Properties

Properties::BASE, Properties::BASE_FIELD_MAP, Properties::BASE_KEYS, Properties::CORE_FIELDS, Properties::DELETE_OP, Properties::TYPES

Constants inherited from Pointer

Pointer::ATTRIBUTES

Constants inherited from Model

Model::CLASS_INSTALLATION, Model::CLASS_PRODUCT, Model::CLASS_ROLE, Model::CLASS_SESSION, Model::CLASS_USER, Model::ID, Model::KEY_CLASS_NAME, Model::KEY_CREATED_AT, Model::KEY_OBJECT_ID, Model::KEY_UPDATED_AT, Model::OBJECT_ID, Model::TYPE_ACL, Model::TYPE_BYTES, Model::TYPE_DATE, Model::TYPE_FIELD, Model::TYPE_FILE, Model::TYPE_GEOPOINT, Model::TYPE_NUMBER, Model::TYPE_OBJECT, Model::TYPE_POINTER, Model::TYPE_RELATION

Instance Attribute Summary collapse

Attributes inherited from Object

#acl, #created_at, #id, #updated_at

Attributes inherited from Pointer

#id, #parse_class

Class Method Summary collapse

Methods inherited from Object

#[], #[]=, #__type, #after_create, #after_destroy, #after_save, #apply_defaults!, #as_json, #before_create, #before_destroy, #before_save, build, #clear_attribute_change!, #clear_changes!, #existed?, #initialize, #new?, #parse_class, #persisted?, pointer, #pretty, #reload!, #rollback!, #schema, set_default_acl, #twin, #updates, #validate!, webhook, webhook_function

Methods included from Core::Schema

#auto_upgrade!, #create_schema, #fetch_schema, #schema, #update_schema

Methods included from Core::Querying

#all, #count, #each, #find, #first, #literal_where, #newest, #oldest, #query, #scope

Methods included from Core::Actions

#change_requests, #changes_applied!, #changes_payload, #create, #destroy, #destroy_request, #op_add!, #op_add_relation!, #op_add_unique!, #op_destroy!, #op_increment!, #op_remove!, #op_remove_relation!, #operate_field!, #prepare_save!, #relation_change_operations, #save, #save!, #set_attributes!, #update, #update!, #update_relations, #uri_path

Methods included from Core::Fetching

#autofetch!, #fetch, #fetch!

Methods included from Associations::HasMany

has_many, #relation_changes?, #relation_updates, #relations

Methods included from Associations::BelongsTo

belongs_to, #key?

Methods included from Associations::HasOne

has_one

Methods included from Properties

#apply_attributes!, #attribute_changes?, #attribute_updates, #attributes, #attributes=, #field_map, #fields, #format_operation, #format_value

Methods inherited from Pointer

#==, #[], #[]=, #__type, #attributes, #className, #fetch, #fetched?, #hash, #initialize, #json_hash, #pointer, #pointer?, #present?, #sig

Methods inherited from Model

find_class

Methods included from Client::Connectable

#client

Constructor Details

This class inherits a constructor from Parse::Object

Instance Attribute Details

#created_withHash

Returns data on how this Session was created.

Returns:

  • (Hash)

    data on how this Session was created.


36
# File 'lib/parse/model/classes/session.rb', line 36

property :created_with, :object

#expires_atParse::Date

Returns when the session token expires.

Returns:


40
# File 'lib/parse/model/classes/session.rb', line 40

property :expires_at, :date

#installationParse::Installation (readonly)

Returns the Installation where the sessions installation_id field matches the installation_id field in the Installation collection. This is implemented as a has_one scope.

Returns:

Version:

  • 1.7.1


66
# File 'lib/parse/model/classes/session.rb', line 66

has_one :installation, ->{ where(installation_id: i.installation_id) }, scope_only: true

#installation_idString

Returns The installation id from the Installation table.

Returns:

  • (String)

    The installation id from the Installation table.

See Also:


45
# File 'lib/parse/model/classes/session.rb', line 45

property :installation_id

#restrictedBoolean (readonly)

Returns whether this session token is restricted.

Returns:

  • (Boolean)

    whether this session token is restricted.


49
# File 'lib/parse/model/classes/session.rb', line 49

property :restricted, :boolean

#session_tokenString (readonly)

Returns the session token for this installation and user pair.

Returns:

  • (String)

    the session token for this installation and user pair.


53
# File 'lib/parse/model/classes/session.rb', line 53

property :session_token

#userUser (readonly)

This property is mapped as a `belongs_to` association with the User class. Every session instance is tied to a specific logged in user.

Returns:

  • (User)

    the user corresponding to this session.

See Also:


59
# File 'lib/parse/model/classes/session.rb', line 59

belongs_to :user

Class Method Details

.session(token, **opts) ⇒ Session

Return the Session record for this session token.

Parameters:

  • token (String)

    the session token

Returns:

  • (Session)

    the session for this token, otherwise nil.


71
72
73
74
75
76
77
# File 'lib/parse/model/classes/session.rb', line 71

def self.session(token, **opts)
  response = client.fetch_session(token, opts)
  if response.success?
    return Parse::Session.build response.result
  end
  nil
end