scaleapi 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3d36f009c1a892fb36bdd5125e5c52734c793d19
4
+ data.tar.gz: d250862fd65bbaa62f4e5abc66c76c9d5a6f13bb
5
+ SHA512:
6
+ metadata.gz: edd4b4b9a1b5f25f8753e227790d719843194acc282b2dd9f809d49bea548c2add22a983f4da43cdffccdfddca5c5361f9efc2d881b6e05beb6c755d27fb2a03
7
+ data.tar.gz: 01d59e8b137d2b60852b70799b44d610acd6c11b0f056d2dc74acfae643a4ff6aaa2260df647ff83aafca94465250338231e84cf503719f5f96d67500d71d9e5
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in scaleapi-ruby.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Jarred Sumner
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,573 @@
1
+ # Scale API
2
+ ![Scale API Logo](https://www.scaleapi.com/static/global/facebook-card.png)
3
+
4
+ This is the official Scale API RubyGem (`scaleapi`).
5
+
6
+ [Scale](https://www.scaleapi.com) is an API for Human Intelligence. Businesses like Alphabet (Google), Uber, Proctor & Gamble, Houzz, and many more use us to power tasks such as:
7
+ - Draw bounding boxes and label parts of images (to train ML algorithms for self-driving cars)
8
+ - Place phone calls
9
+ - Transcribe documents, images, and webpages
10
+ - Scrape websites
11
+ - Triage support tickets
12
+ - Categorize and compare images, documents, and webpages
13
+
14
+ Scale is actively hiring software engineers - [apply here](https://www.scaleapi.com/about#jobs).
15
+
16
+ ## Installation
17
+
18
+ Add this line to your application's Gemfile:
19
+
20
+ ```ruby
21
+ gem 'scaleapi'
22
+ ```
23
+
24
+ And then execute:
25
+
26
+ $ bundle
27
+
28
+ Or install it yourself as:
29
+
30
+ $ gem install scaleapi
31
+
32
+ ## Usage
33
+
34
+ First, initialize the Scale API client:
35
+
36
+ ```ruby
37
+ require 'scale'
38
+
39
+ scale = Scale.new(api_key: 'SCALE_API_KEY')
40
+ ```
41
+
42
+ Note that you can optionally provide a `callback_auth_key` and `callback_url` when initializing the Scale API client. You can also set `default_request_params` which is a `Hash` that will be included in every request sent to Scale (either as a query string param or part of the request body).
43
+
44
+ If you're having trouble finding your API Key or Callback Auth Key, then go to the [Scale Dashboard](https://dashboard.scaleapi.com). If you set a default `callback_url` in your account settings, you won't need to pass it in everytime.
45
+
46
+ ## Creating Tasks
47
+
48
+ This gem supports two ways of creating tasks. You can call `create_#{tasktype}_task` on the `scale` object or you can call `scale.tasks.create` and pass in the corresponding `type`. Upon success, it will return the appropriate object for that task type. Upon failure, it will raise an application-level error.
49
+
50
+ For every type of task, you can pass in the following options when creating:
51
+ - `callback_url`: a URL to send the webhook to upon completion. This is required when there is no default callback URL set when either initializing the `Scale` object or in your account settings.
52
+ - `urgency`: a string indicating how long the task should take, options are `immediate`, `day`, or `week`. The default is `day`.
53
+ - `metadata`: a `Hash` that contains anything you want in it. Use it for storing data relevant to that task, such as an internal ID for your application to associate the task with. Note that the keys of the `Hash` will be returned as `String` rather than `Symbol`.
54
+
55
+ ### Categoriation Tasks
56
+
57
+ To create a [categorization task](https://docs.scaleapi.com/#create-categorization-task), run the following:
58
+ ```ruby
59
+ require 'scale'
60
+ scale = Scale.new(api_key: 'SCALE_API_KEY')
61
+
62
+ scale.create_categorization_task({
63
+ callback_url: 'http://www.example.com/callback',
64
+ instruction: 'Is this company public or private?',
65
+ attachment_type: 'website',
66
+ attachment: 'https://www.google.com',
67
+ categories: ['public', 'private']
68
+ })
69
+ ```
70
+
71
+ Upon success, this will return a `Scale::Api::Tasks::Categorization` object. It will raise one of the [errors](#user-content-errors) if it's not successful.
72
+
73
+ Alternatively, you can also create a task this way
74
+ ```ruby
75
+ require 'scale'
76
+ scale = Scale.new(api_key: 'SCALE_API_KEY')
77
+
78
+ scale.tasks.create({
79
+ type: 'categorization',
80
+ callback_url: 'http://www.example.com/callback',
81
+ instruction: 'Is this company public or private?',
82
+ attachment_type: 'website',
83
+ attachment: 'https://www.google.com',
84
+ categories: ['public', 'private']
85
+ })
86
+ ```
87
+
88
+ This will also return a `Scale::Api::Tasks::Categorization` object.
89
+
90
+ [Read more about creating categorization tasks](https://docs.scaleapi.com/#create-categorization-task)
91
+
92
+ ### Comparison Tasks
93
+
94
+ To create a [comparison task](https://docs.scaleapi.com/#create-comparison-task), run the following:
95
+ ```ruby
96
+ require 'scale'
97
+ scale = Scale.new(api_key: 'SCALE_API_KEY')
98
+
99
+ scale.create_comparison_task({
100
+ callback_url: 'http://www.example.com/callback',
101
+ instruction: 'Do the objects in these images have the same pattern?',
102
+ attachments: [
103
+ 'http://i.ebayimg.com/00/$T2eC16dHJGwFFZKjy5ZjBRfNyMC4Ig~~_32.JPG',
104
+ 'http://images.wisegeek.com/checkered-tablecloth.jpg'
105
+ ],
106
+ attachment_type: 'image',
107
+ choices: ['yes', 'no']
108
+ })
109
+ ```
110
+
111
+ Upon success, this will return a `Scale::Api::Tasks::Comparison` object. If it fails, it will raise one of the [errors](#user-content-errors).
112
+
113
+ Alternatively, you can also create a task this way
114
+ ```ruby
115
+ require 'scale'
116
+ scale = Scale.new(api_key: 'SCALE_API_KEY')
117
+
118
+ scale.tasks.create({
119
+ type: 'comparison',
120
+ callback_url: 'http://www.example.com/callback',
121
+ instruction: 'Do the objects in these images have the same pattern?',
122
+ attachments: [
123
+ 'http://i.ebayimg.com/00/$T2eC16dHJGwFFZKjy5ZjBRfNyMC4Ig~~_32.JPG',
124
+ 'http://images.wisegeek.com/checkered-tablecloth.jpg'
125
+ ],
126
+ attachment_type: 'image',
127
+ choices: ['yes', 'no']
128
+ })
129
+ ```
130
+
131
+ This will also return a `Scale::Api::Tasks::Comparison` object.
132
+
133
+ [Read more about creating comparison tasks](https://docs.scaleapi.com/#create-comparison-task)
134
+
135
+ ### Datacollection Tasks
136
+
137
+ To create a [datacollection task](https://docs.scaleapi.com/#create-datacollection-task), run the following:
138
+ ```ruby
139
+ require 'scale'
140
+ scale = Scale.new(api_key: 'SCALE_API_KEY')
141
+
142
+ scale.create_datacollection_task({
143
+ callback_url: 'http://www.example.com/callback',
144
+ instruction: 'Find the URL for the hiring page for the company with attached website.',
145
+ attachment: 'https://www.scaleapi.com/',
146
+ attachment_type: 'website',
147
+ fields: {
148
+ hiring_page: 'Hiring Page URL'
149
+ }
150
+ })
151
+ ```
152
+
153
+ Upon success, this will return a `Scale::Api::Tasks::Datacollection` object. If it fails, it will raise one of the [errors](#user-content-errors).
154
+
155
+ Alternatively, you can also create a task this way
156
+ ```ruby
157
+ require 'scale'
158
+ scale = Scale.new(api_key: 'SCALE_API_KEY')
159
+
160
+ scale.tasks.create({
161
+ type: 'datacollection',
162
+ callback_url: 'http://www.example.com/callback',
163
+ instruction: 'Find the URL for the hiring page for the company with attached website.',
164
+ attachment: 'https://www.scaleapi.com/',
165
+ attachment_type: 'website',
166
+ fields: {
167
+ hiring_page: 'Hiring Page URL'
168
+ }
169
+ })
170
+ ```
171
+
172
+ This will also return a `Scale::Api::Tasks::Datacollection` object.
173
+
174
+ [Read more about creating datacollection tasks](https://docs.scaleapi.com/#create-data-collection-task)
175
+
176
+
177
+ ### Image Recognition Tasks
178
+
179
+ To create an [image recognition task](https://docs.scaleapi.com/#create-image-recognition-task), run the following:
180
+ ```ruby
181
+ require 'scale'
182
+ scale = Scale.new(api_key: 'SCALE_API_KEY')
183
+
184
+ scale.create_annotation_task({
185
+ callback_url: 'http://www.example.com/callback',
186
+ instruction: 'Draw a box around each **baby cow** and **big cow**',
187
+ attachment_type: 'image',
188
+ attachment: 'http://i.imgur.com/v4cBreD.jpg',
189
+ objects_to_annotate: ['baby cow', 'big cow'],
190
+ with_labels: true,
191
+ examples: [
192
+ {
193
+ correct: false,
194
+ image: 'http://i.imgur.com/lj6e98s.jpg',
195
+ explanation: 'The boxes are tight and accurate'
196
+ },
197
+ {
198
+ correct: true,
199
+ image: 'http://i.imgur.com/HIrvIDq.jpg',
200
+ explanation: 'The boxes are neither accurate nor complete'
201
+ }
202
+ ]
203
+ })
204
+ ```
205
+ Upon success, this will return a `Scale::Api::Tasks::ImageRecognition` object. If it fails, it will raise one of the [errors](
206
+ ).
207
+
208
+ Note: `create_annotation_task` is also aliased to `create_image_recognition_task`, to help avoid confusion.
209
+
210
+ Alternatively, you can also create a task this way
211
+ ```ruby
212
+ require 'scale'
213
+ scale = Scale.new(api_key: 'SCALE_API_KEY')
214
+
215
+ scale.tasks.create({
216
+ type: 'annotation',
217
+ callback_url: 'http://www.example.com/callback',
218
+ instruction: 'Draw a box around each **baby cow** and **big cow**',
219
+ attachment_type: 'image',
220
+ attachment: 'http://i.imgur.com/v4cBreD.jpg',
221
+ objects_to_annotate: ['baby cow', 'big cow'],
222
+ with_labels: true,
223
+ examples: [
224
+ {
225
+ correct: false,
226
+ image: 'http://i.imgur.com/lj6e98s.jpg',
227
+ explanation: 'The boxes are tight and accurate'
228
+ },
229
+ {
230
+ correct: true,
231
+ image: 'http://i.imgur.com/HIrvIDq.jpg',
232
+ explanation: 'The boxes are neither accurate nor complete'
233
+ }
234
+ ]
235
+ })
236
+ ```
237
+
238
+ This will also return a `Scale::Api::Tasks::ImageRecognition` object.
239
+
240
+ [Read more about creating image recognition tasks](https://docs.scaleapi.com/#create-image-recognition-task)
241
+
242
+ ### Phone Call Tasks
243
+
244
+ You can use this to have real people call other people! Isn't that cool?
245
+
246
+ To create a [phone call task](https://docs.scaleapi.com/#create-phone-call-task), run the following:
247
+ ```ruby
248
+ require 'scale'
249
+ scale = Scale.new(api_key: 'SCALE_API_KEY')
250
+
251
+ scale.create_phone_call_task({
252
+ callback_url: 'http://www.example.com/callback',
253
+ instruction: 'Call this person and follow the script provided, recording responses',
254
+ phone_number: '5055006865',
255
+ entity_name: 'Alexandr Wang',
256
+ script: 'Hello ! Are you happy today? (pause) One more thing - what is your email address?',
257
+ fields: {
258
+ email: 'Email Address',
259
+ },
260
+ choices: ['He is happy', 'He is not happy']
261
+ })
262
+ ```
263
+ Upon success, this will return a `Scale::Api::Tasks::PhoneCall` object. If it fails, it will raise one of the [errors](#user-content-errors).
264
+
265
+ Note: `create_phone_call_task` is also aliased to `create_phonecall_task`, to help avoid confusion.
266
+
267
+ Alternatively, you can also create a task this way
268
+ ```ruby
269
+ require 'scale'
270
+ scale = Scale.new(api_key: 'SCALE_API_KEY')
271
+
272
+ scale.tasks.create({
273
+ type: 'phonecall',
274
+ callback_url: 'http://www.example.com/callback',
275
+ instruction: 'Call this person and follow the script provided, recording responses',
276
+ phone_number: '5055006865',
277
+ entity_name: 'Alexandr Wang',
278
+ script: 'Hello ! Are you happy today? (pause) One more thing - what is your email address?',
279
+ fields: {
280
+ email: 'Email Address',
281
+ },
282
+ choices: ['He is happy', 'He is not happy']
283
+ })
284
+ ```
285
+
286
+ This will also return a `Scale::Api::Tasks::PhoneCall` object.
287
+
288
+ [Read more about creating phone call tasks](https://docs.scaleapi.com/#create-phone-call-task)
289
+
290
+
291
+ ### Transcription Tasks
292
+
293
+ To create a [transcription task](https://docs.scaleapi.com/#create-transcription-task), run the following:
294
+ ```ruby
295
+ require 'scale'
296
+ scale = Scale.new(api_key: 'SCALE_API_KEY')
297
+
298
+ scale.create_transcription_task({
299
+ callback_url: 'http://www.example.com/callback',
300
+ instruction: 'Transcribe the given fields.',
301
+ attachment_type: 'website',
302
+ attachment: 'http://news.ycombinator.com/',
303
+ fields: {
304
+ title: 'Title of Webpage',
305
+ top_result: 'Title of the top result'
306
+ }
307
+ })
308
+ ```
309
+ Upon success, this will return a `Scale::Api::Tasks::Transcription` object. If it fails, it will raise one of the [errors](#user-content-errors).
310
+
311
+ Alternatively, you can also create a task this way
312
+ ```ruby
313
+ require 'scale'
314
+ scale = Scale.new(api_key: 'SCALE_API_KEY')
315
+
316
+ scale.tasks.create({
317
+ type: 'transcription',
318
+ callback_url: 'http://www.example.com/callback',
319
+ instruction: 'Transcribe the given fields.',
320
+ attachment_type: 'website',
321
+ attachment: 'http://news.ycombinator.com/',
322
+ fields: {
323
+ title: 'Title of Webpage',
324
+ top_result: 'Title of the top result'
325
+ }
326
+ })
327
+ ```
328
+
329
+ This will also return a `Scale::Api::Tasks::Transcription` object.
330
+
331
+ [Read more about creating transcription tasks](https://docs.scaleapi.com/#create-transcription-task)
332
+
333
+
334
+ ### Audio Transcription Tasks
335
+
336
+ To create an [audio transcription task](https://docs.scaleapi.com/#create-audio-transcription-task), run the following:
337
+ ```ruby
338
+ require 'scale'
339
+ scale = Scale.new(api_key: 'SCALE_API_KEY')
340
+
341
+ scale.create_audiotranscription_task({
342
+ callback_url: 'http://www.example.com/callback',
343
+ attachment_type: 'audio',
344
+ attachment: 'https://storage.googleapis.com/deepmind-media/pixie/knowing-what-to-say/second-list/speaker-3.wav',
345
+ verbatim: false
346
+ })
347
+ ```
348
+
349
+ Upon success, this will return a `Scale::Api::Tasks::AudioTranscription` object. If it fails, it will raise one of the [errors](#user-content-errors).
350
+
351
+ Alternatively, you can also create a task this way
352
+ ```ruby
353
+ require 'scale'
354
+ scale = Scale.new(api_key: 'SCALE_API_KEY')
355
+
356
+ scale.tasks.create({
357
+ type: 'audiotranscription',
358
+ callback_url: 'http://www.example.com/callback',
359
+ attachment_type: 'audio',
360
+ attachment: 'https://storage.googleapis.com/deepmind-media/pixie/knowing-what-to-say/second-list/speaker-3.wav',
361
+ verbatim: false
362
+ })
363
+ ```
364
+
365
+ This will also return a `Scale::Api::Tasks::AudioTranscription` object.
366
+
367
+ [Read more about creating audio transcription tasks](https://docs.scaleapi.com/#create-audio-transcription-task)
368
+
369
+ ## Listing Tasks
370
+
371
+ To get a list of tasks, run the following command:
372
+
373
+ ```ruby
374
+ require 'scale'
375
+ scale = Scale.new(api_key: 'SCALE_API_KEY')
376
+
377
+ scale.tasks.list
378
+ ```
379
+
380
+ This will return a `Scale::Api::TaskList` object.
381
+
382
+ `Scale::Api::TaskList` implements `Enumerable`, meaning you can do fun stuff like this:
383
+
384
+ ```ruby
385
+ require 'scale'
386
+ scale = Scale.new(api_key: 'SCALE_API_KEY')
387
+
388
+ scale.tasks.list.map(&:id)
389
+ ```
390
+
391
+ This will return an array containing the last 100 tasks' `task_id`.
392
+
393
+ You can also access it like a normal array:
394
+ ```ruby
395
+ require 'scale'
396
+ scale = Scale.new(api_key: 'SCALE_API_KEY')
397
+
398
+ scale.tasks.list[0]
399
+ ```
400
+
401
+ This will return the appropriate Task object (or nil if empty).
402
+
403
+ You can filter this list by:
404
+ - `start_time` (which expects a `Time` object)
405
+ - `end_time` (which expects a `Time` object)
406
+ - `type` (which expects one of the [tasks types](#user-content-task-object))
407
+ - `status` (which expects a string which is either `completed`, `pending`, or `canceled`)
408
+
409
+ For example:
410
+
411
+ ```ruby
412
+ require 'scale'
413
+ scale = Scale.new(api_key: 'SCALE_API_KEY')
414
+
415
+ scale.tasks.list(end_time: Time.parse('January 20th, 2017'), status: 'completed')
416
+ ```
417
+
418
+ This will return a `Scale::Api::TaskList` object up to 100 tasks that were completed by January 20th, 2017.
419
+
420
+ By default, `scale.tasks.list` only returns up to 100 tasks, but you can pass in the `limit` yourself.
421
+
422
+ It also supports pagination, here's an example:
423
+
424
+ ```ruby
425
+ require 'scale'
426
+ scale = Scale.new(api_key: 'SCALE_API_KEY')
427
+
428
+ first_page = scale.tasks.list
429
+ second_page = first_page.next_page
430
+ ```
431
+
432
+ `Scale::Api::TaskList#next_page` returns the next page in the list of tasks (as a new `Scale::Api::TaskList`). You can see if there are more pages by calling `Scale::Api::TaskList#has_more?` on the object.
433
+
434
+ `scale.tasks.list` is aliased to `scale.tasks.where` and `scale.tasks.all`.
435
+
436
+ For more information, [read our documentation](https://docs.scaleapi.com/#list-all-tasks)
437
+
438
+ ## Finding tasks by ID
439
+
440
+ To find a task by ID, run the following:
441
+
442
+ ```ruby
443
+ require 'scale'
444
+ scale = Scale.new(api_key: 'SCALE_API_KEY')
445
+
446
+ task_id = 'TASK_ID'
447
+ scale.tasks.find(task_id)
448
+ ```
449
+
450
+ This will return the appropriate Scaler::Api::Tasks object based on the [task type](#task-types)
451
+
452
+ ## Canceling tasks
453
+
454
+ There are two ways to cancel a task.
455
+
456
+ Cancel by `task_id`:
457
+
458
+ ```ruby
459
+ require 'scale'
460
+ scale = Scale.new(api_key: 'SCALE_API_KEY')
461
+
462
+ task_id = 'TASK_ID'
463
+ scale.tasks.cancel(task_id)
464
+ ```
465
+
466
+ Cancel on the task object:
467
+
468
+ ```ruby
469
+ require 'scale'
470
+ scale = Scale.new(api_key: 'SCALE_API_KEY')
471
+
472
+ task_id = 'TASK_ID'
473
+ scale.tasks.find(task_id).cancel!
474
+ ```
475
+
476
+ Both ways will return a new [task object](#user-content-task-object) for the type, with the `status` set to `canceled` and calling `canceled?` on the task will return true.
477
+
478
+ ## Task Object
479
+
480
+ All tasks return a task object for their `type`. Currently, this gem supports the following task types:
481
+ - `categorization` (`Scale::Api::Tasks::Categorization`)
482
+ - `comparison` (`Scale::Api::Tasks::Comparison`)
483
+ - `datacollection` (`Scale::Api::Tasks::Datacollection`)
484
+ - `annotation` (`Scale::Api::Tasks::ImageRecognition`)
485
+ - `phonecall` (`Scale::Api::Tasks::PhoneCall`)
486
+ - `transcription` (`Scale::Api::Tasks::Transcription`)
487
+ - `audiotranscription` (`Scale::Api::Tasks::AudioTranscription`)
488
+
489
+ At the time of writing, this is every task type that Scale supports.
490
+
491
+ ### Convenience Methods
492
+
493
+ Every one of the task type objects has the following convenience (instance) methods:
494
+ - `day?`: returns `true` when a task's `urgency` is set to `day`
495
+ - `week?`: returns `true` when a task's `urgency` is set to `week`
496
+ - `immediate?`: returns `true` when a task's `urgency` is set to `immediate`
497
+ - `pending?`: returns `true` when a task's `status` is set to `pending`
498
+ - `completed?`: returns `true` when a task's `status` is set to `completed`
499
+ - `canceled?`: returns `true` when a task's `status` is set to `canceled`
500
+ - `callback_succeeded?`: returns `true` when the response from the callback was successful
501
+
502
+ You can also access all the properties of the task object directly, some examples:
503
+ ```ruby
504
+ irb(main):009:0> task.instruction
505
+ => "Find the URL for the hiring page for the company with attached website."
506
+ ```
507
+
508
+ ```ruby
509
+ irb(main):013:0> task.metadata
510
+ => {"bagel"=>true}
511
+ ```
512
+
513
+ ```ruby
514
+ irb(main):016:0> task.completed_at
515
+ => 2017-02-10 20:41:12 UTC
516
+ ```
517
+
518
+ ## Callbacks
519
+
520
+ This gem allows you to create and parse callback data, so it can be easily used for web applications:
521
+
522
+ For example, for Ruby on Rails:
523
+
524
+ ```ruby
525
+ # app/controllers/scale_api_controller.rb
526
+
527
+ require 'scale'
528
+
529
+ class ScaleApiController < ApplicationController
530
+ # POST /scale_api
531
+ def create
532
+ scale = Scale.new(api_key: 'SCALE_API_KEY', callback_auth_key: 'SCALE_CALLBACK_AUTH_KEY')
533
+
534
+ callback = scale.build_callback params, callback_key: request.headers['scale-callback-auth']
535
+ return render status: 403 unless callback.verified? # Render forbidden if verifying the callback fails
536
+
537
+ callback.response # Response content hash (code and result)
538
+ callback.task # Scale::Api::Tasks object for task type
539
+
540
+ end
541
+ end
542
+ ```
543
+
544
+ ## Errors
545
+
546
+ This gem will raise exceptions on application-level errors. Here are the list of errors:
547
+
548
+ ```ruby
549
+ Scale::Api::BadRequest
550
+ Scale::Api::TooManyRequests
551
+ Scale::Api::NotFound
552
+ Scale::Api::Unauthorized
553
+ Scale::Api::InternalServerError
554
+ Scale::Api::ConnectionError
555
+ Scale::Api::APIKeyInvalid
556
+ ```
557
+
558
+ ## Development
559
+
560
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
561
+
562
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `scaleapi-ruby.gemspec`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
563
+
564
+ ## Contributing
565
+
566
+ Bug reports and pull requests are welcome on GitHub at https://github.com/scaleapi/scaleapi-ruby.
567
+
568
+ Currently, this repository has no tests - and adding tests using RSpec would make a for a great PR :)
569
+
570
+ ## License
571
+
572
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
573
+