class Glassfrog::Person

Encapsulates GlassFrog People.

Constants

PARAMS
PATH
TYPE

Attributes

email[RW]

@return [String]

external_id[RW]

@return [Integer]

name[RW]

@return [String]

Public Class Methods

delete(client, options) click to toggle source

Sends a DELETE request to delete a Person on GlassFrog. @param client [Glassforg::Client] The client that will send the request. Contains the API key. @param options [Hash, Glassfrog::Base] The options containing the ID of the Person to delete.

@return [Boolean] Whether the request failed or not.

# File lib/glassfrog/person.rb, line 61
def self.delete(client, options)
  path = PATH + '/' + options.delete(:id).to_s
  response = Glassfrog::REST::Delete.delete(client, path, options)
end
get(client, options) click to toggle source

Sends a GET request for Person(s) to GlassFrog. @param client [Glassfrog::Client] The client that will send the request. Contains the API key. @param options [Hash, Glassfrog::Base] The options used to find the correct Persons(s).

@return [Array<Glassfrog::Person>] The array of Person(s) fetched from GlassFrog.

# File lib/glassfrog/person.rb, line 27
def self.get(client, options)
  response = Glassfrog::REST::Get.get(client, PATH, options)
  response[TYPE].map { |object| self.new(object) }
end
patch(client, identifier, options) click to toggle source

Sends a PATCH request to update a Person on GlassFrog. @param client [Glassforg::Client] The client that will send the request. Contains the API key. @param identifier [Integer] The ID of the Person to be updated. @param options [Hash, Glassfrog::Base] The options used to update the Person.

@return [Boolean] Whether the request failed or not.

# File lib/glassfrog/person.rb, line 50
def self.patch(client, identifier, options)
  options = Glassfrog::REST::Patch.formify(parse_options(options), self)
  response = Glassfrog::REST::Patch.patch(client, PATH + '/' + identifier.to_s, options)
end
post(client, options) click to toggle source

Sends a POST request to create a Person on GlassFrog. @param client [Glassforg::Client] The client that will send the request. Contains the API key. @param options [Hash, Glassforg::Base] The options used to create the new Persons.

@return [Array<Glassfrog::Person>] The array containing the new Person.

# File lib/glassfrog/person.rb, line 38
def self.post(client, options)
  response = Glassfrog::REST::Post.post(client, PATH, { TYPE => [parse_options(options)] })
  response[TYPE].map { |object| self.new(object) }
end

Private Class Methods

parse_options(options) click to toggle source

Grabs only the parameters accepted by GlassFrog. @param options [Hash] Inputed options.

@return [Hash] Valid GlassFrog options.

# File lib/glassfrog/person.rb, line 78
def self.parse_options(options)
  params_hash = Hash.new
  PARAMS.each { |param| params_hash[param] = options[param] if options[param] }
  params_hash
end