Skip to content

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

Merged
merged 2 commits into from
Oct 4, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 112 additions & 0 deletions USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# Usage

Usage examples for SendGrid ruby-http-client

## Initialization

```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add ruby code formatter
i.e.

 ```ruby
 <code>
 ....

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>
Copy link
Contributor

Choose a reason for hiding this comment

The 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

```
Copy link
Contributor

Choose a reason for hiding this comment

The 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

```
Copy link
Contributor

Choose a reason for hiding this comment

The 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>
Copy link
Contributor

Choose a reason for hiding this comment

The 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

```
Copy link
Contributor

Choose a reason for hiding this comment

The 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>
Copy link
Contributor

Choose a reason for hiding this comment

The 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

```
Copy link
Contributor

Choose a reason for hiding this comment

The 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>
Copy link
Contributor

Choose a reason for hiding this comment

The 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
[create an anchor](#anchors-in-markdown)

## PUT

```
Copy link
Contributor

Choose a reason for hiding this comment

The 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>
Copy link
Contributor

Choose a reason for hiding this comment

The 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

```
Copy link
Contributor

Choose a reason for hiding this comment

The 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
```