Skip to content

Commit 79c0490

Browse files
authored
Merge pull request #14 from skylab-tech/SCR-2-v2-features
Scr 2 v2 features
2 parents af6c833 + 1c79b53 commit 79c0490

File tree

7 files changed

+346
-145
lines changed

7 files changed

+346
-145
lines changed

.github/workflows/test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ jobs:
1818
with:
1919
ruby-version: 2.7
2020

21+
- name: Install libvips
22+
run: sudo apt install libvips-dev --no-install-recommends
23+
2124
- name: Install Bundler
2225
run: gem install bundler -v '~>2.4.22'
2326

Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
source 'https://rubygems.org'
44

5+
# Used for image processing
6+
gem 'ruby-vips', '~> 2.2.1'
7+
58
# Specify your gem's dependencies in skylab_client.gemspec
69
gemspec
710

Gemfile.lock

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
skylab_studio (1.0.5)
4+
skylab_studio (1.0.6)
55

66
GEM
77
remote: https://rubygems.org/
@@ -29,6 +29,7 @@ GEM
2929
diff-lcs (1.5.1)
3030
docile (1.4.0)
3131
drb (2.2.1)
32+
ffi (1.16.3)
3233
hashdiff (1.1.0)
3334
i18n (1.14.4)
3435
concurrent-ruby (~> 1.0)
@@ -72,6 +73,8 @@ GEM
7273
rubocop-ast (1.31.2)
7374
parser (>= 3.3.0.4)
7475
ruby-progressbar (1.13.0)
76+
ruby-vips (2.2.1)
77+
ffi (~> 1.12)
7578
shoulda-matchers (5.3.0)
7679
activesupport (>= 5.2.0)
7780
simplecov (0.22.0)
@@ -94,6 +97,7 @@ PLATFORMS
9497
DEPENDENCIES
9598
rspec (~> 3.12.0)
9699
rubocop
100+
ruby-vips (~> 2.2.1)
97101
shoulda-matchers (~> 5.3.0)
98102
simplecov (~> 0.22.0)
99103
skylab_studio!

README.md

Lines changed: 111 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
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
5254
begin
53-
result = SkylabStudio::Client.new.create_job(job: { profile_id: 123 })
55+
result = SkylabStudio::Client.new.create_job({ profile_id: 123 })
5456
puts result
5557
rescue => e
5658
puts "Error - #{e.class.name}: #{e.message}"
5759
end
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
160212
This 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
171223
This 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

Comments
 (0)