Class: Ecoportal::API::V1::People
- Inherits:
-
Object
- Object
- Ecoportal::API::V1::People
- Includes:
- Common::DocHelpers, Enumerable
- Defined in:
- lib/ecoportal/api/v1/people.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #batch {|operation| ... } ⇒ Object
- #create(doc) ⇒ Object
- #delete(doc) ⇒ Object
- #each(params: {}, &block) ⇒ Object
- #get(doc) ⇒ Object
- #get_all(params: {}) ⇒ Object
-
#initialize(client) ⇒ People
constructor
A new instance of People.
- #new ⇒ Object
- #update(doc) ⇒ Object
- #upsert(doc) ⇒ Object
Methods included from Common::DocHelpers
Constructor Details
#initialize(client) ⇒ People
Returns a new instance of People.
10 11 12 |
# File 'lib/ecoportal/api/v1/people.rb', line 10 def initialize(client) @client = client end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
8 9 10 |
# File 'lib/ecoportal/api/v1/people.rb', line 8 def client @client end |
Instance Method Details
#batch {|operation| ... } ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/ecoportal/api/v1/people.rb', line 55 def batch operation = Common::BatchOperation.new("/people", person_class) yield operation @client.post("/people/batch", data: operation.as_json).tap do |response| operation.process_response(response) end end |
#create(doc) ⇒ Object
44 45 46 47 |
# File 'lib/ecoportal/api/v1/people.rb', line 44 def create(doc) body = get_body(doc) @client.post("/people", data: body) end |
#delete(doc) ⇒ Object
63 64 65 66 |
# File 'lib/ecoportal/api/v1/people.rb', line 63 def delete(doc) id = get_id(doc) @client.delete("/people/"+CGI::escape(id)) end |
#each(params: {}, &block) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ecoportal/api/v1/people.rb', line 14 def each(params: {}, &block) return to_enum(:each) unless block page = 1 loop do response = @client.get("/people", params: params.merge(page: page)) raise "Request failed." unless response.success? response.body["results"].each do |person| yield person_class.new(person) end break if page >= response.body["total_pages"] page += 1 end self end |
#get(doc) ⇒ Object
29 30 31 32 |
# File 'lib/ecoportal/api/v1/people.rb', line 29 def get(doc) response = @client.get("/people/"+CGI::escape(get_id(doc))) Common::WrappedResponse.new(response, person_class) end |
#get_all(params: {}) ⇒ Object
34 35 36 |
# File 'lib/ecoportal/api/v1/people.rb', line 34 def get_all(params: {}) each(params: params).to_a end |
#new ⇒ Object
68 69 70 |
# File 'lib/ecoportal/api/v1/people.rb', line 68 def new person_class.new end |
#update(doc) ⇒ Object
38 39 40 41 42 |
# File 'lib/ecoportal/api/v1/people.rb', line 38 def update(doc) body = get_body(doc) id = get_id(doc) @client.patch("/people/"+CGI::escape(id), data: body) end |
#upsert(doc) ⇒ Object
49 50 51 52 53 |
# File 'lib/ecoportal/api/v1/people.rb', line 49 def upsert(doc) body = get_body(doc) id = get_id(doc) @client.post("/people/"+CGI::escape(id), data: body) end |