module DisiidUser::ClassMethods

Class Methods

Public Instance Methods

build_from_identity(url)
build_from_identity_url(url) click to toggle source

Creates a new user object with the identity attribute assigned and returns a not presisted record. You’ll need to call .save or .save! on the returned result if you want to persist it in a local database.

Note: your local :users table should :identity_url string attribute for this to work.

# File lib/disiid_user.rb, line 58
def build_from_identity_url(url)
  user = new
  user.identity_url = url
  user
end
Also aliased as: build_from_identity
find_local_or_remote_by_uuid!(id) click to toggle source

Looks for a local user record with a given UUID by matching its local attribute :identity_url. Creates a new user if it doesn’t exist locally but is present remotely using build_from_identity method. This method will throw ActiveRecord::RecordNotFound exception if persistance process didn’t go well.

# File lib/disiid_user.rb, line 69
def find_local_or_remote_by_uuid!(id)
  user = where('identity_url LIKE ?', "%#{id}").first
  if !user && DisiidUser::RemoteUser.exists?(id, params: {auth_token: DisiidUser::RemoteUser.auth_token})
    # DisiidUser::RemoteUser.site is a URI::HTTP object, not a string
    user_url = DisiidUser::RemoteUser.site.merge("#{DisiidUser::RemoteUser.collection_name}/#{id}").to_s
    user = build_from_identity(user_url)
    user.save!
  end
  user
rescue
  raise ::ActiveRecord::RecordNotFound
end
remote_count(args = {}) click to toggle source

Same as search but returns just an integer, a number of how many search result items the search method would return (give the same arguments)

User.remote_count(:q => "dude")                    # => 1
User.remote_count(:position => 'technical_staff')  # => 13
# File lib/disiid_user.rb, line 47
def remote_count(args = {})
  args.merge! :auth_token => DisiidUser::RemoteUser.auth_token
  DisiidUser::RemoteUser.get :count, args
end