testrail-ruby 0.0.27 → 0.0.28

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 928183b23034905ff5b66c5a8aa1f6ce5635ecd8
4
- data.tar.gz: 802c7abb8fe7766de441ba64fbcc0083e2d47299
3
+ metadata.gz: bfc411c67bb3d1920e59b1523435c7cd105c7b02
4
+ data.tar.gz: f73f7dcbccc7f16ede17c3657c0dc5ddec6dbdc5
5
5
  SHA512:
6
- metadata.gz: a601eec402e070a1322282b6bf262a2f94c625aaf49b7ff9aa3ccc1548d575e635a92cbf41f6f5e76e59c16863d3ca189cb22f2c427b1f469c907f11f37d1abe
7
- data.tar.gz: 4f820237599e4b8f86db03a5841f91bccf572b32eb60e9faa6df0912a0026fc604a906df2a945706c86af655df94dffdefac138e6517462cb614959608d8c8b1
6
+ metadata.gz: d3c037e5e711b9eeed531a6e2fd6b82629b2cf218eb6d16716c09a7eb7064e44d1cecd9baa469fdc14959c7b67264fff8c9c148a175743a7e31c9e8879f8ec6b
7
+ data.tar.gz: 4b88dce3fb1bf394bc497eeed5158103a7361b74545cc9ecdbeca53d7cea313d454def42514b99b74ba5c3f12b452a69a4865cbb1cd1ffbaa74f59909afbc590
data/lib/endpoints.rb CHANGED
@@ -1,493 +1,673 @@
1
1
  module Endpoints
2
+ ##########################++
3
+ ####get_case################
4
+ ############################
2
5
  # Returns an existing test case
3
6
  # @param case_id [int] The id of the test case you want.
4
- # @param [Hash] opts
5
- # @example Endpoint
6
- # index.php?/api/v2/get_case/:case_id
7
+ # @example Code Example
8
+ # @client.get_case(1)
9
+ # @example Endpoint Example
10
+ # GET index.php?/api/v2/get_case/1
11
+ # @example Response Example
12
+ # {
13
+ # "created_by": 5,
14
+ # "created_on": 1392300984,
15
+ # "custom_expected": "..",
16
+ # "custom_preconds": "..",
17
+ # "custom_steps": "..",
18
+ # "custom_steps_separated": [
19
+ # {
20
+ # "content": "Step 1",
21
+ # "expected": "Expected Result 1"
22
+ # },
23
+ # {
24
+ # "content": "Step 2",
25
+ # "expected": "Expected Result 2"
26
+ # }
27
+ # ],
28
+ # "estimate": "1m 5s",
29
+ # "estimate_forecast": null,
30
+ # "id": 1,
31
+ # "milestone_id": 7,
32
+ # "priority_id": 2,
33
+ # "refs": "RF-1, RF-2",
34
+ # "section_id": 1,
35
+ # "suite_id": 1,
36
+ # "title": "Change document attributes (author, title, organization)",
37
+ # "type_id": 4,
38
+ # "updated_by": 1,
39
+ # "updated_on": 1393586511
40
+ # }
7
41
  # @see http://docs.gurock.com/testrail-api2/reference-cases
8
- def get_case(case_id, opts = nil)
9
- send_get("get_case/#{case_id}", opts)
42
+ def get_case(case_id)
43
+ send_get("get_case/#{case_id}")
10
44
  end
11
45
 
46
+ ##########################++
47
+ ####get_cases###############
48
+ ############################
12
49
  # Returns a list of test cases for a test suite or specific section in a test suite.
13
50
  # @param project_id [int] The id of the project that contains your tests
14
51
  # @param [Hash] opts
15
- # @example Endpoint
16
- # index.php?/api/v2/get_cases/:project_id
52
+ # @option opts [int] :suite_id The ID of the test suite (optional if the project is operating in single suite mode)
53
+ # @option opts [int] :section_id The ID of the section (optional)
54
+ # @option opts [unix timestamp] :created_after Only return test cases created after this date (as UNIX timestamp).
55
+ # @option opts [unix timestamp] :created_before Only return test cases created before this date (as UNIX timestamp).
56
+ # @option opts [int(list)] :created_by A comma-separated list of creators (user IDs) to filter by.
57
+ # @option opts [int(list)] :milestone_id A comma-separated list of milestone IDs to filter by (not available if the milestone field is disabled for the project).
58
+ # @option opts [int(list)] :priority_id A comma-separated list of priority IDs to filter by.
59
+ # @option opts [int(list)] :template_id A comma-separated list of template IDs to filter by (requires TestRail 5.2 or later)
60
+ # @option opts [int(list)] :type_id A comma-separated list of case type IDs to filter by.
61
+ # @option opts [unix timestamp] :updated_after Only return test cases updated after this date (as UNIX timestamp).
62
+ # @option opts [unix timestamp] :updated_before Only return test cases updated before this date (as UNIX timestamp).
63
+ # @option opts [int(list)] :updated_by A comma-separated list of users who updated test cases to filter by.
64
+ # @example Code Example
65
+ # @client.get_cases(1, {"suite_id":1, "section_id":1})
66
+ # @example Endpoint Example
67
+ # GET index.php?/api/v2/get_cases/1&suite_id=1&section_id=1
68
+ # @example Response Example
69
+ # [
70
+ # { "id": 1, "title": "..", .. },
71
+ # { "id": 2, "title": "..", .. },
72
+ # ..
73
+ # ]
17
74
  # @see http://docs.gurock.com/testrail-api2/reference-cases
