Class: Sensit::Api::Report

Inherits:
Object
  • Object
show all
Defined in:
lib/sensit/api/report.rb

Overview

Reports are stored filter and facet queries on the Feed data. A report is a assigned a ‘name` and the `query` is any elasticsearch query which filters only the desired data for the facets (See the [elasticsearch Query DSL](www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-queries.html) for valid queries). A report can have many `facets` with each facet is referred to by a user defined `name`. Valid `type`’s of facet include terms, range, histogram, filter, statistical, query, terms_stats, or geo_distance. The ‘query` within a facet defines the field counts or statistics which the data is calculated over. See the [elasticsearch facet dsl](www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-facets.html) for information about the various facet types and valid query fields.

topic_id - The key for the parent topic id - The identifier of the report

Instance Method Summary collapse

Constructor Details

#initialize(topic_id, id, client) ⇒ Report

Returns a new instance of Report.



11
12
13
14
15
# File 'lib/sensit/api/report.rb', line 11

def initialize(topic_id, id, client)
  @topic_id = topic_id
  @id = id
  @client = client
end

Instance Method Details

#create(report, options = {}) ⇒ Object

Create a new report on the associated Topic which can be easily retrieved later using an id. Requires authorization of manage_any_reports, or manage_application_reports. ‘/topics/:topic_id/reports’ POST

report - A Hash containing ‘name`: The name of the report (required).`query`:The search query acccording to the [elasticsearch Query DSL](www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-queries.html) to filter the data for the facets (Defaults to match all).`facets`:An array of facet hashes which each contain a `name` ad type of the facet along with its query hash (required).



43
44
45
46
47
48
49
50
# File 'lib/sensit/api/report.rb', line 43

def create(report, options = {})
  body = options.has_key?(:body) ? options[:body] : {}
  body[:report] = report

  response = @client.post "/topics/#{@topic_id}/reports", body, options

  return response
end

#delete(options = {}) ⇒ Object

Remove a saved report on the associated Topic by Id. Requires authorization of manage_any_reports, or manage_application_reports. ‘/topics/:topic_id/reports/:id’ DELETE



68
69
70
71
72
73
74
# File 'lib/sensit/api/report.rb', line 68

def delete(options = {})
  body = options.has_key?(:body) ? options[:body] : {}

  response = @client.delete "/topics/#{@topic_id}/reports/#{@id}", body, options

  return response
end

#find(options = {}) ⇒ Object

Retrieve a specific report on the associated topic by Id. Requires authorization of read_any_reports, or read_application_reports. ‘/topics/:topic_id/reports/:id’ GET



31
32
33
34
35
36
37
# File 'lib/sensit/api/report.rb', line 31

def find(options = {})
  body = options.has_key?(:query) ? options[:query] : {}

  response = @client.get "/topics/#{@topic_id}/reports/#{@id}", body, options

  return response
end

#list(options = {}) ⇒ Object

Get all reports for the associated Topic. Requires authorization of read_any_reports, or read_application_reports. ‘/topics/:topic_id/reports’ GET



20
21
22
23
24
25
26
# File 'lib/sensit/api/report.rb', line 20

def list(options = {})
  body = options.has_key?(:query) ? options[:query] : {}

  response = @client.get "/topics/#{@topic_id}/reports", body, options

  return response
end

#update(report, options = {}) ⇒ Object

Update the query, facets or name of the report. Requires authorization of manage_any_reports, or manage_application_reports. ‘/topics/:topic_id/reports/:id’ PUT

report - A Hash containing ‘name`: The name of the report (required).`query`:The search query acccording to the [elasticsearch Query DSL](www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-queries.html) to filter the data for the facets (Defaults to match all).`facets`:An array of facet hashes which each contain a `name` ad type of the facet along with its query hash (required).



56
57
58
59
60
61
62
63
# File 'lib/sensit/api/report.rb', line 56

def update(report, options = {})
  body = options.has_key?(:body) ? options[:body] : {}
  body[:report] = report

  response = @client.put "/topics/#{@topic_id}/reports/#{@id}", body, options

  return response
end