Class: Backlex::Collection
- Inherits:
-
Object
- Object
- Backlex::Collection
- Defined in:
- lib/backlex/collection.rb
Overview
A CRUD handle for one collection. Obtain via client.from(“slug”).
Instance Method Summary collapse
-
#aggregate(body) ⇒ Object
Single-function aggregate (count/sum/avg/min/max), optionally grouped.
- #create(data) ⇒ Object
- #delete(id) ⇒ Object
-
#initialize(client, slug) ⇒ Collection
constructor
A new instance of Collection.
- #list(query = nil) ⇒ Object
-
#one(id, query = nil) ⇒ Object
query may carry expand/locale, the same params the list endpoint accepts.
-
#publish(id) ⇒ Object
Flip a versioned item to published.
-
#query ⇒ Object
Fluent builder that compiles to a ListQuery.
-
#unpublish(id) ⇒ Object
Flip a versioned item back to draft.
- #update(id, patch) ⇒ Object
Constructor Details
#initialize(client, slug) ⇒ Collection
Returns a new instance of Collection.
6 7 8 9 |
# File 'lib/backlex/collection.rb', line 6 def initialize(client, slug) @client = client @slug = slug end |
Instance Method Details
#aggregate(body) ⇒ Object
Single-function aggregate (count/sum/avg/min/max), optionally grouped. body = { “agg” => “sum”, “field” => “price”, “groupBy” => “status” }
22 23 24 |
# File 'lib/backlex/collection.rb', line 22 def aggregate(body) @client.request("POST", "/api/items/#{@slug}/aggregate", body) end |
#create(data) ⇒ Object
31 32 33 |
# File 'lib/backlex/collection.rb', line 31 def create(data) @client.request("POST", "/api/items/#{@slug}", data) end |
#delete(id) ⇒ Object
39 40 41 |
# File 'lib/backlex/collection.rb', line 39 def delete(id) @client.request("DELETE", "/api/items/#{@slug}/#{id}") end |
#list(query = nil) ⇒ Object
11 12 13 |
# File 'lib/backlex/collection.rb', line 11 def list(query = nil) @client.request("GET", "/api/items/#{@slug}#{Client.build_search(query)}") end |
#one(id, query = nil) ⇒ Object
query may carry expand/locale, the same params the list endpoint accepts.
27 28 29 |
# File 'lib/backlex/collection.rb', line 27 def one(id, query = nil) @client.request("GET", "/api/items/#{@slug}/#{id}#{Client.build_search(query)}") end |
#publish(id) ⇒ Object
Flip a versioned item to published.
44 45 46 |
# File 'lib/backlex/collection.rb', line 44 def publish(id) @client.request("POST", "/api/items/#{@slug}/#{id}/publish") end |
#query ⇒ Object
Fluent builder that compiles to a ListQuery.
16 17 18 |
# File 'lib/backlex/collection.rb', line 16 def query QueryBuilder.new(method(:list)) end |
#unpublish(id) ⇒ Object
Flip a versioned item back to draft.
49 50 51 |
# File 'lib/backlex/collection.rb', line 49 def unpublish(id) @client.request("POST", "/api/items/#{@slug}/#{id}/publish?unpublish=1") end |
#update(id, patch) ⇒ Object
35 36 37 |
# File 'lib/backlex/collection.rb', line 35 def update(id, patch) @client.request("PATCH", "/api/items/#{@slug}/#{id}", patch) end |