Class: Ecoportal::API::V1::PersonSchemas

Inherits:
Object
  • Object
show all
Extended by:
Common::BaseClass
Includes:
Enumerable
Defined in:
lib/ecoportal/api/v1/person_schemas.rb

Direct Known Subclasses

Internal::PersonSchemas

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Common::BaseClass

class_resolver, redef_without_warning, resolve_class

Constructor Details

#initialize(client) ⇒ Schemas

Returns an instance object ready to make schema api requests.

Parameters:

  • client (Common::Client)

    a Common::Client object that holds the configuration of the api connection.



15
16
17
# File 'lib/ecoportal/api/v1/person_schemas.rb', line 15

def initialize(client)
  @client = client
end

Instance Attribute Details

#clientCommon::Client (readonly)

a Common::Client object that holds the configuration of the api connection.

Returns:



5
6
7
# File 'lib/ecoportal/api/v1/person_schemas.rb', line 5

def client
  @client
end

Instance Method Details

#each(params: {}) {|schema| ... } ⇒ Enumerable<PersonSchema>

Note:
  • :params doesn't really do anything.
  • same as #get_all but with block :)
  • to_a will call each (see this detailed explanation)
    • however, as far as you have an iterator, such as each, to_a should be last resource (see this explanation)

If a block is not given it calls Object#to_enum Otherwise it calls get_all.

Yields:

  • (schema)

    does some stuff with the schema.

Yield Parameters:

Yield Returns:

Returns:

  • (Enumerable<PersonSchema>)

    an Enumerable with all the person schema objects.



37
38
39
40
# File 'lib/ecoportal/api/v1/person_schemas.rb', line 37

def each(params: {}, &block)
  return to_enum(:each) unless block
  get_all.each(&block)
end

#get_allEnumerable<PersonSchema>

Gets all the schemas via api request.

Returns:

  • (Enumerable<PersonSchema>)

    an Enumerable with all schemas already wrapped as PersonSchema objects.



21
22
23
24
# File 'lib/ecoportal/api/v1/person_schemas.rb', line 21

def get_all
  response = client.get("/person_schemas")
  Common::WrappedResponse.new(response, person_schema_class)
end