Skip to content
This repository was archived by the owner on Oct 4, 2023. It is now read-only.

Commit 8322d90

Browse files
committed
Merge pull request #14 from Imgur/v1.1
v1.1
2 parents 3459122 + 2d76c32 commit 8322d90

40 files changed

Lines changed: 1056 additions & 378 deletions
File renamed without changes.

README.md

Lines changed: 195 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,185 @@ Installation
2626

2727
pip install imgurpython
2828

29+
Library Usage
30+
------------
31+
32+
Using imgurpython in your application takes just a couple quick steps.
33+
34+
To use the client from a strictly anonymous context (no actions on behalf of a user)
35+
36+
```python
37+
38+
from imgurpython import ImgurClient
39+
40+
client_id = 'YOUR CLIENT ID'
41+
client_secret = 'YOUR CLIENT SECRET'
42+
43+
client = ImgurClient(client_id, client_secret)
44+
45+
# Example request
46+
items = client.gallery()
47+
for item in items
48+
print(item.link)
49+
50+
```
51+
52+
To initialize a client that takes actions on behalf of a user
53+
54+
```python
55+
from imgurpython import ImgurClient
56+
57+
client_id = 'YOUR CLIENT ID'
58+
client_secret = 'YOUR CLIENT SECRET'
59+
60+
client = ImgurClient(client_id, client_secret)
61+
62+
# Authorization flow, pin example (see docs for other auth types)
63+
authorization_url = client.get_auth_url('pin')
64+
65+
# ... redirect user to `authorization_url`, obtain pin (or code or token) ...
66+
67+
credentials = client.authorize('PIN OBTAINED FROM AUTHORIZATION', 'pin')
68+
client.set_user_auth(credentials['access_token'], credentials['refresh_token'])
69+
```
70+
71+
or if you already have an access/refresh token pair you can simply do
72+
73+
```python
74+
from imgurpython import ImgurClient
75+
76+
# If you already have an access/refresh pair in hand
77+
client_id = 'YOUR CLIENT ID'
78+
client_secret = 'YOUR CLIENT SECRET'
79+
access_token = 'USER ACCESS TOKEN'
80+
refresh_token = 'USER REFRESH TOKEN'
81+
82+
# Note since access tokens expire after an hour, only the refresh token is required (library handles autorefresh)
83+
client = ImgurClient(client_id, client_secret, access_token, refresh_token)
84+
```
85+
86+
### Error Handling
87+
Error types
88+
* ImgurClientError - General error handler, access message and status code via
89+
90+
```python
91+
try
92+
...
93+
except ImgurClientError as e
94+
print(e.error_message)
95+
print(e.status_code)
96+
```
97+
98+
* ImgurClientRateLimitError - Rate limit error
99+
100+
## ImgurClient Functions
101+
102+
### Account
103+
104+
* `get_account(username)`
105+
* `get_gallery_favorites(username)`
106+
* `get_account_favorites(username)`
107+
* `get_account_submissions(username, page=0)`
108+
* `get_account_settings(username)`
109+
* `change_account_settings(username, fields)`
110+
* `get_email_verification_status(username)`
111+
* `send_verification_email(username)`
112+
* `get_account_albums(username, page=0)`
113+
* `get_account_album_ids(username, page=0)`
114+
* `get_account_album_count(username)`
115+
* `get_account_comments(username, sort='newest', page=0)`
116+
* `get_account_comment_ids(username, sort='newest', page=0)`
117+
* `get_account_comment_count(username)`
118+
* `get_account_images(username, page=0)`
119+
* `get_account_image_ids(username, page=0)`
120+
* `get_account_album_count(username)`
121+
122+
### Album
123+
* `get_album(album_id)`
124+
* `get_album_images(album_id)`
125+
* `create_album(fields)`
126+
* `update_album(album_id, fields)`
127+
* `album_delete(album_id)`
128+
* `album_favorite(album_id)`
129+
* `album_set_images(album_id, ids)`
130+
* `album_add_images(album_id, ids)`
131+
* `album_remove_images(album_id, ids)`
132+
133+
### Comment
134+
* `get_comment(comment_id)`
135+
* `delete_comment(comment_id)`
136+
* `create_album(fields)`
137+
* `get_comment_replies(comment_id)`
138+
* `post_comment_reply(comment_id, image_id, comment)`
139+
* `comment_vote(comment_id, vote='up')`
140+
* `comment_report(comment_id)`
141+
142+
### Custom Gallery
143+
144+
* `get_custom_gallery(gallery_id, sort='viral', window='week', page=0)`
145+
* `get_user_galleries()`
146+
* `create_custom_gallery(name, tags=None)`
147+
* `custom_gallery_update(gallery_id, name)`
148+
* `custom_gallery_add_tags(gallery_id, tags)`
149+
* `custom_gallery_remove_tags(gallery_id, tags)`
150+
* `custom_gallery_delete(gallery_id)`
151+
* `filtered_out_tags()`
152+
* `block_tag(tag)`
153+
* `unblock_tag(tag)`
154+
155+
### Gallery
156+
157+
* `gallery(section='hot', sort='viral', page=0, window='day', show_viral=True)`
158+
* `memes_subgallery(sort='viral', page=0, window='week')`
159+
* `memes_subgallery_image(item_id)`
160+
* `subreddit_gallery(subreddit, sort='time', window='week', page=0)`
161+
* `subreddit_image(subreddit, image_id)`
162+
* `gallery_tag(tag, sort='viral', page=0, window='week')`
163+
* `gallery_tag_image(tag, item_id)`
164+
* `gallery_item_tags(item_id)`
165+
* `gallery_tag_vote(item_id, tag, vote)`
166+
* `gallery_search(q, advanced=None, sort='time', window='all', page=0)`
167+
* `gallery_random(page=0)`
168+
* `share_on_imgur(item_id, title, terms=1)`
169+
* `remove_from_gallery(item_id)`
170+
* `gallery_item(item_id)`
171+
* `report_gallery_item(item_id)`
172+
* `gallery_item_vote(item_id, vote='up')`
173+
* `gallery_item_comments(item_id, sort='best')`
174+
* `gallery_comment(item_id, comment)`
175+
* `gallery_comment_ids(item_id)`
176+
* `gallery_comment_count(item_id)`
177+
178+
### Image
179+
180+
* `get_image(image_id)`
181+
* `upload_from_path(path, config=None, anon=True)`
182+
* `upload_from_url(url, config=None, anon=True)`
183+
* `delete_image(image_id)`
184+
* `favorite_image(image_id)`
185+
186+
### Conversation
187+
188+
* `conversation_list()`
189+
* `get_conversation(conversation_id, page=1, offset=0)`
190+
* `create_message(recipient, body)`
191+
* `delete_conversation(conversation_id)`
192+
* `report_sender(username)`
193+
* `block_sender(username)`
194+
195+
### Notification
196+
197+
* `get_notifications(new=True)`
198+
* `get_notification(notification_id)`
199+
* `mark_notifications_as_read(notification_ids)`
200+
201+
### Memegen
202+
203+
* `default_memes()`
204+
205+
Command Line Demo (deprecated)
206+
------------
207+
29208
Configuration
30209
-------------
31210

