Git Product home page Git Product logo

giphyswift's Introduction

GiphySwift

GiphySwift allows you to interact with the Giphy API on iOS

GiphySwift Example GiphySwift Gif Search

##Installation

####CocoaPods (iOS 9+, OS X 10.9+) You can use CocoaPods to install GiphySwiftby adding it to your Podfile:

platform :ios, '9.0'
use_frameworks!

target 'MyApp' do
    pod 'GiphySwift'
end

Note that this requires CocoaPods version 36, and your iOS deployment target to be at least 9.0

##Usage

###Configuration You need to configure GiphySwift to use your Giphy API Key. In order to release your application to production, you will need to request a Production Key from Giphy. Instructions to do so can be found here.

####Development For development purposes you can use Giphy's Public Beta Key

Giphy.configure(with: .publicKey)

####Production For production purposes you will need to specify your private access key

Giphy.configure(with: .private(key: "dc6zaTOxFJmzC"))

##Requesting Gifs

There are five different endpoint through which you can request Gifs:

You can read more about Giphy's endpoints here.

####Request Results All GiphySwift requests return a GiphyResult enum, that will indicate if the request was successful or not, encapsulating the data from the response or any errors thrown:

public enum GiphyResult<T> {
    case success(result: T, properties: GiphyResultProperties?)
    case error(_: Error)
}

####Trending Use the following command to retreieve Trending Gifs:

Giphy.Gif.request(.trending) { result in
    switch result {

    case .success(result: let gifs, properties: let paginationProperties):
        // DO SOMETHING WITH RESULTS
        displayTableView(with: gifs)

    case .error(let error):
        print(error)

    }
}

####Search Use the following command to search for Gifs:

Giphy.Gif.request(.search("cats")) { result in
    switch result {

    case .success(result: let gifs, properties: _):
        // DO SOMETHING WITH RESULTS
        displayTableView(with: gifs)

    case .error(let error):
        print(error)

    }
}

####Translate Use the following command to translate text into Gifs:

Giphy.Gif.request(.translate("hello")) { result in
    switch result {

    case .success(result: let gifs, properties: _):
        // DO SOMETHING WITH RESULTS
        displayTableView(with: gifs)

    case .error(let error):
        print(error)

    }
}

####By ID You can retrieve Gifs by passing in a single Gif ID as a String, or passing in an array of IDs.

Giphy.Gif.request(.withId("3o7qDPfGhunRMZikI8")) { result in
    switch result {

    case .success(result: let gifs, properties: _):
        // DO SOMETHING WITH RESULTS
        displayTableView(with: gifs)

    case .error(let error):
        print(error)

    }
}

####Random Use the following command to request a Random Gif. You can optionally submit a tag as a search string to limit your random results to a particular query.

Giphy.Gif.request(.random(tag: "superstar")) { result in
    switch result {

    case .success(result: let gifs, properties: _):
        // DO SOMETHING WITH RESULTS
        displayTableView(with: gifs)

    case .error(let error):
        print(error)

    }
}

##Requesting Stickers

There are four different endpoint through which you can request Stickers:

  • Trending
  • Search
  • Translate
  • Random

You can read more about Giphy's endpoints here.

To request Stickers, use the same command as those for requesting Gifs, but specifying the Sticker endpoint.

For example:

Giphy.Sticker.request(.trending) { result in
    switch result {

    case .success(result: let gifs, properties: let paginationProperties):
        // DO SOMETHING WITH RESULTS
        displayTableView(with: gifs)

    case .error(let error):
        print(error)

    }
}

Author

Matias Seijas

Mail: [email protected]
Website: mseijas.com
Twitter: @mseijas_

License

GiphySwift is available under the MIT license. See the LICENSE file for more info.

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.