18
75
  def get_cases(project_id, opts = {})
19
76
  options = opts.to_a.map { |x| "#{x[0]}=#{x[1]}" }.join("&")
20
- send_get("get_cases/#{project_id.to_s}&#{options}", opts)
21
- end
22
-
23
- # Return all test cases in a given project by suite_id and section_id
24
- # @param project_id [int] The id of the project that contains your tests
25
- # @param suite_id [int] The id of the suite within the project
26
- # @param section_id [int] The id of the section within the suite
27
- # @param [Hash] opts
28
- # @example Endpoint
29
- # index.php?/api/v2/get_cases/:project_id&suite_id=:suite_id&section_id=:section_id
30
- # @see http://docs.gurock.com/testrail-api2/reference-cases
31
- def get_cases_by_section(project_id, suite_id, section_id, opts = {})
32
- send_get("get_cases/:#{project_id.to_s}&suite_id=:#{suite_id.to_s}&section_id=:#{section_id.to_s}", opts)
33
- end
34
-
35
- # Return all test cases in a given project by suite_id
36
- # @param project_id [int] The id of the project that contains your tests
37
- # @param suite_id [int] The id of the suite within the project
38
- # @param [Hash] opts
39
- # @example Endpoint
40
- # index.php?/api/v2/get_cases/:project_id&suite_id=:suite_id
41
- # @see http://docs.gurock.com/testrail-api2/reference-cases
42
- def get_cases_by_suite(project_id, suite_id, opts = {})
43
- send_get("get_cases/:#{project_id.to_s}&suite_id=:#{suite_id.to_s}", opts)
77
+ send_get("get_cases/#{project_id.to_s}&#{options}")
44
78
  end
45
79
 
80
+ ############################
81
+ ####add_case################
82
+ ############################
46
83
  # Creates a new test case
47
84
  # @param section_id [int] The id of the test case
48
85
  # @param [Hash] opts
49
- # @example Endpoint
50
- # index.php?/api/v2/add_case/:section_id
86
+ # @option opts [string] :title The title of the test case (required)
87
+ # @option opts [int] :template_id The ID of the template (field layout) (requires TestRail 5.2 or later)
88
+ # @option opts [int] :type_id The ID of the case type
89
+ # @option opts [int] :priority_id The ID of the case priority
90
+ # @option opts [timespan] :estimate The estimate, e.g. "30s" or "1m 45s"
91
+ # @option opts [int] :milestone_id The ID of the milestone to link to the test case
92
+ # @option opts [string] :refs A comma-separated list of references/requirements
93
+ # @example Code Example
94
+ # @client.add_case(1, {"title":"testCaseName", "type_id":1})
95
+ # @example Endpoint Example
96
+ # index.php?/api/v2/add_case/1&title="foo"&type_id=1
51
97
  # @see http://docs.gurock.com/testrail-api2/reference-cases
52
98
  def add_case(section_id, opts = {})
53
- send_post("add_case/:#{section_id.to_s}", opts)
99
+ send_post("add_case/#{section_id.to_s}", opts)
54
100
  end
55
101
 
102
+ ############################
103
+ ####update_case#############
104
+ ############################
56
105
  # Update test result by case id
57
106
  # @param case_id [int] The id of the test case
58
107
  # @param [Hash] opts
59
- # @example Endpoint
108
+ # @example Endpoint Example
60
109
  # index.php?/api/v2/update_case/:case_id
61
110
  # @see http://docs.gurock.com/testrail-api2/reference-cases
62
111
  def update_case(case_id, opts = {})
63
112
  send_post("update_case/:#{case_id.to_s}", opts)
64
113
  end
65
114
 
115
+ ############################
116
+ ####delete_case################
117
+ ############################
66
118
  # Delete test case by case id
67
119
  # @param case_id [int] The id of the test case
68
120
  # @param [Hash] opts
69
- # @example Endpoint
121
+ # @example Endpoint Example
70
122
  # index.php?/api/v2/delete_case/:case_id
71
123
  # @see http://docs.gurock.com/testrail-api2/reference-cases
72
124
  def delete_case(case_id, opts = {})
73
125
  send_post("delete_case/:#{case_id.to_s}", opts)
74
126
  end
75
127
 
128
+ ############################
129
+ ####get_suite###############
130
+ ############################
76
131
  # Return suite by suite id
77
132
  # @param suite_id [int] The suite id
78
133
  # @param [Hash] opts
79
- # @example Endpoint
134
+ # @example Endpoint Example
80
135
  # index.php?/api/v2/get_suite/:suite_id
