Skip to content

Commit

Permalink
Better error triggering and updated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jgillmanjr committed Feb 19, 2018
1 parent 3ef76fa commit 1bec949
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
38 changes: 37 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,40 @@ client.endpoint.storm.server.list()
pprint(client.endpoint.storm.server.list.result)
```

More detailed documentation to follow
Or if you wanted 99 records per page:
```
client.endpoint.storm.server.list(page_size=99)
```

### The Rest of the Story ###

#### Calling API Methods ###
Basically, when a `Client` object is instantiated, it pulls a list of
methods by way of the source JSON document that's actually used
for building the API documentation.

From the method list, an "attribute path", if you will, is created off of
the `endpoint` attribute, as demonstrated in the above example. You can
either directly call the attribute as previously shown, or if desired,
you can call the `request` method.

Either of these ways allow passing in parameters via `kwargs`.

#### Returns & Accessing the Results ####
The return is a boolean indicating the success of the API call.

A few things will cause this to return false:
* A non-200 status code
* The `error` key being present in the returned result dictionary
* The returned content isn't able to be parsed by the `json()` method

If the returned content isn't able to be parsed (a good situation where
this would happen is an authentication failure), the `result_text` of
the method object will still be accessible.

Additionally, the raw `Response` object is available by way of the
`raw_result` attribute of the method object. See the documentation for
[requests](http://docs.python-requests.org/en/master/) for more information.

If JSON parsing was successful (remember, you can still have an error),
the result will be transformed into a dictionary named `result`.
5 changes: 3 additions & 2 deletions snakeStorm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,13 @@ def request(self, **kwargs):

self.raw_result = requests.post(**request_args)
self.result_text = self.raw_result.text

try:
self.result = self.raw_result.json()
self.request_error = (self.raw_result.status_code != requests.codes.ok) or 'error' in self.result
except Exception:
pass
self.request_error = True

self.request_error = (self.raw_result.status_code != requests.codes.ok)
return not self.request_error


Expand Down

0 comments on commit 1bec949

Please sign in to comment.