Skip to content

Commit d8ebb0a

Browse files
authored
Create functionality for creating a service (#6)
1 parent 2f84e13 commit d8ebb0a

File tree

3 files changed

+7
-18
lines changed

3 files changed

+7
-18
lines changed

lib/render_ruby/objects/service.rb

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
module RenderRuby
44
class Service < Object
5+
TYPES = %w[static_site web_service private_service background_worker cron_job].freeze
6+
57
def auto_deploy_enabled?
68
autoDeploy.equal?('yes')
79
end

lib/render_ruby/resource.rb

+1-18
Original file line numberDiff line numberDiff line change
@@ -30,27 +30,10 @@ def delete_request(url, params: {}, headers: {})
3030
handle_response client.connection.delete(url, params, headers)
3131
end
3232

33-
# rubocop:disable Metrics/CyclomaticComplexity
3433
def handle_response(response)
35-
case response.status
36-
when 400
37-
raise Error, "Your request was malformed. #{response.body}"
38-
when 401
39-
raise Error, "You did not supply valid authentication credentials. #{response.body}"
40-
when 403
41-
raise Error, "You are not allowed to perform that action. #{response.body}"
42-
when 404
43-
raise Error, "No results were found for your request. #{response.body}"
44-
when 429
45-
raise Error, "Your request exceeded the API rate limit. #{response.body}"
46-
when 500
47-
raise Error, "We were unable to perform the request due to server-side problems. #{response.body}"
48-
when 503
49-
raise Error, "You have been rate limited for sending more than 30 requests per minute. #{response.body}"
50-
end
34+
raise Error, response.body['message'] unless [200, 201].include?(response.status)
5135

5236
response
5337
end
54-
# rubocop:enable Metrics/CyclomaticComplexity
5538
end
5639
end

lib/render_ruby/resources/services.rb

+4
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,9 @@ def list(**params)
1111
def retrieve(service_id:)
1212
Service.new get_request("services/#{service_id}").body
1313
end
14+
15+
def create(**attributes)
16+
Service.new post_request('services', body: attributes).body
17+
end
1418
end
1519
end

0 commit comments

Comments
 (0)