nexosis_api 2.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/lib/nexosis_api/algorithm.rb +22 -22
  3. data/lib/nexosis_api/algorithm_contestant.rb +43 -43
  4. data/lib/nexosis_api/calendar_jointarget.rb +35 -35
  5. data/lib/nexosis_api/classifier_result.rb +25 -25
  6. data/lib/nexosis_api/client/contest.rb +66 -66
  7. data/lib/nexosis_api/client/datasets.rb +155 -155
  8. data/lib/nexosis_api/client/imports.rb +141 -141
  9. data/lib/nexosis_api/client/models.rb +108 -108
  10. data/lib/nexosis_api/client/sessions.rb +213 -213
  11. data/lib/nexosis_api/client/views.rb +105 -105
  12. data/lib/nexosis_api/client.rb +118 -118
  13. data/lib/nexosis_api/column.rb +50 -50
  14. data/lib/nexosis_api/column_options.rb +38 -38
  15. data/lib/nexosis_api/column_role.rb +19 -19
  16. data/lib/nexosis_api/column_type.rb +23 -19
  17. data/lib/nexosis_api/dataset_data.rb +22 -22
  18. data/lib/nexosis_api/dataset_jointarget.rb +18 -18
  19. data/lib/nexosis_api/dataset_model.rb +26 -26
  20. data/lib/nexosis_api/dataset_summary.rb +33 -33
  21. data/lib/nexosis_api/http_exception.rb +28 -28
  22. data/lib/nexosis_api/impact_metric.rb +22 -22
  23. data/lib/nexosis_api/imports_response.rb +74 -79
  24. data/lib/nexosis_api/join.rb +63 -63
  25. data/lib/nexosis_api/link.rb +18 -18
  26. data/lib/nexosis_api/message.rb +19 -19
  27. data/lib/nexosis_api/metric.rb +16 -16
  28. data/lib/nexosis_api/model_summary.rb +66 -66
  29. data/lib/nexosis_api/paged_array.rb +35 -35
  30. data/lib/nexosis_api/predict_response.rb +35 -35
  31. data/lib/nexosis_api/session.rb +118 -118
  32. data/lib/nexosis_api/session_contest.rb +30 -30
  33. data/lib/nexosis_api/session_response.rb +33 -33
  34. data/lib/nexosis_api/session_result.rb +27 -27
  35. data/lib/nexosis_api/session_selection_metrics.rb +20 -20
  36. data/lib/nexosis_api/time_interval.rb +15 -15
  37. data/lib/nexosis_api/view_data.rb +14 -14
  38. data/lib/nexosis_api/view_definition.rb +64 -64
  39. data/lib/nexosis_api.rb +11 -11
  40. data/nexosisapi.gemspec +20 -20
  41. metadata +3 -3
