nexosis_api 1.1.2 → 1.2.0
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.
- checksums.yaml +4 -4
- data/lib/nexosis_api.rb +11 -11
- data/lib/nexosis_api/algorithm.rb +18 -18
- data/lib/nexosis_api/algorithm_run.rb +32 -32
- data/lib/nexosis_api/algorithm_selection.rb +34 -34
- data/lib/nexosis_api/client.rb +98 -72
- data/lib/nexosis_api/client/datasets.rb +157 -162
- data/lib/nexosis_api/client/imports.rb +74 -75
- data/lib/nexosis_api/client/sessions.rb +213 -213
- data/lib/nexosis_api/client/views.rb +109 -0
- data/lib/nexosis_api/column.rb +49 -0
- data/lib/nexosis_api/column_options.rb +33 -0
- data/lib/nexosis_api/column_role.rb +15 -12
- data/lib/nexosis_api/column_type.rb +19 -15
- data/lib/nexosis_api/dataset_data.rb +24 -24
- data/lib/nexosis_api/dataset_model.rb +26 -26
- data/lib/nexosis_api/dataset_summary.rb +27 -27
- data/lib/nexosis_api/http_exception.rb +28 -24
- data/lib/nexosis_api/impact_metric.rb +22 -22
- data/lib/nexosis_api/imports_response.rb +66 -66
- data/lib/nexosis_api/join.rb +58 -0
- data/lib/nexosis_api/link.rb +18 -18
- data/lib/nexosis_api/metric.rb +21 -21
- data/lib/nexosis_api/session.rb +88 -80
- data/lib/nexosis_api/session_response.rb +26 -26
- data/lib/nexosis_api/session_result.rb +23 -23
- data/lib/nexosis_api/time_interval.rb +15 -15
- data/lib/nexosis_api/view_data.rb +13 -0
- data/lib/nexosis_api/view_definition.rb +51 -0
- data/nexosisapi.gemspec +20 -20
- metadata +10 -5
- data/lib/nexosis_api/dataset_column.rb +0 -47
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c023f2428d99d8724c7f278b96e71b1faf560c1
|
4
|
+
data.tar.gz: 2baabb2e8f32f47f9ddb19f33059f5b6643b5ad9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67fa1be6df48ed79569ad3cbc0f698bc381f2a61139f8c39ea7b51f5c27d637c2d59548362521d41fb783fa3e221464d9fccbdd940f889e4c65ac0b3447c6ea1
|
7
|
+
data.tar.gz: 92dd19462ab7bda527ff2bc6ea7ffbab4de7cec87cb0d748a828b195467393e2a19955993c47912a1ff133f505f3be7ee4b3ccfa163c088821e7a5de573f13cc
|
data/lib/nexosis_api.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
require 'httparty'
|
2
|
-
require 'nexosis_api/client'
|
3
|
-
|
4
|
-
# The container for the Nexosis API Client
|
5
|
-
module NexosisApi
|
6
|
-
class << self
|
7
|
-
def client options = {}
|
8
|
-
return @client if defined?(@client)
|
9
|
-
@client = NexosisApi::Client.new(options)
|
10
|
-
end
|
11
|
-
end
|
1
|
+
require 'httparty'
|
2
|
+
require 'nexosis_api/client'
|
3
|
+
|
4
|
+
# The container for the Nexosis API Client
|
5
|
+
module NexosisApi
|
6
|
+
class << self
|
7
|
+
def client options = {}
|
8
|
+
return @client if defined?(@client)
|
9
|
+
@client = NexosisApi::Client.new(options)
|
10
|
+
end
|
11
|
+
end
|
12
12
|
end
|
@@ -1,18 +1,18 @@
|
|
1
|
-
module NexosisApi
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
1
|
+
module NexosisApi
|
2
|
+
# Class to parse an individual algorithm
|
3
|
+
class Algorithm
|
4
|
+
def initialize(algo_hash)
|
5
|
+
algo_hash.each do |k, v|
|
6
|
+
instance_variable_set("@#{k}", v) unless v.nil?
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
# A friendly name for the algorithm
|
11
|
+
# @return [String]
|
12
|
+
attr_accessor :name
|
13
|
+
|
14
|
+
# Descriptive explanation of the algorithm implementation
|
15
|
+
# @return [String]
|
16
|
+
attr_accessor :description
|
17
|
+
end
|
18
|
+
end
|
@@ -1,32 +1,32 @@
|
|
1
|
-
module NexosisApi
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
end
|
1
|
+
module NexosisApi
|
2
|
+
# Class to parse results of an algorithm run
|
3
|
+
class AlgorithmRun
|
4
|
+
def initialize(run_hash)
|
5
|
+
run_hash.each do |k, v|
|
6
|
+
if k == 'metrics'
|
7
|
+
metric_set = []
|
8
|
+
v.each { |m| metric_set << NexosisApi::Metric.new(m) unless m.nil? }
|
9
|
+
instance_variable_set("@#{k}", metric_set)
|
10
|
+
elsif k == 'links'
|
11
|
+
link_set = []
|
12
|
+
v.each { |l| link_set << NexosisApi::Link.new(l) unless l.nil? }
|
13
|
+
instance_variable_set("@#{k}", link_set)
|
14
|
+
else
|
15
|
+
instance_variable_set("@#{k}", NexosisApi::Algorithm.new(v)) unless v.nil?
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Identifier of algorithm run
|
21
|
+
# @return [NexosisApi::Algorithm]
|
22
|
+
attr_accessor :algorithm
|
23
|
+
|
24
|
+
# Set of {NexosisApi::Metric} on algorithm
|
25
|
+
# @return [Array]
|
26
|
+
attr_accessor :metrics
|
27
|
+
|
28
|
+
# Relevant hypermedia as {NexosisApi::Link}
|
29
|
+
# @return [Array]
|
30
|
+
attr_accessor :links
|
31
|
+
end
|
32
|
+
end
|
@@ -1,34 +1,34 @@
|
|
1
|
-
module NexosisApi
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
end
|
1
|
+
module NexosisApi
|
2
|
+
# Class to parse the model data results from a session
|
3
|
+
class AlgorithmSelection
|
4
|
+
def initialize(data_hash)
|
5
|
+
data_hash.each do |k, v|
|
6
|
+
if k == 'champion'
|
7
|
+
instance_variable_set("@#{k}", NexosisApi::AlgorithmRun.new(v))
|
8
|
+
elsif k == 'contestants'
|
9
|
+
contestant_array = []
|
10
|
+
v.each { |c| contestant_array << NexosisApi::AlgorithmRun.new(c) }
|
11
|
+
instance_variable_set("@#{k}", contestant_array)
|
12
|
+
else
|
13
|
+
instance_variable_set("@#{k}", v) unless v.nil?
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# The date on which this algo was selected as champion
|
19
|
+
# @return [DateTime]
|
20
|
+
attr_accessor :date
|
21
|
+
|
22
|
+
# The session which selected the algorithm
|
23
|
+
# @return [String] session identifier
|
24
|
+
attr_accessor :sessionId
|
25
|
+
|
26
|
+
# The champion algorithm used
|
27
|
+
# @return [NexosisApi::AlgorithmRun]
|
28
|
+
attr_accessor :champion
|
29
|
+
|
30
|
+
# All other algorithms which competed
|
31
|
+
# @return [Array of NexosisApi::AlgorithmRun]
|
32
|
+
attr_accessor :contestants
|
33
|
+
end
|
34
|
+
end
|
data/lib/nexosis_api/client.rb
CHANGED
@@ -1,72 +1,98 @@
|
|
1
|
-
require 'nexosis_api/algorithm_run'
|
2
|
-
require 'nexosis_api/algorithm_selection'
|
3
|
-
require 'nexosis_api/algorithm'
|
4
|
-
require 'nexosis_api/
|
5
|
-
require 'nexosis_api/
|
6
|
-
require 'nexosis_api/
|
7
|
-
require 'nexosis_api/
|
8
|
-
require 'nexosis_api/
|
9
|
-
require 'nexosis_api/
|
10
|
-
require 'nexosis_api/
|
11
|
-
require 'nexosis_api/
|
12
|
-
require 'nexosis_api/
|
13
|
-
require 'nexosis_api/
|
14
|
-
require 'nexosis_api/
|
15
|
-
require 'nexosis_api/
|
16
|
-
require 'nexosis_api/
|
17
|
-
require 'nexosis_api/
|
18
|
-
require 'nexosis_api/
|
19
|
-
require 'nexosis_api/
|
20
|
-
require 'nexosis_api/
|
21
|
-
require 'nexosis_api/
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
end
|
71
|
-
|
72
|
-
|
1
|
+
require 'nexosis_api/algorithm_run'
|
2
|
+
require 'nexosis_api/algorithm_selection'
|
3
|
+
require 'nexosis_api/algorithm'
|
4
|
+
require 'nexosis_api/column'
|
5
|
+
require 'nexosis_api/column_options'
|
6
|
+
require 'nexosis_api/column_role'
|
7
|
+
require 'nexosis_api/column_type'
|
8
|
+
require 'nexosis_api/dataset_data'
|
9
|
+
require 'nexosis_api/dataset_model'
|
10
|
+
require 'nexosis_api/dataset_summary'
|
11
|
+
require 'nexosis_api/http_exception'
|
12
|
+
require 'nexosis_api/impact_metric'
|
13
|
+
require 'nexosis_api/imports_response'
|
14
|
+
require 'nexosis_api/join'
|
15
|
+
require 'nexosis_api/link'
|
16
|
+
require 'nexosis_api/metric'
|
17
|
+
require 'nexosis_api/session_response'
|
18
|
+
require 'nexosis_api/session_result'
|
19
|
+
require 'nexosis_api/session'
|
20
|
+
require 'nexosis_api/time_interval'
|
21
|
+
require 'nexosis_api/view_definition'
|
22
|
+
require 'nexosis_api/view_data'
|
23
|
+
require 'nexosis_api/client/sessions'
|
24
|
+
require 'nexosis_api/client/datasets'
|
25
|
+
require 'nexosis_api/client/imports'
|
26
|
+
require 'nexosis_api/client/views'
|
27
|
+
|
28
|
+
module NexosisApi
|
29
|
+
# Primary entry point to working with Nexosis API
|
30
|
+
class Client
|
31
|
+
include HTTParty
|
32
|
+
base_uri 'https://ml.nexosis.com/v1'
|
33
|
+
include Client::Sessions
|
34
|
+
include Client::Datasets
|
35
|
+
include Client::Imports
|
36
|
+
include Client::Views
|
37
|
+
|
38
|
+
def initialize(options = {})
|
39
|
+
raise ArgumentError, 'api_key was not defined' unless options[:api_key].nil? == false
|
40
|
+
@api_key = options[:api_key]
|
41
|
+
self.class.base_uri options[:base_uri] unless options[:base_uri].nil?
|
42
|
+
@headers = {'api-key' => @api_key, 'Content-Type' => 'application/json'}
|
43
|
+
@options = {headers: @headers, format: :json}
|
44
|
+
end
|
45
|
+
|
46
|
+
# Gets the current account balance.
|
47
|
+
#
|
48
|
+
# @return [String] a string with the numeric balance and currency identifier postfix - 10.0 USD
|
49
|
+
# @example Get account balance
|
50
|
+
# client.get_account_balance
|
51
|
+
def get_account_balance()
|
52
|
+
session_url = '/sessions'
|
53
|
+
response = self.class.get(session_url,@options)
|
54
|
+
response.headers['nexosis-account-balance']
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
# @private
|
60
|
+
def process_csv_to_s csv
|
61
|
+
content = ''
|
62
|
+
if(csv.is_a?(CSV))
|
63
|
+
csv.each do |row|
|
64
|
+
if(csv.headers.nil?)
|
65
|
+
# not using row.to_csv because it uses non-compliant '\n' newline
|
66
|
+
content.concat(row.join(',')).concat("\r\n")
|
67
|
+
else
|
68
|
+
content.concat(row.fields.join(',')).concat("\r\n")
|
69
|
+
end
|
70
|
+
end
|
71
|
+
if(csv.headers.nil? == false)
|
72
|
+
content.prepend(csv.headers.join(',').concat("\r\n")) unless csv.headers.nil?
|
73
|
+
end
|
74
|
+
else
|
75
|
+
content = csv
|
76
|
+
end
|
77
|
+
content
|
78
|
+
end
|
79
|
+
|
80
|
+
# @private
|
81
|
+
def create_query(page_number, page_size, options = {})
|
82
|
+
options.store(:page_number, page_number)
|
83
|
+
options.store(:page_size, page_size)
|
84
|
+
query = {
|
85
|
+
'page' => [page_number],
|
86
|
+
'pageSize' => [page_size]
|
87
|
+
}
|
88
|
+
query['startDate'] = [options[:start_date].iso8601.gsub(/\+/,'%2B')] unless options[:start_date].nil?
|
89
|
+
query['endDate'] = [options[:end_date].iso8601.gsub(/\+/,'%2B')] unless options[:end_date].nil?
|
90
|
+
query['include'] = options[:include] unless options[:include].nil?
|
91
|
+
query
|
92
|
+
end
|
93
|
+
|
94
|
+
def array_query_normalizer(query_set)
|
95
|
+
query_set.map { |key, value| value.map { |v| "#{key}=#{v}" } }.join('&')
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -1,162 +1,157 @@
|
|
1
|
-
require 'csv'
|
2
|
-
|
3
|
-
module NexosisApi
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
query
|
159
|
-
end
|
160
|
-
end
|
161
|
-
end
|
162
|
-
end
|
1
|
+
require 'csv'
|
2
|
+
|
3
|
+
module NexosisApi
|
4
|
+
class Client
|
5
|
+
# Dataset-based API operations
|
6
|
+
#
|
7
|
+
# @see http://docs.nexosis.com/
|
8
|
+
module Datasets
|
9
|
+
# save data in a named dataset
|
10
|
+
#
|
11
|
+
# @param dataset_name [String] name to save the dataset
|
12
|
+
# @param json_data [Hash] parsed json data
|
13
|
+
# @return [NexosisApi::DatasetSummary] information about your upload
|
14
|
+
# @note input json is to be a hash, do not send a json string via to_json.
|
15
|
+
def create_dataset_json(dataset_name, json_data)
|
16
|
+
create_dataset dataset_name, json_data.to_json, 'application/json'
|
17
|
+
end
|
18
|
+
|
19
|
+
# save data in a named dataset from csv content
|
20
|
+
#
|
21
|
+
# @param dataset_name [String] name to save the dataset
|
22
|
+
# @param csv [CSV] csv content ready for reading
|
23
|
+
# @return [NexosisApi::DatasetSummary] information about your upload
|
24
|
+
def create_dataset_csv(dataset_name, csv)
|
25
|
+
content = process_csv_to_s csv
|
26
|
+
create_dataset dataset_name, content, 'text/csv'
|
27
|
+
end
|
28
|
+
|
29
|
+
# Gets the list of data sets that have been saved to the system, optionally filtering by partial name match.
|
30
|
+
#
|
31
|
+
# @param partial_name [String] if provided, all datasets returned will contain this string
|
32
|
+
# @return [Array of NexosisApi::DatasetSummary] array of datasets found
|
33
|
+
def list_datasets(partial_name = '')
|
34
|
+
list_dataset_url = "/data?partialName=#{partial_name}"
|
35
|
+
response = self.class.get(list_dataset_url, headers: @headers)
|
36
|
+
if response.success?
|
37
|
+
results = []
|
38
|
+
response.parsed_response['items'].each do |dr|
|
39
|
+
results << NexosisApi::DatasetSummary.new(dr)
|
40
|
+
end
|
41
|
+
results
|
42
|
+
else
|
43
|
+
raise HttpException.new("There was a problem listing datasets: #{response.code}.", "listing datasets with partial name #{partial_name}", response)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Get the data in the set, with paging, and optional projection.
|
48
|
+
#
|
49
|
+
# @param dataset_name [String] name of the dataset for which to retrieve data.
|
50
|
+
# @param page_number [Integer] zero-based page number of results to retrieve
|
51
|
+
# @param page_size [Integer] Count of results to retrieve in each page (max 1000).
|
52
|
+
# @param query_options [Hash] options hash for limiting and projecting returned results
|
53
|
+
# @note Query Options includes start_date as a DateTime or ISO 8601 compliant string,
|
54
|
+
# end_date, also as a DateTime or string, and :include as an Array of strings indicating the columns to return.
|
55
|
+
# The dates can be used independently and are inclusive. Lack of options returns all values within the given page.
|
56
|
+
def get_dataset(dataset_name, page_number = 0, page_size = 50, query_options = {})
|
57
|
+
response = get_dataset_internal(dataset_name, page_number, page_size, query_options)
|
58
|
+
if response.success?
|
59
|
+
NexosisApi::DatasetData.new(response.parsed_response)
|
60
|
+
else
|
61
|
+
raise HttpException.new("There was a problem getting the dataset: #{response.code}.", "getting dataset #{dataset_name}", response)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# Get the data in the set, written to a CSV file, optionally filtering it.
|
66
|
+
#
|
67
|
+
# @param dataset_name [String] name of the dataset for which to retrieve data.
|
68
|
+
# @param page_number [Integer] zero-based page number of results to retrieve
|
69
|
+
# @param page_size [Integer] Count of results to retrieve in each page (max 1000).
|
70
|
+
# @param query_options [Hash] options hash for limiting and projecting returned results
|
71
|
+
# @note Query Options includes start_date as a DateTime or ISO 8601 compliant string,
|
72
|
+
# end_date, also as a DateTime or string, and :include as an Array of strings indicating the columns to return.
|
73
|
+
# The dates can be used independently and are inclusive. Lack of options returns all values within the given page.
|
74
|
+
# @example get page 1 with 20 results each page
|
75
|
+
# NexosisApi.client.get_dataset_csv('MyDataset', 1, 20, {:include => 'sales'})
|
76
|
+
def get_dataset_csv(dataset_name, page_number = 0, page_size = 50, query_options = {})
|
77
|
+
response = get_dataset_internal(dataset_name, page_number, page_size, query_options, 'text/csv')
|
78
|
+
if response.success?
|
79
|
+
response.body
|
80
|
+
else
|
81
|
+
raise HttpException.new("There was a problem getting the dataset: #{response.code}.", "getting dataset #{dataset_name}", response)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# Remove data from a data set or the entire set.
|
86
|
+
#
|
87
|
+
# @param dataset_name [String] the name of the dataset from which to remove data
|
88
|
+
# @param filter_options [Hash] filtering which data to remove
|
89
|
+
# @note Options: start_date, end_date, cascade_forecast, cascade_sessions, cascade
|
90
|
+
# - start_date - the first date on which to start removing data
|
91
|
+
# - end_date - the last date on which to finish removing data
|
92
|
+
# - cascade_forecast - will cascade deletes to all related forecasts
|
93
|
+
# - cascade_session - will cascade deletes to all related sessions
|
94
|
+
# - cascade_view - will cascade deletes to all related views (any part of join - think twice)
|
95
|
+
# - cascade - will cascade deletes to all related forecasts and sessions
|
96
|
+
# @example - request delete with cascade forecast
|
97
|
+
# NexosisApi.client.remove_dataset('mydataset', {:cascade_forecast => true})
|
98
|
+
def remove_dataset(dataset_name, filter_options = {})
|
99
|
+
raise ArgumentError 'dataset_name was not provided and is not optional ' if dataset_name.to_s.empty?
|
100
|
+
dataset_remove_url = "/data/#{dataset_name}"
|
101
|
+
query = {}
|
102
|
+
if filter_options.empty? == false
|
103
|
+
cascade_query = create_cascade_options(filter_options)
|
104
|
+
query['cascade'] = cascade_query unless cascade_query.nil?
|
105
|
+
query['startDate'] = [filter_options[:start_date].to_s] unless filter_options[:start_date].nil?
|
106
|
+
query['endDate'] = [filter_options[:end_date].to_s] unless filter_options[:end_date].nil?
|
107
|
+
end
|
108
|
+
#normalizer = proc { |query_set| query_set.map { |key, value| value.map { |v| "#{key}=#{v}" } }.join('&') }
|
109
|
+
response = self.class.delete(dataset_remove_url,
|
110
|
+
headers: @headers,
|
111
|
+
query: query,
|
112
|
+
query_string_normalizer: ->(query_map) {array_query_normalizer(query_map)})
|
113
|
+
if response.success?
|
114
|
+
return
|
115
|
+
else
|
116
|
+
raise HttpException.new("There was a problem removing the dataset: #{response.code}.", "removing dataset #{dataset_name}", response)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
private
|
121
|
+
|
122
|
+
# @private
|
123
|
+
def create_dataset(dataset_name, content, content_type)
|
124
|
+
raise ArgumentError 'dataset_name was not provided and is not optional ' if dataset_name.to_s.empty?
|
125
|
+
dataset_url = "/data/#{dataset_name}"
|
126
|
+
headers = { 'api-key' => @api_key, 'Content-Type' => content_type }
|
127
|
+
response = self.class.put(dataset_url, headers: headers, body: content)
|
128
|
+
if response.success?
|
129
|
+
NexosisApi::DatasetSummary.new(response)
|
130
|
+
else
|
131
|
+
raise HttpException.new("There was a problem uploading the dataset: #{response.code}.", "uploading dataset #{dataset_name}", response)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
# @private
|
136
|
+
def get_dataset_internal(dataset_name, page_number = 0, page_size = 50, query_options = {}, content_type = 'application/json')
|
137
|
+
raise ArgumentError 'page size must be <= 100 items per page' unless page_size <= 100
|
138
|
+
raise ArgumentError 'dataset_name was not provided and is not optional' unless dataset_name.to_s.empty? == false
|
139
|
+
dataset_url = "/data/#{dataset_name}"
|
140
|
+
headers = { 'api-key' => @api_key, 'Accept' => content_type }
|
141
|
+
self.class.get(dataset_url, headers: headers,
|
142
|
+
query: create_query(page_number, page_size, query_options),
|
143
|
+
query_string_normalizer: ->(query_map) { array_query_normalizer(query_map) })
|
144
|
+
end
|
145
|
+
|
146
|
+
# @private
|
147
|
+
def create_cascade_options(option_hash)
|
148
|
+
return nil if option_hash.nil?
|
149
|
+
return %w[session view forecast] if option_hash.key?(:cascade)
|
150
|
+
options_set = []
|
151
|
+
option_hash.each_key { |k| options_set << k.to_s.gsub(/cascade_/, '') if k.to_s.include? 'cascade_' }
|
152
|
+
# HACK: required to be backward compatible with incorrect key names
|
153
|
+
options_set.map { |s| s.chomp('s') }
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|