Skip to content

Commit 00f7535

Browse files
authored
Add usage guide to readme (#12)
1 parent 51c3b80 commit 00f7535

File tree

1 file changed

+175
-2
lines changed

1 file changed

+175
-2
lines changed

README.md

+175-2
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,187 @@ Or install it yourself as:
2222

2323
$ gem install render_ruby
2424

25+
## Usage
26+
To access the API, you'll need to create a RenderRuby::Client and pass in your API key. You can find your API key at https://render.com/docs/api
27+
28+
```ruby
29+
client = RenderRuby::Client.new(api_key: ENV['RENDER_API_KEY'])
30+
```
31+
The client then gives you access to each of the resources.
32+
33+
## Resources
34+
The gem maps as closely as we can to the Render API so you can easily convert API examples to gem code.
35+
36+
Responses are created as objects like RenderRuby::Owner. Having types like RenderRuby::Owner is handy for understanding what type of object you're working with. They're built using OpenStruct so you can easily access data in a Ruby-ish way.
37+
38+
#### Pagination
39+
40+
`list` endpoints return pages of results. The result object will have a data key to access the results, as well as metadata like next_cursor and prev_cursor for retrieving the next and previous pages. You may also specify the
41+
42+
```ruby
43+
results = client.owners.list(limit: 100) # limit is optional, defaults to 20.
44+
#=> RenderRuby::Collection
45+
46+
results.total
47+
#=> 55
48+
49+
results.data
50+
#=> [#<RenderRuby::Owner>, #<RenderRuby::Owner>]
51+
52+
results.next_cursor
53+
#=> "XMTjXEjiQJmNjEwZ2QwZWQ5N2x2MGZ"
54+
55+
# Retrieve the next page
56+
client.owners.list(limit: 100, cursor: results.next_cursor)
57+
#=> RenderRuby::Collection
58+
```
59+
60+
### Owners
61+
```ruby
62+
response = client.owners.list
63+
#=> RenderRuby::Collection
64+
65+
response.data.first.user?
66+
#=> true
67+
68+
response.data.first.team?
69+
#=> false
70+
71+
client.owners.retrieve(owner_id: 'XMTjXEjiQJmNjEwZ2QwZWQ5N2x2MGZ')
72+
#=> RenderRuby::Owner
73+
```
74+
75+
### Services
76+
```ruby
77+
client.services.list
78+
#=> RenderRuby::Collection
79+
80+
service = client.services.retrieve(service_id: 'XMTjXEjiQJmNjEwZ2QwZWQ5N2x2MGZ')
81+
#=> RenderRuby::Service
82+
83+
service.auto_deploy_enabled?
84+
#=> true
85+
86+
service.suspended?
87+
#=> false
88+
89+
RenderRuby::Service::TYPES
90+
#=> ['static_site', 'web_service', 'private_service', 'background_worker', 'cron_job']
91+
92+
client.services.create(
93+
type: RenderRuby::Service::TYPES.sample,
94+
name: 'foo bar',
95+
ownerId: 'XMTjXEjiQJmNjEwZ2QwZWQ5N2x2MGZ',
96+
repo: 'https://github.com/render-examples/flask-hello-world',
97+
autoDeploy: 'yes', # or 'no',
98+
branch: 'master'
99+
)
100+
#=> RenderRuby::Service
101+
102+
client.services.update(
103+
service_id: 'XMTjXEjiQJmNjEwZ2QwZWQ5N2x2MGZ',
104+
name: 'foo bar',
105+
autoDeploy: 'yes', # or 'no',
106+
branch: 'master'
107+
)
108+
#=> RenderRuby::Service
109+
110+
client.services.delete(service_id: 'XMTjXEjiQJmNjEwZ2QwZWQ5N2x2MGZ')
111+
#=> Faraday::Response
112+
113+
client.services.suspend(service_id: 'XMTjXEjiQJmNjEwZ2QwZWQ5N2x2MGZ')
114+
#=> Faraday::Response
115+
116+
client.services.resume(service_id: 'XMTjXEjiQJmNjEwZ2QwZWQ5N2x2MGZ')
117+
#=> Faraday::Response
118+
119+
client.services.retrieve_env_vars(service_id:'XMTjXEjiQJmNjEwZ2QwZWQ5N2x2MGZ')
120+
#=> RenderRuby::Collection
121+
122+
client.services.update_env_var(
123+
service_id: 'XMTjXEjiQJmNjEwZ2QwZWQ5N2x2MGZ',
124+
env_vars: [
125+
{
126+
name: 'FOO',
127+
value: 'bar'
128+
}
129+
]
130+
)
131+
#=> RenderRuby::EnvironmentVariable
132+
133+
client.services.retrieve_headers(service_id: 'XMTjXEjiQJmNjEwZ2QwZWQ5N2x2MGZ')
134+
#=> RenderRuby::Collection
135+
136+
results = client.services.retrieve_redirect_and_rewrite_rules(service_id: 'XMTjXEjiQJmNjEwZ2QwZWQ5N2x2MGZ')
137+
#=> RenderRuby::Collection
138+
139+
results.data.first.redirect?
140+
#=> true
141+
142+
results.data.first.rewrite?
143+
#=> false
144+
145+
client.services.scale(service_id: 'XMTjXEjiQJmNjEwZ2QwZWQ5N2x2MGZ', num_instances: 1)
146+
#=> RenderRuby::Scale
147+
```
148+
149+
### Jobs
150+
```ruby
151+
client.jobs.list(service_id: 'XMTjXEjiQJmNjEwZ2QwZWQ5N2x2MGZ')
152+
#=> RenderRuby::Collection
153+
154+
client.jobs.retrieve(service_id: 'XMTjXEjiQJm', job_id: 'XMTjXEjiQJ')
155+
#=> RenderRuby::Job
156+
157+
client.jobs.create(
158+
service_id: 'XMTjXEjiQJmNjEwZ2QwZWQ5N2x2MGZ',
159+
start_command: 'yarn dev',
160+
planId: 'XMTjXEjiQJmNjEwZ2QwZWQ5N2x2MGZ' # optional
161+
)
162+
#=> RenderRuby::Job
163+
```
164+
165+
### Deploys
166+
```ruby
167+
client.deploys.list(service_id: 'XMTjXEjiQJmNjEwZ2QwZWQ5N2x2MGZ')
168+
#=> RenderRuby::Collection
169+
170+
client.deploys.retrieve(service_id: 'XMTjXEjiQJm', deploy_id: 'XMTjXEjiQJ')
171+
#=> RenderRuby::Deploy
172+
173+
client.deploys.trigger(
174+
service_id: 'XMTjXEjiQJmNjEwZ2QwZWQ5N2x2MGZ',
175+
clear_cache: 'clear' # or 'do_not_clear'
176+
)
177+
#=> RenderRuby::Deploy
178+
```
179+
180+
### Custom Domains
181+
```ruby
182+
client.custom_domains.list(service_id: 'XMTjXEjiQJmNjEwZ2QwZWQ5N2x2MGZ')
183+
#=> RenderRuby::Collection
184+
185+
client.custom_domains.retrieve(service_id: 'XMTjXEjiQJm', custom_domain_id: 'XMTjXEjiQJ')
186+
#=> RenderRuby::CustomDomain
187+
188+
client.custom_domains.create(
189+
service_id: 'XMTjXEjiQJmNjEwZ2QwZWQ5N2x2MGZ',
190+
domain: 'www.nejdetkadirbektas.com'
191+
)
192+
#=> RenderRuby::CustomDomain
193+
194+
client.custom_domains.delete(service_id: 'XMTjXEjiQJm', custom_domain_id: 'XMTjXEjiQJ')
195+
#=> Faraday::Response
196+
```
197+
25198
## Contributing
26199

27-
Bug reports and pull requests are welcome on GitHub at https://github.com/nejdetkadir/render_ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/nejdetkadir/render_ruby/blob/main/CODE_OF_CONDUCT.md).
200+
Bug reports and pull requests are welcome on GitHub at https://github.com/nejdetkadir/render-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/nejdetkadir/render-ruby/blob/main/CODE_OF_CONDUCT.md).
28201

29202
## License
30203

31204
The gem is available as open source under the terms of the [MIT License](LICENSE).
32205

33206
## Code of Conduct
34207

35-
Everyone interacting in the RenderRuby project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/nejdetkadir/render_ruby/blob/main/CODE_OF_CONDUCT.md).
208+
Everyone interacting in the RenderRuby project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/nejdetkadir/render-ruby/blob/main/CODE_OF_CONDUCT.md).

0 commit comments

Comments
 (0)