Code Monkey home page Code Monkey logo

giphy-ios-sdk-core's Introduction

Giphy Core SDK for Swift

The Giphy Core SDK is a wrapper around Giphy API.

Build Status Carthage compatible CocoaPods Swift Version

Giphy is the best way to search, share, and discover GIFs on the Internet. Similar to the way other search engines work, the majority of our content comes from indexing based on the best and most popular GIFs and search terms across the web. We organize all those GIFs so you can find the good content easier and share it out through your social channels. We also feature some of our favorite GIF artists and work with brands to create and promote their original GIF content.

Getting Started

Supported Platforms

  • iOS
  • macOS
  • tvOS
  • watchOS

Supported End-points

Setup

CocoaPods Setup

Add the GiphyCoreSDK entry to your Podfile

pod 'GiphyCoreSDK'

Run pods to grab the GiphyCoreSDK framework

pod install

Initialize Giphy SDK

let client = GPHClient(apiKey: "YOUR_API_KEY")

Search Endpoint

Search all Giphy GIFs for a word or phrase. Punctuation will be stripped and ignored.

/// Gif Search
let op = client.search("cats") { (response, error) in

    if let error = error as NSError? {
        // Do what you want with the error
    }

    if let response = response, let data = response.data, let pagination = response.pagination {
        print(response.meta)
        print(pagination)
        for result in data {
            print(result)
        }
    } else {
        print("No Results Found")
    }
}

/// Sticker Search
let op = client.search("dogs", media: .sticker) { (response, error) in
    //...
}

Trending Endpoint

Fetch GIFs currently trending online. Hand curated by the Giphy editorial team. The data returned mirrors the GIFs showcased on the Giphy homepage.

/// Trending GIFs
let op = client.trending() { (response, error) in
    //...
}

/// Trending Stickers
let op = client.trending(.sticker) { (response, error) in
    //...
}

Translate Endpoint

The translate API draws on search, but uses the Giphy "special sauce" to handle translating from one vocabulary to another. In this case, words and phrases to GIFs. Example implementations of translate can be found in the Giphy Slack, Hipchat, Wire, or Dasher integrations. Use a plus or url encode for phrases.

/// Translate to a GIF
let op = client.translate("cats") { (response, error) in
    //...
}

/// Translate to a Sticker
let op = client.translate("cats", media: .sticker) { (response, error) in
    //...
}

Random Endpoint

Returns a random GIF, limited by tag. Excluding the tag parameter will return a random GIF from the Giphy catalog.

/// Random GIF
let op = client.random("cats") { (response, error) in

    if let error = error as NSError? {
        // Do what you want with the error
    }

    if let response = response, let data = response.data  {
        print(response.meta)
        print(data)
    } else {
        print("No Result Found")
    }
}

/// Random Sticker
let op = client.random("cats", media: .sticker) { (response, error) in
    //...
}

Get GIF by ID Endpoint

Returns meta data about a GIF, by GIF id. In the below example, the GIF ID is "feqkVgjJpYtjy"

/// Gif by Id
let op = client.gifByID("feqkVgjJpYtjy") { (response, error) in
    //...
}

Get GIFs by IDs Endpoint

A multiget version of the get GIF by ID endpoint. In this case the IDs are feqkVgjJpYtjy and 7rzbxdu0ZEXLy.

/// GIFs by Ids
let ids = ["feqkVgjJpYtjy", "7rzbxdu0ZEXLy"]

let op = client.gifsByIDs(ids) { (response, error) in

    if let error = error as NSError? {
        // Do what you want with the error
    }

    if let response = response, let data = response.data, let pagination = response.pagination {
        print(response.meta)
        print(pagination)
        for result in data {
            print(result)
        }
    } else {
        print("No Result Found")
    }
}

Categories Endpoint

A multiget version of the get GIF by ID endpoint. In this case the IDs are feqkVgjJpYtjy and 7rzbxdu0ZEXLy.

/// Get top trending categories for GIFs.
let op = client.categoriesForGifs() { (response, error) in

    if let error = error as NSError? {
        // Do what you want with the error
    }

    if let response = response, let data = response.data, let pagination = response.pagination {
        print(response.meta)
        print(pagination)
        for result in data {
            print(result)
        }
    } else {
        print("No Top Categories Found")
    }
}

Sub-Categories Endpoint

Get Sub-Categories for GIFs given a cateory. You will need this sub-category object to pull GIFs for this category.

/// Sub-Categories for a given category.
let category = "actions"

let op = client.subCategoriesForGifs(category) { (response, error) in

    if let error = error as NSError? {
        // Do what you want with the error
    }

    if let response = response, let data = response.data, let pagination = response.pagination {
        print(response.meta)
        print(pagination)
        for subcategory in data {
            print(subcategory)
        }
    } else {
        print("No Result Found")
    }
}

Sub-Category Content Endpoint

Get GIFs for a given Sub-Category.

/// Sub-Category Content
let category = "actions"
let subCategory = "cooking"

let op = client.gifsByCategory(category, subCategory: subCategory) { (response, error) in

    if let error = error as NSError? {
        // Do what you want with the error
    }

    if let response = response, let data = response.data, let pagination = response.pagination {
        print(response.meta)
        print(pagination)
        for result in data {
            print(result)
        }
    } else {
        print("No GIFs Found")
    }
}

Term Suggestions Endpoint

Get term suggestions give a search term, or a substring.

/// Term Suggestions
let op = client.termSuggestions("carm") { (response, error) in

    if let error = error as NSError? {
        // Do what you want with the error
    }

    if let response = response, let data = response.data {
        print(response.meta)
        for term in data {
            print(term)
        }
    } else {
        print("No Terms Suggestions Found")
    }
}

giphy-ios-sdk-core's People

Contributors

af-inet avatar genegoykhman avatar giorgia avatar seanpquig 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.