Class: Keboola::GoodDataWriter::API

Inherits:
Object
  • Object
show all
Defined in:
lib/keboola/gooddata_writer/api.rb

Constant Summary collapse

QUEUE_ENDPOINT_URL =
'https://syrup.keboola.com/queue/'
WRITER_ENDPOINT_URL =
'https://syrup.keboola.com/gooddata-writer/'
QUEUE_MOCK_ENDPOINT_URL =
'https://private-anon-c1bf53b9c-syrupqueue.apiary-mock.com/queue/'
WRITER_MOCK_ENDPOINT_URL =
'https://private-anon-df256c5fb-keboolagooddatawriter.apiary-mock.com/gooddata-writer/'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token: nil, endpoint: nil, client: nil, queue: nil, parser: nil) ⇒ API


13
14
15
16
17
18
# File 'lib/keboola/gooddata_writer/api.rb', line 13

def initialize(token: nil, endpoint: nil, client: nil, queue: nil, parser: nil)
  @token  = token  || raise(ArgumentError, "token is required")
  @client = client || self.class.build_client(endpoint: endpoint || WRITER_ENDPOINT_URL, token: token)
  @queue  = queue  || self.class.build_client(endpoint: QUEUE_ENDPOINT_URL, token: token)
  @parser = parser || self.class.build_parser
end

Instance Attribute Details

#clientObject

Returns the value of attribute client


10
11
12
# File 'lib/keboola/gooddata_writer/api.rb', line 10

def client
  @client
end

#parserObject

Returns the value of attribute parser


10
11
12
# File 'lib/keboola/gooddata_writer/api.rb', line 10

def parser
  @parser
end

#queueObject

Returns the value of attribute queue


10
11
12
# File 'lib/keboola/gooddata_writer/api.rb', line 10

def queue
  @queue
end

#tokenObject

Returns the value of attribute token


10
11
12
# File 'lib/keboola/gooddata_writer/api.rb', line 10

def token
  @token
end

Class Method Details

.build_client(token: nil, endpoint: nil) ⇒ Object


20
21
22
# File 'lib/keboola/gooddata_writer/api.rb', line 20

def self.build_client(token: nil, endpoint: nil)
  Client.factory(token: token, endpoint: endpoint)
end

.build_parserObject


24
25
26
# File 'lib/keboola/gooddata_writer/api.rb', line 24

def self.build_parser
  Parser.new
end

Instance Method Details

#add_project_users(writer_id, project_id, email, role, optionals: {}, async: true) ⇒ Object

Adds GoodData user to specified project.


108
109
110
111
# File 'lib/keboola/gooddata_writer/api.rb', line 108

def add_project_users(writer_id, project_id, email, role, optionals: {}, async: true)
  params = { writerId: writer_id, pid: project_id, email: email, role: role }.reverse_merge(optionals)
  handle(@client.post("project-users", params.to_json)) { |result| job_handler(result, async) }
end

#assign_filters_users(writer_id, email, filters = [], optionals: {}, async: true) ⇒ Object

Assign Filter to User


222
223
224
225
# File 'lib/keboola/gooddata_writer/api.rb', line 222

def assign_filters_users(writer_id, email, filters = [], optionals: {}, async: true)
  params = { writerId: writer_id, email: email, filters: filters }.reverse_merge(optionals)
  handle(@client.post("filters-users", params.to_json)) { |result| job_handler(result, async) }
end

#bulk_update_table_column(writer_id, table_id, columns = []) ⇒ Object

Bulk update table column configuration


145
146
147
148
# File 'lib/keboola/gooddata_writer/api.rb', line 145

def bulk_update_table_column(writer_id, table_id, columns = [])
  params = { writerId: writer_id, tableId: table_id, columns: columns }
  handle(@client.post("tables", params.to_json)) { |result| job_handler(result).ok? }
end

#create_filter(writer_id, project_id, name, attribute, value, operator = '=', optionals: {}, async: true) ⇒ Object


197
198
199
200
# File 'lib/keboola/gooddata_writer/api.rb', line 197

def create_filter(writer_id, project_id, name, attribute, value, operator = '=', optionals: {}, async: true)
  params = { writerId: writer_id, pid: project_id, name: name, attribute: attribute, operator: operator, value: value }.reverse_merge(optionals)
  handle(@client.post("filters", params.to_json)) { |result| job_handler(result, async) }
end

#create_project(writer_id, optionals: {}, async: true) ⇒ Object

