Skip to content

add USAGE.md #49

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 1 commit into from
Oct 27, 2017
Merged
Changes from all commits
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
96 changes: 96 additions & 0 deletions USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# INITIALIZATION

```python
import python_http_client

host = "https://api.sendgrid.com"
api_key = os.environ.get('SENDGRID_API_KEY')
request_headers = {
"Authorization": 'Bearer {0}'.format(api_key)
}
version = 3
client = python_http_client.Client(host=host,
request_headers=request_headers,
version=version)
```

# Table of Contents

* [CLIENT](#client)
* [RESPONSE](#response)

<a name="response"></a>
# RESPONSE

Response object holds the response or data from a return statement from a client API call. It has three main properties, status_code, headers and body, which can be retrieved via a simple call:

```python
print(response.status_code)
print(response.headers)
print(response.body)
```

<a name="client"></a>
# CLIENT
Client object that allows quick access a REST-like API. All methods return a Response object that can be treated with as explained in Response.

## GET
HTTP request to retrieve information from a source.

```python
response = client.api_keys.get()
```

```python
response = client.api_keys._(api_key_id).get()
```

## POST
HTTP request to send data to a source.

```python
data = {
"name": "My API Key",
"scopes": [
"mail.send",
"alerts.create",
"alerts.read"
]
}
response = client.api_keys.post(request_body=data)
# print(response) as shown above
```

## PATCH
HTTP request to update partial resources in a source.

```python
data = {
"name": "A New Hope"
}
response = client.api_keys._(api_key_id).patch(request_body=data)
# print(response) as shown above
```

## PUT
HTTP request used to replace a collection or element in a source.

```python
data = {
"name": "The Empire Strikes Back",
"scopes": [
"user.profile.read",
"user.profile.update"
]
}
response = client.api_keys.put(request_body=data)
# print(response) as shown above
```

## DELETE
HTTP request to delete elements in a source.

```python
response = client.api_keys._(api_keys_id).delete()
# print(response) as shown above
```