Class: Cursor

Inherits:
Object
  • Object
show all
Includes:
Enumerable, OneLogin::Api::Util
Defined in:
lib/onelogin/api/cursor.rb

Overview

Cursor

Used for paginating requests to the OneLogin API

Returns an enumerable object

Constant Summary

Constants included from OneLogin::Api::Util::Constants

OneLogin::Api::Util::Constants::ACTIVATE_FACTOR_URL, OneLogin::Api::Util::Constants::ADD_ROLE_TO_USER_URL, OneLogin::Api::Util::Constants::ASSIGN_ROLES_TO_PRIVILEGE_URL, OneLogin::Api::Util::Constants::ASSIGN_USERS_TO_PRIVILEGE_URL, OneLogin::Api::Util::Constants::CREATE_APP_URL, OneLogin::Api::Util::Constants::CREATE_EVENT_URL, OneLogin::Api::Util::Constants::CREATE_GROUP_URL, OneLogin::Api::Util::Constants::CREATE_PRIVILEGE_URL, OneLogin::Api::Util::Constants::CREATE_ROLE_URL, OneLogin::Api::Util::Constants::CREATE_USER_URL, OneLogin::Api::Util::Constants::DELETE_APP_PARAMETER_URL, OneLogin::Api::Util::Constants::DELETE_APP_URL, OneLogin::Api::Util::Constants::DELETE_PRIVILEGE_URL, OneLogin::Api::Util::Constants::DELETE_ROLE_TO_USER_URL, OneLogin::Api::Util::Constants::DELETE_USER_URL, OneLogin::Api::Util::Constants::EMBED_APP_URL, OneLogin::Api::Util::Constants::ENROLL_FACTOR_URL, OneLogin::Api::Util::Constants::GENERATE_INVITE_LINK_URL, OneLogin::Api::Util::Constants::GENERATE_MFA_TOKEN_URL, OneLogin::Api::Util::Constants::GET_APPS_FOR_USER_URL, OneLogin::Api::Util::Constants::GET_APPS_URL, OneLogin::Api::Util::Constants::GET_APPS_URL_V1, OneLogin::Api::Util::Constants::GET_APP_URL, OneLogin::Api::Util::Constants::GET_CONNECTORS_URL, OneLogin::Api::Util::Constants::GET_CUSTOM_ATTRIBUTES_URL, OneLogin::Api::Util::Constants::GET_ENROLLED_FACTORS_URL, OneLogin::Api::Util::Constants::GET_EVENTS_URL, OneLogin::Api::Util::Constants::GET_EVENT_TYPES_URL, OneLogin::Api::Util::Constants::GET_EVENT_URL, OneLogin::Api::Util::Constants::GET_FACTORS_URL, OneLogin::Api::Util::Constants::GET_GROUPS_URL, OneLogin::Api::Util::Constants::GET_GROUP_URL, OneLogin::Api::Util::Constants::GET_PRIVILEGE_URL, OneLogin::Api::Util::Constants::GET_RATE_URL, OneLogin::Api::Util::Constants::GET_ROLES_ASSIGNED_TO_PRIVILEGE_URL, OneLogin::Api::Util::Constants::GET_ROLES_FOR_USER_URL, OneLogin::Api::Util::Constants::GET_ROLES_URL, OneLogin::Api::Util::Constants::GET_ROLE_URL, OneLogin::Api::Util::Constants::GET_SAML_ASSERTION_URL, OneLogin::Api::Util::Constants::GET_SAML_VERIFY_FACTOR, OneLogin::Api::Util::Constants::GET_TOKEN_VERIFY_FACTOR, OneLogin::Api::Util::Constants::GET_USERS_ASSIGNED_TO_PRIVILEGE_URL, OneLogin::Api::Util::Constants::GET_USERS_URL, OneLogin::Api::Util::Constants::GET_USER_URL, OneLogin::Api::Util::Constants::LIST_PRIVILEGES_URL, OneLogin::Api::Util::Constants::LOCK_USER_URL, OneLogin::Api::Util::Constants::LOG_USER_OUT_URL, OneLogin::Api::Util::Constants::REMOVE_FACTOR_URL, OneLogin::Api::Util::Constants::REMOVE_ROLE_FROM_PRIVILEGE_URL, OneLogin::Api::Util::Constants::REMOVE_USER_FROM_PRIVILEGE_URL, OneLogin::Api::Util::Constants::SEND_INVITE_LINK_URL, OneLogin::Api::Util::Constants::SESSION_LOGIN_TOKEN_URL, OneLogin::Api::Util::Constants::SET_CUSTOM_ATTRIBUTE_TO_USER_URL, OneLogin::Api::Util::Constants::SET_PW_CLEARTEXT, OneLogin::Api::Util::Constants::SET_PW_SALT, OneLogin::Api::Util::Constants::SET_USER_STATE_URL, OneLogin::Api::Util::Constants::TOKEN_REFRESH_URL, OneLogin::Api::Util::Constants::TOKEN_REQUEST_URL, OneLogin::Api::Util::Constants::TOKEN_REVOKE_URL, OneLogin::Api::Util::Constants::UPDATE_APP_URL, OneLogin::Api::Util::Constants::UPDATE_PRIVILEGE_URL, OneLogin::Api::Util::Constants::UPDATE_USER_URL, OneLogin::Api::Util::Constants::VALID_ACTIONS, OneLogin::Api::Util::Constants::VERIFY_FACTOR_URL

Instance Method Summary collapse

Methods included from OneLogin::Api::Util::Parser

#extract_error_attribute_from_response, #extract_error_message_from_response, #extract_status_code_from_response

Methods included from OneLogin::Api::Util::UrlBuilder

#url_for

Constructor Details

#initialize(client, url, options = {}) ⇒ Cursor

Create a new instance of the Cursor.

Parameters:

  • url (String)

    The url of the API endpoint

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

    Configuation options


18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/onelogin/api/cursor.rb', line 18

def initialize(client, url, options = {})
  @client = client
  @url = url
  @options = options

  @model = options[:model]
  @headers = options[:headers] || {}
  @params = options[:params] || {}
  @max_results = options[:max_results]
  @container = options[:container] || 'data'

  @collection = []
  @after_cursor = options.fetch(:after_cursor, nil)
end

Instance Method Details

#each(start = 0, &proc) ⇒ Object


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/onelogin/api/cursor.rb', line 33

def each(start = 0, &proc)
  return to_enum(:each, start) unless block_given?

  Array(@collection[start..-1]).each do |item|
    if @model
      yield(@model.new(item))
    else
      yield(item)
    end
  end

  unless last?
    start = [@collection.size, start].max

    fetch_next_page

    each(start, &proc)
  end
end