README.md in imgurapi-3.0.2 vs README.md in imgurapi-3.1.0

- old
+ new

@@ -44,11 +44,11 @@ ## Usage and overview Create a session object to communicate to Imgur. ```ruby -imgur_session = Imgurapi::Session.new(client_id: 'CLIENT_ID', client_secret: 'CLIENT_SECRET', refresh_token: 'REFRESH_TOKEN') +imgur_session = Imgurapi::Session.instance(client_id: 'CLIENT_ID', client_secret: 'CLIENT_SECRET', refresh_token: 'REFRESH_TOKEN') ``` Your account: ```ruby account = imgur_session.account.account @@ -58,13 +58,17 @@ How many images you have: ```ruby puts imgur_session.account.image_count ``` -Upload your first image. Argument can be either a String or a File: +Upload your first image. Argument can either be a path to a file, a File or a link: ```ruby image = imgur_session.image.image_upload('portrait.jpg') +# or +image = imgur_session.image.image_upload(portrait_file) +# or +image = imgur_session.image.image_upload('http://domain.tld/portrait.jpg') ``` image is now an instance of Imgurapi::Image, a convenient way to manage all the attributes of your image (at least more convenient than a multilevel dictionary): ```ruby name = nil @@ -113,10 +117,11 @@ imgur_session.image.image_delete('xyzzy') ``` It will return true if succeeded, false otherwise. ## Available endpoints + Not all the endpoints available at https://api.imgur.com/ have been implemented. Feel free to suggest or pull request your needs. The API methods have been named following Imgur's endpoints, for easy mental mapping. Although I consider this is clearer, in the future it may change to follow the naming conventions of the official Python API. @@ -127,5 +132,17 @@ | Account | account.images | https://api.imgur.com/endpoints/account#images | | Account | account.image_count | https://api.imgur.com/endpoints/account#image-count | | Image | image.image | https://api.imgur.com/endpoints/image#image | | Image | image.image_upload | https://api.imgur.com/endpoints/image#image-upload | | Image | image.image_delete | https://api.imgur.com/endpoints/image#image-delete | + +## Accessing more than one account at once + +Imgur's ACCESS_TOKEN expires after 1 month. When you make an API request, if the ACCESS_TOKEN is invalid, the library will attempt to get a new one via the REFRESH_TOKEN. This new ACCESS_TOKEN will live with the instance of the library, if you instantiated the Imgurapi::Session with `.new`. So if you instantiate a new session, the token will be requested again. + +Given requesting a new ACCESS_TOKEN on every API call is slow, the recommended way of using Imgurapi::Session is via `.instance`, not `.new` so it requests a fresh ACCESS_TOKEN only once, which will be stored at class level, reducing optimally the number of token requests. + +This approach is not feasible if you want to handle several Imgur accounts at once. + +In short: + - instantiate Imgurapi::Session via `.instance` if you manage 1 account + - instantiate Imgurapi::Session via `.new` if you manage 2 or more accounts