@@ -62,46 +241,46 @@ Command Line Usage
62241
> Usage: python main.py (action) [options...]
63242
>
64243
> ### OAuth Actions
65-
>
66-
> **credits**
244+
>
245+
> **credits**
67246
> View the rate limit information for this client
68247
>
69-
> **authorize**
248+
> **authorize**
70249
> Start the authorization process
71250
>
72-
> **authorize [pin]**
251+
> **authorize [pin]**
73252
> Get an access token after starting authorization
74253
>
75-
> **refresh [refresh-token]**
254+
> **refresh [refresh-token]**
76255
> Return a new OAuth access token after it's expired
77256
>
78257
> ### Unauthorized Actions
79-
>
80-
> **upload [file]**
258+
>
259+
> **upload [file]**
81260
> Anonymously upload a file
82261
>
83-
> **list-comments [hash]**
262+
> **list-comments [hash]**
84263
> Get the comments (raw JSON) for a gallery post
85264
>
86-
> **get-album [id]**
265+
> **get-album [id]**
87266
> Get information (raw JSON) about an album
88267
>
89-
> **get-comment [id]**
268+
> **get-comment [id]**
90269
> Get a particular comment (raw JSON) for a gallery comment
91270
>
92-
> **get-gallery [hash]**
271+
> **get-gallery [hash]**
93272
> Get information (raw JSON) about a gallery post
94-
>
273+
>
95274
> ### Authorized Actions
96-
>
275+
>
97276
> **upload-auth [access-token] [file]**
98277
> Upload a file to your account
99278
>
100279
> **comment [access-token] [hash] [text]**
101280
> Comment on a gallery post
102281
>
103-
> **vote-gallery [token] [hash] [direction]**
282+
> **vote-gallery [token] [hash] [direction]**
104283
> Vote on a gallery post. Direction can be either 'up', 'down', or 'veto'
105284
>
106-
> **vote-comment [token] [id] [direction]**
107-
> Vote on a gallery comment. Direction can be either 'up', 'down', or 'veto'
285+
> **vote-comment [token] [id] [direction]**
286+
> Vote on a gallery comment. Direction can be either 'up', 'down', or 'veto'

0 commit comments

Comments
 (0)