keboola-gooddata-writer 2.0.0.pre1 → 2.0.0.pre2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 85346de59e1ea53f6e4ba5e15629accc9ca519d5
4
- data.tar.gz: 11eed840a3b3f0d4dcf741fb289b988f4183e853
3
+ metadata.gz: 02ad328c3cd45c30b12d4c72f99cd41b1c1c4a3c
4
+ data.tar.gz: 2d169017e12b85b1bc938b4d0754cc7ac0bbd012
5
5
  SHA512:
6
- metadata.gz: 58927fffa6fb30be7bc722dfd76ab0e37e544f5f81d3967170ab7ed0268c380b1750eea3b895e58b97f9df6f252eb2a5bd45d0a550afedc88ac647c204f025b4
7
- data.tar.gz: f7409cd5e031b9d94f30e478e5a4e6d6d8bec50d35726f2bd9e315852a07813ea7cb1d860469f6d569c239e553cb0b4aa797dbaf3354bca9d534c97c75f1988c
6
+ metadata.gz: 87d630793b782adbab07fae2d77810849eef82ce72bd1dc2509831b720b1e213c8e10860477ad545ffbefc5175c150d4c42c3e16a348ecf3175699d064cf13ca
7
+ data.tar.gz: a3741e0fc43ca669d5786fae1444d9eb7277054b67492d6a9979fe1814cc59ab82e90e754ecebfe24ce00397085a2507b7070ca5364e449b6bc3553ccfed71c2
data/README.md CHANGED
@@ -4,12 +4,12 @@
4
4
  [![Coverage](http://img.shields.io/codeclimate/coverage/github/romansklenar/gooddata-writer-ruby-client.svg?style=flat-square)](https://codeclimate.com/github/romansklenar/gooddata-writer-ruby-client)
5
5
  [![Build](http://img.shields.io/travis-ci/romansklenar/gooddata-writer-ruby-client.svg?style=flat-square)](https://travis-ci.org/romansklenar/gooddata-writer-ruby-client)
6
6
  [![Dependencies](http://img.shields.io/gemnasium/romansklenar/gooddata-writer-ruby-client.svg?style=flat-square)](https://gemnasium.com/romansklenar/gooddata-writer-ruby-client)
7
- [![Downloads](http://img.shields.io/gem/dtv/gooddata-writer-ruby-client.svg?style=flat-square)](https://rubygems.org/gems/gooddata-writer-ruby-client)
8
7
  [![Tags](http://img.shields.io/github/tag/romansklenar/gooddata-writer-ruby-client.svg?style=flat-square)](http://github.com/romansklenar/gooddata-writer-ruby-client/tags)
9
8
  [![Releases](http://img.shields.io/github/release/romansklenar/gooddata-writer-ruby-client.svg?style=flat-square)](http://github.com/romansklenar/gooddata-writer-ruby-client/releases)
10
9
  [![Issues](http://img.shields.io/github/issues/romansklenar/gooddata-writer-ruby-client.svg?style=flat-square)](http://github.com/romansklenar/gooddata-writer-ruby-client/issues)
11
10
  [![License](http://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](http://opensource.org/licenses/MIT)
12
- [![Version](http://img.shields.io/gem/v/gooddata-writer-ruby-client.svg?style=flat-square)](https://rubygems.org/gems/gooddata-writer-ruby-client)
11
+ [![Downloads](http://img.shields.io/gem/dtv/gooddata-writer-ruby-client.svg?style=flat-square)](https://rubygems.org/gems/keboola-gooddata-writer)
12
+ [![Version](http://img.shields.io/gem/v/gooddata-writer-ruby-client.svg?style=flat-square)](https://rubygems.org/gems/keboola-gooddata-writer)
13
13
 
14
14
 
15
15
  Simple Ruby wrapper library for [Keboola GoodData Writer REST API](http://docs.keboolagooddatawriter.apiary.io/).
@@ -45,13 +45,13 @@ api.writer('MyWriter') # {"bucket"=>"sys.c-wr-gooddata-writer1", "writer"=>"good
45
45
  api.create_project('MyWriter', optionals: { name: 'KBC - MyProject - MyWriter' }) # <Keboola::GoodDataWriter::Job url="https://syrup.keboola.com/queue/jobs/123456", id="123456">
46
46
 
47
47
  # create user
48
- api.create_user('MyWriter', 'john.snow@test.keboola.com', 't0pS3cr3t', 'John', 'Snow') # <Keboola::GoodDataWriter::Job url="https://syrup.keboola.com/queue/jobs/123456", id="123456">
48
+ api.create_user('MyWriter', 'jon.snow@test.keboola.com', 't0pS3cr3t', 'Jon', 'Snow') # <Keboola::GoodDataWriter::Job url="https://syrup.keboola.com/queue/jobs/123456", id="123456">
49
49
 
50
50
  # assign user to existing GoodData project
51
- api.add_project_users('MyWriter', 'xjywplmhejceb6j3ezzlxiganmjavqio', 'john.snow@test.keboola.com', 'editor') #<Keboola::GoodDataWriter::Job url="https://syrup.keboola.com/queue/jobs/123456", id="123456">
51
+ api.add_project_users('MyWriter', 'xjywplmhejceb6j3ezzlxiganmjavqio', 'jon.snow@test.keboola.com', 'editor') #<Keboola::GoodDataWriter::Job url="https://syrup.keboola.com/queue/jobs/123456", id="123456">
52
52
 
53
53
  # getretreive GoodData SSO link
54
- api.sso('MyWriter', 'xjywplmhejceb6j3ezzlxiganmjavqio', 'john.snow@test.keboola.com') # "https://secure.gooddata.com/gdc/account/customerlogin?sessionId=-----BEGIN+PGP+MESSAGE-----s0m3_l0000n6_h4sh"
54
+ api.sso('MyWriter', 'xjywplmhejceb6j3ezzlxiganmjavqio', 'jon.snow@test.keboola.com') # "https://secure.gooddata.com/gdc/account/customerlogin?sessionId=-----BEGIN+PGP+MESSAGE-----s0m3_l0000n6_h4sh"
55
55
  ```
56
56
 
57
57
  ## Development
@@ -17,8 +17,9 @@ Gem::Specification.new do |spec|
17
17
 
18
18
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
19
  spec.require_paths = ["lib"]
20
+ spec.required_ruby_version = '>= 2.0.0'
20
21
 
21
- spec.add_development_dependency "bundler", "~> 1.8"
22
+ spec.add_development_dependency "bundler", ">= 1.7.0"
22
23
  spec.add_development_dependency "rake", "~> 10.0"
23
24
  spec.add_development_dependency "minitest", "~> 5.7"
24
25
  spec.add_development_dependency "webmock"
@@ -10,14 +10,14 @@ module Keboola
10
10
  attr_accessor :token, :client, :queue, :parser
11
11
 
12
12
 
13
- def initialize(token:, endpoint: nil, client: nil, queue: nil, parser: nil)
14
- @token = token
13
+ def initialize(token: nil, endpoint: nil, client: nil, queue: nil, parser: nil)
14
+ @token = token || raise(ArgumentError, "token is required")
15
15
  @client = client || self.class.build_client(endpoint: endpoint || WRITER_ENDPOINT_URL, token: token)
16
16
  @queue = queue || self.class.build_client(endpoint: QUEUE_ENDPOINT_URL, token: token)
17
17
  @parser = parser || self.class.build_parser
18
18
  end
19
19
 
20
- def self.build_client(token:, endpoint:)
20
+ def self.build_client(token: nil, endpoint: nil)
21
21
  Client.factory(token: token, endpoint: endpoint)
22
22
  end
23
23
 
@@ -30,38 +30,29 @@ module Keboola
30
30
 
31
31
  # Returns list of available writers and their buckets
32
32
  def writers
33
- handle @client.get("writers") do |result|
34
- result["writers"]
35
- end
33
+ handle(@client.get("writers")) { |result| result["writers"] }
36
34
  end
37
35
 
38
36
  # Returns attributes of the writer
39
37
  def writer(writer_id)
40
- handle @client.get("writers", { writerId: writer_id }) do |result|
41
- result["writers"].first rescue result["writer"]
42
- end
38
+ handle(@client.get("writers", { writerId: writer_id })) { |result| result["writers"].first rescue result["writer"] }
43
39
  end
44
40
 
45
41
  # Creates new configuration bucket and either uses existing GoodData
46
42
  # project or creates new one along with dedicated GoodData user.
47
43
  def create_writer(writer_id, optionals: {}, async: true)
48
- handle @client.post("writers", { writerId: writer_id }.reverse_merge(optionals).to_json) do |result|
49
- async ? Job.new(result) : wait_for_job(result["id"])
50
- end
44
+ params = { writerId: writer_id }.reverse_merge(optionals)
45
+ handle(@client.post("writers", params.to_json)) { |result| job_handler(result, async) }
51
46
  end
52
47
 
53
48
  # Sets attributes to writer's configuration
54
49
  def update_writer(writer_id, attributes: {})
55
- handle @client.post("writers/#{writer_id}", attributes.to_json) do |result|
56
- Job.new(result).ok?
57
- end
50
+ handle(@client.post("writers/#{writer_id}", attributes.to_json)) { |result| job_handler(result).ok? }
58
51
  end
59
52
 
60
53
  # Deletes configuration bucket and enqueues GoodData project and dedicated GoodData user for removal
61
54
  def delete_writer(writer_id, async: true)
62
- handle @client.delete("writers", { writerId: writer_id }) do |result|
63
- async ? Job.new(result) : wait_for_job(result["id"])
64
- end
55
+ handle(@client.delete("writers", { writerId: writer_id })) { |result| job_handler(result, async) }
65
56
  end
66
57
 
67
58
 
@@ -69,31 +60,26 @@ module Keboola
69
60
 
70
61
  # Returns list of project clones including main project marked with main: 1 field
71
62
  def projects(writer_id)
72
- handle @client.get("projects", { writerId: writer_id }) do |result|
73
- result["projects"]
74
- end
63
+ handle(@client.get("projects", { writerId: writer_id })) { |result| result["projects"] }
75
64
  end
76
65
 
77
66
  # Creates new configuration bucket and either uses existing GoodData
78
67
  # project or creates new one along with dedicated GoodData user.
79
68
  def create_project(writer_id, optionals: {}, async: true)
80
- handle @client.post("projects", { writerId: writer_id }.reverse_merge(optionals).to_json) do |result|
81
- async ? Job.new(result) : wait_for_job(result["id"])
82
- end
69
+ params = { writerId: writer_id }.reverse_merge(optionals)
70
+ handle(@client.post("projects", params.to_json)) { |result| job_handler(result, async) }
83
71
  end
84
72
 
85
73
  # Creates new GoodData project for the writer and enqueues the old for deletion
86
74
  def reset_project(writer_id, optionals: {}, async: true)
87
- handle @client.post("reset-project", { writerId: writer_id }.reverse_merge(optionals).to_json) do |result|
88
- async ? Job.new(result) : wait_for_job(result["id"])
89
- end
75
+ params = { writerId: writer_id }.reverse_merge(optionals)
76
+ handle(@client.post("reset-project", params.to_json)) { |result| job_handler(result, async) }
90
77
  end
91
78
 
92
79
  # Upload project to GoodData
93
80
  def upload_project(writer_id, optionals: {}, async: true)
94
- handle @client.post("upload-project", { writerId: writer_id }.reverse_merge(optionals).to_json) do |result|
95
- async ? Job.new(result) : wait_for_job(result["id"])
96
- end
81
+ params = { writerId: writer_id }.reverse_merge(optionals)
82
+ handle(@client.post("upload-project", params.to_json)) { |result| job_handler(result, async) }
97
83
  end
98
84
 
99
85
 
@@ -101,17 +87,13 @@ module Keboola
101
87
 
102
88
  # Get users list
103
89
  def users(writer_id)
104
- handle @client.get("users", { writerId: writer_id }) do |result|
105
- result["users"]
106
- end
90
+ handle(@client.get("users", { writerId: writer_id })) { |result| result["users"] }
107
91
  end
108
92
 
109
93
  # Creates new GoodData user in Keboola domain.
110
94
  def create_user(writer_id, email, password, first_name, last_name, optionals: {}, async: true)
111
- required = { writerId: writer_id, email: email, password: password, firstName: first_name, lastName: last_name }
112
- handle @client.post("users", required.reverse_merge(optionals).to_json) do |result|
113
- async ? Job.new(result) : wait_for_job(result["id"])
114
- end
95
+ params = { writerId: writer_id, email: email, password: password, firstName: first_name, lastName: last_name }.reverse_merge(optionals)
96
+ handle(@client.post("users", params.to_json)) { |result| job_handler(result, async) }
115
97
  end
116
98
 
117
99
 
@@ -119,24 +101,19 @@ module Keboola
119
101
 
120
102
  # Get list of users in project
121
103
  def project_users(writer_id, project_id)
122
- handle @client.get("project-users", { writerId: writer_id, pid: project_id }) do |result|
123
- result["users"]
124
- end
104
+ handle(@client.get("project-users", { writerId: writer_id, pid: project_id })) { |result| result["users"] }
125
105
  end
126
106
 
127
107
  # Adds GoodData user to specified project.
128
108
  def add_project_users(writer_id, project_id, email, role, optionals: {}, async: true)
129
- required = { writerId: writer_id, pid: project_id, email: email, role: role }
130
- handle @client.post("project-users", required.reverse_merge(optionals).to_json) do |result|
131
- async ? Job.new(result) : wait_for_job(result["id"])
132
- end
109
+ params = { writerId: writer_id, pid: project_id, email: email, role: role }.reverse_merge(optionals)
110
+ handle(@client.post("project-users", params.to_json)) { |result| job_handler(result, async) }
133
111
  end
134
112
 
135
113
  # Remove user from specified project.
136
114
  def remove_project_users(writer_id, project_id, email, async: true)
137
- handle @client.delete("project-users", { writerId: writer_id, pid: project_id, email: email }) do |result|
138
- async ? Job.new(result) : wait_for_job(result["id"])
139
- end
115
+ params = { writerId: writer_id, pid: project_id, email: email }
116
+ handle(@client.delete("project-users", params)) { |result| job_handler(result, async) }
140
117
  end
141
118
 
142
119
 
@@ -144,66 +121,55 @@ module Keboola
144
121
 
145
122
  # Get tables list
146
123
  def tables(writer_id)
147
- handle @client.get("tables", { writerId: writer_id }) do |result|
148
- result["tables"]
149
- end
124
+ handle(@client.get("tables", { writerId: writer_id })) { |result| result["tables"] }
150
125
  end
151
126
 
152
127
  # Get table detail
153
128
  def table(writer_id, table_id)
154
- handle @client.get("tables", { writerId: writer_id, tableId: table_id }) do |result|
155
- result["tables"].first rescue result["table"]
156
- end
129
+ handle(@client.get("tables", { writerId: writer_id, tableId: table_id })) { |result| result["tables"].first rescue result["table"] }
157
130
  end
158
131
 
159
132
  # Update table configuration
160
133
  def update_table(writer_id, table_id, optionals: {})
161
- handle @client.post("tables", { writerId: writer_id, tableId: table_id }.reverse_merge(optionals).to_json) do |result|
162
- Job.new(result).ok?
163
- end
134
+ params = { writerId: writer_id, tableId: table_id }.reverse_merge(optionals)
135
+ handle(@client.post("tables", params.to_json)) { |result| job_handler(result).ok? }
164
136
  end
165
137
 
166
138
  # Update table column configuration
167
139
  def update_table_column(writer_id, table_id, column, optionals: {})
168
- handle @client.post("tables", { writerId: writer_id, tableId: table_id, column: column }.reverse_merge(optionals).to_json) do |result|
169
- Job.new(result).ok?
170
- end
140
+ params = { writerId: writer_id, tableId: table_id, column: column }.reverse_merge(optionals)
141
+ handle(@client.post("tables", params.to_json)) { |result| job_handler(result).ok? }
171
142
  end
172
143
 
173
144
  # Bulk update table column configuration
174
145
  def bulk_update_table_column(writer_id, table_id, columns = [])
175
- handle @client.post("tables", { writerId: writer_id, tableId: table_id, columns: columns }.to_json) do |result|
176
- Job.new(result).ok?
177
- end
146
+ params = { writerId: writer_id, tableId: table_id, columns: columns }
147
+ handle(@client.post("tables", params.to_json)) { |result| job_handler(result).ok? }
178
148
  end
179
149
 
180
150
  # Upload selected table to GoodData
181
151
  def upload_table(writer_id, table_id, optionals: {}, async: true)
182
- handle @client.post("upload-table", { writerId: writer_id, tableId: table_id }.reverse_merge(optionals).to_json) do |result|
183
- async ? Job.new(result) : wait_for_job(result["id"])
184
- end
152
+ params = { writerId: writer_id, tableId: table_id }.reverse_merge(optionals)
153
+ handle(@client.post("upload-table", params.to_json)) { |result| job_handler(result, async) }
185
154
  end
186
155
 
187
156
  # Update model of selected table in GoodData
188
157
  def update_table_model(writer_id, optionals: {}, async: true)
189
- handle @client.post("update-model", { writerId: writer_id }.reverse_merge(optionals).to_json) do |result|
190
- async ? Job.new(result) : wait_for_job(result["id"])
191
- end
158
+ params = { writerId: writer_id }.reverse_merge(optionals)
159
+ handle(@client.post("update-model", params.to_json)) { |result| job_handler(result, async) }
192
160
  end
193
161
  alias_method :update_model, :update_table_model
194
162
 
195
163
  # Remove dataset in GoodData project belonging to the table and reset it's export status
196
164
  def reset_table(writer_id, table_id, optionals: {}, async: true)
197
- handle @client.post("reset-table", { writerId: writer_id, tableId: table_id }.reverse_merge(optionals).to_json) do |result|
198
- async ? Job.new(result) : wait_for_job(result["id"])
199
- end
165
+ params = { writerId: writer_id, tableId: table_id }.reverse_merge(optionals)
166
+ handle(@client.post("reset-table", params.to_json)) { |result| job_handler(result, async) }
200
167
  end
201
168
 
202
169
  # Selectively upload date dimension (must be already configured in Writer)
203
170
  def upload_date_dimension(writer_id, name, optionals: {}, async: true)
204
- handle @client.post("reset-table", { writerId: writer_id, name: name }.reverse_merge(optionals).to_json) do |result|
205
- async ? Job.new(result) : wait_for_job(result["id"])
206
- end
171
+ params = { writerId: writer_id, name: name }.reverse_merge(optionals)
172
+ handle(@client.post("reset-table", params.to_json)) { |result| job_handler(result, async) }
207
173
  end
208
174
 
209
175
 
@@ -211,37 +177,30 @@ module Keboola
211
177
 
212
178
  # Load data to selected tables in GoodData
213
179
  def load_data(writer_id, optionals: {}, async: true)
214
- handle @client.post("load-data", { writerId: writer_id }.reverse_merge(optionals).to_json) do |result|
215
- async ? Job.new(result) : wait_for_job(result["id"])
216
- end
180
+ params = { writerId: writer_id }.reverse_merge(optionals)
181
+ handle(@client.post("load-data", params.to_json)) { |result| job_handler(result, async) }
217
182
  end
218
183
 
219
184
  # Load data to selected tables in GoodData concurrently
220
185
  def load_data_multi(writer_id, optionals: {}, async: true)
221
- handle @client.post("load-data-multi", { writerId: writer_id }.reverse_merge(optionals).to_json) do |result|
222
- async ? Job.new(result) : wait_for_job(result["id"])
223
- end
186
+ params = { writerId: writer_id }.reverse_merge(optionals)
187
+ handle(@client.post("load-data-multi", params.to_json)) { |result| job_handler(result, async) }
224
188
  end
225
189
 
226
190
  # === Filter resource
227
191
 
228
192
  def filters(writer_id, optionals: {})
229
- handle @client.get("filters", { writerId: writer_id }.reverse_merge(optionals)) do |result|
230
- result["filters"]
231
- end
193
+ params = { writerId: writer_id }.reverse_merge(optionals)
194
+ handle(@client.get("filters", params)) { |result| result["filters"] }
232
195
  end
233
196
 
234
197
  def create_filter(writer_id, project_id, name, attribute, value, operator = '=', optionals: {}, async: true)
235
- required = { writerId: writer_id, pid: project_id, name: name, attribute: attribute, operator: operator, value: value }
236
- handle @client.post("filters", required.reverse_merge(optionals).to_json) do |result|
237
- async ? Job.new(result) : wait_for_job(result["id"])
238
- end
198
+ params = { writerId: writer_id, pid: project_id, name: name, attribute: attribute, operator: operator, value: value }.reverse_merge(optionals)
199
+ handle(@client.post("filters", params.to_json)) { |result| job_handler(result, async) }
239
200
  end
240
201
 
241
202
  def delete_filter(writer_id, name, async: true)
242
- handle @client.delete("filters", { writerId: writer_id, name: name }) do |result|
243
- async ? Job.new(result) : wait_for_job(result["id"])
244
- end
203
+ handle(@client.delete("filters", { writerId: writer_id, name: name })) { |result| job_handler(result, async) }
245
204
  end
246
205
 
247
206
 
@@ -249,31 +208,26 @@ module Keboola
249
208
 
250
209
  # Get Filters for Projects
251
210
  def filters_projects(writer_id, optionals: {})
252
- handle @client.get("filters-projects", { writerId: writer_id }.reverse_merge(optionals)) do |result|
253
- result["filters"]
254
- end
211
+ params = { writerId: writer_id }.reverse_merge(optionals)
212
+ handle(@client.get("filters-projects", params)) { |result| result["filters"] }
255
213
  end
256
214
 
257
215
  # Get Filters for Users
258
216
  def filters_users(writer_id, optionals: {})
259
- handle @client.get("filters-users", { writerId: writer_id }.reverse_merge(optionals)) do |result|
260
- result["filters"]
261
- end
217
+ params = { writerId: writer_id }.reverse_merge(optionals)
218
+ handle(@client.get("filters-users", params)) { |result| result["filters"] }
262
219
  end
263
220
 
264
221
  # Assign Filter to User
265
222
  def assign_filters_users(writer_id, email, filters = [], optionals: {}, async: true)
266
- required = { writerId: writer_id, email: email, filters: filters }
267
- handle @client.post("filters-users", required.reverse_merge(optionals).to_json) do |result|
268
- async ? Job.new(result) : wait_for_job(result["id"])
269
- end
223
+ params = { writerId: writer_id, email: email, filters: filters }.reverse_merge(optionals)
224
+ handle(@client.post("filters-users", params.to_json)) { |result| job_handler(result, async) }
270
225
  end
271
226
 
272
227
  # Synchronizes filters in GoodData project according to writer's configuration
273
228
  def sync_filters(writer_id, optionals: {}, async: true)
274
- handle @client.post("sync-filters", { writerId: writer_id }.reverse_merge(optionals).to_json) do |result|
275
- async ? Job.new(result) : wait_for_job(result["id"])
276
- end
229
+ params = { writerId: writer_id }.reverse_merge(optionals)
230
+ handle(@client.post("sync-filters", params.to_json)) { |result| job_handler(result, async) }
277
231
  end
278
232
 
279
233
 
@@ -281,28 +235,28 @@ module Keboola
281
235
 
282
236
  # Execute selected reports in GoodData
283
237
  def execute_reports(writer_id, project_id, optionals: {}, async: true)
284
- handle @client.post("execute-reports", { writerId: writer_id, pid: project_id }.reverse_merge(optionals).to_json) do |result|
285
- async ? Job.new(result) : wait_for_job(result["id"])
286
- end
238
+ params = { writerId: writer_id, pid: project_id }.reverse_merge(optionals)
239
+ handle(@client.post("execute-reports", params.to_json)) { |result| job_handler(result, async) }
287
240
  end
288
241
 
289
242
  # Call to obtain an SSO link for user
290
243
  def sso(writer_id, project_id, email, optionals: {})
291
- handle @client.get("sso", { writerId: writer_id, pid: project_id, email: email }.reverse_merge(optionals)) do |result|
292
- result["ssoLink"]
293
- end
244
+ params = { writerId: writer_id, pid: project_id, email: email }.reverse_merge(optionals)
245
+ handle(@client.get("sso", params)) { |result| result["ssoLink"] }
294
246
  end
295
247
 
296
248
  # Simple proxy for direct calls to GoodData API
297
249
  def proxy(method, writer_id, query, optionals: {}, async: true)
298
- required = { writerId: writer_id, query: query }
250
+ params = { writerId: writer_id, query: query }.reverse_merge(optionals)
299
251
  case method.to_sym
300
252
  when :get
301
- handle @client.get("proxy", required.reverse_merge(optionals))
302
- when :post
303
- handle @client.post("proxy", required.reverse_merge(optionals).to_json) do |result|
304
- async ? Job.new(result) : wait_for_job(result["id"])
253
+ if block_given?
254
+ handle(@client.get("proxy", params)) { |result| yield result }
255
+ else
256
+ handle(@client.get("proxy", params))
305
257
  end
258
+ when :post
259
+ handle(@client.post("proxy", params.to_json)) { |result| job_handler(result, async) }
306
260
  end
307
261
  end
308
262
 
@@ -311,16 +265,12 @@ module Keboola
311
265
 
312
266
  # Return list of jobs for given writer
313
267
  def jobs(writer_id)
314
- handle @queue.get("jobs", { q: "+params.writerId:#{writer_id}", limit: 50 }) do |result|
315
- result.map { |hash| Job.new(hash) }
316
- end
268
+ handle(@queue.get("jobs", { q: "+params.writerId:#{writer_id}", limit: 50 })) { |result| result.map { |hash| job_handler(hash) } }
317
269
  end
318
270
 
319
271
  # Return detail of given job
320
272
  def job(job_id)
321
- handle @queue.get("jobs/#{job_id}") do |result|
322
- Job.new(result)
323
- end
273
+ handle(@queue.get("jobs/#{job_id}")) { |result| job_handler(result) }
324
274
  end
325
275
 
326
276
  # Ask repeatedly for job status until it is finished
@@ -335,8 +285,12 @@ module Keboola
335
285
 
336
286
  private
337
287
 
288
+ def job_handler(result, async = true)
289
+ async ? Job.new(result) : wait_for_job(result["id"])
290
+ end
291
+
338
292
  # Properly handle response of API call request
339
- def handle(response)
293
+ def handle(response, &handler)
340
294
  result = case response.status_type
341
295
  when :success # Is this a 2xx response?
342
296
  @parser.parse(response.body)
@@ -354,7 +308,7 @@ module Keboola
354
308
  raise ResponseError.new(response)
355
309
  end
356
310
 
357
- block_given? ? yield(result) : result
311
+ handler.nil? ? result : handler.call(result)
358
312
 
359
313
  rescue ::Hurley::Error, ::Hurley::Timeout => e
360
314
  raise ResponseError.new(e)
@@ -4,12 +4,16 @@ module Keboola
4
4
  module GoodDataWriter
5
5
 
6
6
  class Client < ::Hurley::Client
7
- def self.factory(endpoint:, token:)
7
+ def self.factory(endpoint: nil, token: nil)
8
+ endpoint || raise(ArgumentError, "endpoint is required")
9
+ token || raise(ArgumentError, "token is required")
10
+
8
11
  client = new(endpoint)
9
12
  client.header[:x_storageapi_token] = token
10
13
  client.header[:accept] = "application/json"
11
14
  client.request_options.redirection_limit = 5
12
15
  client.request_options.timeout = 5
16
+ client.ssl_options.skip_verification = true
13
17
  client
14
18
  end
15
19
  end
@@ -1,5 +1,5 @@
1
1
  module Keboola
2
2
  module GoodDataWriter
3
- VERSION = "2.0.0.pre1"
3
+ VERSION = "2.0.0.pre2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: keboola-gooddata-writer
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.pre1
4
+ version: 2.0.0.pre2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roman Sklenář
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-19 00:00:00.000000000 Z
11
+ date: 2015-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.8'
19
+ version: 1.7.0
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.8'
26
+ version: 1.7.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -160,7 +160,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
160
160
  requirements:
161
161
  - - ">="
162
162
  - !ruby/object:Gem::Version
163
- version: '0'
163
+ version: 2.0.0
164
164
  required_rubygems_version: !ruby/object:Gem::Requirement
165
165
  requirements:
166
166
  - - ">"