81
136
  # @see http://docs.gurock.com/testrail-api2/reference-suites
82
137
  def get_suite(suite_id, opts = {})
83
138
  send_get("get_suite/:#{suite_id.to_s}", opts)
84
139
  end
85
140
 
141
+ ############################
142
+ ####get_suites##############
143
+ ############################
86
144
  # Return all suites in project by project id
87
- # @param project_id [int] The id of the project containing suites
145
+ # @param project_id (see get_cases)
88
146
  # @param [Hash] opts
89
- # @example Endpoint
147
+ # @example Endpoint Example
90
148
  # index.php?/api/v2/get_suites/:project_id
91
149
  # @see http://docs.gurock.com/testrail-api2/reference-suites
92
150
  def get_suites(project_id, opts = {})
93
151
  send_get("get_suites/:#{project_id.to_s}", opts)
94
152
  end
95
153
 
154
+ ############################
155
+ ####add_suite###############
156
+ ############################
96
157
  # Add a test suite
97
158
  # @param project_id [int] The id of the project containing suites
98
159
  # @param [Hash] opts
99
- # @example Endpoint
160
+ # @example Endpoint Example
100
161
  # index.php?/api/v2/add_suite/:project_id
101
162
  # @see http://docs.gurock.com/testrail-api2/reference-suites
102
163
  def add_suite(project_id, opts = {})
103
164
  send_post("add_suite/:#{project_id.to_s}", opts)
104
165
  end
105
166
 
167
+ ############################
168
+ ####update_suite############
169
+ ############################
106
170
  # update a test suite
107
171
  # @param suite_id [int] The suite id
108
172
  # @param [Hash] opts
109
- # @example Endpoint
173
+ # @example Endpoint Example
110
174
  # index.php?/api/v2/update_suite/:suite_id
111
175
  # @see http://docs.gurock.com/testrail-api2/reference-suites
112
176
  def update_suite(suite_id, opts = {})
113
177
  send_post("update_suite/:#{suite_id.to_s}", opts)
114
178
  end
115
179
 
180
+ ############################
181
+ ####delete_suite############
182
+ ############################
116
183
  # Delete a test suite
117
184
  # @param suite_id [int] The suite id
118
185
  # @param [Hash] opts
119
- # @example Endpoint
186
+ # @example Endpoint Example
120
187
  # index.php?/api/v2/delete_suite/:suite_id
121
188
  # @see http://docs.gurock.com/testrail-api2/reference-suites
122
189
  def delete_suite(suite_id, opts = {})
123
190
  send_post("delete_suite/:#{suite_id.to_s}", opts)
124
191
  end
125
192
 
193
+
194
+ ############################
195
+ ####get_section#############
196
+ ############################
126
197
  # Return section by id
127
198
  # @param section_id [int]
128
199
  # @param [Hash] opts
129
- # @example Endpoint
200
+ # @example Endpoint Example
130
201
  # index.php?/api/v2/get_section/:section_id
131
202
  # @see http://docs.gurock.com/testrail-api2/reference-sections
132
203
  def get_section(section_id, opts = {})
133
204
  send_get("get_section/:#{section_id.to_s}", opts)
134
205
  end
135
206
 
207
+ ############################
208
+ ####get_sections############
209
+ ############################
136
210
  # Get sections for suite
137
211
  # @param suite_id [int]
138
212
  # @param [Hash] opts
139
- # @example Endpoint
213
+ # @example Endpoint Example
140
214
  # index.php?/api/v2/get_sections/:project_id&suite_id=:suite_id
141
215
  # @see http://docs.gurock.com/testrail-api2/reference-sections
142
216
  def get_sections(project_id, suite_id, opts = {})
143
- send_get("get_sections/#{project_id.to_s}&suite_id=#{suite_id.to_s}", opts)
217
+ send_get("get_sections/#{project_id.to_s}&suite_id=#{suite_id.to_s}")
144
218
  end
145
219
 
220
+ ############################
221
+ ####add_section#############
222
+ ############################
146
223
  # Add section to suite
147
224
  # @param project_id [int]
148
225
  # @param [Hash] opts
149
226
  # @option opts [Int] suite_id
150
227
  # @option opts [String] name
151
228
  # @option opts [Int] parent_id
152
- # @example Endpoint
229
+ # @example Endpoint Example
153
230
  # index.php?/api/v2/add_section/:project_id
154
- # @example Code
231
+ # @example Code Example
155
232
  # @client.add_section(1, {"suite_id": 5, "name": "This is a new section", "parent_id": 10})
156
233
  # @see http://docs.gurock.com/testrail-api2/reference-sections
157
234
  def add_section(project_id, opts = {})
158
235
  send_post("add_section/#{project_id.to_s}", opts)
159
236
  end
160
237
 
238
+ ############################
239
+ ####get_milestone###########
240
+ ############################
161
241
  # Get milestone by milestone id
162
242
  # @param milestone_id [int]
163
243
  # @param [Hash] opts
164
- # @example Endpoint
244
+ # @example Endpoint Example
165
245
  # index.php?/api/v2/get_milestone/:milestone_id
