skylab_studio 1.0.8 → 1.0.9
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 +4 -4
- data/lib/skylab_studio/client.rb +31 -28
- data/lib/skylab_studio/version.rb +1 -1
- data/lib/skylab_studio.rb +19 -0
- data/spec/lib/skylab_studio/client_spec.rb +5 -5
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0be4e813eaaeefc166701f414e7312bb0c49adec754429d7c7c3a25b4ed0cd7d
|
4
|
+
data.tar.gz: 2f2efb2aea31469afa87fce6a8ab26f1f7417ccded50aa21ae1f5bfcde9ae429
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31a05a41368c85714165aed69ac087c1e9b15299ff0811e68182d37d7b73f0068b6d239d68fb640e98faf4eab19c3713aa23fb345f31abbba2f8226cf5691065
|
7
|
+
data.tar.gz: 1ca009f37032c449ece76ca20400b861c2ecc58941c6adaf31447f6422d0e8ac53b77df3e4b5fec59fcd3893dd03ba3a65416ad1b56aff27854e6c658c45d857
|
data/lib/skylab_studio/client.rb
CHANGED
@@ -275,9 +275,11 @@ module SkylabStudio
|
|
275
275
|
photo_data = { "#{model}_id": id, name: "#{photo_name}#{photo_ext}", path: photo_path, 'use_cache_upload': false }
|
276
276
|
|
277
277
|
if model == 'job'
|
278
|
-
|
278
|
+
job = get_job(id)
|
279
279
|
|
280
|
-
|
280
|
+
raise "No job found with id: #{id}" unless job.has_key?('type')
|
281
|
+
|
282
|
+
headers = { 'X-Amz-Tagging' => 'job=photo&api=true' } if job['type'] == 'regular'
|
281
283
|
end
|
282
284
|
|
283
285
|
# Ask studio to create the photo record
|
@@ -303,36 +305,37 @@ module SkylabStudio
|
|
303
305
|
# PUT request to presigned url with image data
|
304
306
|
headers['Content-MD5'] = b64md5
|
305
307
|
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
308
|
+
retries = 0
|
309
|
+
while retries < 3
|
310
|
+
begin
|
311
|
+
uri = URI(upload_url)
|
312
|
+
request = Net::HTTP::Put.new(uri, headers)
|
313
|
+
request.body = data
|
314
|
+
|
315
|
+
upload_photo_resp = Net::HTTP.start(uri.hostname) { |http| http.request(request) }
|
316
|
+
upload_status_code = upload_photo_resp.code.to_i
|
317
|
+
|
318
|
+
if upload_status_code >= 400
|
319
|
+
raise StandardError.new("HTTP Error: #{upload_photo_resp.code}")
|
320
|
+
end
|
321
|
+
|
322
|
+
# If no error, the upload is successful, exit the loop
|
323
|
+
break
|
324
|
+
rescue Exception => e
|
325
|
+
if retries == 2
|
326
|
+
delete_photo(photo_id)
|
327
|
+
Sentry.capture_exception(e)
|
328
|
+
raise e
|
329
|
+
else
|
330
|
+
# If we haven't retried 3 times, wait and retry
|
331
|
+
puts "Attempt ##{retries + 1} to upload failed, retrying..."
|
332
|
+
retries += 1
|
333
|
+
sleep(retries + 1)
|
327
334
|
end
|
328
335
|
end
|
329
|
-
rescue StandardError => e
|
330
|
-
puts "An exception of type #{e.class} occurred: #{e.message}"
|
331
|
-
puts 'Deleting created, but unuploaded photo...'
|
332
|
-
delete_photo({ id: photo_id }) if photo_id
|
333
336
|
end
|
334
337
|
|
335
|
-
photo_response_json
|
338
|
+
{ photo: photo_response_json, upload_response: upload_status_code }
|
336
339
|
end
|
337
340
|
|
338
341
|
def download_image_async(image_url)
|
data/lib/skylab_studio.rb
CHANGED
@@ -9,7 +9,26 @@ require 'net/https'
|
|
9
9
|
require 'uri'
|
10
10
|
require 'json'
|
11
11
|
|
12
|
+
# sentry
|
13
|
+
require 'stackprof'
|
14
|
+
require 'sentry-ruby'
|
15
|
+
|
12
16
|
require_relative 'skylab_studio/request'
|
13
17
|
require_relative 'skylab_studio/client'
|
14
18
|
require_relative 'skylab_studio/config'
|
15
19
|
require_relative 'skylab_studio/version' unless defined?(Skylab::VERSION)
|
20
|
+
|
21
|
+
Sentry.init do |config|
|
22
|
+
config.dsn = 'https://b2c54fe447391bac2134b1a679050139@o1409269.ingest.us.sentry.io/4507891689717760'
|
23
|
+
|
24
|
+
# get breadcrumbs from logs
|
25
|
+
config.breadcrumbs_logger = [:sentry_logger, :http_logger]
|
26
|
+
|
27
|
+
# enable tracing
|
28
|
+
# we recommend adjusting this value in production
|
29
|
+
config.traces_sample_rate = 1.0
|
30
|
+
|
31
|
+
# enable profiling
|
32
|
+
# this is relative to traces_sample_rate
|
33
|
+
config.profiles_sample_rate = 1.0
|
34
|
+
end
|
@@ -135,13 +135,13 @@ RSpec.describe SkylabStudio::Client do
|
|
135
135
|
describe '#upload_job_photo' do
|
136
136
|
before do
|
137
137
|
stub_request(:post, 'https://studio.skylabtech.ai/api/public/v1/photos')
|
138
|
-
.to_return(status: 200, body: { id: 1
|
138
|
+
.to_return(status: 200, body: { id: 1 }.to_json, headers: {})
|
139
139
|
|
140
140
|
stub_request(:get, 'https://studio.skylabtech.ai/api/public/v1/photos/upload_url')
|
141
141
|
.to_return(status: 200, body: { url: 'http://test.test/' }.to_json, headers: {})
|
142
142
|
|
143
143
|
stub_request(:get, 'https://studio.skylabtech.ai/api/public/v1/jobs/1')
|
144
|
-
.to_return(status: 200, body: {}.to_json, headers: {})
|
144
|
+
.to_return(status: 200, body: { type: 'regular' }.to_json, headers: {})
|
145
145
|
|
146
146
|
stub_request(:delete, 'https://studio.skylabtech.ai/api/public/v1/photos/1')
|
147
147
|
.to_return(status: 200, body: { id: 1 }.to_json, headers: {})
|
@@ -156,7 +156,7 @@ RSpec.describe SkylabStudio::Client do
|
|
156
156
|
photo_path = "#{File.expand_path('../../', File.dirname(__FILE__))}/test-portrait-1.JPG"
|
157
157
|
id = 1
|
158
158
|
|
159
|
-
expected_response = { id: id,
|
159
|
+
expected_response = { photo: { id: id }, upload_response: 200 }.to_json
|
160
160
|
|
161
161
|
expect(subject.upload_job_photo(photo_path, id).to_json).to eq(expected_response)
|
162
162
|
end
|
@@ -165,7 +165,7 @@ RSpec.describe SkylabStudio::Client do
|
|
165
165
|
describe '#upload_profile_photo' do
|
166
166
|
before do
|
167
167
|
stub_request(:post, 'https://studio.skylabtech.ai/api/public/v1/photos')
|
168
|
-
.to_return(status: 200, body: { id: 1
|
168
|
+
.to_return(status: 200, body: { id: 1 }.to_json, headers: {})
|
169
169
|
|
170
170
|
stub_request(:get, 'https://studio.skylabtech.ai/api/public/v1/photos/upload_url')
|
171
171
|
.to_return(status: 200, body: { url: 'http://test.test/' }.to_json, headers: {})
|
@@ -187,7 +187,7 @@ RSpec.describe SkylabStudio::Client do
|
|
187
187
|
photo_path = "#{File.expand_path('../../', File.dirname(__FILE__))}/test-portrait-1.JPG"
|
188
188
|
id = 1
|
189
189
|
|
190
|
-
expected_response = { id: id,
|
190
|
+
expected_response = { photo: { id: id }, upload_response: 200 }.to_json
|
191
191
|
|
192
192
|
expect(subject.upload_profile_photo(photo_path, 1).to_json).to eq(expected_response)
|
193
193
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: skylab_studio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Lam
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-10-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -60,7 +60,7 @@ homepage: https://github.com/skylab-tech/studio_client_ruby
|
|
60
60
|
licenses:
|
61
61
|
- Apache-2.0
|
62
62
|
metadata: {}
|
63
|
-
post_install_message:
|
63
|
+
post_install_message:
|
64
64
|
rdoc_options: []
|
65
65
|
require_paths:
|
66
66
|
- lib
|
@@ -75,13 +75,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
75
|
- !ruby/object:Gem::Version
|
76
76
|
version: '0'
|
77
77
|
requirements: []
|
78
|
-
rubygems_version: 3.
|
79
|
-
signing_key:
|
78
|
+
rubygems_version: 3.4.10
|
79
|
+
signing_key:
|
80
80
|
specification_version: 4
|
81
81
|
summary: A HTTP client for accessing studio.skylabtech.ai services.
|
82
82
|
test_files:
|
83
|
-
- spec/spec_helper.rb
|
84
|
-
- spec/lib/skylab_studio/request_spec.rb
|
85
83
|
- spec/lib/skylab_studio/client_spec.rb
|
86
84
|
- spec/lib/skylab_studio/config_spec.rb
|
85
|
+
- spec/lib/skylab_studio/request_spec.rb
|
87
86
|
- spec/lib/skylab_studio/version_spec.rb
|
87
|
+
- spec/spec_helper.rb
|