Git Product home page Git Product logo

giphy-ios's Introduction

Giphy-iOS

Version License Platform

Giphy-iOS is a Giphy API client for iOS in Objective-C.

Usage

To run the example project, clone the repo, and run pod install from the Example directory first.

You should read about Giphy's Access and API keys here.

Giphy-iOS / AXCGiphy

'AXCGiphy' provides convenient access to Giphy's API endpoints:

  • search
  • trending
  • translate
  • GIF by ID
  • GIFs by IDs

You can query the endpoints through the blocks based interface:

- (void)viewDidLoad
{
    [super viewDidLoad];
	// set your API key before making any requests. You may use kGiphyPublicAPIKey for development.
    [AXCGiphy setGiphyAPIKey:kGiphyPublicAPIKey];

    [AXCGiphy searchGiphyWithTerm:@"frogs" limit:10 offset:0 completion:^(NSArray *results, NSError *error) {
        self.giphyResults = results;
        [[NSOperationQueue mainQueue] addOperationWithBlock:^{
            [self.collectionView reloadData];
        }];
    }];
}


- (UICollectionViewCell *) collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    AXCCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:kCollectionViewCellIdentifier forIndexPath:indexPath];
    AXCGiphy * gif = self.giphyResults[indexPath.item];
    
    NSURLRequest * request = [NSURLRequest requestWithURL:gif.originalImage.url];
    [[[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
        UIImage * image = [UIImage imageWithData:data];
        [[NSOperationQueue mainQueue] addOperationWithBlock:^{
            cell.imageView.image = image;
        }];
    }] resume];
    
    return cell;
}

AXCGiphy blocks based class methods provide asynchronous access to either AXCGiphy instances or an NSArray of AXCGiphy instances. AXCGiphy instances represent Giphy's gifs and their metadata. However, AXCGiphy only provides URLs to gifs. How you use these URLs is up to you.

My example uses NSURLRequests with NSURLSession to fetch the image data at the URLs and mattt's AnimatedGifSerialization to decode the animated GIFs into animated UIImages. If you are unsure of how to proceed, use my example app as a starting point.

The blocks based class methods return NSURLSessionDataTasks for additional control, should you need it.

AXCGiphy also provides class methods to generate NSURLRequests for these endpoints.

Requirements

AFNetworking/Serialization 2.3.1

Installation

Giphy-iOS is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "Giphy-iOS"
pod 'AFNetworking/Serialization', '~> 2.3.1'

Author

Alex Choi, [email protected]

License

Giphy-iOS is available under the MIT license. See the LICENSE file for more info.

giphy-ios's People

Contributors

heyalexchoi avatar tsheaff avatar

Watchers

 avatar  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.