166
246
  # @see http://docs.gurock.com/testrail-api2/reference-milestones
167
247
  def get_milestone(milestone_id, opts = {})
168
248
  send_get("get_milestone/:#{milestone_id.to_s}", opts)
169
249
  end
170
250
 
251
+ ############################
252
+ ####get_milestones##########
253
+ ############################
171
254
  # Get project milestones by project id
172
255
  # @param project_id [int]
173
256
  # @param [Hash] opts
174
- # @example Endpoint
257
+ # @example Endpoint Example
175
258
  # index.php?/api/v2/get_milestones/:project_id
176
259
  # @see http://docs.gurock.com/testrail-api2/reference-milestones
177
260
  def get_milestones(project_id, opts = {})
178
261
  send_get("get_milestones/:#{project_id.to_s}", opts)
179
262
  end
180
263
 
264
+ ############################
265
+ ####add_milestone###########
266
+ ############################
181
267
  # Add milestone to project id
182
268
  # @param project_id [int]
183
269
  # @param [Hash] opts
184
- # @example Endpoint
270
+ # @example Endpoint Example
185
271
  # index.php?/api/v2/add_milestone/:project_id
186
272
  # @see http://docs.gurock.com/testrail-api2/reference-milestones
187
273
  def add_milestone(project_id, opts = {})
188
274
  send_post("add_milestone/:#{project_id.to_s}", opts)
189
275
  end
190
276
 
277
+ ############################
278
+ ####update_milestone########
279
+ ############################
191
280
  # Add milestone to project id
192
281
  # @param milestone_id [int]
193
282
  # @param [Hash] opts
194
- # @example Endpoint
283
+ # @example Endpoint Example
195
284
  # index.php?/api/v2/update_milestone/:milestone_id
196
285
  # @see http://docs.gurock.com/testrail-api2/reference-milestones
197
286
  def update_milestone(milestone_id, opts = {})
198
287
  send_post("update_milestone/:#{milestone_id.to_s}", opts)
199
288
  end
200
289
 
290
+ ############################
291
+ ####delete_milestone########
292
+ ############################
201
293
  # Add milestone to project id
202
294
  # @param milestone_id [int]
203
295
  # @param [Hash] opts
204
- # @example Endpoint
296
+ # @example Endpoint Example
205
297
  # index.php?/api/v2/delete_milestone/:milestone_id
206
298
  # @see http://docs.gurock.com/testrail-api2/reference-milestones
207
299
  def delete_milestone(milestone_id, opts = {})
208
300
  send_post("delete_milestone/:#{milestone_id.to_s}", opts)
209
301
  end
210
302
 
303
+ ############################
304
+ ####get_plan################
305
+ ############################
211
306
  # Get plan by id
212
307
  # @param plan_id [int]
213
308
  # @param [Hash] opts
214
- # @example Endpoint
309
+ # @example Endpoint Example
215
310
  # index.php?/api/v2/get_plan/:plan_id
216
311
  # @see http://docs.gurock.com/testrail-api2/reference-plans
217
312
  def get_plan(plan_id, opts = {})
218
313
  send_get("get_plan/:#{plan_id.to_s}", opts)
219
314
  end
220
315
 
316
+ ############################
317
+ ####get_plans###############
318
+ ############################
221
319
  # Get plans in project by project id
222
320
  # @param project_id [int]
223
321
  # @param [Hash] opts
224
- # @example Endpoint
322
+ # @example Endpoint Example
225
323
  # index.php?/api/v2/get_plans/:project_id
226
324
  # @see http://docs.gurock.com/testrail-api2/reference-plans
227
325
  def get_plans(project_id, opts = {})
228
326
  send_get("get_plans/:#{project_id.to_s}", opts)
229
327
  end
230
328
 
329
+ ############################
330
+ ####add_plan################
331
+ ############################
231
332
  # Add plan to project by project id
232
333
  # @param project_id [int]
233
334
  # @param [Hash] opts
234
- # @example Endpoint
335
+ # @example Endpoint Example
235
336
  # index.php?/api/v2/add_plan/:project_id
236
337
  # @see http://docs.gurock.com/testrail-api2/reference-plans
237
338
  def add_plan(project_id, opts = {})
238
339
  send_post("add_plan/:#{project_id.to_s}", opts)
239
340
  end
240
341
 
342
+ ############################
343
+ ####add_plan_entry##########
344
+ ############################
241
345
  # Add plan entries by plan id
242
346
  # @param plan_id [int]
243
347
  # @param [Hash] opts
244
- # @example Endpoint
348
+ # @example Endpoint Example
245
349
  # index.php?/api/v2/add_plan_entry/:plan_id
246
350
  # @see http://docs.gurock.com/testrail-api2/reference-plans
247
351
  def add_plan_entry(plan_id, opts = {})
248
352
  send_post("add_plan_entry/:#{plan_id.to_s}", opts)
249
353
  end
250
354
 
355
+ ############################
356
+ ####update_plan#############
357
+ ############################
251
358
  # Update plan by plan id
