forked from Marx314/python-ubersmithclient
-
Notifications
You must be signed in to change notification settings - Fork 5
Ability to use POST as default request method
#5
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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,39 @@ | ||
| # Ubersmith API Client for Python | ||
| Ubersmith API Client for Python | ||
| =============================== | ||
|
|
||
| .. image:: https://travis-ci.org/internap/python-ubersmithclient.svg?branch=master | ||
| :target: https://travis-ci.org/internap/python-ubersmithclient | ||
|
|
||
| .. image:: https://img.shields.io/pypi/v/ubersmith_client.svg?style=flat | ||
| :target: https://pypi.python.org/pypi/ubersmith_client | ||
|
|
||
| # Usage | ||
| Usage | ||
| ----- | ||
| .. code:: python | ||
|
|
||
| >>> import ubersmith_client | ||
| >>> api = ubersmith_client.api.init('http://ubersmith.com/api/2.0/', 'username', 'password') | ||
| >>> api.client.count() | ||
| u'264' | ||
| >>> api.client.latest_client() | ||
| 1265 | ||
| import ubersmith_client | ||
|
|
||
| api = ubersmith_client.api.init('http://ubersmith.com/api/2.0/', 'username', 'password') | ||
| api.client.count() | ||
| >>> u'264' | ||
| api.client.latest_client() | ||
| >>> 1265 | ||
|
|
||
| API | ||
| --------- | ||
|
|
||
| **ubersmith_client.api.init(url, user, password, timeout, use_http_post)** | ||
| :url: | ||
| URL of your API | ||
|
|
||
| *Example:* ``http://ubersmith.example.org/api/2.0/`` | ||
|
|
||
| :user: API username | ||
| :password: API Password or token | ||
| :timeout: api timeout given to requests | ||
|
|
||
| *Default:* ``60`` | ||
| :use_http_post: | ||
| Use `POST` requests instead of `GET` | ||
|
|
||
| *Default:* ``False`` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| requests<=2.9.1 | ||
| six>=1.10.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,37 +16,42 @@ | |
| from ubersmith_client.exceptions import UbersmithException, get_exception_for | ||
|
|
||
|
|
||
| def init(url, user, password, timeout=60): | ||
| return UbersmithApi(url, user, password, timeout) | ||
| def init(url, user, password, timeout=60, use_http_post=False): | ||
|
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. Please document this new parameter and what it does. |
||
| return UbersmithApi(url, user, password, timeout, use_http_post) | ||
|
|
||
|
|
||
| class UbersmithApi(object): | ||
| def __init__(self, url, user, password, timeout): | ||
| def __init__(self, url, user, password, timeout, use_http_post): | ||
| self.url = url | ||
| self.user = user | ||
| self.password = password | ||
| self.timeout = timeout | ||
| self.use_http_post = use_http_post | ||
|
|
||
| def __getattr__(self, module): | ||
| return UbersmithRequest(self.url, self.user, self.password, module, self.timeout) | ||
| return UbersmithRequest(self.url, self.user, self.password, module, self.timeout, self.use_http_post) | ||
|
|
||
|
|
||
| class UbersmithRequest(object): | ||
| def __init__(self, url, user, password, module, timeout): | ||
| def __init__(self, url, user, password, module, timeout, use_http_post): | ||
| self.url = url | ||
| self.user = user | ||
| self.password = password | ||
| self.module = module | ||
| self.methods = [] | ||
| self.http_methods = {'GET': 'get', 'POST': 'post'} | ||
| self.timeout = timeout | ||
| self.use_http_post = use_http_post | ||
|
|
||
| def __getattr__(self, function): | ||
| self.methods.append(function) | ||
| return self | ||
|
|
||
| def __call__(self, **kwargs): | ||
| return self.http_get(**kwargs) | ||
| if self.use_http_post: | ||
| return self.http_post(**kwargs) | ||
| else: | ||
| return self.http_get(**kwargs) | ||
|
|
||
| def process_request(self, http_method, **kwargs): | ||
| callable_http_method = getattr(requests, http_method) | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Make sure that this style of import still works even if you proved it with the exceptions.