skylab_studio 1.0.5

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 74d45652e950eb110f6d634681b5caad2830017e50da39a7610a3c2e148f5c8f
4
+ data.tar.gz: 71f434342a60a6e1604b5d2258c00f2766d571a4d81959a494c6d9bc7e07cacd
5
+ SHA512:
6
+ metadata.gz: a2be823c425b7c9754d3c92e0777429fd5ad32bc795ac5dd1e1964f3299913fe527a805c856f6bab2eba787aafc5df26869126e95113a8b65b5acfd6320413d1
7
+ data.tar.gz: 7223682dfcb1368c03e493b57b53377ff7f9085d9ba0a71e7f40a85894e0a9d8e3efe916eb289ae9f89adc7b0949c88ac4d6ce23e09aa7855f9477d81c43f460
@@ -0,0 +1,13 @@
1
+ module SkylabStudio
2
+ end
3
+
4
+ require 'rubygems'
5
+ require 'net/http'
6
+ require 'net/https'
7
+ require 'uri'
8
+ require 'json'
9
+
10
+ require 'skylab_studio/request'
11
+ require 'skylab_studio/client'
12
+ require 'skylab_studio/config'
13
+ require 'skylab_studio/version' unless defined?(Skylab::VERSION)
@@ -0,0 +1,133 @@
1
+ require_relative 'error'
2
+
3
+ module SkylabStudio
4
+ class ClientNilArgument < Error; end
5
+
6
+ class Client
7
+ # Attributes
8
+ attr_reader :configuration
9
+
10
+ # ------------------------------ Class Methods ------------------------------
11
+
12
+ def self.configuration
13
+ @configuration ||= SkylabStudio::Config.new
14
+ end
15
+
16
+ def self.configure
17
+ yield configuration if block_given?
18
+ end
19
+
20
+ # ------------------------------ Instance Methods ------------------------------
21
+
22
+ def initialize(options = {})
23
+ settings = SkylabStudio::Client.configuration.settings.merge(options)
24
+
25
+ @configuration = SkylabStudio::Config.new(settings)
26
+ end
27
+
28
+ def list_jobs(options = {})
29
+ SkylabStudio::Request.new(@configuration).get(:jobs, payload: options)
30
+ end
31
+
32
+ def create_job(options = {})
33
+ validate_argument_presence options, :job
34
+
35
+ SkylabStudio::Request.new(@configuration).post(:jobs, payload: options)
36
+ end
37
+
38
+ def get_job(options = {})
39
+ validate_argument_presence options, :id
40
+
41
+ SkylabStudio::Request.new(@configuration).get("jobs/#{options[:id]}", payload: options)
42
+ end
43
+
44
+ def update_job(options = {})
45
+ validate_argument_presence options, :id
46
+ validate_argument_presence options, :job
47
+
48
+ SkylabStudio::Request.new(@configuration).patch("jobs/#{options[:id]}", payload: options)
49
+ end
50
+
51
+ def delete_job(options = {})
52
+ validate_argument_presence options, :id
53
+
54
+ SkylabStudio::Request.new(@configuration).delete("jobs/#{options[:id]}")
55
+ end
56
+
57
+ def process_job(options = {})
58
+ validate_argument_presence options, :id
59
+
60
+ SkylabStudio::Request.new(@configuration).post("jobs/#{options[:id]}/process", payload: options)
61
+ end
62
+
63
+ def cancel_job(options = {})
64
+ validate_argument_presence options, :id
65
+
66
+ SkylabStudio::Request.new(@configuration).post("jobs/#{options[:id]}/cancel", payload: options)
67
+ end
68
+
69
+ def list_profiles(options = {})
70
+ SkylabStudio::Request.new(@configuration).get(:profiles, payload: options)
71
+ end
72
+
73
+ def create_profile(options = {})
74
+ validate_argument_presence options, :profile
75
+
76
+ SkylabStudio::Request.new(@configuration).post(:profiles, payload: options)
77
+ end
78
+
79
+ def get_profile(options = {})
80
+ validate_argument_presence options, :id
81
+
82
+ SkylabStudio::Request.new(@configuration).get("profiles/#{options[:id]}", payload: options)
83
+ end
84
+
85
+ def update_profile(options = {})
86
+ validate_argument_presence options, :id
87
+ validate_argument_presence options, :profile
88
+
89
+ SkylabStudio::Request.new(@configuration).patch("profiles/#{options[:id]}", payload: options)
90
+ end
91
+
92
+ def delete_profile(options = {})
93
+ validate_argument_presence options, :id
94
+
95
+ SkylabStudio::Request.new(@configuration).delete("profiles/#{options[:id]}")
96
+ end
97
+
98
+ def list_photos(options = {})
99
+ SkylabStudio::Request.new(@configuration).get(:photos, payload: options)
100
+ end
101
+
102
+ def create_photo(options = {})
103
+ validate_argument_presence options, :photo
104
+
105
+ SkylabStudio::Request.new(@configuration).post(:photos, payload: options)
106
+ end
107
+
108
+ def get_photo(options = {})
109
+ validate_argument_presence options, :id
110
+
111
+ SkylabStudio::Request.new(@configuration).get("photos/#{options[:id]}", payload: options)
112
+ end
113
+
114
+ def update_photo(options = {})
115
+ validate_argument_presence options, :id
116
+ validate_argument_presence options, :photo
117
+
118
+ SkylabStudio::Request.new(@configuration).patch("photos/#{options[:id]}", payload: options)
119
+ end
120
+
121
+ def delete_photo(options = {})
122
+ validate_argument_presence options, :id
123
+
124
+ SkylabStudio::Request.new(@configuration).delete("photos/#{options[:id]}")
125
+ end
126
+
127
+ private
128
+
129
+ def validate_argument_presence(options, key)
130
+ raise SkylabStudio::ClientNilArgument, "#{key} cannot be nil" if options[key].nil?
131
+ end
132
+ end
133
+ end
@@ -0,0 +1,52 @@
1
+ require_relative 'version'
2
+
3
+ module SkylabStudio
4
+ class Config
5
+ attr_accessor :settings
6
+
7
+ DEFAULT_URL = 'https://studio.skylabtech.ai'.freeze
8
+
9
+ def self.defaults
10
+ source = URI.parse(DEFAULT_URL)
11
+
12
+ {
13
+ url: DEFAULT_URL,
14
+ api_key: nil,
15
+ protocol: source.scheme,
16
+ host: source.host,
17
+ port: source.port,
18
+ api_version: 'v1',
19
+ debug: true,
20
+ client_stub: "ruby-#{VERSION}"
21
+ }
22
+ end
23
+
24
+ def initialize(options = {})
25
+ @settings = SkylabStudio::Config.defaults.merge(options)
26
+ end
27
+
28
+ def method_missing(meth, *args, &block)
29
+ meth_str = meth.to_s
30
+
31
+ if meth_str.include?('=')
32
+ # If this is a write attempt, see if we can write to that key
33
+ meth_sym = meth_str.delete('=').to_sym
34
+
35
+ has?(meth_sym) ? @settings[meth_sym] = args[0] : super
36
+ else
37
+ # It's a read attempt, see if that key exists
38
+ has?(meth) ? @settings[meth] : super
39
+ end
40
+ end
41
+
42
+ def respond_to_missing?(meth, include_private = false)
43
+ has?(meth) || super
44
+ end
45
+
46
+ private
47
+
48
+ def has?(key)
49
+ @settings.key?(key)
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,3 @@
1
+ module SkylabStudio
2
+ class Error < StandardError; end
3
+ end
@@ -0,0 +1,85 @@
1
+ require_relative 'error'
2
+
3
+ module SkylabStudio
4
+ class ClientInvalidEndpoint < Error; end
5
+ class ClientConnectionRefused < Error; end
6
+ class ClientBadRequest < Error; end
7
+ class ClientInvalidKey < Error; end
8
+ class ClientUnknownError < Error; end
9
+
10
+ class Request
11
+ attr_reader :response
12
+
13
+ def initialize(configuration)
14
+ @configuration = configuration
15
+ end
16
+
17
+ def post(endpoint, payload)
18
+ request(Net::HTTP::Post, request_path(endpoint), payload)
19
+ end
20
+
21
+ def get(endpoint, payload = nil)
22
+ request(Net::HTTP::Get, request_path(endpoint), payload)
23
+ end
24
+
25
+ def delete(endpoint)
26
+ request(Net::HTTP::Delete, request_path(endpoint))
27
+ end
28
+
29
+ def put(endpoint, payload)
30
+ request(Net::HTTP::Put, request_path(endpoint), payload)
31
+ end
32
+
33
+ def patch(endpoint, payload)
34
+ request(Net::HTTP::Patch, request_path(endpoint), payload)
35
+ end
36
+
37
+ private
38
+
39
+ def request_path(end_point)
40
+ "/api/#{@configuration.api_version}/#{end_point}"
41
+ end
42
+
43
+ def use_ssl?
44
+ @configuration.protocol == 'https'
45
+ end
46
+
47
+ def request(method_klass, path, payload = {})
48
+ request = method_klass.new(path, 'Content-Type' => 'application/json')
49
+
50
+ request.add_field('X-SLT-API-KEY', @configuration.api_key)
51
+ request.add_field('X-SLT-API-CLIENT', @configuration.client_stub)
52
+
53
+ payload = payload.to_json
54
+
55
+ http = Net::HTTP.new(@configuration.host, @configuration.port)
56
+ http.use_ssl = use_ssl?
57
+ http.set_debug_output($stdout) if @configuration.debug
58
+
59
+ @response = http.request(request, payload)
60
+
61
+ handle_response(@response)
62
+ rescue Errno::ECONNREFUSED
63
+ raise SkylabStudio::ClientConnectionRefused, 'The connection was refused'
64
+ end
65
+
66
+ def handle_response(response)
67
+ case @response
68
+ when Net::HTTPUnauthorized then
69
+ raise SkylabStudio::ClientInvalidKey, 'Invalid api key'
70
+ when Net::HTTPForbidden then
71
+ raise SkylabStudio::ClientInvalidKey, 'Invalid api key'
72
+ when Net::HTTPNotFound then
73
+ raise SkylabStudio::ClientInvalidEndpoint, 'Resource not found'
74
+ when Net::HTTPBadRequest then
75
+ raise SkylabStudio::ClientBadRequest, 'There was an error processing your request'
76
+ when Net::HTTPTooManyRequests then
77
+ raise SkylabStudio::ClientBadRequest, 'The rate limit has been met'
78
+ when Net::HTTPSuccess
79
+ response
80
+ else
81
+ raise SkylabStudio::ClientUnknownError, 'An error has occurred'
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,3 @@
1
+ module SkylabStudio
2
+ VERSION = '1.0.5'.freeze
3
+ end
@@ -0,0 +1,217 @@
1
+ require File.expand_path('../../../lib/skylab_studio.rb', __dir__)
2
+
3
+ RSpec.describe SkylabStudio::Client do
4
+ before(:each) do
5
+ @client = SkylabStudio::Client.new
6
+ end
7
+
8
+ subject { @client }
9
+
10
+ it { should respond_to(:list_jobs) }
11
+ it { should respond_to(:get_job) }
12
+
13
+ describe '#configuration' do
14
+ it 'should return a configuration object' do
15
+ SkylabStudio::Client.configuration.settings.empty?.should eq(false)
16
+ end
17
+ end
18
+
19
+ describe '#configure' do
20
+ it 'should return a configuration object' do
21
+ SkylabStudio::Client.configure do |config|
22
+ config.settings.empty?.should eq(false)
23
+ end
24
+ end
25
+ end
26
+
27
+ describe '#initialize' do
28
+ it 'should set configuration' do
29
+ SkylabStudio::Client.new(protocol: 'foo').configuration.protocol.should eq('foo')
30
+ end
31
+ end
32
+
33
+ describe '#list_jobs' do
34
+ it 'should return response' do
35
+ SkylabStudio::Request.any_instance.stub(:get).and_return(true)
36
+
37
+ @client.list_jobs.should eq(true)
38
+ end
39
+ end
40
+
41
+ describe '#create_job' do
42
+ it 'should return response' do
43
+ SkylabStudio::Request.any_instance.stub(:post).and_return(true)
44
+
45
+ @client.create_job(
46
+ job: {
47
+ profile_id: 1
48
+ }
49
+ ).should eq(true)
50
+ end
51
+ end
52
+
53
+ describe '#get_job' do
54
+ it 'should raise error with no id' do
55
+ expect { @client.get_job }.to raise_error(SkylabStudio::ClientNilArgument)
56
+ end
57
+
58
+ it 'should return response' do
59
+ SkylabStudio::Request.any_instance.stub(:get).and_return(true)
60
+
61
+ @client.get_job(id: 123).should eq(true)
62
+ end
63
+ end
64
+
65
+ describe '#update_job' do
66
+ it 'should return response' do
67
+ SkylabStudio::Request.any_instance.stub(:patch).and_return(true)
68
+
69
+ @client.update_job(
70
+ id: 1,
71
+ job: {
72
+ profile_id: 2
73
+ }
74
+ ).should eq(true)
75
+ end
76
+ end
77
+
78
+ describe '#delete_job' do
79
+ it 'should return response' do
80
+ SkylabStudio::Request.any_instance.stub(:delete).and_return(true)
81
+
82
+ @client.delete_job(
83
+ id: 1
84
+ ).should eq(true)
85
+ end
86
+ end
87
+
88
+ describe '#process_job' do
89
+ it 'should return response' do
90
+ SkylabStudio::Request.any_instance.stub(:post).and_return(true)
91
+
92
+ @client.process_job(
93
+ id: 1
94
+ ).should eq(true)
95
+ end
96
+ end
97
+
98
+ describe '#cancel_job' do
99
+ it 'should return response' do
100
+ SkylabStudio::Request.any_instance.stub(:post).and_return(true)
101
+
102
+ @client.cancel_job(
103
+ id: 1
104
+ ).should eq(true)
105
+ end
106
+ end
107
+
108
+ describe '#list_profiles' do
109
+ it 'should return response' do
110
+ SkylabStudio::Request.any_instance.stub(:get).and_return(true)
111
+
112
+ @client.list_profiles.should eq(true)
113
+ end
114
+ end
115
+
116
+ describe '#create_profile' do
117
+ it 'should return response' do
118
+ SkylabStudio::Request.any_instance.stub(:post).and_return(true)
119
+
120
+ @client.create_profile(
121
+ profile: {
122
+ name: 'Foo'
123
+ }
124
+ ).should eq(true)
125
+ end
126
+ end
127
+
128
+ describe '#get_profile' do
129
+ it 'should raise error with no id' do
130
+ expect { @client.get_profile }.to raise_error(SkylabStudio::ClientNilArgument)
131
+ end
132
+
133
+ it 'should return response' do
134
+ SkylabStudio::Request.any_instance.stub(:get).and_return(true)
135
+
136
+ @client.get_profile(id: 123).should eq(true)
137
+ end
138
+ end
139
+
140
+ describe '#update_profile' do
141
+ it 'should return response' do
142
+ SkylabStudio::Request.any_instance.stub(:patch).and_return(true)
143
+
144
+ @client.update_profile(
145
+ id: 1,
146
+ profile: {
147
+ name: 'Bar'
148
+ }
149
+ ).should eq(true)
150
+ end
151
+ end
152
+
153
+ describe '#delete_profile' do
154
+ it 'should return response' do
155
+ SkylabStudio::Request.any_instance.stub(:delete).and_return(true)
156
+
157
+ @client.delete_profile(
158
+ id: 1
159
+ ).should eq(true)
160
+ end
161
+ end
162
+
163
+ describe '#list_photos' do
164
+ it 'should return response' do
165
+ SkylabStudio::Request.any_instance.stub(:get).and_return(true)
166
+
167
+ @client.list_photos.should eq(true)
168
+ end
169
+ end
170
+
171
+ describe '#create_photo' do
172
+ it 'should return response' do
173
+ SkylabStudio::Request.any_instance.stub(:post).and_return(true)
174
+
175
+ @client.create_photo(
176
+ photo: {
177
+ name: 'Foo'
178
+ }
179
+ ).should eq(true)
180
+ end
181
+ end
182
+
183
+ describe '#get_photo' do
184
+ it 'should raise error with no id' do
185
+ expect { @client.get_photo }.to raise_error(SkylabStudio::ClientNilArgument)
186
+ end
187
+
188
+ it 'should return response' do
189
+ SkylabStudio::Request.any_instance.stub(:get).and_return(true)
190
+
191
+ @client.get_photo(id: 123).should eq(true)
192
+ end
193
+ end
194
+
195
+ describe '#update_photo' do
196
+ it 'should return response' do
197
+ SkylabStudio::Request.any_instance.stub(:patch).and_return(true)
198
+
199
+ @client.update_photo(
200
+ id: 1,
201
+ photo: {
202
+ name: 'Bar'
203
+ }
204
+ ).should eq(true)
205
+ end
206
+ end
207
+
208
+ describe '#delete_photo' do
209
+ it 'should return response' do
210
+ SkylabStudio::Request.any_instance.stub(:delete).and_return(true)
211
+
212
+ @client.delete_photo(
213
+ id: 1
214
+ ).should eq(true)
215
+ end
216
+ end
217
+ end
@@ -0,0 +1,51 @@
1
+ require File.expand_path('../../../lib/skylab_studio.rb', __dir__)
2
+
3
+ RSpec.describe SkylabStudio::Config do
4
+ before(:each) do
5
+ @config = SkylabStudio::Config.new
6
+ end
7
+
8
+ subject { @config }
9
+
10
+ it { should respond_to(:api_key) }
11
+ it { should respond_to(:api_version) }
12
+ it { should respond_to(:client_stub) }
13
+ it { should respond_to(:debug) }
14
+ it { should respond_to(:host) }
15
+ it { should respond_to(:port) }
16
+ it { should respond_to(:protocol) }
17
+ it { should respond_to(:url) }
18
+
19
+ # Class methods
20
+ describe '#defaults' do
21
+ it 'return the proper default config' do
22
+ SkylabStudio::Config.defaults.empty?.should eq(false)
23
+ SkylabStudio::Config.defaults[:protocol].should eq('https')
24
+ end
25
+ end
26
+
27
+ describe '#initialize' do
28
+ it 'return override default config' do
29
+ SkylabStudio::Config.new(protocol: 'proto').protocol.should eq('proto')
30
+ end
31
+ end
32
+
33
+ # Instance methods
34
+ describe '#method_missing' do
35
+ it 'should allow the assignment of a config key' do
36
+ expect { @config.url = 'http://google.com' }.to_not raise_error
37
+ end
38
+
39
+ it 'should allow the fetch of a config key' do
40
+ expect { @config.url }.to_not raise_error
41
+ end
42
+
43
+ it 'should raise error on missing method' do
44
+ expect { @config.bad }.to raise_error(StandardError)
45
+ end
46
+
47
+ it 'should raise error on missing method assignment' do
48
+ expect { @config.bad = '123' }.to raise_error(StandardError)
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,262 @@
1
+ require File.expand_path('../../../lib/skylab_studio.rb', __dir__)
2
+
3
+ RSpec.describe SkylabStudio::Request do
4
+ before(:each) do
5
+ @client = SkylabStudio::Client.new
6
+ @config = SkylabStudio::Config.new
7
+
8
+ @request = SkylabStudio::Request.new(@config)
9
+ end
10
+
11
+ subject { @request }
12
+
13
+ describe '#post' do
14
+ it 'should return success' do
15
+ Net::HTTP.any_instance.stub(:request).and_return(Net::HTTPSuccess.new(1.0, 200, 'OK'))
16
+
17
+ @request.post(:jobs, {}).should be_instance_of(Net::HTTPSuccess)
18
+ end
19
+
20
+ it 'should raise error on 401' do
21
+ Net::HTTP.any_instance.stub(:request).and_return(Net::HTTPUnauthorized.new(1.0, 401, 'Error'))
22
+
23
+ expect { @request.post(:jobs, {}) }.to raise_error(SkylabStudio::ClientInvalidKey)
24
+ end
25
+
26
+ it 'should raise error on 403' do
27
+ Net::HTTP.any_instance.stub(:request).and_return(Net::HTTPForbidden.new(1.0, 403, 'Error'))
28
+
29
+ expect { @request.post(:jobs, {}) }.to raise_error(SkylabStudio::ClientInvalidKey)
30
+ end
31
+
32
+ it 'should raise error on 404' do
33
+ Net::HTTP.any_instance.stub(:request).and_return(Net::HTTPNotFound.new(1.0, 404, 'Error'))
34
+
35
+ expect { @request.post(:jobs, {}) }.to raise_error(SkylabStudio::ClientInvalidEndpoint)
36
+ end
37
+
38
+ it 'should raise error on 422' do
39
+ Net::HTTP.any_instance.stub(:request).and_return(Net::HTTPBadRequest.new(1.0, 422, 'Error'))
40
+
41
+ expect { @request.post(:jobs, {}) }.to raise_error(SkylabStudio::ClientBadRequest)
42
+ end
43
+
44
+ it 'should raise error on 429' do
45
+ Net::HTTP.any_instance.stub(:request).and_return(Net::HTTPTooManyRequests.new(1.0, 429, 'Error'))
46
+
47
+ expect { @request.post(:jobs, {}) }.to raise_error(SkylabStudio::ClientBadRequest)
48
+ end
49
+
50
+ it 'should raise error on unknown response' do
51
+ Net::HTTP.any_instance.stub(:request).and_return(false)
52
+
53
+ expect { @request.post(:jobs, {}) }.to raise_error(SkylabStudio::ClientUnknownError)
54
+ end
55
+
56
+ it 'should raise error on connection refused' do
57
+ Net::HTTP.any_instance.stub(:request).and_raise(Errno::ECONNREFUSED)
58
+
59
+ expect { @request.post(:jobs, {}) }.to raise_error(SkylabStudio::ClientConnectionRefused)
60
+ end
61
+ end
62
+
63
+ describe '#get' do
64
+ it 'should return success' do
65
+ Net::HTTP.any_instance.stub(:request).and_return(Net::HTTPSuccess.new(1.0, 200, 'OK'))
66
+
67
+ @request.get(:jobs, {}).should be_instance_of(Net::HTTPSuccess)
68
+ end
69
+
70
+ it 'should raise error on 401' do
71
+ Net::HTTP.any_instance.stub(:request).and_return(Net::HTTPUnauthorized.new(1.0, 401, 'Error'))
72
+
73
+ expect { @request.get(:jobs, {}) }.to raise_error(SkylabStudio::ClientInvalidKey)
74
+ end
75
+
76
+ it 'should raise error on 403' do
77
+ Net::HTTP.any_instance.stub(:request).and_return(Net::HTTPForbidden.new(1.0, 403, 'Error'))
78
+
79
+ expect { @request.get(:jobs, {}) }.to raise_error(SkylabStudio::ClientInvalidKey)
80
+ end
81
+
82
+ it 'should raise error on 404' do
83
+ Net::HTTP.any_instance.stub(:request).and_return(Net::HTTPNotFound.new(1.0, 404, 'Error'))
84
+
85
+ expect { @request.get(:jobs, {}) }.to raise_error(SkylabStudio::ClientInvalidEndpoint)
86
+ end
87
+
88
+ it 'should raise error on 422' do
89
+ Net::HTTP.any_instance.stub(:request).and_return(Net::HTTPBadRequest.new(1.0, 422, 'Error'))
90
+
91
+ expect { @request.get(:jobs, {}) }.to raise_error(SkylabStudio::ClientBadRequest)
92
+ end
93
+
94
+ it 'should raise error on 429' do
95
+ Net::HTTP.any_instance.stub(:request).and_return(Net::HTTPTooManyRequests.new(1.0, 429, 'Error'))
96
+
97
+ expect { @request.get(:jobs, {}) }.to raise_error(SkylabStudio::ClientBadRequest)
98
+ end
99
+
100
+ it 'should raise error on unknown response' do
101
+ Net::HTTP.any_instance.stub(:request).and_return(false)
102
+
103
+ expect { @request.get(:jobs, {}) }.to raise_error(SkylabStudio::ClientUnknownError)
104
+ end
105
+
106
+ it 'should raise error on connection refused' do
107
+ Net::HTTP.any_instance.stub(:request).and_raise(Errno::ECONNREFUSED)
108
+
109
+ expect { @request.get(:jobs, {}) }.to raise_error(SkylabStudio::ClientConnectionRefused)
110
+ end
111
+ end
112
+
113
+ describe '#delete' do
114
+ it 'should return success' do
115
+ Net::HTTP.any_instance.stub(:request).and_return(Net::HTTPSuccess.new(1.0, 200, 'OK'))
116
+
117
+ @request.delete(:jobs).should be_instance_of(Net::HTTPSuccess)
118
+ end
119
+
120
+ it 'should raise error on 401' do
121
+ Net::HTTP.any_instance.stub(:request).and_return(Net::HTTPUnauthorized.new(1.0, 401, 'Error'))
122
+
123
+ expect { @request.delete(:jobs) }.to raise_error(SkylabStudio::ClientInvalidKey)
124
+ end
125
+
126
+ it 'should raise error on 403' do
127
+ Net::HTTP.any_instance.stub(:request).and_return(Net::HTTPForbidden.new(1.0, 403, 'Error'))
128
+
129
+ expect { @request.delete(:jobs) }.to raise_error(SkylabStudio::ClientInvalidKey)
130
+ end
131
+
132
+ it 'should raise error on 404' do
133
+ Net::HTTP.any_instance.stub(:request).and_return(Net::HTTPNotFound.new(1.0, 404, 'Error'))
134
+
135
+ expect { @request.delete(:jobs) }.to raise_error(SkylabStudio::ClientInvalidEndpoint)
136
+ end
137
+
138
+ it 'should raise error on 422' do
139
+ Net::HTTP.any_instance.stub(:request).and_return(Net::HTTPBadRequest.new(1.0, 422, 'Error'))
140
+
141
+ expect { @request.delete(:jobs) }.to raise_error(SkylabStudio::ClientBadRequest)
142
+ end
143
+
144
+ it 'should raise error on 429' do
145
+ Net::HTTP.any_instance.stub(:request).and_return(Net::HTTPTooManyRequests.new(1.0, 429, 'Error'))
146
+
147
+ expect { @request.delete(:jobs) }.to raise_error(SkylabStudio::ClientBadRequest)
148
+ end
149
+
150
+ it 'should raise error on unknown response' do
151
+ Net::HTTP.any_instance.stub(:request).and_return(false)
152
+
153
+ expect { @request.delete(:jobs) }.to raise_error(SkylabStudio::ClientUnknownError)
154
+ end
155
+
156
+ it 'should raise error on connection refused' do
157
+ Net::HTTP.any_instance.stub(:request).and_raise(Errno::ECONNREFUSED)
158
+
159
+ expect { @request.delete(:jobs) }.to raise_error(SkylabStudio::ClientConnectionRefused)
160
+ end
161
+ end
162
+
163
+ describe '#put' do
164
+ it 'should return success' do
165
+ Net::HTTP.any_instance.stub(:request).and_return(Net::HTTPSuccess.new(1.0, 200, 'OK'))
166
+
167
+ @request.put(:jobs, {}).should be_instance_of(Net::HTTPSuccess)
168
+ end
169
+
170
+ it 'should raise error on 401' do
171
+ Net::HTTP.any_instance.stub(:request).and_return(Net::HTTPUnauthorized.new(1.0, 401, 'Error'))
172
+
173
+ expect { @request.put(:jobs, {}) }.to raise_error(SkylabStudio::ClientInvalidKey)
174
+ end
175
+
176
+ it 'should raise error on 403' do
177
+ Net::HTTP.any_instance.stub(:request).and_return(Net::HTTPForbidden.new(1.0, 403, 'Error'))
178
+
179
+ expect { @request.put(:jobs, {}) }.to raise_error(SkylabStudio::ClientInvalidKey)
180
+ end
181
+
182
+ it 'should raise error on 404' do
183
+ Net::HTTP.any_instance.stub(:request).and_return(Net::HTTPNotFound.new(1.0, 404, 'Error'))
184
+
185
+ expect { @request.put(:jobs, {}) }.to raise_error(SkylabStudio::ClientInvalidEndpoint)
186
+ end
187
+
188
+ it 'should raise error on 422' do
189
+ Net::HTTP.any_instance.stub(:request).and_return(Net::HTTPBadRequest.new(1.0, 422, 'Error'))
190
+
191
+ expect { @request.put(:jobs, {}) }.to raise_error(SkylabStudio::ClientBadRequest)
192
+ end
193
+
194
+ it 'should raise error on 429' do
195
+ Net::HTTP.any_instance.stub(:request).and_return(Net::HTTPTooManyRequests.new(1.0, 429, 'Error'))
196
+
197
+ expect { @request.put(:jobs, {}) }.to raise_error(SkylabStudio::ClientBadRequest)
198
+ end
199
+
200
+ it 'should raise error on unknown response' do
201
+ Net::HTTP.any_instance.stub(:request).and_return(false)
202
+
203
+ expect { @request.put(:jobs, {}) }.to raise_error(SkylabStudio::ClientUnknownError)
204
+ end
205
+
206
+ it 'should raise error on connection refused' do
207
+ Net::HTTP.any_instance.stub(:request).and_raise(Errno::ECONNREFUSED)
208
+
209
+ expect { @request.put(:jobs, {}) }.to raise_error(SkylabStudio::ClientConnectionRefused)
210
+ end
211
+ end
212
+
213
+ describe '#patch' do
214
+ it 'should return success' do
215
+ Net::HTTP.any_instance.stub(:request).and_return(Net::HTTPSuccess.new(1.0, 200, 'OK'))
216
+
217
+ @request.patch(:jobs, {}).should be_instance_of(Net::HTTPSuccess)
218
+ end
219
+
220
+ it 'should raise error on 401' do
221
+ Net::HTTP.any_instance.stub(:request).and_return(Net::HTTPUnauthorized.new(1.0, 401, 'Error'))
222
+
223
+ expect { @request.patch(:jobs, {}) }.to raise_error(SkylabStudio::ClientInvalidKey)
224
+ end
225
+
226
+ it 'should raise error on 403' do
227
+ Net::HTTP.any_instance.stub(:request).and_return(Net::HTTPForbidden.new(1.0, 403, 'Error'))
228
+
229
+ expect { @request.patch(:jobs, {}) }.to raise_error(SkylabStudio::ClientInvalidKey)
230
+ end
231
+
232
+ it 'should raise error on 404' do
233
+ Net::HTTP.any_instance.stub(:request).and_return(Net::HTTPNotFound.new(1.0, 404, 'Error'))
234
+
235
+ expect { @request.patch(:jobs, {}) }.to raise_error(SkylabStudio::ClientInvalidEndpoint)
236
+ end
237
+
238
+ it 'should raise error on 422' do
239
+ Net::HTTP.any_instance.stub(:request).and_return(Net::HTTPBadRequest.new(1.0, 422, 'Error'))
240
+
241
+ expect { @request.patch(:jobs, {}) }.to raise_error(SkylabStudio::ClientBadRequest)
242
+ end
243
+
244
+ it 'should raise error on 429' do
245
+ Net::HTTP.any_instance.stub(:request).and_return(Net::HTTPTooManyRequests.new(1.0, 429, 'Error'))
246
+
247
+ expect { @request.patch(:jobs, {}) }.to raise_error(SkylabStudio::ClientBadRequest)
248
+ end
249
+
250
+ it 'should raise error on unknown response' do
251
+ Net::HTTP.any_instance.stub(:request).and_return(false)
252
+
253
+ expect { @request.patch(:jobs, {}) }.to raise_error(SkylabStudio::ClientUnknownError)
254
+ end
255
+
256
+ it 'should raise error on connection refused' do
257
+ Net::HTTP.any_instance.stub(:request).and_raise(Errno::ECONNREFUSED)
258
+
259
+ expect { @request.patch(:jobs, {}) }.to raise_error(SkylabStudio::ClientConnectionRefused)
260
+ end
261
+ end
262
+ end
@@ -0,0 +1,5 @@
1
+ RSpec.describe SkylabStudio::VERSION do
2
+ it 'provides the current version number' do
3
+ SkylabStudio::VERSION.nil?.should eq(false)
4
+ end
5
+ end
@@ -0,0 +1,106 @@
1
+ require 'simplecov'
2
+
3
+ SimpleCov.start
4
+
5
+ # This file was generated by the `rspec --init` command. Conventionally, all
6
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
7
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
8
+ # this file to always be loaded, without a need to explicitly require it in any
9
+ # files.
10
+ #
11
+ # Given that it is always loaded, you are encouraged to keep this file as
12
+ # light-weight as possible. Requiring heavyweight dependencies from this file
13
+ # will add to the boot time of your test suite on EVERY test run, even for an
14
+ # individual file that may not need all of that loaded. Instead, consider making
15
+ # a separate helper file that requires the additional dependencies and performs
16
+ # the additional setup, and require it from the spec files that actually need
17
+ # it.
18
+ #
19
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
20
+ RSpec.configure do |config|
21
+ # rspec-expectations config goes here. You can use an alternate
22
+ # assertion/expectation library such as wrong or the stdlib/minitest
23
+ # assertions if you prefer.
24
+ config.expect_with :rspec do |expectations|
25
+ # This option will default to `true` in RSpec 4. It makes the `description`
26
+ # and `failure_message` of custom matchers include text for helper methods
27
+ # defined using `chain`, e.g.:
28
+ # be_bigger_than(2).and_smaller_than(4).description
29
+ # # => "be bigger than 2 and smaller than 4"
30
+ # ...rather than:
31
+ # # => "be bigger than 2"
32
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
33
+
34
+ expectations.syntax = %i[should expect]
35
+ end
36
+
37
+ # rspec-mocks config goes here. You can use an alternate test double
38
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
39
+ config.mock_with :rspec do |mocks|
40
+ # Prevents you from mocking or stubbing a method that does not exist on
41
+ # a real object. This is generally recommended, and will default to
42
+ # `true` in RSpec 4.
43
+ mocks.verify_partial_doubles = true
44
+
45
+ mocks.syntax = %i[should expect]
46
+ end
47
+
48
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
49
+ # have no way to turn it off -- the option exists only for backwards
50
+ # compatibility in RSpec 3). It causes shared context metadata to be
51
+ # inherited by the metadata hash of host groups and examples, rather than
52
+ # triggering implicit auto-inclusion in groups with matching metadata.
53
+ config.shared_context_metadata_behavior = :apply_to_host_groups
54
+
55
+ # The settings below are suggested to provide a good initial experience
56
+ # with RSpec, but feel free to customize to your heart's content.
57
+ # # This allows you to limit a spec run to individual examples or groups
58
+ # # you care about by tagging them with `:focus` metadata. When nothing
59
+ # # is tagged with `:focus`, all examples get run. RSpec also provides
60
+ # # aliases for `it`, `describe`, and `context` that include `:focus`
61
+ # # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
62
+ # config.filter_run_when_matching :focus
63
+ #
64
+ # # Allows RSpec to persist some state between runs in order to support
65
+ # # the `--only-failures` and `--next-failure` CLI options. We recommend
66
+ # # you configure your source control system to ignore this file.
67
+ # config.example_status_persistence_file_path = "spec/examples.txt"
68
+ #
69
+ # # Limits the available syntax to the non-monkey patched syntax that is
70
+ # # recommended. For more details, see:
71
+ # # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
72
+ # # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
73
+ # # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
74
+ # config.disable_monkey_patching!
75
+ #
76
+ # # This setting enables warnings. It's recommended, but in some cases may
77
+ # # be too noisy due to issues in dependencies.
78
+ # config.warnings = true
79
+ #
80
+ # # Many RSpec users commonly either run the entire suite or an individual
81
+ # # file, and it's useful to allow more verbose output when running an
82
+ # # individual spec file.
83
+ # if config.files_to_run.one?
84
+ # # Use the documentation formatter for detailed output,
85
+ # # unless a formatter has already been configured
86
+ # # (e.g. via a command-line flag).
87
+ # config.default_formatter = "doc"
88
+ # end
89
+ #
90
+ # # Print the 10 slowest examples and example groups at the
91
+ # # end of the spec run, to help surface which specs are running
92
+ # # particularly slow.
93
+ # config.profile_examples = 10
94
+ #
95
+ # # Run specs in random order to surface order dependencies. If you find an
96
+ # # order dependency and want to debug it, you can fix the order by providing
97
+ # # the seed, which is printed after each run.
98
+ # # --seed 1234
99
+ # config.order = :random
100
+ #
101
+ # # Seed global randomization in this process using the `--seed` CLI option.
102
+ # # Setting this allows you to use `--seed` to deterministically reproduce
103
+ # # test failures related to randomization by passing the same `--seed` value
104
+ # # as the one that triggered the failure.
105
+ # Kernel.srand config.seed
106
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: skylab_studio
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.5
5
+ platform: ruby
6
+ authors:
7
+ - Paul Lam
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-05-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.8'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: shoulda-matchers
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 3.1.2
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 3.1.2
41
+ description: studio.skylabtech.ai ruby client
42
+ email:
43
+ - info@skylabtech.ai
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - lib/skylab_studio.rb
49
+ - lib/skylab_studio/client.rb
50
+ - lib/skylab_studio/config.rb
51
+ - lib/skylab_studio/error.rb
52
+ - lib/skylab_studio/request.rb
53
+ - lib/skylab_studio/version.rb
54
+ - spec/lib/skylab_studio/client_spec.rb
55
+ - spec/lib/skylab_studio/config_spec.rb
56
+ - spec/lib/skylab_studio/request_spec.rb
57
+ - spec/lib/skylab_studio/version_spec.rb
58
+ - spec/spec_helper.rb
59
+ homepage: https://github.com/skylab-tech/studio_client_ruby
60
+ licenses:
61
+ - Apache-2.0
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubygems_version: 3.1.6
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: A HTTP client for accessing studio.skylabtech.ai services.
82
+ test_files:
83
+ - spec/spec_helper.rb
84
+ - spec/lib/skylab_studio/config_spec.rb
85
+ - spec/lib/skylab_studio/client_spec.rb
86
+ - spec/lib/skylab_studio/version_spec.rb
87
+ - spec/lib/skylab_studio/request_spec.rb