252
359
  # @param plan_id [int]
253
360
  # @param [Hash] opts
254
- # @example Endpoint
361
+ # @example Endpoint Example
255
362
  # index.php?/api/v2/update_plan/:plan_id
256
363
  # @see http://docs.gurock.com/testrail-api2/reference-plans
257
364
  def update_plan(plan_id, opts = {})
258
365
  send_post("update_plan/:#{plan_id.to_s}", opts)
259
366
  end
260
367
 
368
+ ############################
369
+ ####update_plan_entry#######
370
+ ############################
261
371
  # Update plan entry by plan id
262
372
  # @param plan_id [int]
263
373
  # @param entry_id [int] Id of entry
264
374
  # @param [Hash] opts
265
- # @example Endpoint
375
+ # @example Endpoint Example
266
376
  # index.php?/api/v2/update_plan_entry/:plan_id/:entry_id
267
377
  # @see http://docs.gurock.com/testrail-api2/reference-plans
268
378
  def update_plan_entry(plan_id, entry_id, opts = {})
269
379
  send_post("update_plan_entry/:#{plan_id.to_s}/:#{entry_id.to_s}", opts)
270
380
  end
271
381
 
382
+ ############################
383
+ ####close_plan##############
384
+ ############################
272
385
  # Close plan by plan id
273
386
  # @param plan_id [int]
274
387
  # @param [Hash] opts
275
- # @example Endpoint
388
+ # @example Endpoint Example
276
389
  # index.php?/api/v2/close_plan/:plan_id
277
390
  # @see http://docs.gurock.com/testrail-api2/reference-plans
278
391
  def close_plan(plan_id, opts = {})
279
392
  send_post("close_plan/:#{plan_id.to_s}", opts)
280
393
  end
281
394
 
282
- # @example Endpoint
395
+ ############################
396
+ ####delete_plan#############
397
+ ############################
398
+ # @example Endpoint Example
283
399
  # index.php?/api/v2/delete_plan/:plan_id
284
400
  # @see http://docs.gurock.com/testrail-api2/reference-plans
285
401
  def delete_plan(plan_id, opts)
286
402
  send_post("delete_plan/:#{plan_id.to_s}", opts)
287
403
  end
288
404
 
289
- # @example Endpoint
405
+ ############################
406
+ ####delete_plan_by_entry####
407
+ ############################
408
+ # @example Endpoint Example
290
409
  # index.php?/api/v2/delete_plan_entry/:plan_id/:entry_id
291
410
  def delete_plan_entry(plan_id, entry_id, opts = {})
292
411
  send_post("delete_plan_entry/:#{plan_id.to_s}/:#{entry_id.to_s}", opts)
293
412
  end
294
413
 
414
+ ############################
415
+ ####get_project#############
416
+ ############################
295
417
  # Get project by project id
296
418
  # @param project_id [int]
297
419
  # @param [Hash] opts
298
- # @example Endpoint
420
+ # @example Endpoint Example
299
421
  # index.php?/api/v2/get_project/:project_id
300
422
  # @see http://docs.gurock.com/testrail-api2/reference-projects
301
423
  def get_project(project_id, opts = {})
302
- send_get("get_project/:#{project_id.to_s}", opts)
424
+ options = opts.to_a.map { |x| "#{x[0]}=#{x[1]}" }.join("&")
425
+ send_get("get_project/#{project_id.to_s}&#{options}")
303
426
  end
304
427
 
428
+ ############################
429
+ ####get_projects############
430
+ ############################
305
431
  # Get all projects
306
432
  # @param [Hash] opts
307
- # @example Endpoint
433
+ # @example Endpoint Example
308
434
  # index.php?/api/v2/get_projects
309
435
  # @see http://docs.gurock.com/testrail-api2/reference-projects
310
436
  def get_projects(opts = {})
311
- send_get('get_projects', opts)
437
+ options = opts.to_a.map { |x| "#{x[0]}=#{x[1]}" }.join("&")
438
+ send_get("get_projects&#{options}")
312
439
  end
313
440
 
441
+ ############################
442
+ ####add_project#############
443
+ ############################
314
444
  # Add a project
315
445
  # @param [Hash] opts
316
- # @example Endpoint
446
+ # @example Endpoint Example
317
447
  # index.php?/api/v2/add_project
318
448
  # @see http://docs.gurock.com/testrail-api2/reference-projects
319
449
  def add_project(opts = {})
320
450
  send_post("add_project", opts)
321
451
  end
322
452
 
453
+ ############################
454
+ ####update_project##########
455
+ ############################
323
456
  # Update a project
324
457
  # @param project_id [int] The project you want to update
325
458
  # @param [Hash] opts
326
- # @example Endpoint
459
+ # @example Endpoint Example
327
460
  # index.php?/api/v2/update_project/:project_id
328
461
  # @see http://docs.gurock.com/testrail-api2/reference-projects
329
462
  def update_project(project_id, opts)
330
463
  send_post("update_project/:#{project_id.to_s}", opts)
331
464
  end
332
465
 
