Module: NexosisApi::Client::Views
- Included in:
- NexosisApi::Client
- Defined in:
- lib/nexosis_api/client/views.rb
Overview
Views-based API operations
Instance Method Summary collapse
-
#create_view(view_name, dataset_name, right_datasource_name) ⇒ NexosisApi::ViewDefinition
Create a new view or update an existing one by name.
-
#create_view_by_def(view_definition) ⇒ NexosisApi::ViewDefinition
Create or update a view based on a view definition object.
-
#get_view(view_name, page_number = 0, page_size = 50, query_options = {}) ⇒ Object
Get the processed data from the view definition.
-
#list_views(partial_name = '', dataset_name = '', page = 0, page_size = 50) ⇒ NexosisApi::PagedArray of NexosisApi::ViewDefinition
List all existing view defintions, optionally limited by partial name or participating data sources.
-
#remove_view(view_name, cascade = nil) ⇒ void
Deletes the named view and optionally all sessions created from it.
Instance Method Details
permalink #create_view(view_name, dataset_name, right_datasource_name) ⇒ NexosisApi::ViewDefinition
@view_name Must be unique within your organization
Create a new view or update an existing one by name
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/nexosis_api/client/views.rb', line 37 def create_view(view_name, dataset_name, right_datasource_name) raise ArgumentError, 'view_name was not provided and is not optional' unless view_name.to_s.empty? == false raise ArgumentError, 'dataset_name was not provided and is not optional' unless dataset_name.to_s.empty? == false raise ArgumentError, 'right_datasource_name was not provided and is not optional' unless right_datasource_name.to_s.empty? == false view_definition = NexosisApi::ViewDefinition.new('viewName' => view_name) view_definition.dataset_name = dataset_name join = NexosisApi::Join.new('dataSet' => { 'name' => right_datasource_name }) view_definition.joins = [join] create_view_by_def(view_definition) end |
permalink #create_view_by_def(view_definition) ⇒ NexosisApi::ViewDefinition
Create or update a view based on a view definition object
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/nexosis_api/client/views.rb', line 52 def create_view_by_def(view_definition) view_name = view_definition.view_name raise ArgumentError, 'view_name was not provided and is not optional' unless view_name.to_s.empty? == false url = "/views/#{view_name}" response = self.class.put(url, headers: @headers, body: view_definition.to_json) if response.success? return NexosisApi::ViewDefinition.new(response.parsed_response) else raise NexosisApi::HttpException.new('Could not create the requested view', "Attempting to create view named #{view_name}", response) end end |
permalink #get_view(view_name, page_number = 0, page_size = 50, query_options = {}) ⇒ Object
Query Options includes start_date as a DateTime or ISO 8601 compliant string, end_date, also as a DateTime or string, and :include as an Array of strings indicating the columns to return. The dates can be used independently and are inclusive. Lack of options returns all values within the given page.
-
the results include any transformations or imputations required to prepare the data for a session
Get the processed data from the view definition
94 95 96 97 98 99 100 101 102 |
# File 'lib/nexosis_api/client/views.rb', line 94 def get_view(view_name, page_number = 0, page_size = 50, = {}) raise ArgumentError, 'view_name was not provided and is not optional' unless view_name.to_s.empty? == false url = "/views/#{view_name}" response = self.class.get(url, headers: @headers, query: create_query(page_number, page_size, ), query_string_normalizer: ->(query_map) { array_query_normalizer(query_map) } ) raise NexosisApi::HttpException.new('Could not retrieve data for the given view', "Requesting data for view #{view_name}", response) unless response.success? NexosisApi::ViewData.new(response.parsed_response) end |
permalink #list_views(partial_name = '', dataset_name = '', page = 0, page_size = 50) ⇒ NexosisApi::PagedArray of NexosisApi::ViewDefinition
List all existing view defintions, optionally limited by partial name or participating data sources
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/nexosis_api/client/views.rb', line 16 def list_views(partial_name = '', dataset_name = '', page = 0, page_size = 50) url = '/views' query = { 'page': page, 'pageSize': page_size } query.store 'partialName', partial_name if partial_name.empty? == false query.store 'dataSetName', dataset_name if dataset_name.empty? == false response = self.class.get(url, headers: @headers, query: query) raise NexosisApi::HttpException('Could not retrieve list of views.', 'attempting list of views', response) unless response.success? NexosisApi::PagedArray.new(response.parsed_response, response.parsed_response['items'] .map { |definition| NexosisApi::ViewDefinition.new(definition) }) end |
permalink #remove_view(view_name, cascade = nil) ⇒ void
This method returns an undefined value.
Deletes the named view and optionally all sessions created from it
71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/nexosis_api/client/views.rb', line 71 def remove_view(view_name, cascade = nil) raise ArgumentError, 'view_name was not provided and is not optional' unless view_name.to_s.empty? == false url = "/views/#{view_name}" query = 'cascade=sessions' unless cascade.nil? response = self.class.delete(url, headers: @headers, query: query) unless response.success? raise NexosisApi::HttpException.new('Could not delete view', "Attempting to delete view #{view_name}", response) end end |