@@ -1,213 +1,213 @@
1
- require 'csv'
2
- require 'json'
3
-
4
- module NexosisApi
5
- class Client
6
- # Session-based API operations
7
- #
8
- # @see http://docs.nexosis.com/
9
- module Sessions
10
-
11
- # List sessions previously submitted
12
- #
13
- # @param query_options [Hash] optionally provide query parameters to limit the search of sessions.
14
- # @param page [Integer] optionally provide a page number for paging. Defaults to 0 (first page).
15
- # @param pageSize [Integer] optionally provide a page size to limit the total number of results. Defaults to 50, max 1000
16
- # @return [NexosisApi::PagedArray of NexosisApi::SessionResponse] with all sessions matching the query or all if no query
17
- # @note query parameters hash members are dataset_name, event_name, requested_before_date, and requested_after_date.
18
- # After and before dates refer to the session requested date.
19
- # @example query for just one dataset
20
- # sessions = NexosisApi.client.list_sessions :dataset_name => 'MyDataset'
21
- def list_sessions(query_options = {}, page = 0, pageSize = 50)
22
- sessions_url = '/sessions'
23
- query = {
24
- 'dataSetName' => query_options[:dataset_name],
25
- 'eventName' => query_options[:event_name],
26
- 'requestedAfterDate' => query_options[:requested_after_date],
27
- 'requestedBeforeDate' => query_options[:requested_before_date],
28
- 'type' => query_options[:type],
29
- 'page' => page,
30
- 'pageSize' => pageSize
31
- }
32
- response = self.class.get(sessions_url, headers: @headers, query: query)
33
- raise HttpException.new('Could not retrieve sessions',
34
- "Get all sessions with query #{query_options}",
35
- response) unless response.success?
36
- NexosisApi::PagedArray.new(response.parsed_response, response.parsed_response['items'].map do |session_hash|
37
- response_hash = { 'session' => session_hash }.merge(response.headers)
38
- NexosisApi::SessionResponse.new(response_hash)
39
- end)
40
- end
41
-
42
- # Remove a session
43
- # @param session_id [String] required session identifier
44
- def remove_session(session_id)
45
- if (session_id.to_s.empty?)
46
- raise ArgumentError 'session_id cannot be empty or nil'
47
- end
48
- session_url = "/sessions/#{session_id}"
49
- response = self.class.delete(session_url, headers: @headers)
50
- return if response.success?
51
- raise HttpException.new('Could not delete session with given id', "remove session with id #{session_id}", response)
52
- end
53
-
54
- # Remove sessions that have been run. All query options are optional and will be used to limit the sessions removed.
55
- # @param query_options [Hash] optionally provide query parametes to limit the set of sessions removed.
56
- # @note query parameters hash members are type, dataset_name, event_name, start_date, and end_date.
57
- # Start and end dates refer to the session requested date.
58
- # Results are not removed but then can only be accessed by dataset name
59
- # @example Remove all sessions based on a dataset by name
60
- # NexosisApi.client.remove_sessions :dataset_name => 'existing_dataset'
61
- def remove_sessions(query_options = {})
62
- sessions_url = '/sessions'
63
- response = self.class.delete(sessions_url, :headers => @headers, :query => get_query_from_options(query_options))
64
- return if response.success?
65
- raise HttpException.new('Could not remove sessions', "Remove sessions with query #{query_options.to_s}",response)
66
- end
67
-
68
- # Initiate a new forecast session based on a named dataset.
69
- #
70
- # @param dataset_name [String] The name of the saved data set that has the data to forecast on.
71
- # @param start_date [DateTime] The starting date of the forecast period. Can be ISO 8601 string.
72
- # @param end_date [DateTime] The ending date of the forecast period. Can be ISO 8601 string.
73
- # @param target_column [String] The name of the column for which you want predictions. Nil if defined in dataset.
74
- # @param result_interval [NexosisApi::TimeInterval] (optional) - The date/time interval (e.g. Day, Hour) at which predictions should be generated. So, if Hour is specified for this parameter you will get a Result record for each hour between startDate and endDate. If unspecified, we’ll generate predictions at a Day interval.
75
- # @param column_metadata [Array of NexosisApi::Column] (optional) - specification for how to handle columns if different from existing metadata on dataset
76
- # @return [NexosisApi::SessionResponse] providing information about the sesssion
77
- # @note The time interval selected must be greater than or equal to the finest granularity of the data provided.
78
- # For instance if your data includes many recoreds per hour, then you could request hour, day, or any other result interval.
79
- # However, if your data includes only a few records per day or fewer, then a request for an hourly result interval will produce poor results.
80
- def create_forecast_session(dataset_name, start_date, end_date, target_column = nil, result_interval = NexosisApi::TimeInterval::DAY, column_metadata = nil)
81
- create_session(dataset_name, start_date, end_date, target_column, nil, 'forecast', result_interval, column_metadata)
82
- end
83
-
84
- # Analyze impact for an event with data already saved to the API.
85
- #
86
- # @param dataset_name [String] The name of the saved data set that has the data to forecast on.
87
- # @param start_date [DateTime] The starting date of the impactful event. Can be ISO 8601 string.
88
- # @param end_date [DateTime] The ending date of the impactful event. Can be ISO 8601 string.
89
- # @param event_name [String] The name of the event.
90
- # @param target_column [String] The name of the column for which you want predictions. Nil if defined in datatset.
91
- # @param result_interval [NexosisApi::TimeInterval] (optional) - The date/time interval (e.g. Day, Hour) at which predictions should be generated. So, if Hour is specified for this parameter you will get a Result record for each hour between startDate and endDate. If unspecified, we’ll generate predictions at a Day interval.
92
- # @param column_metadata [Array of NexosisApi::Column] (optional) - specification for how to handle columns if different from existing metadata on dataset
93
- # @return [NexosisApi::SessionResponse] providing information about the sesssion
94
- def create_impact_session(dataset_name, start_date, end_date, event_name, target_column = nil, result_interval = NexosisApi::TimeInterval::DAY, column_metadata = nil)
95
- create_session(dataset_name, start_date, end_date, target_column, event_name, 'impact', result_interval, column_metadata)
96
- end
97
-
98
- # Get the results of the session.
99
- #
100
- # @param session_id [String] the Guid string returned in a previous session request
101
- # @param as_csv [Boolean] indicate whether results should be returned in csv format
102
- # @param prediction_interval [Float] one of the available prediction intervals for the session.
103
- # @return [NexosisApi::SessionResult] SessionResult if parsed, String of csv data otherwise
104
- def get_session_results(session_id, as_csv = false, prediction_interval = nil)
105
- session_result_url = "/sessions/#{session_id}/results"
106
- @headers['Accept'] = 'text/csv' if as_csv
107
- query = { predictionInterval: prediction_interval } unless prediction_interval.nil?
108
- response = self.class.get(session_result_url, headers: @headers, query: query)
109
- @headers.delete('Accept')
110
-
111
- if (response.success?)
112
- return response.body if as_csv
113
- NexosisApi::SessionResult.new(response.parsed_response)
114
- else
115
- raise HttpException.new("There was a problem getting the session: #{response.code}.", "get results for session #{session_id}" ,response)
116
- end
117
- end
118
-
119
- # Get a specific session by id.
120
- #
121
- # @param session_id [String] the Guid string returned in a previous session request
122
- # @return [NexosisApi::Session] a Session object populated with the session's data
123
- def get_session(session_id)
124
- session_url = "/sessions/#{session_id}"
125
- response = self.class.get(session_url, @options)
126
- return NexosisApi::Session.new(response.parsed_response) if response.success?
127
- raise HttpException.new("There was a problem getting the session: #{response.code}.", "getting session #{session_id}" ,response)
128
- end
129
-
130
- # Create a new model based on a data source
131
- #
132
- # @param datasource_name [String] The datasource from which to build the model
133
- # @param target_column [String] The column which will be predicted when using the model
134
- # @param columns [Hash] column metadata to modify roles, imputation, or target.
135
- # @param options [Hash] prediction_domain and or balance (true or false) indicator for classification
136
- # @note - classifcation assumes balanced classes. The use of a 'balanced=false' option
137
- # indicates that no attempt should be made to sample the classes in balanced fashion.
138
- # @since 1.3.0
139
- def create_model(datasource_name, target_column, columns = {}, options = { prediction_domain: 'regression' })
140
- model_url = '/sessions/model'
141
- body = {
142
- dataSourceName: datasource_name,
143
- targetColumn: target_column,
144
- predictionDomain: options[:prediction_domain].downcase
145
- }
146
- body.store(:extraParameters, { balance: options[:balance] }) if options.include?(:balance) && body[:predictionDomain] == 'classification'
147
- body.store(columns: columns) unless columns.empty?
148
- response = self.class.post(model_url, headers: @headers, body: body.to_json)
149
- if response.success?
150
- session_hash = { 'session' => response.parsed_response }.merge(response.headers)
151
- NexosisApi::SessionResponse.new(session_hash)
152
- else
153
- raise HttpException.new("There was a problem creating the model session: #{response.code}.", 'creating model session' ,response)
154
- end
155
- end
156
-
157
- # Get the confusion matrix for a completed classification session
158
- # @param session_id [String] The unique id of the completed classification session
159
- # @return [NexosisApi::ClassifierResult] a confusion matrix along with class labels and other session information.
160
- # @since 1.4.1
161
- # @note - This endpoint returns a 404 for requests of non-classification sessions
162
- def get_confusion_matrix(session_id)
163
- result_url = "/sessions/#{session_id}/results/confusionmatrix"
164
- response = self.class.get(result_url, headers: @headers)
165
- raise HttpException.new("There was a problem getting a confusion matrix for session #{session_id}", 'getting confusion matrix', response) unless response.success?
166
- NexosisApi::ClassifierResult.new(response.parsed_response)
167
- end
168
-
169
- private
170
-
171
- # @private
172
- def create_session(dataset_name, start_date, end_date, target_column = nil, event_name = nil, type = 'forecast', result_interval = NexosisApi::TimeInterval::DAY, column_metadata = nil)
173
- session_url = "/sessions/#{type}"
174
- query = {
175
- 'targetColumn' => target_column.to_s,
176
- 'startDate' => start_date.to_s,
177
- 'endDate' => end_date.to_s,
178
- 'resultInterval' => result_interval.to_s
179
- }
180
- query['dataSetName'] = dataset_name.to_s unless dataset_name.to_s.empty?
181
- if (event_name.nil? == false)
182
- query['eventName'] = event_name
183
- end
184
- body = ''
185
- if (column_metadata.nil? == false)
186
- column_json = Column.to_json(column_metadata)
187
- body = {
188
- 'dataSetName' => dataset_name,
189
- 'columns' => column_json
190
- }
191
- end
192
- response = self.class.post(session_url, headers: @headers, query: query, body: body.to_json)
193
- if (response.success?)
194
- session_hash = { 'session' => response.parsed_response }.merge(response.headers)
195
- NexosisApi::SessionResponse.new(session_hash)
196
- else
197
- raise HttpException.new("Unable to create new #{type} session", "Create session for dataset #{dataset_name}", response)
198
- end
199
- end
200
-
201
- def get_query_from_options(options)
202
- query = {
203
- 'dataSetName' => options[:dataset_name],
204
- 'eventName' => options[:event_name],
205
- 'startDate' => options[:start_date],
206
- 'endDate' => options[:end_date],
207
- 'type' => options[:type]
208
- }
209
- query
210
- end
211
- end
212
- end
213
- end
1
+ require 'csv'
2
+ require 'json'
3
+
4
+ module NexosisApi
5
+ class Client
6
+ # Session-based API operations
7
+ #
8
+ # @see http://docs.nexosis.com/
9
+ module Sessions
10
+
11
+ # List sessions previously submitted
12
+ #
13
+ # @param query_options [Hash] optionally provide query parameters to limit the search of sessions.
14
+ # @param page [Integer] optionally provide a page number for paging. Defaults to 0 (first page).
15
+ # @param pageSize [Integer] optionally provide a page size to limit the total number of results. Defaults to 50, max 1000
16
+ # @return [NexosisApi::PagedArray of NexosisApi::SessionResponse] with all sessions matching the query or all if no query
17
+ # @note query parameters hash members are dataset_name, event_name, requested_before_date, and requested_after_date.
18
+ # After and before dates refer to the session requested date.
19
+ # @example query for just one dataset
20
+ # sessions = NexosisApi.client.list_sessions :dataset_name => 'MyDataset'
21
+ def list_sessions(query_options = {}, page = 0, pageSize = 50)
22
+ sessions_url = '/sessions'
23
+ query = {
24
+ 'dataSetName' => query_options[:dataset_name],
25
+ 'eventName' => query_options[:event_name],
26
+ 'requestedAfterDate' => query_options[:requested_after_date],
27
+ 'requestedBeforeDate' => query_options[:requested_before_date],
28
+ 'type' => query_options[:type],
29
+ 'page' => page,
30
+ 'pageSize' => pageSize
31
+ }
32
+ response = self.class.get(sessions_url, headers: @headers, query: query)
33
+ raise HttpException.new('Could not retrieve sessions',
34
+ "Get all sessions with query #{query_options}",
35
+ response) unless response.success?
36
+ NexosisApi::PagedArray.new(response.parsed_response, response.parsed_response['items'].map do |session_hash|
37
+ response_hash = { 'session' => session_hash }.merge(response.headers)
38
+ NexosisApi::SessionResponse.new(response_hash)
39
+ end)
40
+ end
41
+
42
+ # Remove a session
43
+ # @param session_id [String] required session identifier
44
+ def remove_session(session_id)
45
+ if (session_id.to_s.empty?)
46
+ raise ArgumentError 'session_id cannot be empty or nil'
47
+ end
48
+ session_url = "/sessions/#{session_id}"
49
+ response = self.class.delete(session_url, headers: @headers)
50
+ return if response.success?
51
+ raise HttpException.new('Could not delete session with given id', "remove session with id #{session_id}", response)
52
+ end
53
+
54
+ # Remove sessions that have been run. All query options are optional and will be used to limit the sessions removed.
55
+ # @param query_options [Hash] optionally provide query parametes to limit the set of sessions removed.
56
+ # @note query parameters hash members are type, dataset_name, event_name, start_date, and end_date.
57
+ # Start and end dates refer to the session requested date.
58
+ # Results are not removed but then can only be accessed by dataset name
59
+ # @example Remove all sessions based on a dataset by name
60
+ # NexosisApi.client.remove_sessions :dataset_name => 'existing_dataset'
61
+ def remove_sessions(query_options = {})
62
+ sessions_url = '/sessions'
63
+ response = self.class.delete(sessions_url, :headers => @headers, :query => get_query_from_options(query_options))
64
+ return if response.success?
65
+ raise HttpException.new('Could not remove sessions', "Remove sessions with query #{query_options.to_s}",response)
66
+ end
67
+
68
+ # Initiate a new forecast session based on a named dataset.
69
+ #
70
+ # @param dataset_name [String] The name of the saved data set that has the data to forecast on.
71
+ # @param start_date [DateTime] The starting date of the forecast period. Can be ISO 8601 string.
72
+ # @param end_date [DateTime] The ending date of the forecast period. Can be ISO 8601 string.
73
+ # @param target_column [String] The name of the column for which you want predictions. Nil if defined in dataset.
74
+ # @param result_interval [NexosisApi::TimeInterval] (optional) - The date/time interval (e.g. Day, Hour) at which predictions should be generated. So, if Hour is specified for this parameter you will get a Result record for each hour between startDate and endDate. If unspecified, we’ll generate predictions at a Day interval.
75
+ # @param column_metadata [Array of NexosisApi::Column] (optional) - specification for how to handle columns if different from existing metadata on dataset
76
+ # @return [NexosisApi::SessionResponse] providing information about the sesssion
77
+ # @note The time interval selected must be greater than or equal to the finest granularity of the data provided.
78
+ # For instance if your data includes many recoreds per hour, then you could request hour, day, or any other result interval.
79
+ # However, if your data includes only a few records per day or fewer, then a request for an hourly result interval will produce poor results.
80
+ def create_forecast_session(dataset_name, start_date, end_date, target_column = nil, result_interval = NexosisApi::TimeInterval::DAY, column_metadata = nil)
81
+ create_session(dataset_name, start_date, end_date, target_column, nil, 'forecast', result_interval, column_metadata)
82
+ end
83
+
84
+ # Analyze impact for an event with data already saved to the API.
85
+ #
86
+ # @param dataset_name [String] The name of the saved data set that has the data to forecast on.
87
+ # @param start_date [DateTime] The starting date of the impactful event. Can be ISO 8601 string.
88
+ # @param end_date [DateTime] The ending date of the impactful event. Can be ISO 8601 string.
89
+ # @param event_name [String] The name of the event.
90
+ # @param target_column [String] The name of the column for which you want predictions. Nil if defined in datatset.
91
+ # @param result_interval [NexosisApi::TimeInterval] (optional) - The date/time interval (e.g. Day, Hour) at which predictions should be generated. So, if Hour is specified for this parameter you will get a Result record for each hour between startDate and endDate. If unspecified, we’ll generate predictions at a Day interval.
92
+ # @param column_metadata [Array of NexosisApi::Column] (optional) - specification for how to handle columns if different from existing metadata on dataset
93
+ # @return [NexosisApi::SessionResponse] providing information about the sesssion
94
+ def create_impact_session(dataset_name, start_date, end_date, event_name, target_column = nil, result_interval = NexosisApi::TimeInterval::DAY, column_metadata = nil)
95
+ create_session(dataset_name, start_date, end_date, target_column, event_name, 'impact', result_interval, column_metadata)
96
+ end
97
+
98
+ # Get the results of the session.
99
+ #
100
+ # @param session_id [String] the Guid string returned in a previous session request
101
+ # @param as_csv [Boolean] indicate whether results should be returned in csv format
102
+ # @param prediction_interval [Float] one of the available prediction intervals for the session.
103
+ # @return [NexosisApi::SessionResult] SessionResult if parsed, String of csv data otherwise
104
+ def get_session_results(session_id, as_csv = false, prediction_interval = nil)
105
+ session_result_url = "/sessions/#{session_id}/results"
106
+ @headers['Accept'] = 'text/csv' if as_csv
107
+ query = { predictionInterval: prediction_interval } unless prediction_interval.nil?
108
+ response = self.class.get(session_result_url, headers: @headers, query: query)
109
+ @headers.delete('Accept')
110
+
111
+ if (response.success?)
112
+ return response.body if as_csv
113
+ NexosisApi::SessionResult.new(response.parsed_response)
114
+ else
115
+ raise HttpException.new("There was a problem getting the session: #{response.code}.", "get results for session #{session_id}" ,response)
116
+ end
117
+ end
118
+
119
+ # Get a specific session by id.
120
+ #
121
+ # @param session_id [String] the Guid string returned in a previous session request
122
+ # @return [NexosisApi::Session] a Session object populated with the session's data
123
+ def get_session(session_id)
124
+ session_url = "/sessions/#{session_id}"
125
+ response = self.class.get(session_url, @options)
126
+ return NexosisApi::Session.new(response.parsed_response) if response.success?
127
+ raise HttpException.new("There was a problem getting the session: #{response.code}.", "getting session #{session_id}" ,response)
128
+ end
129
+
130
+ # Create a new model based on a data source
131
+ #
132
+ # @param datasource_name [String] The datasource from which to build the model
133
+ # @param target_column [String] The column which will be predicted when using the model
134
+ # @param columns [Hash] column metadata to modify roles, imputation, or target.
135
+ # @param options [Hash] prediction_domain and or balance (true or false) indicator for classification
136
+ # @note - classifcation assumes balanced classes. The use of a 'balanced=false' option
137
+ # indicates that no attempt should be made to sample the classes in balanced fashion.
138
+ # @since 1.3.0
139
+ def create_model(datasource_name, target_column, columns = {}, options = { prediction_domain: 'regression' })
140
+ model_url = '/sessions/model'
141
+ body = {
142
+ dataSourceName: datasource_name,
143
+ targetColumn: target_column,
144
+ predictionDomain: options[:prediction_domain].downcase
145
+ }
146
+ body.store(:extraParameters, { balance: options[:balance] }) if options.include?(:balance) && body[:predictionDomain] == 'classification'
147
+ body.store(columns: columns) unless columns.empty?
148
+ response = self.class.post(model_url, headers: @headers, body: body.to_json)
149
+ if response.success?
150
+ session_hash = { 'session' => response.parsed_response }.merge(response.headers)
151
+ NexosisApi::SessionResponse.new(session_hash)
152
+ else
153
+ raise HttpException.new("There was a problem creating the model session: #{response.code}.", 'creating model session' ,response)
154
+ end
155
+ end
156
+
157
+ # Get the confusion matrix for a completed classification session
158
+ # @param session_id [String] The unique id of the completed classification session
159
+ # @return [NexosisApi::ClassifierResult] a confusion matrix along with class labels and other session information.
160
+ # @since 1.4.1
161
+ # @note - This endpoint returns a 404 for requests of non-classification sessions
162
+ def get_confusion_matrix(session_id)
163
+ result_url = "/sessions/#{session_id}/results/confusionmatrix"
164
+ response = self.class.get(result_url, headers: @headers)
165
+ raise HttpException.new("There was a problem getting a confusion matrix for session #{session_id}", 'getting confusion matrix', response) unless response.success?
166
+ NexosisApi::ClassifierResult.new(response.parsed_response)
167
+ end
168
+
169
+ private
170
+
171
+ # @private
172
+ def create_session(dataset_name, start_date, end_date, target_column = nil, event_name = nil, type = 'forecast', result_interval = NexosisApi::TimeInterval::DAY, column_metadata = nil)
173
+ session_url = "/sessions/#{type}"
174
+ query = {
175
+ 'targetColumn' => target_column.to_s,
176
+ 'startDate' => start_date.to_s,
177
+ 'endDate' => end_date.to_s,
178
+ 'resultInterval' => result_interval.to_s
179
+ }
180
+ query['dataSetName'] = dataset_name.to_s unless dataset_name.to_s.empty?
181
+ if (event_name.nil? == false)
182
+ query['eventName'] = event_name
183
+ end
184
+ body = ''
185
+ if (column_metadata.nil? == false)
186
+ column_json = Column.to_json(column_metadata)
187
+ body = {
188
+ 'dataSetName' => dataset_name,
189
+ 'columns' => column_json
190
+ }
191
+ end
192
+ response = self.class.post(session_url, headers: @headers, query: query, body: body.to_json)
193
+ if (response.success?)
194
+ session_hash = { 'session' => response.parsed_response }.merge(response.headers)
195
+ NexosisApi::SessionResponse.new(session_hash)
196
+ else
197
+ raise HttpException.new("Unable to create new #{type} session", "Create session for dataset #{dataset_name}", response)
198
+ end
199
+ end
200
+
201
+ def get_query_from_options(options)
202
+ query = {
203
+ 'dataSetName' => options[:dataset_name],
204
+ 'eventName' => options[:event_name],
205
+ 'startDate' => options[:start_date],
206
+ 'endDate' => options[:end_date],
207
+ 'type' => options[:type]
208
+ }
209
+ query
210
+ end
211
+ end
212
+ end
213
+ end