skylab_studio 1.0.5 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/skylab_studio/client.rb +145 -28
- data/lib/skylab_studio/error.rb +2 -0
- data/lib/skylab_studio/request.rb +10 -8
- data/lib/skylab_studio/version.rb +3 -1
- data/lib/skylab_studio.rb +6 -4
- data/spec/lib/skylab_studio/client_spec.rb +64 -44
- data/spec/lib/skylab_studio/config_spec.rb +2 -0
- data/spec/lib/skylab_studio/request_spec.rb +17 -10
- data/spec/lib/skylab_studio/version_spec.rb +2 -0
- data/spec/spec_helper.rb +3 -0
- metadata +14 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f99a61b73fab6e35ba741ca1c841822634c163b1542e96008f4a6126c7fc7e1e
|
4
|
+
data.tar.gz: 41cf785d1ff581766b3ba7fc05bd262648cbf0dde78daaabe3558c09e176dd9a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06ca0fa9eb3a14c85c463abfe59b275a612181ffbfe1db9c5f3b61fda266911372446ecdf1db3c0666376b972ca7dec5147dec1ea6e14fdf3862bbd4df0f4855
|
7
|
+
data.tar.gz: 1aaaf67aeb7be27fd165a7b75d324db4408188b238d0b06eda13ff1f18dbd52969b09ee230ddac8b10422033f4da0b5c728d9687f82891fb578be087d15dec75
|
data/lib/skylab_studio/client.rb
CHANGED
@@ -1,4 +1,9 @@
|
|
1
1
|
require_relative 'error'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'digest'
|
4
|
+
require 'open-uri'
|
5
|
+
require 'base64'
|
6
|
+
require 'net/http'
|
2
7
|
|
3
8
|
module SkylabStudio
|
4
9
|
class ClientNilArgument < Error; end
|
@@ -26,96 +31,113 @@ module SkylabStudio
|
|
26
31
|
end
|
27
32
|
|
28
33
|
def list_jobs(options = {})
|
29
|
-
SkylabStudio::Request.new(@configuration).get(:jobs,
|
34
|
+
SkylabStudio::Request.new(@configuration).get(:jobs, options)
|
30
35
|
end
|
31
36
|
|
32
37
|
def create_job(options = {})
|
33
|
-
validate_argument_presence options, :
|
38
|
+
validate_argument_presence options, :name
|
39
|
+
validate_argument_presence options, :profile_id
|
34
40
|
|
35
|
-
SkylabStudio::Request.new(@configuration).post(:jobs,
|
41
|
+
SkylabStudio::Request.new(@configuration).post(:jobs, options)
|
36
42
|
end
|
37
43
|
|
38
44
|
def get_job(options = {})
|
39
45
|
validate_argument_presence options, :id
|
40
46
|
|
41
|
-
SkylabStudio::Request.new(@configuration).get("jobs/#{options[:id]}",
|
47
|
+
SkylabStudio::Request.new(@configuration).get("jobs/#{options[:id]}", options)
|
48
|
+
end
|
49
|
+
|
50
|
+
def get_job_by_name(options = {})
|
51
|
+
validate_argument_presence options, :name
|
52
|
+
|
53
|
+
SkylabStudio::Request.new(@configuration).get('jobs/find_by_name', options)
|
42
54
|
end
|
43
55
|
|
44
56
|
def update_job(options = {})
|
45
57
|
validate_argument_presence options, :id
|
46
58
|
validate_argument_presence options, :job
|
47
59
|
|
48
|
-
SkylabStudio::Request.new(@configuration).patch("jobs/#{options[:id]}",
|
60
|
+
SkylabStudio::Request.new(@configuration).patch("jobs/#{options[:id]}", options)
|
49
61
|
end
|
50
62
|
|
51
|
-
def
|
63
|
+
def queue_job(options = {})
|
52
64
|
validate_argument_presence options, :id
|
53
65
|
|
54
|
-
SkylabStudio::Request.new(@configuration).
|
66
|
+
SkylabStudio::Request.new(@configuration).post("jobs/#{options[:id]}/queue", options)
|
55
67
|
end
|
56
68
|
|
57
|
-
def
|
69
|
+
def fetch_jobs_in_front(options = {})
|
70
|
+
SkylabStudio::Request.new(@configuration).get("jobs/#{options[:id]}/jobs_in_front", options)
|
71
|
+
end
|
72
|
+
|
73
|
+
def delete_job(options = {})
|
58
74
|
validate_argument_presence options, :id
|
59
75
|
|
60
|
-
SkylabStudio::Request.new(@configuration).
|
76
|
+
SkylabStudio::Request.new(@configuration).delete("jobs/#{options[:id]}")
|
61
77
|
end
|
62
78
|
|
63
79
|
def cancel_job(options = {})
|
64
80
|
validate_argument_presence options, :id
|
65
81
|
|
66
|
-
SkylabStudio::Request.new(@configuration).post("jobs/#{options[:id]}/cancel",
|
82
|
+
SkylabStudio::Request.new(@configuration).post("jobs/#{options[:id]}/cancel", options)
|
67
83
|
end
|
68
84
|
|
69
85
|
def list_profiles(options = {})
|
70
|
-
SkylabStudio::Request.new(@configuration).get(:profiles,
|
86
|
+
SkylabStudio::Request.new(@configuration).get(:profiles, options)
|
71
87
|
end
|
72
88
|
|
73
89
|
def create_profile(options = {})
|
74
|
-
validate_argument_presence options, :
|
90
|
+
validate_argument_presence options, :name
|
75
91
|
|
76
|
-
SkylabStudio::Request.new(@configuration).post(:profiles,
|
92
|
+
SkylabStudio::Request.new(@configuration).post(:profiles, options)
|
77
93
|
end
|
78
94
|
|
79
95
|
def get_profile(options = {})
|
80
96
|
validate_argument_presence options, :id
|
81
97
|
|
82
|
-
SkylabStudio::Request.new(@configuration).get("profiles/#{options[:id]}",
|
98
|
+
SkylabStudio::Request.new(@configuration).get("profiles/#{options[:id]}", options)
|
83
99
|
end
|
84
100
|
|
85
101
|
def update_profile(options = {})
|
86
102
|
validate_argument_presence options, :id
|
87
103
|
validate_argument_presence options, :profile
|
88
104
|
|
89
|
-
SkylabStudio::Request.new(@configuration).patch("profiles/#{options[:id]}",
|
105
|
+
SkylabStudio::Request.new(@configuration).patch("profiles/#{options[:id]}", options)
|
90
106
|
end
|
91
107
|
|
92
|
-
def
|
93
|
-
validate_argument_presence
|
108
|
+
def upload_job_photo(photo_path = nil, job_id = nil)
|
109
|
+
validate_argument_presence nil, job_id
|
110
|
+
validate_argument_presence nil, photo_path
|
94
111
|
|
95
|
-
|
112
|
+
upload_photo(photo_path, job_id, 'job')
|
96
113
|
end
|
97
114
|
|
98
|
-
def
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
def create_photo(options = {})
|
103
|
-
validate_argument_presence options, :photo
|
115
|
+
def upload_profile_photo(photo_path = nil, profile_id = nil)
|
116
|
+
validate_argument_presence nil, :photo_path
|
117
|
+
validate_argument_presence nil, :profile_id
|
104
118
|
|
105
|
-
|
119
|
+
upload_photo(photo_path, profile_id, 'profile')
|
106
120
|
end
|
107
121
|
|
108
122
|
def get_photo(options = {})
|
109
123
|
validate_argument_presence options, :id
|
110
124
|
|
111
|
-
SkylabStudio::Request.new(@configuration).get("photos/#{options[:id]}",
|
125
|
+
SkylabStudio::Request.new(@configuration).get("photos/#{options[:id]}", options)
|
126
|
+
end
|
127
|
+
|
128
|
+
def get_job_photos(job_identifier, value)
|
129
|
+
{
|
130
|
+
"job_#{job_identifier}".to_sym => value
|
131
|
+
}
|
132
|
+
|
133
|
+
SkylabStudio::Request.new(@configuration).get('phtos/list_for_job', options)
|
112
134
|
end
|
113
135
|
|
114
136
|
def update_photo(options = {})
|
115
137
|
validate_argument_presence options, :id
|
116
138
|
validate_argument_presence options, :photo
|
117
139
|
|
118
|
-
SkylabStudio::Request.new(@configuration).patch("photos/#{options[:id]}",
|
140
|
+
SkylabStudio::Request.new(@configuration).patch("photos/#{options[:id]}", options)
|
119
141
|
end
|
120
142
|
|
121
143
|
def delete_photo(options = {})
|
@@ -126,8 +148,103 @@ module SkylabStudio
|
|
126
148
|
|
127
149
|
private
|
128
150
|
|
151
|
+
def get_upload_url(options = { use_cache_upload: false })
|
152
|
+
SkylabStudio::Request.new(@configuration).get('photos/upload_url', options)
|
153
|
+
end
|
154
|
+
|
155
|
+
def create_photo(options = {})
|
156
|
+
SkylabStudio::Request.new(@configuration).post(:photos, options)
|
157
|
+
end
|
158
|
+
|
159
|
+
def upload_photo(photo_path, id, model = 'job')
|
160
|
+
res = {}
|
161
|
+
valid_exts_to_check = %w[.jpg .jpeg .png .webp]
|
162
|
+
|
163
|
+
raise 'Invalid file type: must be of type jpg/jpeg/png/webp' unless valid_exts_to_check.any? { |ext| photo_path.downcase.end_with?(ext) }
|
164
|
+
|
165
|
+
file_size = File.size(photo_path)
|
166
|
+
|
167
|
+
raise 'Invalid file size: must be no larger than 27MB' if file_size > 27 * 1024 * 1024
|
168
|
+
|
169
|
+
photo_name = File.basename(photo_path)
|
170
|
+
headers = {}
|
171
|
+
md5hash = ''
|
172
|
+
|
173
|
+
# Read file contents to binary
|
174
|
+
data = nil
|
175
|
+
File.open(photo_path, 'rb') do |file|
|
176
|
+
data = file.read
|
177
|
+
md5hash = Digest::MD5.hexdigest(data)
|
178
|
+
end
|
179
|
+
|
180
|
+
# model - either job or profile (job_id/profile_id)
|
181
|
+
photo_data = { "#{model}_id" => id, name: photo_name, 'use_cache_upload' => false }
|
182
|
+
|
183
|
+
if model == 'job'
|
184
|
+
job_type = get_job(id: id)['type']
|
185
|
+
|
186
|
+
headers = { 'X-Amz-Tagging' => 'job=photo&api=true' } if job_type == 'regular'
|
187
|
+
end
|
188
|
+
|
189
|
+
# Ask studio to create the photo record
|
190
|
+
photo_response_json = create_photo(photo_data)
|
191
|
+
|
192
|
+
unless photo_response_json
|
193
|
+
raise 'Unable to create the photo object, if creating profile photo, ensure enable_extract and replace_background is set to: True'
|
194
|
+
end
|
195
|
+
|
196
|
+
photo_id = photo_response_json['id']
|
197
|
+
|
198
|
+
b64md5 = Base64.strict_encode64([md5hash].pack('H*'))
|
199
|
+
payload = {
|
200
|
+
'use_cache_upload' => false,
|
201
|
+
'photo_id' => photo_id,
|
202
|
+
'content_md5' => b64md5
|
203
|
+
}
|
204
|
+
|
205
|
+
# Ask studio for a presigned url
|
206
|
+
upload_url_resp = get_upload_url(payload)
|
207
|
+
upload_url = upload_url_resp['url']
|
208
|
+
|
209
|
+
# PUT request to presigned url with image data
|
210
|
+
headers['Content-MD5'] = b64md5
|
211
|
+
|
212
|
+
begin
|
213
|
+
uri = URI(upload_url)
|
214
|
+
request = Net::HTTP::Put.new(uri, headers)
|
215
|
+
request.body = data
|
216
|
+
upload_photo_resp = Net::HTTP.start(uri.hostname) {|http| http.request(request) }
|
217
|
+
|
218
|
+
unless upload_photo_resp
|
219
|
+
puts 'First upload attempt failed, retrying...'
|
220
|
+
retry_count = 0
|
221
|
+
# Retry upload
|
222
|
+
|
223
|
+
while retry_count < 3
|
224
|
+
upload_photo_resp = Net::HTTP.start(uri.hostname) {|http| http.request(request) }
|
225
|
+
if upload_photo_resp
|
226
|
+
break # Upload was successful, exit the loop
|
227
|
+
elsif retry_count == 2 # Check if retry count is 2 (0-based indexing)
|
228
|
+
raise 'Unable to upload to the bucket after retrying.'
|
229
|
+
else
|
230
|
+
sleep(1) # Wait for a moment before retrying
|
231
|
+
retry_count += 1
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
235
|
+
rescue StandardError => e
|
236
|
+
puts "An exception of type #{e.class} occurred: #{e.message}"
|
237
|
+
puts 'Deleting created, but unuploaded photo...'
|
238
|
+
delete_photo({ id: photo_id }) if photo_id
|
239
|
+
end
|
240
|
+
|
241
|
+
photo_response_json
|
242
|
+
end
|
243
|
+
|
129
244
|
def validate_argument_presence(options, key)
|
130
|
-
raise SkylabStudio::ClientNilArgument, "#{key} cannot be nil" if options[key].nil?
|
245
|
+
raise SkylabStudio::ClientNilArgument, "#{key} cannot be nil" if options.is_a?(Hash) && options[key].nil?
|
246
|
+
|
247
|
+
raise SkylabStudio::ClientNilArgument, "#{key} cannot be nil" if key.nil?
|
131
248
|
end
|
132
249
|
end
|
133
250
|
end
|
data/lib/skylab_studio/error.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'error'
|
2
4
|
|
3
5
|
module SkylabStudio
|
@@ -37,7 +39,7 @@ module SkylabStudio
|
|
37
39
|
private
|
38
40
|
|
39
41
|
def request_path(end_point)
|
40
|
-
"/api/#{@configuration.api_version}/#{end_point}"
|
42
|
+
"/api/public/#{@configuration.api_version}/#{end_point}"
|
41
43
|
end
|
42
44
|
|
43
45
|
def use_ssl?
|
@@ -64,19 +66,19 @@ module SkylabStudio
|
|
64
66
|
end
|
65
67
|
|
66
68
|
def handle_response(response)
|
67
|
-
case
|
68
|
-
when Net::HTTPUnauthorized
|
69
|
+
case response
|
70
|
+
when Net::HTTPUnauthorized
|
69
71
|
raise SkylabStudio::ClientInvalidKey, 'Invalid api key'
|
70
|
-
when Net::HTTPForbidden
|
72
|
+
when Net::HTTPForbidden
|
71
73
|
raise SkylabStudio::ClientInvalidKey, 'Invalid api key'
|
72
|
-
when Net::HTTPNotFound
|
74
|
+
when Net::HTTPNotFound
|
73
75
|
raise SkylabStudio::ClientInvalidEndpoint, 'Resource not found'
|
74
|
-
when Net::HTTPBadRequest
|
76
|
+
when Net::HTTPBadRequest
|
75
77
|
raise SkylabStudio::ClientBadRequest, 'There was an error processing your request'
|
76
|
-
when Net::HTTPTooManyRequests
|
78
|
+
when Net::HTTPTooManyRequests
|
77
79
|
raise SkylabStudio::ClientBadRequest, 'The rate limit has been met'
|
78
80
|
when Net::HTTPSuccess
|
79
|
-
response
|
81
|
+
JSON.parse(response.body)
|
80
82
|
else
|
81
83
|
raise SkylabStudio::ClientUnknownError, 'An error has occurred'
|
82
84
|
end
|
data/lib/skylab_studio.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module SkylabStudio
|
2
4
|
end
|
3
5
|
|
@@ -7,7 +9,7 @@ require 'net/https'
|
|
7
9
|
require 'uri'
|
8
10
|
require 'json'
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
require_relative 'skylab_studio/request'
|
13
|
+
require_relative 'skylab_studio/client'
|
14
|
+
require_relative 'skylab_studio/config'
|
15
|
+
require_relative 'skylab_studio/version' unless defined?(Skylab::VERSION)
|
@@ -1,11 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require File.expand_path('../../../lib/skylab_studio.rb', __dir__)
|
2
4
|
|
3
5
|
RSpec.describe SkylabStudio::Client do
|
4
|
-
|
5
|
-
@client = SkylabStudio::Client.new
|
6
|
-
end
|
6
|
+
let(:client) { SkylabStudio::Client.new }
|
7
7
|
|
8
|
-
subject {
|
8
|
+
subject { client }
|
9
9
|
|
10
10
|
it { should respond_to(:list_jobs) }
|
11
11
|
it { should respond_to(:get_job) }
|
@@ -34,7 +34,7 @@ RSpec.describe SkylabStudio::Client do
|
|
34
34
|
it 'should return response' do
|
35
35
|
SkylabStudio::Request.any_instance.stub(:get).and_return(true)
|
36
36
|
|
37
|
-
|
37
|
+
subject.list_jobs.should eq(true)
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
@@ -42,23 +42,19 @@ RSpec.describe SkylabStudio::Client do
|
|
42
42
|
it 'should return response' do
|
43
43
|
SkylabStudio::Request.any_instance.stub(:post).and_return(true)
|
44
44
|
|
45
|
-
|
46
|
-
job: {
|
47
|
-
profile_id: 1
|
48
|
-
}
|
49
|
-
).should eq(true)
|
45
|
+
subject.create_job({ name: 'test-job', profile_id: 1 }).should eq(true)
|
50
46
|
end
|
51
47
|
end
|
52
48
|
|
53
49
|
describe '#get_job' do
|
54
50
|
it 'should raise error with no id' do
|
55
|
-
expect {
|
51
|
+
expect { subject.get_job }.to raise_error(SkylabStudio::ClientNilArgument)
|
56
52
|
end
|
57
53
|
|
58
54
|
it 'should return response' do
|
59
55
|
SkylabStudio::Request.any_instance.stub(:get).and_return(true)
|
60
56
|
|
61
|
-
|
57
|
+
subject.get_job(id: 123).should eq(true)
|
62
58
|
end
|
63
59
|
end
|
64
60
|
|
@@ -66,7 +62,7 @@ RSpec.describe SkylabStudio::Client do
|
|
66
62
|
it 'should return response' do
|
67
63
|
SkylabStudio::Request.any_instance.stub(:patch).and_return(true)
|
68
64
|
|
69
|
-
|
65
|
+
subject.update_job(
|
70
66
|
id: 1,
|
71
67
|
job: {
|
72
68
|
profile_id: 2
|
@@ -79,17 +75,17 @@ RSpec.describe SkylabStudio::Client do
|
|
79
75
|
it 'should return response' do
|
80
76
|
SkylabStudio::Request.any_instance.stub(:delete).and_return(true)
|
81
77
|
|
82
|
-
|
78
|
+
subject.delete_job(
|
83
79
|
id: 1
|
84
80
|
).should eq(true)
|
85
81
|
end
|
86
82
|
end
|
87
83
|
|
88
|
-
describe '#
|
84
|
+
describe '#queue_job' do
|
89
85
|
it 'should return response' do
|
90
86
|
SkylabStudio::Request.any_instance.stub(:post).and_return(true)
|
91
87
|
|
92
|
-
|
88
|
+
subject.queue_job(
|
93
89
|
id: 1
|
94
90
|
).should eq(true)
|
95
91
|
end
|
@@ -99,7 +95,7 @@ RSpec.describe SkylabStudio::Client do
|
|
99
95
|
it 'should return response' do
|
100
96
|
SkylabStudio::Request.any_instance.stub(:post).and_return(true)
|
101
97
|
|
102
|
-
|
98
|
+
subject.cancel_job(
|
103
99
|
id: 1
|
104
100
|
).should eq(true)
|
105
101
|
end
|
@@ -109,7 +105,7 @@ RSpec.describe SkylabStudio::Client do
|
|
109
105
|
it 'should return response' do
|
110
106
|
SkylabStudio::Request.any_instance.stub(:get).and_return(true)
|
111
107
|
|
112
|
-
|
108
|
+
subject.list_profiles.should eq(true)
|
113
109
|
end
|
114
110
|
end
|
115
111
|
|
@@ -117,8 +113,8 @@ RSpec.describe SkylabStudio::Client do
|
|
117
113
|
it 'should return response' do
|
118
114
|
SkylabStudio::Request.any_instance.stub(:post).and_return(true)
|
119
115
|
|
120
|
-
|
121
|
-
|
116
|
+
subject.create_profile(
|
117
|
+
{
|
122
118
|
name: 'Foo'
|
123
119
|
}
|
124
120
|
).should eq(true)
|
@@ -127,13 +123,13 @@ RSpec.describe SkylabStudio::Client do
|
|
127
123
|
|
128
124
|
describe '#get_profile' do
|
129
125
|
it 'should raise error with no id' do
|
130
|
-
expect {
|
126
|
+
expect { subject.get_profile }.to raise_error(SkylabStudio::ClientNilArgument)
|
131
127
|
end
|
132
128
|
|
133
129
|
it 'should return response' do
|
134
130
|
SkylabStudio::Request.any_instance.stub(:get).and_return(true)
|
135
131
|
|
136
|
-
|
132
|
+
subject.get_profile(id: 123).should eq(true)
|
137
133
|
end
|
138
134
|
end
|
139
135
|
|
@@ -141,7 +137,7 @@ RSpec.describe SkylabStudio::Client do
|
|
141
137
|
it 'should return response' do
|
142
138
|
SkylabStudio::Request.any_instance.stub(:patch).and_return(true)
|
143
139
|
|
144
|
-
|
140
|
+
subject.update_profile(
|
145
141
|
id: 1,
|
146
142
|
profile: {
|
147
143
|
name: 'Bar'
|
@@ -150,45 +146,69 @@ RSpec.describe SkylabStudio::Client do
|
|
150
146
|
end
|
151
147
|
end
|
152
148
|
|
153
|
-
describe '#
|
154
|
-
|
155
|
-
|
149
|
+
describe '#upload_job_photo' do
|
150
|
+
before do
|
151
|
+
stub_request(:post, 'https://studio.skylabtech.ai/api/public/v1/photos')
|
152
|
+
.to_return(status: 200, body: { id: 1, photo: {} }.to_json, headers: {})
|
156
153
|
|
157
|
-
|
158
|
-
|
159
|
-
|
154
|
+
stub_request(:get, 'https://studio.skylabtech.ai/api/public/v1/photos/upload_url')
|
155
|
+
.to_return(status: 200, body: '', headers: {})
|
156
|
+
|
157
|
+
stub_request(:get, 'https://studio.skylabtech.ai/api/public/v1/jobs/1')
|
158
|
+
.to_return(status: 200, body: '', headers: {})
|
159
|
+
|
160
|
+
stub_request(:delete, 'https://studio.skylabtech.ai/api/public/v1/photos/1')
|
161
|
+
.to_return(status: 200, body: { id: 1 }.to_json, headers: {})
|
162
|
+
|
163
|
+
allow_any_instance_of(Net::HTTPSuccess).to receive(:body) { { id: 1 }.to_json }
|
160
164
|
end
|
161
|
-
end
|
162
165
|
|
163
|
-
describe '#list_photos' do
|
164
166
|
it 'should return response' do
|
165
|
-
|
167
|
+
photo_path = "#{File.expand_path('../../', File.dirname(__FILE__))}/test-portrait-1.JPG"
|
168
|
+
id = 1
|
169
|
+
|
170
|
+
expected_response = { "id" => id }
|
166
171
|
|
167
|
-
|
172
|
+
subject.upload_job_photo(photo_path, id).should eq(expected_response)
|
168
173
|
end
|
169
174
|
end
|
170
175
|
|
171
|
-
describe '#
|
176
|
+
describe '#upload_profile_photo' do
|
177
|
+
before do
|
178
|
+
stub_request(:post, 'https://studio.skylabtech.ai/api/public/v1/photos')
|
179
|
+
.to_return(status: 200, body: { id: 1, photo: {} }.to_json, headers: {})
|
180
|
+
|
181
|
+
stub_request(:get, 'https://studio.skylabtech.ai/api/public/v1/photos/upload_url')
|
182
|
+
.to_return(status: 200, body: '', headers: {})
|
183
|
+
|
184
|
+
stub_request(:get, 'https://studio.skylabtech.ai/api/public/v1/jobs/1')
|
185
|
+
.to_return(status: 200, body: '', headers: {})
|
186
|
+
|
187
|
+
stub_request(:delete, 'https://studio.skylabtech.ai/api/public/v1/photos/1')
|
188
|
+
.to_return(status: 200, body: { id: 1 }.to_json, headers: {})
|
189
|
+
|
190
|
+
allow_any_instance_of(Net::HTTPSuccess).to receive(:body) { { id: 1 }.to_json }
|
191
|
+
end
|
192
|
+
|
172
193
|
it 'should return response' do
|
173
|
-
|
194
|
+
photo_path = "#{File.expand_path('../../', File.dirname(__FILE__))}/test-portrait-1.JPG"
|
195
|
+
id = 1
|
174
196
|
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
}
|
179
|
-
).should eq(true)
|
197
|
+
expected_response = { "id" => id }
|
198
|
+
|
199
|
+
subject.upload_profile_photo(photo_path, 1).should eq(expected_response)
|
180
200
|
end
|
181
201
|
end
|
182
202
|
|
183
203
|
describe '#get_photo' do
|
184
204
|
it 'should raise error with no id' do
|
185
|
-
expect {
|
205
|
+
expect { subject.get_photo }.to raise_error(SkylabStudio::ClientNilArgument)
|
186
206
|
end
|
187
207
|
|
188
208
|
it 'should return response' do
|
189
209
|
SkylabStudio::Request.any_instance.stub(:get).and_return(true)
|
190
210
|
|
191
|
-
|
211
|
+
subject.get_photo(id: 123).should eq(true)
|
192
212
|
end
|
193
213
|
end
|
194
214
|
|
@@ -196,7 +216,7 @@ RSpec.describe SkylabStudio::Client do
|
|
196
216
|
it 'should return response' do
|
197
217
|
SkylabStudio::Request.any_instance.stub(:patch).and_return(true)
|
198
218
|
|
199
|
-
|
219
|
+
subject.update_photo(
|
200
220
|
id: 1,
|
201
221
|
photo: {
|
202
222
|
name: 'Bar'
|
@@ -209,7 +229,7 @@ RSpec.describe SkylabStudio::Client do
|
|
209
229
|
it 'should return response' do
|
210
230
|
SkylabStudio::Request.any_instance.stub(:delete).and_return(true)
|
211
231
|
|
212
|
-
|
232
|
+
subject.delete_photo(
|
213
233
|
id: 1
|
214
234
|
).should eq(true)
|
215
235
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require File.expand_path('../../../lib/skylab_studio.rb', __dir__)
|
2
4
|
|
3
5
|
RSpec.describe SkylabStudio::Request do
|
@@ -12,9 +14,10 @@ RSpec.describe SkylabStudio::Request do
|
|
12
14
|
|
13
15
|
describe '#post' do
|
14
16
|
it 'should return success' do
|
15
|
-
Net::HTTP.
|
17
|
+
allow_any_instance_of(Net::HTTP).to receive(:request) { Net::HTTPSuccess.new(1.0, 200, 'OK') }
|
18
|
+
allow_any_instance_of(Net::HTTPSuccess).to receive(:body) { {}.to_json }
|
16
19
|
|
17
|
-
@request.post(:jobs, {}).should be_instance_of(
|
20
|
+
@request.post(:jobs, {}).should be_instance_of(Hash)
|
18
21
|
end
|
19
22
|
|
20
23
|
it 'should raise error on 401' do
|
@@ -62,9 +65,10 @@ RSpec.describe SkylabStudio::Request do
|
|
62
65
|
|
63
66
|
describe '#get' do
|
64
67
|
it 'should return success' do
|
65
|
-
Net::HTTP.
|
68
|
+
allow_any_instance_of(Net::HTTP).to receive(:request) { Net::HTTPSuccess.new(1.0, 200, 'OK') }
|
69
|
+
allow_any_instance_of(Net::HTTPSuccess).to receive(:body) { {}.to_json }
|
66
70
|
|
67
|
-
@request.get(:jobs, {}).should be_instance_of(
|
71
|
+
@request.get(:jobs, {}).should be_instance_of(Hash)
|
68
72
|
end
|
69
73
|
|
70
74
|
it 'should raise error on 401' do
|
@@ -112,9 +116,10 @@ RSpec.describe SkylabStudio::Request do
|
|
112
116
|
|
113
117
|
describe '#delete' do
|
114
118
|
it 'should return success' do
|
115
|
-
Net::HTTP.
|
119
|
+
allow_any_instance_of(Net::HTTP).to receive(:request) { Net::HTTPSuccess.new(1.0, 200, 'OK') }
|
120
|
+
allow_any_instance_of(Net::HTTPSuccess).to receive(:body) { {}.to_json }
|
116
121
|
|
117
|
-
@request.delete(:jobs).should be_instance_of(
|
122
|
+
@request.delete(:jobs).should be_instance_of(Hash)
|
118
123
|
end
|
119
124
|
|
120
125
|
it 'should raise error on 401' do
|
@@ -162,9 +167,10 @@ RSpec.describe SkylabStudio::Request do
|
|
162
167
|
|
163
168
|
describe '#put' do
|
164
169
|
it 'should return success' do
|
165
|
-
Net::HTTP.
|
170
|
+
allow_any_instance_of(Net::HTTP).to receive(:request) { Net::HTTPSuccess.new(1.0, 200, 'OK') }
|
171
|
+
allow_any_instance_of(Net::HTTPSuccess).to receive(:body) { {}.to_json }
|
166
172
|
|
167
|
-
@request.put(:jobs, {}).should be_instance_of(
|
173
|
+
@request.put(:jobs, {}).should be_instance_of(Hash)
|
168
174
|
end
|
169
175
|
|
170
176
|
it 'should raise error on 401' do
|
@@ -212,9 +218,10 @@ RSpec.describe SkylabStudio::Request do
|
|
212
218
|
|
213
219
|
describe '#patch' do
|
214
220
|
it 'should return success' do
|
215
|
-
Net::HTTP.
|
221
|
+
allow_any_instance_of(Net::HTTP).to receive(:request) { Net::HTTPSuccess.new(1.0, 200, 'OK') }
|
222
|
+
allow_any_instance_of(Net::HTTPSuccess).to receive(:body) { {}.to_json }
|
216
223
|
|
217
|
-
@request.patch(:jobs, {}).should be_instance_of(
|
224
|
+
@request.patch(:jobs, {}).should be_instance_of(Hash)
|
218
225
|
end
|
219
226
|
|
220
227
|
it 'should raise error on 401' do
|
data/spec/spec_helper.rb
CHANGED
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.6
|
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:
|
11
|
+
date: 2024-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 3.12.0
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 3.12.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: shoulda-matchers
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 3.
|
33
|
+
version: 5.3.0
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 3.
|
40
|
+
version: 5.3.0
|
41
41
|
description: studio.skylabtech.ai ruby client
|
42
42
|
email:
|
43
43
|
- info@skylabtech.ai
|
@@ -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
|
@@ -68,7 +68,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
68
68
|
requirements:
|
69
69
|
- - ">="
|
70
70
|
- !ruby/object:Gem::Version
|
71
|
-
version:
|
71
|
+
version: 2.7.0
|
72
72
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
74
|
- - ">="
|
@@ -76,12 +76,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
76
|
version: '0'
|
77
77
|
requirements: []
|
78
78
|
rubygems_version: 3.1.6
|
79
|
-
signing_key:
|
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
83
|
- spec/spec_helper.rb
|
84
|
-
- spec/lib/skylab_studio/
|
84
|
+
- spec/lib/skylab_studio/request_spec.rb
|
85
85
|
- spec/lib/skylab_studio/client_spec.rb
|
86
|
+
- spec/lib/skylab_studio/config_spec.rb
|
86
87
|
- spec/lib/skylab_studio/version_spec.rb
|
87
|
-
- spec/lib/skylab_studio/request_spec.rb
|