Class: Osm::Myscout::ParentLoginHistory

Inherits:
Osm::Model
  • Object
show all
Defined in:
lib/osm/myscout.rb

Constant Summary collapse

SORT_BY =
[:last_name, :first_name, :member_id]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Osm::Model

#<, #<=, #<=>, #>, #>=, #between?, #changed_attributes, configure, #reset_changed_attributes, #to_i

Constructor Details

#initializeObject

Initialize a new Member

Parameters:

  • attributes (Hash)

    The hash of attributes (see attributes for descriptions, use Symbol of attribute name as the key)



# File 'lib/osm/myscout.rb', line 35

Instance Attribute Details

#first_nameString

Returns the member’s first name.

Returns:

  • (String)

    the member’s first name



19
# File 'lib/osm/myscout.rb', line 19

attribute :member_id, type: Integer

#last_loginDateTime

Returns the time and date of the last login.

Returns:

  • (DateTime)

    the time and date of the last login



19
# File 'lib/osm/myscout.rb', line 19

attribute :member_id, type: Integer

#last_nameString

Returns the member’s last name.

Returns:

  • (String)

    the member’s last name



19
# File 'lib/osm/myscout.rb', line 19

attribute :member_id, type: Integer

#loginsFixnum

Returns the total number of logins.

Returns:

  • (Fixnum)

    the total number of logins



19
# File 'lib/osm/myscout.rb', line 19

attribute :member_id, type: Integer

#member_idFixnum

Returns the id for the member.

Returns:

  • (Fixnum)

    the id for the member



19
# File 'lib/osm/myscout.rb', line 19

attribute :member_id, type: Integer

Class Method Details

.get_for_section(api, section, options = {}) ⇒ Array<Osm::Myscout::ParentLoginHistory>

Get parent login history

Parameters:

  • api (Osm::Api)

    The api to use to make the request

  • section (Osm::Section, Fixnum, #to_i)

    The section (or its ID) to get login history for

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :no_cache (Boolean) — default: optional

    if true then the data will be retreived from OSM not the cache

Returns:



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/osm/myscout.rb', line 45

def self.get_for_section(api, section, options={})
  section_id = section.to_i
  require_ability_to(api, :read, :member, section, options)
  cache_key = ['myscout', 'parent_login_history', section_id]

  if !options[:no_cache] && cache_exist?(api, cache_key)
    return cache_read(api, cache_key)
  end

  data = api.perform_query("ext/settings/parents/loginhistory/?action=getLoginHistory&sectionid=#{section_id}")
  return [] unless data.is_a?(Hash)
  data = data['items']
  return [] unless data.is_a?(Array)

  data.map! do |item|
    new(
      member_id:    Osm::to_i_or_nil(item['scoutid']),
      first_name:   item['firstname'],
      last_name:    item['lastname'],
      logins:       Osm::to_i_or_nil(item['numlogins']),
      last_login:   (item['lastlogin'],)
    )
  end

  cache_write(api, cache_key, data)
  return data
end