Creates new configuration bucket and either uses existing GoodData project or creates new one along with dedicated GoodData user.


68
69
70
71
# File 'lib/keboola/gooddata_writer/api.rb', line 68

def create_project(writer_id, optionals: {}, async: true)
  params = { writerId: writer_id }.reverse_merge(optionals)
  handle(@client.post("projects", params.to_json)) { |result| job_handler(result, async) }
end

#create_user(writer_id, email, password, first_name, last_name, optionals: {}, async: true) ⇒ Object

Creates new GoodData user in Keboola domain.


94
95
96
97
# File 'lib/keboola/gooddata_writer/api.rb', line 94

def create_user(writer_id, email, password, first_name, last_name, optionals: {}, async: true)
  params = { writerId: writer_id, email: email, password: password, firstName: first_name, lastName: last_name }.reverse_merge(optionals)
  handle(@client.post("users", params.to_json)) { |result| job_handler(result, async) }
end

#create_writer(writer_id, optionals: {}, async: true) ⇒ Object

Creates new configuration bucket and either uses existing GoodData project or creates new one along with dedicated GoodData user.


43
44
45
46
# File 'lib/keboola/gooddata_writer/api.rb', line 43

def create_writer(writer_id, optionals: {}, async: true)
  params = { writerId: writer_id }.reverse_merge(optionals)
  handle(@client.post("writers", params.to_json)) { |result| job_handler(result, async) }
end

#delete_filter(writer_id, name, async: true) ⇒ Object


202
203
204
# File 'lib/keboola/gooddata_writer/api.rb', line 202

def delete_filter(writer_id, name, async: true)
  handle(@client.delete("filters", { writerId: writer_id, name: name })) { |result| job_handler(result, async) }
end

#delete_writer(writer_id, async: true) ⇒ Object

Deletes configuration bucket and enqueues GoodData project and dedicated GoodData user for removal


54
55
56
# File 'lib/keboola/gooddata_writer/api.rb', line 54

def delete_writer(writer_id, async: true)
  handle(@client.delete("writers", { writerId: writer_id })) { |result| job_handler(result, async) }
end

#execute_reports(writer_id, project_id, optionals: {}, async: true) ⇒ Object

Execute selected reports in GoodData


237
238
239
240
# File 'lib/keboola/gooddata_writer/api.rb', line 237

def execute_reports(writer_id, project_id, optionals: {}, async: true)
  params = { writerId: writer_id, pid: project_id }.reverse_merge(optionals)
  handle(@client.post("execute-reports", params.to_json)) { |result| job_handler(result, async) }
end

#filters(writer_id, optionals: {}) ⇒ Object

Filter resource


192
193
194
195
# File 'lib/keboola/gooddata_writer/api.rb', line 192

def filters(writer_id, optionals: {})
  params = { writerId: writer_id }.reverse_merge(optionals)
  handle(@client.get("filters", params)) { |result| result["filters"] }
end

#filters_projects(writer_id, optionals: {}) ⇒ Object

Get Filters for Projects


210
211
212
213
# File 'lib/keboola/gooddata_writer/api.rb', line 210

def filters_projects(writer_id, optionals: {})
  params = { writerId: writer_id }.reverse_merge(optionals)
  handle(@client.get("filters-projects", params)) { |result| result["filters"] }
end

#filters_users(writer_id, optionals: {}) ⇒ Object

Get Filters for Users


216
217
218
219
# File 'lib/keboola/gooddata_writer/api.rb', line 216

def filters_users(writer_id, optionals: {})
  params = { writerId: writer_id }.reverse_merge(optionals)
  handle(@client.get("filters-users", params)) { |result| result["filters"] }
end

#job(job_id) ⇒ Object

Return detail of given job


268
269
270
# File 'lib/keboola/gooddata_writer/api.rb', line 268

def job(job_id)
  handle(@queue.get("jobs/#{job_id}")) { |result| job_handler(result) }
end

#jobs(writer_id) ⇒ Object

Return list of jobs for given writer


263
264
265
# File 'lib/keboola/gooddata_writer/api.rb', line 263

def jobs(writer_id)
  handle(@queue.get("jobs", { q: "+params.writerId:#{writer_id}", limit: 50 })) { |result| result.map { |hash| job_handler(hash) } }
end

#load_data(writer_id, optionals: {}, async: true) ⇒ Object

Load data to selected tables in GoodData


