-
Notifications
You must be signed in to change notification settings - Fork 56
docs: Add USAGE.md #72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
# Usage | ||
|
||
Usage examples for SendGrid ruby-http-client | ||
|
||
## Initialization | ||
|
||
``` | ||
require_relative '../lib/ruby_http_client' | ||
|
||
# This uses the SendGrid API as an example | ||
headers = JSON.parse(' | ||
{ | ||
"Authorization": "Bearer ' + ENV['SENDGRID_API_KEY'] + '" | ||
} | ||
') | ||
host = 'https://api.sendgrid.com' | ||
client = SendGrid::Client.new(host: host, request_headers: headers) | ||
``` | ||
|
||
## Table of Contents | ||
|
||
- [GET](#get) | ||
- [DELETE](#delete) | ||
- [POST](#post) | ||
- [PUT](#put) | ||
- [PATCH](#patch) | ||
|
||
<a name="get"></a> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. markdown automatically generates anchors to each header, you can remove all the html tags |
||
## GET | ||
|
||
#### GET Collection | ||
|
||
``` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ruby formatter |
||
query_params = { 'limit' => 100, 'offset' => 0 } | ||
response = client.version('v3').api_keys.get(query_params: query_params) | ||
puts response.status_code | ||
puts response.body | ||
puts response.headers | ||
``` | ||
|
||
#### GET Single | ||
|
||
``` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ruby formatter |
||
response = client.version('v3').api_keys._(api_key_id).get | ||
puts response.status_code | ||
puts response.body | ||
puts response.headers | ||
``` | ||
|
||
<a name="delete"></a> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. markdown automatically generates anchors to each header, you can remove all the html tags |
||
## DELETE | ||
|
||
``` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ruby formatter |
||
response = client.api_keys._(api_key_id).delete | ||
puts response.status_code | ||
puts response.headers | ||
``` | ||
|
||
<a name="post"></a> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. markdown automatically generates anchors to each header, you can remove all the html tags |
||
## POST | ||
|
||
``` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ruby formatter |
||
request_body = JSON.parse(' | ||
{ | ||
"name": "My API Key Ruby Test", | ||
"scopes": [ | ||
"mail.send", | ||
"alerts.create", | ||
"alerts.read" | ||
] | ||
} | ||
') | ||
response = client.version('v3').api_keys.post(request_body: request_body) | ||
puts response.status_code | ||
puts response.body | ||
puts response.headers | ||
api_key_id = JSON.parse(response.body)['api_key_id'] | ||
``` | ||
|
||
<a name="put"></a> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. markdown automatically generates anchors to each header, you can remove all the html tags |
||
## PUT | ||
|
||
``` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add ruby formatter |
||
request_body = JSON.parse(' | ||
{ | ||
"name": "A New Hope", | ||
"scopes": [ | ||
"user.profile.read", | ||
"user.profile.update" | ||
] | ||
} | ||
') | ||
response = client.api_keys._(api_key_id).put(request_body: request_body) | ||
puts response.status_code | ||
puts response.body | ||
puts response.headers | ||
``` | ||
|
||
<a name="patch"></a> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. markdown automatically generates anchors to each header, you can remove all the html tags |
||
## PATCH | ||
|
||
``` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ruby formatter |
||
request_body = JSON.parse(' | ||
{ | ||
"name": "A New Hope" | ||
} | ||
') | ||
response = client.api_keys._(api_key_id).patch(request_body: request_body) | ||
puts response.status_code | ||
puts response.body | ||
puts response.headers | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add
ruby
code formatteri.e.