333
-
466
+ ############################
467
+ ####delete_project##########
468
+ ############################
334
469
  # Delete a project
335
470
  # @param project_id [int] The project you want to delete
336
471
  # @param [Hash] opts
337
- # @example Endpoint
472
+ # @example Endpoint Example
338
473
  # index.php?/api/v2/delete_project/:project_id
339
474
  # @see http://docs.gurock.com/testrail-api2/reference-projects
340
475
  def delete_project(project_id, opts)
341
476
  send_post("delete_project/:#{project_id.to_s}", opts)
342
477
  end
343
478
 
479
+ ############################
480
+ ####get_results#############
481
+ ############################
344
482
  # Returns a list of test results for a test
345
483
  # @param test_id [int]
346
484
  # @param [Hash] opts
347
- # @example Endpoint
485
+ # @example Endpoint Example
348
486
  # index.php?/api/v2/get_results/:test_id
349
487
  # @see http://docs.gurock.com/testrail-api2/reference-results
350
488
  def get_results(test_id, opts = {})
351
489
  send_get("get_results/:#{test_id.to_s}", opts)
352
490
  end
353
491
 
492
+ ############################
493
+ ####get_results_for_case####
494
+ ############################
354
495
  # Returns a list of test results for a test run and case combination
355
496
  # @param run_id [int]
356
497
  # @param case_id [int]
357
498
  # @param [Hash] opts
358
- # @example Endpoint
499
+ # @example Endpoint Example
359
500
  # index.php?/api/v2/get_results_for_case/:run_id/:case_id
360
501
  # @see http://docs.gurock.com/testrail-api2/reference-results
361
502
  def get_results_for_case(run_id, case_id, opts = {})
362
503
  send_get("get_results_for_case/:#{run_id.to_s}/:#{case_id.to_s}", opts)
363
504
  end
364
505
 
506
+ ############################
507
+ ####get_results_for_run#####
508
+ ############################
365
509
  # Returns a list of test results for a test run
366
510
  # @param run_id [int]
367
511
  # @param [Hash] opts
368
- # @example Endpoint
512
+ # @example Endpoint Example
369
513
  # index.php?/api/v2/get_results_for_run/:run_id
370
514
  # @see http://docs.gurock.com/testrail-api2/reference-results
371
515
  def get_results_for_run(run_id, opts = {})
372
516
  send_get("get_results_for_run/:#{run_id.to_s}", opts)
373
517
  end
374
518
 
519
+ ############################
520
+ ####add_result##############
521
+ ############################
375
522
  # Adds a new test result, comment or assigns a test. It's recommended to use add_results instead if you plan to add results for multiple tests.
376
523
  # @param test_id [int]
377
524
  # @param [Hash] opts
378
- # @example Endpoint
525
+ # @example Endpoint Example
379
526
  # index.php?/api/v2/add_result/:test_id
380
527
  # @see http://docs.gurock.com/testrail-api2/reference-results
381
528
  def add_result(test_id, opts = {})
382
529
  send_post("add_result/:#{test_id.to_s}", opts)
383
530
  end
384
531
 
532
+ ############################
533
+ ####add_result_for_case#####
534
+ ############################
385
535
  # Adds a new test result, comment or assigns a test (for a test run and case combination)
386
536
  # @param run_id [int]
387
537
  # @param case_id [int]
388
538
  # @param [Hash] opts
389
- # @example Endpoint
539
+ # @example Endpoint Example
390
540
  # index.php?/api/v2/add_result_for_case/:run_id/:case_id
391
541
  # @see http://docs.gurock.com/testrail-api2/reference-results
392
542
  def add_result_for_case(run_id, case_id, opts = {})
393
543
  send_post("add_result_for_case/:#{run_id.to_s}/:#{case_id.to_s}", opts)
394
544
  end
395
545
 
546
+ ############################
547
+ ####add_results#############
548
+ ############################
396
549
  # Adds one or more new test results, comments or assigns one or more tests
397
550
  # @param run_id [int]
398
551
  # @param [Hash] opts
399
- # @example Endpoint
552
+ # @example Endpoint Example
400
553
  # index.php?/api/v2/add_results/:run_id
401
554
  # @see http://docs.gurock.com/testrail-api2/reference-results
402
555
  def add_results(run_id, opts = {})
403
556
  send_post("add_results/:#{run_id.to_s}", opts)
404
557
  end
405
558
 
559
+ ############################
560
+ ####add_results_for_cases###
561
+ ############################
406
562
  # Adds one or more new test results, comments or assigns one or more tests (using the case IDs)
407
563
  # @param run_id [int]
408
564
  # @param [Hash] opts
409
- # @example Endpoint
565
+ # @example Endpoint Example
410
566
  # index.php?/api/v2/add_results_for_cases/:run_id
411
567
  # @see http://docs.gurock.com/testrail-api2/reference-results
412
568
  def add_results_for_cases(run_id, opts = {})
413
569
  send_post("add_results_for_cases/:#{run_id.to_s}", opts)
414
570
  end
415
571
 
