Skip to content

Commit ad23c74

Browse files
committed
feat: all remaining service endpoints.
1 parent 0b6a567 commit ad23c74

File tree

4 files changed

+519
-2
lines changed

4 files changed

+519
-2
lines changed

README.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
A Ruby interface for [the render.com API](https://render.com/docs/api).
44

5-
**Please note**: this gem is currently a proof-of-concept and does not support all of the API's endpoints yet - what's covered below in Usage is what's available right now. Full support is definitely the plan, and pull requests are welcome.
5+
At this point in time all known API endpoints are supported.
66

77
## Installation
88

@@ -51,6 +51,30 @@ services.each do |service|
5151
puts service.cursor
5252
puts service.service_details.build_command
5353
end
54+
55+
# https://api-docs.render.com/reference/create-service
56+
client.services.create(name: "my-new-service", ...)
57+
# https://api-docs.render.com/reference/update-service
58+
client.services.update(service_id, name: "my-new-service", ...)
59+
client.services.delete(service_id)
60+
61+
client.services.suspend(service_id)
62+
client.services.resume(service_id)
63+
client.services.scale(service_id, num_instances: 5)
64+
65+
client.services.list_headers(service_id, limit: nil, cursor: nil, filters: nil)
66+
client.services.list_routes(service_id, limit: nil, cursor: nil, filters: nil)
67+
client.services.list_variables(service_id, limit: nil, cursor: nil)
68+
# Note that updating variables requires all variables to be provided.
69+
# https://api-docs.render.com/reference/update-env-vars-for-service
70+
# (i.e. a full update, not a partial update)
71+
client.services.update_variables(
72+
service_id,
73+
[
74+
{ key: "RAILS_ENV", value: "production" },
75+
{ key: "RAILS_SESSION_SECRET", generate_value: "yes" }
76+
]
77+
)
5478
```
5579

5680
### Deploys

lib/render_api/clients/services.rb

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,62 @@
55
module RenderAPI
66
module Clients
77
class Services < Base
8+
def create(**payload)
9+
endpoint.post("/services", body: payload)
10+
end
11+
12+
def delete(service_id)
13+
endpoint.delete("/services/#{service_id}")
14+
end
15+
816
def find(service_id)
917
endpoint.get("/services/#{service_id}")
1018
end
1119

1220
def list(...)
1321
endpoint.get("/services", params: list_parameters(...))
1422
end
23+
24+
def list_headers(service_id, ...)
25+
endpoint.get(
26+
"/services/#{service_id}/headers", params: list_parameters(...)
27+
)
28+
end
29+
30+
def list_routes(service_id, ...)
31+
endpoint.get(
32+
"/services/#{service_id}/routes", params: list_parameters(...)
33+
)
34+
end
35+
36+
def list_variables(service_id, ...)
37+
endpoint.get(
38+
"/services/#{service_id}/env-vars", params: list_parameters(...)
39+
)
40+
end
41+
42+
def resume(service_id)
43+
endpoint.post("/services/#{service_id}/resume")
44+
end
45+
46+
def scale(service_id, num_instances:)
47+
endpoint.post(
48+
"/services/#{service_id}/scale",
49+
body: { num_instances: num_instances }
50+
)
51+
end
52+
53+
def suspend(service_id)
54+
endpoint.post("/services/#{service_id}/suspend")
55+
end
56+
57+
def update(service_id, **payload)
58+
endpoint.patch("/services/#{service_id}", body: payload)
59+
end
60+
61+
def update_variables(service_id, payloads)
62+
endpoint.put("/services/#{service_id}/env-vars", body: payloads)
63+
end
1564
end
1665
end
1766
end

lib/render_api/endpoint.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,18 @@ def get(path, params: nil)
1818
request(:get, path, params: params)
1919
end
2020

21+
def patch(path, body: nil)
22+
request(:patch, path, body: camelise(body))
23+
end
24+
2125
def post(path, body: nil)
2226
request(:post, path, body: camelise(body))
2327
end
2428

29+
def put(path, body: nil)
30+
request(:put, path, body: camelise(body))
31+
end
32+
2533
def delete(path)
2634
request(:delete, path)
2735
end

0 commit comments

Comments
 (0)