Code Monkey home page Code Monkey logo

imgursession's Introduction

ImgurSession

ImgurSession is an Objective-C networking library to easily make Imgur API requests within iOS and OS X apps. It is built on AFNetworking's AFHTTPSessionManager baseclass. ImgurSession provides access for V3 of the API. It handles OAuth2 authentication for user-authenticated sessions and also supports basic authentication for anonymous sessions. It covers all documented endpoints on Imgur's documentation. This is being used in production for my free app Imgurian.

Features

  • Full Imgur API V3

    • Use any of the Request classes in the ImgurSession/Request folder to make requests. Requests use Session singleton created before request was made.
    • CRUD actions for images, albums, comments, notifcations, messages, conversations, and accounts.
    • Multiple Image upload, upload from url.
  • OAuth2 management.

    • Session only needs your app credentials. Handles all authentication except for when it needs a webview.
    • Session will refresh your tokens lazily. Feel free to use any request at any time.
  • User account

    • Session notifies delegate of replys and messages to the users account automatically every 1 minute. Can be disabled.
    • Session refresh the user's account on token expiry every hour.

Using ImgurSession

Just import ImgurSession.h and setup the session with your credentials before making any requests. For user authorization, you must register for OAuth 2 authorization with or without a callback URL depending on the token type (Read more at Imgur). For authorized login, you must implement the delegate method imgurSessionNeedsExternalWebview: in order to open an external imgur.com page for OAuth authorization.


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
     [IMGSession authenticatedSessionWithClientID:@"clientID" secret:@"secret" authType:IMGCodeAuth withDelegate:self];
    
    return YES;
}

-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{

    /*
    configure you app URL schema to handle the callback url then call completion with retrieved code from URL
    */

}

#pragma mark - IMGSessionDelegate

-(void)imgurSessionNeedsExternalWebview:(NSURL *)url completion:(void (^)())completion{
    
    //open imgur website to authenticate with callback url in safari
    [[UIApplication sharedApplication] openURL:url];

    //save the completion block for later use when imgur responds with url callback
}

Or anonymous session (as configured by registered app on Imgur).

[IMGSession anonymousSessionWithClientID:@"anonToken" withDelegate:self];

Anywhere else in the app, make requests which will use the session singleton previously created to handle authentication and error handling. To retrieve the viral gallery:

    [IMGGalleryRequest hotGalleryPage:0 success:^(NSArray *objects) {
        
        //use gallery objects in a table for example
        self.tableRows = objects;
        [self.tableView reloadData];
        
    } failure:^(NSError *error) {
        
        //handle error
    }];

imgursession's People

Contributors

geoffmacd avatar nolanw avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.