572
+ ############################
573
+ ####get_run#################
574
+ ############################
416
575
  # Get run by run id
417
576
  # @param run_id [int]
418
577
  # @param [Hash] opts
419
- # @example Endpoint
578
+ # @example Endpoint Example
420
579
  # index.php?/api/v2/get_run/:run_id
421
580
  # @see http://docs.gurock.com/testrail-api2/reference-runs
422
581
  def get_run(run_id, opts = {})
423
582
  send_get("get_run/:#{run_id.to_s}", opts)
424
583
  end
425
584
 
585
+ ############################
586
+ ####get_runs################
587
+ ############################
426
588
  # Get runs by project id
427
589
  # @param project_id [int]
428
590
  # @param plan_id [int]
429
591
  # @param [Hash] opts
430
- # @example Endpoint
592
+ # @example Endpoint Example
431
593
  # index.php?/api/v2/get_runs/:project_id
432
594
  # @see http://docs.gurock.com/testrail-api2/reference-runs
433
595
  def get_runs(project_id, opts = {})
434
596
  send_get("get_runs/#{project_id.to_s}", opts)
435
597
  end
436
598
 
599
+ ############################
600
+ ####add_run#################
601
+ ############################
437
602
  # Add run by suite id
438
603
  # @param project_id [int]
439
604
  # @param [Hash] opts
440
- # @example Endpoint
605
+ # @example Endpoint Example
441
606
  # index.php?/api/v2/add_run/:project_id
442
607
  # @see http://docs.gurock.com/testrail-api2/reference-runs
443
608
  def add_run(project_id, opts = {})
444
609
  send_post("add_run/:#{project_id.to_s}", opts)
445
610
  end
446
611
 
612
+ ############################
613
+ ####update_run##############
614
+ ############################
447
615
  # Updates existing test run
448
616
  # @param run_id [int]
449
617
  # @param [Hash] opts
450
- # @example Endpoint
618
+ # @example Endpoint Example
451
619
  # index.php?/api/v2/update_run/:run_id
452
620
  # @see http://docs.gurock.com/testrail-api2/reference-runs
453
621
  def update_run(run_id, opts = {})
454
622
  send_post("update_run/:#{run_id.to_s}", opts)
455
623
  end
456
624
 
625
+ ############################
626
+ ####close_run###############
627
+ ############################
457
628
  # Closes an existing test run and archives its tests & results
458
629
  # @param run_id [int]
459
630
  # @param [Hash] opts
460
- # @example Endpoint
631
+ # @example Endpoint Example
461
632
  # index.php?/api/v2/close_run/:run_id
462
633
  # @see http://docs.gurock.com/testrail-api2/reference-runs
463
634
  def close_run(run_id, opts = {})
464
635
  send_post("close_run/#{run_id.to_s}", opts)
465
636
  end
466
637
 
638
+ ############################
639
+ ####delete_run##############
640
+ ############################
467
641
  # Deletes an existing test run.
468
642
  # @param run_id [int]
469
643
  # @param [Hash] opts
470
- # @example Endpoint
644
+ # @example Endpoint Example
471
645
  # index.php?/api/v2/delete_run/:run_id
472
646
  # @see http://docs.gurock.com/testrail-api2/reference-runs
473
647
  def delete_run(run_id, opts = {})
474
648
  send_post("delete_run/:#{run_id.to_s}", opts)
475
649
  end
476
650
 
651
+ ############################
652
+ ####get_test################
653
+ ############################
477
654
  # Returns an existing test
478
655
  # @param test_id [int]
479
656
  # @param [Hash] opts
480
- # @example Endpoint
657
+ # @example Endpoint Example
481
658
  # index.php?/api/v2/get_test/:test_id
482
659
  # @see http://docs.gurock.com/testrail-api2/reference-tests
483
660
  def get_test(test_id, opts = {})
484
661
  send_get("get_test/:#{test_id.to_s}", opts)
485
662
  end
486
663
 
664
+ ############################
665
+ ####get_tests###############
666
+ ############################
487
667
  # Returns a list of tests for a test run
488
668
  # @param run_id [int]
489
669
  # @param [Hash] opts
490
- # @example Endpoint
670
+ # @example Endpoint Example
491
671
  # index.php?/api/v2/get_tests/:run_id
492
672
  # @see http://docs.gurock.com/testrail-api2/reference-tests
493
673
  def get_tests(run_id, opts = {})