179
180
181
182
# File 'lib/keboola/gooddata_writer/api.rb', line 179

def load_data(writer_id, optionals: {}, async: true)
  params = { writerId: writer_id }.reverse_merge(optionals)
  handle(@client.post("load-data", params.to_json)) { |result| job_handler(result, async) }
end

#load_data_multi(writer_id, optionals: {}, async: true) ⇒ Object

Load data to selected tables in GoodData concurrently


185
186
187
188
# File 'lib/keboola/gooddata_writer/api.rb', line 185

def load_data_multi(writer_id, optionals: {}, async: true)
  params = { writerId: writer_id }.reverse_merge(optionals)
  handle(@client.post("load-data-multi", params.to_json)) { |result| job_handler(result, async) }
end

#project_users(writer_id, project_id) ⇒ Object

Get list of users in project


103
104
105
# File 'lib/keboola/gooddata_writer/api.rb', line 103

def project_users(writer_id, project_id)
  handle(@client.get("project-users", { writerId: writer_id, pid: project_id })) { |result| result["users"] }
end

#projects(writer_id) ⇒ Object

Returns list of project clones including main project marked with main: 1 field


62
63
64
# File 'lib/keboola/gooddata_writer/api.rb', line 62

def projects(writer_id)
  handle(@client.get("projects", { writerId: writer_id })) { |result| result["projects"] }
end

#proxy(method, writer_id, query, optionals: {}, async: true) ⇒ Object

Simple proxy for direct calls to GoodData API


249
250
251
252
253
254
255
256
257
# File 'lib/keboola/gooddata_writer/api.rb', line 249

def proxy(method, writer_id, query, optionals: {}, async: true)
  params = { writerId: writer_id, query: query }.reverse_merge(optionals)
  case method.to_sym
    when :get
      handle @client.get("proxy", params)
    when :post
      handle(@client.post("proxy", params.to_json)) { |result| job_handler(result, async) }
  end
end

#remove_project_users(writer_id, project_id, email, async: true) ⇒ Object

Remove user from specified project.


114
115
116
117
# File 'lib/keboola/gooddata_writer/api.rb', line 114

def remove_project_users(writer_id, project_id, email, async: true)
  params = { writerId: writer_id, pid: project_id, email: email }
  handle(@client.delete("project-users", params)) { |result| job_handler(result, async) }
end

#reset_project(writer_id, optionals: {}, async: true) ⇒ Object

Creates new GoodData project for the writer and enqueues the old for deletion


74
75
76
77
# File 'lib/keboola/gooddata_writer/api.rb', line 74

def reset_project(writer_id, optionals: {}, async: true)
  params = { writerId: writer_id }.reverse_merge(optionals)
  handle(@client.post("reset-project", params.to_json)) { |result| job_handler(result, async) }
end

#reset_table(writer_id, table_id, optionals: {}, async: true) ⇒ Object

Remove dataset in GoodData project belonging to the table and reset it's export status


164
165
166
167
# File 'lib/keboola/gooddata_writer/api.rb', line 164

def reset_table(writer_id, table_id, optionals: {}, async: true)
  params = { writerId: writer_id, tableId: table_id }.reverse_merge(optionals)
  handle(@client.post("reset-table", params.to_json)) { |result| job_handler(result, async) }
end

#sso(writer_id, project_id, email, optionals: {}) ⇒ Object

Call to obtain an SSO link for user


243
244
245
246
# File 'lib/keboola/gooddata_writer/api.rb', line 243

def sso(writer_id, project_id, email, optionals: {})
  params = { writerId: writer_id, pid: project_id, email: email }.reverse_merge(optionals)
  handle(@client.get("sso", params)) { |result| result["ssoLink"] }
end

#sync_filters(writer_id, optionals: {}, async: true) ⇒ Object

Synchronizes filters in GoodData project according to writer's configuration


228
229
230
231
# File 'lib/keboola/gooddata_writer/api.rb', line 228

def sync_filters(writer_id, optionals: {}, async: true)
  params = { writerId: writer_id }.reverse_merge(optionals)
  handle(@client.post("sync-filters", params.to_json)) { |result| job_handler(result, async) }
end

#table(writer_id, table_id) ⇒ Object

Get table detail


128
129
130
# File 'lib/keboola/gooddata_writer/api.rb', line 128

def table(writer_id, table_id)
  handle(@client.get("tables", { writerId: writer_id, tableId: table_id })) { |result| result["tables"].first rescue result["table"] }
