11# Skylab Studio Ruby Client
22
3- [ ![ CircleCI] ( https://circleci.com/gh/skylab-tech/studio_client_ruby.svg?style=svg )] ( https://circleci.com/gh/skylab-tech/studio_client_ruby )
4- [ ![ Maintainability] ( https://api.codeclimate.com/v1/badges/cd6f30ad2b05ecf2ce86/maintainability )] ( https://codeclimate.com/github/skylab-tech/studio_client_ruby/maintainability )
5- [ ![ Test Coverage] ( https://api.codeclimate.com/v1/badges/cd6f30ad2b05ecf2ce86/test_coverage )] ( https://codeclimate.com/github/skylab-tech/studio_client_ruby/test_coverage )
3+ A Ruby client for accessing the Skylab Studio service: [ http://studio.skylabtech.ai ] ( https://studio.skylabtech.ai )
64
7- A Ruby client for accessing the Skylab Studio service .
5+ For all payload options, consult the [ API documentation ] ( https://studio-docs.skylabtech.ai/#tag/job/operation/createJob ) .
86
9- [ studio.skylabtech.ai] ( https://studio.skylabtech.ai )
7+ ## Requirements
8+
9+ libvips is required to be installed on your machine in order to install skylab-studio (for pyvips).
10+
11+ - [ Libvips documentation] ( https://www.libvips.org/install.html )
1012
1113## Installation
1214
@@ -50,13 +52,55 @@ In your application code where you want to access Skylab API:
5052
5153``` ruby
5254begin
53- result = SkylabStudio ::Client .new .create_job(job: { profile_id: 123 })
55+ result = SkylabStudio ::Client .new .create_job({ profile_id: 123 })
5456 puts result
5557rescue => e
5658 puts " Error - #{ e.class .name } : #{ e.message } "
5759end
5860```
5961
62+ ## Example usage
63+
64+ ``` ruby
65+ require skylab_studio
66+
67+ client = SkylabStudio ::Client .new ()
68+ client = SkylabStudio ::Client .new ({ max_download_concurrency: 5 }) # to set download concurrency (default: 5)
69+
70+ # CREATE PROFILE
71+ profile = client.create_profile({ name: " Test Profile" , enable_crop: false , enable_color: false , enable_extract: true })
72+
73+ # CREATE JOB
74+ job_name = " test-job-#{ random_uuid } " ;
75+ job = client.create_job({ name: job_name, profile_id: profile[' id' ] });
76+
77+ # UPLOAD PHOTO
78+ file_path = " /path/to/photo.jpg" ;
79+ client.upload_job_photo(file_path, job[' id' ]);
80+
81+ # QUEUE JOB
82+ queued_job = client.queue_job({ id: job[' id' ], callback_url: " http://server.callback.here/" });
83+
84+ # NOTE: Once the job is queued, it will get queued, processed, and then complete
85+ # We will send a response to the specified callback_url with the output photo download urls
86+ ```
87+
88+ ``` ruby
89+ # OPTIONAL: If you want this SDK to handle photo downloads to a specified output folder
90+
91+ # FETCH COMPLETED JOB (wait until job status is completed)
92+ completed_job = client.get_job(queued_job[' id' ]);
93+
94+ # DOWNLOAD COMPLETED JOB PHOTOS
95+ photos_list = completed_job[' photos' ];
96+ client.download_all_photos(photos_list, completed_job[' profile' ], " photos/output/" );
97+
98+ # OR, download single photo
99+ client.download_photo(photos_list[0 ][" id" ], " /output/folder/" ); # keep original filename
100+ client.download_photo(photos_list[0 ][" id" ], " /output/folder/new_name.jpg" ); # rename output image
101+
102+ ```
103+
60104### List all Jobs
61105
62106- ** page** - _ integer_ - The page of results to return
@@ -70,48 +114,64 @@ client.list_jobs()
70114- ** job** - _ hash_ - The attributes of the job to create
71115
72116``` ruby
73- client.create_job(job: { profile_id: 123 })
117+ client.create_job({ name: " TEST JOB " , profile_id: 123 })
74118```
75119
76120### Get a Job
77121
78122- ** id** - _ integer_ - The ID of the job
79123
80124``` ruby
81- client.get_job(id: 123 )
125+ client.get_job(123 )
126+ ```
127+
128+ ### Get a Job by name
129+
130+ - ** options** - _ hash_ - The hash with job name
131+
132+ ``` ruby
133+ client.get_job({ name: " TEST JOB" })
82134```
83135
84136### Update a Job
85137
86138- ** id** - _ integer_ - The ID of the job to update
87- - ** job ** - _ hash_ - The attributes of the hob to update
139+ - ** options ** - _ hash_ - The attributes of the job to update
88140
89141``` ruby
90- client.update_job(id: 123 , job: { profile_id: 456 })
142+ client.update_job(id: 123 , { name: " new job name " , profile_id: 456 })
91143```
92144
93- ### Delete a Job
145+ ### Queue a Job
94146
95- - ** id ** - _ integer _ - The ID of the job to delete
147+ - ** options ** - _ hash _ - The attributes of the job to queue
96148
97149``` ruby
98- client.delete_job( id: 123 )
150+ client.queue_job({ id: 123 , callback_url: " http://callback.url.here/ } )
99151```
100152
101- ### Process a Job
153+ ### Fetch Jobs in front
102154
103- - ** id ** - _ integer _ - The ID of the job to process
155+ - **job_id ** - _hash_ - The ID of the job
104156
105157```ruby
106- client.process_job(id: 123 )
158+ client.fetch_jobs_in_front(123)
159+ ```
160+
161+ ### Delete a Job
162+
163+ - **id** - _integer_ - The ID of the job to delete
164+
165+ ```ruby
166+ client.delete_job(123)
107167```
108168
109169### Cancel a Job
110170
111171- **id** - _integer_ - The ID of the job to cancel
112172
113173```ruby
114- client.cancel_job(id: 123 )
174+ client.cancel_job(123)
115175```
116176
117177### List all Profiles
@@ -124,90 +184,93 @@ client.list_profiles()
124184
125185### Create a Profile
126186
127- - ** profile ** - _ hash_ - The attributes of the profile to create
187+ - **options ** - _hash_ - The attributes of the profile to create
128188
129189```ruby
130- client.create_profile(profile: { profile_id: 123 })
190+ client.create_profile({ name: " New profile" , enable_crop: false, enable_color: false, enable_extract: true })
131191```
132192
133193### Get a Profile
134194
135195- **id** - _integer_ - The ID of the profile
136196
137197```ruby
138- client.get_profile(id: 123 )
198+ client.get_profile(123)
139199```
140200
141201### Update a Profile
142202
143- - ** id ** - _ integer_ - The ID of the profile to update
144- - ** profile ** - _ hash_ - The attributes of the hob to update
203+ - **profile_id ** - _integer_ - The ID of the profile to update
204+ - **options ** - _hash_ - The attributes of the profile to update
145205
146206```ruby
147- client.update_profile(id: 123 , profile: { profile_id: 456 })
148- ```
149-
150- ### Delete a Profile
151-
152- - ** id** - _ integer_ - The ID of the profile to delete
153-
154- ``` ruby
155- client.delete_profile(id: 123 )
207+ client.update_profile(123, { name: " new profile name" , enable_color: true })
156208```
157209
158210### Upload Job Photo
159211
160212This method handles validating a photo, creating a photo object and uploading it to your job/profile's s3 bucket. If the bucket upload process fails, it retries 3 times and if failures persist, the photo object is deleted.
161213
162- - ** id** - _ integer_ - The ID of the job to associate the image file upload to
163214- **photo_path** - _string_ - The current local file path of the image file
215+ - **job_id** - _integer_ - The ID of the job to associate the image file upload to
164216
165217```ruby
166- client.upload_job_photo(id: 123 , photo_path: ' /path/to/photo.jpg' )
218+ client.upload_job_photo('/path/to/photo.jpg', 123 )
167219```
168220
169221### Upload Profile Photo
170222
171223This function handles validating a background photo for a profile. Note: enable_extract and replace_background (profile attributes) MUST be true in order to create background photos. Follows the same upload process as upload_job_photo.
172224
173- - ** id** - _ integer_ - The ID of the profile to associate the image file upload to
174225- **photo_path** - _string_ - The current local file path of the image file
226+ - **profile_id** - _integer_ - The ID of the profile to associate the image file upload to
175227
176228```ruby
177- client.upload_profile_photo(id: 123 , photo_path: ' /path/to/photo.jpg' )
229+ client.upload_profile_photo('/path/to/photo.jpg', 123 )
178230```
179231
180- ### Create a Photo
232+ ### Get a Photo
181233
182- - ** photo ** - _ hash _ - The attributes of the photo to create
234+ - **id ** - _integer_ - The ID of the photo
183235
184236```ruby
185- client.create_photo( photo: { photo_id: 123 } )
237+ client.get_photo( 123)
186238```
187239
188- ### Get a Photo
240+ ### Delete a Photo
189241
190- - ** id** - _ integer_ - The ID of the photo
242+ - **id** - _integer_ - The ID of the photo to delete
191243
192244```ruby
193- client.get_photo( id: 123 )
245+ client.delete_photo( 123)
194246```
195247
196- ### Update a Photo
248+ ### Get job photos
197249
198- - ** id** - _ integer_ - The ID of the photo to update
199- - ** photo** - _ hash_ - The attributes of the hob to update
250+ - **id** - _integer_ - The ID of the job to get photos from
200251
201252```ruby
202- client.update_photo( id: 123 , photo: { photo_id: 456 } )
253+ client.get_job_photos( 123)
203254```
204255
205- ### Delete a Photo
256+ ### Download photo(s)
206257
207- - ** id** - _ integer_ - The ID of the photo to delete
258+ This function handles downloading the output photos to a specified directory.
259+
260+ ```ruby
261+ photos_list = completed_job['photos']
262+
263+ download_results = client.download_all_photos(photos_list, completed_job['profile'], " / output/ folder/ path" )
264+
265+ Output:
266+ {'success_photos': ['1.JPG'], 'errored_photos': []}
267+ ```
268+
269+ OR
208270
209271```ruby
210- client.delete_photo(id: 123 )
272+ client.download_photo(photo_id, " / output/ folder/ path" ) # download photo with original filename to a directory
273+ client.download_photo(photo_id, " / output/ folder/ test .jpg" ) # download photo with new filename to a directory
211274```
212275
213276## Errors
0 commit comments