@@ -0,0 +1,85 @@
1
+ require_relative 'version'
2
+ require_relative 'endpoints'
3
+ require 'net/http'
4
+ require 'net/https'
5
+ require 'uri'
6
+ require 'json'
7
+
8
+ ## #USAGE:
9
+ ## #@client = TestRail::APIClient.new('YourBaseURLHere')
10
+ ## #@client.user = 'UserName'
11
+ ## #@client.password = 'Password'
12
+
13
+ module TestRail
14
+ class APIClient
15
+ @url = ''
16
+ @user = ''
17
+ @password = ''
18
+
19
+ include Endpoints
20
+ attr_accessor :user
21
+ attr_accessor :password
22
+
23
+ def initialize(base_url)
24
+ base_url += '/' unless base_url =~ /\/$/
25
+ @url = base_url + 'index.php?/api/v2/'
26
+ end
27
+
28
+ def send_get(uri, data)
29
+ puts "Getting: #{uri}"
30
+ puts "Sending Data: #{data}"
31
+ _send_request('GET', uri, data)
32
+ end
33
+
34
+ def send_post(uri, data)
35
+ puts "Posting: #{uri}"
36
+ puts "Sending Data: #{data}"
37
+ _send_request('POST', uri, data)
38
+ end
39
+
40
+ private
41
+
42
+ def _send_request(method, uri, data)
43
+ url = URI.parse(@url + uri)
44
+ puts "URL: #{url}"
45
+ puts "url.query: #{url.query}"
46
+ puts "Data Payload: #{data}"
47
+ if method == 'POST'
48
+ request = Net::HTTP::Post.new(url.path + '?' + url.query)
49
+ request.body = JSON.dump(data)
50
+ else
51
+ request = Net::HTTP::Get.new(url.path + '?' + url.query)
52
+ end
53
+ request.basic_auth(@user, @password)
54
+ request.add_field('Content-Type', 'application/json')
55
+
56
+ conn = Net::HTTP.new(url.host, url.port)
57
+ if url.scheme == 'https'
58
+ conn.use_ssl = true
59
+ conn.verify_mode = OpenSSL::SSL::VERIFY_NONE
60
+ end
61
+ response = conn.request(request)
62
+
63
+ result = if response.body && !response.body.empty?
64
+ JSON.parse(response.body)
65
+ else
66
+ {}
67
+ end
68
+
69
+ if response.code != '200'
70
+ error = if result && result.key?('error')
71
+ '"' + result['error'] + '"'
72
+ else
73
+ 'No additional error message received'
74
+ end
75
+ raise APIError, 'TestRail API returned HTTP %s (%s)' %
76
+ [response.code, error]
77
+ end
78
+
79
+ result
80
+ end
81
+ end
82
+
83
+ class APIError < StandardError
84
+ end
85
+ end
data/lib/testrail-ruby.rb CHANGED
@@ -21,21 +21,36 @@ module TestRail
21
21
  attr_accessor :password
22
22
 
23
23
  def initialize(base_url)
24
- base_url += '/' unless base_url =~ /\/$/
24
+ if !base_url.match(/\/$/)
25
+ base_url += '/'
26
+ end
25
27
  @url = base_url + 'index.php?/api/v2/'
26
28
  end
27
29
 
28
- def send_get(uri, data)
29
- _send_request('GET', uri, data)
30
+ def send_get(uri)
31
+ _send_request('GET', uri)
30
32
  end
31
33
 
34
+ #
35
+ # Send POST
36
+ #
37
+ # Issues a POST request (write) against the API and returns the result
38
+ # (as Ruby hash).
39
+ #
40
+ # Arguments:
41
+ #
42
+ # uri The API method to call including parameters
43
+ # (e.g. add_case/1)
44
+ # data The data to submit as part of the request (as
45
+ # Ruby hash, strings must be UTF-8 encoded)
46
+ #
32
47
  def send_post(uri, data)
33
48
  _send_request('POST', uri, data)
34
49
  end
35
50
 
36
51
  private
37
52
 
38
- def _send_request(method, uri, data)
53
+ def _send_request(method, uri, data = {})
39
54
  url = URI.parse(@url + uri)
40
55
  puts "URL: #{url}"
41
56
  if method == 'POST'
@@ -54,20 +69,20 @@ module TestRail
54
69
  end
55
70
  response = conn.request(request)
56
71
 
57
- result = if response.body && !response.body.empty?
58
- JSON.parse(response.body)
59
- else
60
- {}
61
- end
72
+ if response.body && !response.body.empty?
73
+ result = JSON.parse(response.body)
74
+ else
75
+ result = {}
76
+ end
62
77
 
63
78
  if response.code != '200'
64
- error = if result && result.key?('error')
65
- '"' + result['error'] + '"'
66
- else
67
- 'No additional error message received'
68
- end
69
- raise APIError, 'TestRail API returned HTTP %s (%s)' %
70
- [response.code, error]
79
+ if result && result.key?('error')
80
+ error = '"' + result['error'] + '"'
81
+ else
82
+ error = 'No additional error message received'
83
+ end
84
+ raise APIError.new('TestRail API returned HTTP %s (%s)' %
85
+ [response.code, error])
71
86
  end
72
87
 
73
88
  result
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Testrail
2
- VERSION = '0.0.27'.freeze
2
+ VERSION = '0.0.28'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: testrail-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.27
4
+ version: 0.0.28
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frances Morales
@@ -105,6 +105,7 @@ files:
105
105
  - README.md
106
106
  - Rakefile
107
107
  - lib/endpoints.rb
108
+ - lib/testrail-ruby-broken.rb
108
109
  - lib/testrail-ruby.rb
109
110
  - lib/version.rb
110
111
  - spec/spec_helper.rb