end

#tables(writer_id) ⇒ Object

Get tables list


123
124
125
# File 'lib/keboola/gooddata_writer/api.rb', line 123

def tables(writer_id)
  handle(@client.get("tables", { writerId: writer_id })) { |result| result["tables"] }
end

#update_table(writer_id, table_id, optionals: {}) ⇒ Object

Update table configuration


133
134
135
136
# File 'lib/keboola/gooddata_writer/api.rb', line 133

def update_table(writer_id, table_id, optionals: {})
  params = { writerId: writer_id, tableId: table_id }.reverse_merge(optionals)
  handle(@client.post("tables", params.to_json)) { |result| job_handler(result).ok? }
end

#update_table_column(writer_id, table_id, column, optionals: {}) ⇒ Object

Update table column configuration


139
140
141
142
# File 'lib/keboola/gooddata_writer/api.rb', line 139

def update_table_column(writer_id, table_id, column, optionals: {})
  params = { writerId: writer_id, tableId: table_id, column: column }.reverse_merge(optionals)
  handle(@client.post("tables", params.to_json)) { |result| job_handler(result).ok? }
end

#update_table_model(writer_id, optionals: {}, async: true) ⇒ Object Also known as: update_model

Update model of selected table in GoodData


157
158
159
160
# File 'lib/keboola/gooddata_writer/api.rb', line 157

def update_table_model(writer_id, optionals: {}, async: true)
  params = { writerId: writer_id }.reverse_merge(optionals)
  handle(@client.post("update-model", params.to_json)) { |result| job_handler(result, async) }
end

#update_writer(writer_id, attributes: {}) ⇒ Object

Sets attributes to writer's configuration


49
50
51
# File 'lib/keboola/gooddata_writer/api.rb', line 49

def update_writer(writer_id, attributes: {})
  handle(@client.post("writers/#{writer_id}", attributes.to_json)) { |result| job_handler(result).ok? }
end

#upload_date_dimension(writer_id, name, optionals: {}, async: true) ⇒ Object

Selectively upload date dimension (must be already configured in Writer)


170
171
172
173
# File 'lib/keboola/gooddata_writer/api.rb', line 170

def upload_date_dimension(writer_id, name, optionals: {}, async: true)
  params = { writerId: writer_id, name: name }.reverse_merge(optionals)
  handle(@client.post("reset-table", params.to_json)) { |result| job_handler(result, async) }
end

#upload_project(writer_id, optionals: {}, async: true) ⇒ Object

Upload project to GoodData


80
81
82
83
# File 'lib/keboola/gooddata_writer/api.rb', line 80

def upload_project(writer_id, optionals: {}, async: true)
  params = { writerId: writer_id }.reverse_merge(optionals)
  handle(@client.post("upload-project", params.to_json)) { |result| job_handler(result, async) }
end

#upload_table(writer_id, table_id, optionals: {}, async: true) ⇒ Object

Upload selected table to GoodData


151
152
153
154
# File 'lib/keboola/gooddata_writer/api.rb', line 151

def upload_table(writer_id, table_id, optionals: {}, async: true)
  params = { writerId: writer_id, tableId: table_id }.reverse_merge(optionals)
  handle(@client.post("upload-table", params.to_json)) { |result| job_handler(result, async) }
end

#users(writer_id) ⇒ Object

Get users list


89
90
91
# File 'lib/keboola/gooddata_writer/api.rb', line 89

def users(writer_id)
  handle(@client.get("users", { writerId: writer_id })) { |result| result["users"] }
end

#wait_for_job(job_id) ⇒ Object

Ask repeatedly for job status until it is finished


273
274
275
276
277
278
279
# File 'lib/keboola/gooddata_writer/api.rb', line 273

def wait_for_job(job_id)
  begin
    job = job(job_id)
    sleep 5 unless job.finished?
  end until job.finished?
  job
end

#writer(writer_id) ⇒ Object

Returns attributes of the writer


37
38
39
# File 'lib/keboola/gooddata_writer/api.rb', line 37

def writer(writer_id)
  handle(@client.get("writers", { writerId: writer_id })) { |result| result["writers"].first rescue result["writer"] }
end

#writersObject

Returns list of available writers and their buckets


32
33
34
# File 'lib/keboola/gooddata_writer/api.rb', line 32

def writers
  handle(@client.get("writers")) { |result| result["writers"] }
end