diff --git a/README.md b/README.md index 634526b..8751c5d 100644 --- a/README.md +++ b/README.md @@ -22,4 +22,40 @@ client.endpoint.storm.server.list() pprint(client.endpoint.storm.server.list.result) ``` -More detailed documentation to follow \ No newline at end of file +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`. \ No newline at end of file diff --git a/snakeStorm/__init__.py b/snakeStorm/__init__.py index 8d01df7..b6d07f0 100644 --- a/snakeStorm/__init__.py +++ b/snakeStorm/__init__.py @@ -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