Class: FaithTeams::API::V2::Resource::Person
- Inherits:
-
Base
- Object
- GatewayBase
- Base
- FaithTeams::API::V2::Resource::Person
- Defined in:
- lib/faithteams/api/v2/resource/person.rb
Overview
Person resource
Instance Method Summary collapse
- #create(entity:) ⇒ Entity::Person
- #find(id:) ⇒ Entity::Person?
-
#search(**args) ⇒ Array<Entity::Person>
By default, it only looks for active people.
Methods inherited from Base
Methods inherited from GatewayBase
#initialize, #valid_connection?
Constructor Details
This class inherits a constructor from FaithTeams::API::V2::GatewayBase
Instance Method Details
#create(entity:) ⇒ Entity::Person
40 41 42 43 |
# File 'lib/faithteams/api/v2/resource/person.rb', line 40 def create(entity:) data = connection.post(path: "/people", body: entity.to_h)["data"] Entity::Person.new(attributes: data) end |
#find(id:) ⇒ Entity::Person?
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/faithteams/api/v2/resource/person.rb', line 25 def find(id:) raise FaithTeams::API::V2::Error::NoSearchParameterProvided if id.nil? data = connection.get(path: "/people/#{id}")["data"] return nil unless data Entity::Person.new(attributes: data) rescue Error::Request => e return nil if e.not_found? raise end |
#search(**args) ⇒ Array<Entity::Person>
By default, it only looks for active people. To search for inactive people, pass in status: "I".
13 14 15 16 17 18 19 20 |
# File 'lib/faithteams/api/v2/resource/person.rb', line 13 def search(**args) params = { status: "A" }.merge(args) data = connection.get(path: "/people", params: params.stringify_keys)["data"] return [] unless data.present? data.map { |r| Entity::Person.new(attributes: r) } end |