Giphy Core SDK for Swift
The Giphy Core SDK is a wrapper around Giphy API.
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
- Search GIFs/Stickers
- Trending GIFs/Stickers
- Translate GIFs/Stickers
- Random GIFs/Stickers
- GIF by ID
- GIFs by IDs
- Categories for GIFs
- Subcategories for GIFs
- GIFs for a Subcategory
- Term Suggestions
Advanced Usage
Setup
CocoaPods Setup
Add the GiphyCoreSDK entry to your Podfile
pod 'GiphyCoreSDK'
Run pods to grab the GiphyCoreSDK framework
pod install
Carthage Setup
Add the GiphyCoreSDK entry to your Cartfile
git "git@github.com:Giphy/giphy-ios-sdk-core.git" "master"
Run carthage update to grab the GiphyCoreSDK framework
carthage update
Swift Package Manager Setup
- Add .package(url:"https://github.com/Giphy/giphy-ios-sdk-core", from: "1.2.0") to your package dependencies.
- Then add GiphyCoreSDK to your target dependencies.
Initialize Giphy SDK
// Configure your API Key
GiphyCore.configure(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 = GiphyCore.shared.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 = GiphyCore.shared.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 = GiphyCore.shared.trending() { (response, error) in
//...
}
/// Trending Stickers
let op = GiphyCore.shared.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 = GiphyCore.shared.translate("cats") { (response, error) in
//...
}
/// Translate to a Sticker
let op = GiphyCore.shared.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 = GiphyCore.shared.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 = GiphyCore.shared.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 = GiphyCore.shared.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 = GiphyCore.shared.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 = GiphyCore.shared.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 = GiphyCore.shared.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 = GiphyCore.shared.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 = GiphyCore.shared.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")
}
}
Advanced Usage
Filtering Models
We added support for you to filter results of any models out during requests. Here are few use cases below in code:
GiphyCore.setFilter(filter: { obj in
if let obj = obj as? GPHMedia {
// Check to see if this Media object has tags
// Say we only want GIFs/Stickers with tags, otherwise filter them out
return obj.tags == nil
} else if let obj = obj as? GPHChannel {
// We only want channels which have featured Gifs
return obj.featuredGif != false
}
// Otherwise this is a valid object, don't filter it out
return true
})
User Dictionaries
We figured you might want to attach extra data to our models such us GPHMedia
.. so now all our models have userDictionary
which you can attach any sort of object along with any of our models.
/// Gif Search
let op = GiphyCore.shared.search("cats") { (response, error) in
if let error = error as NSError? {
......
}
if let response = response, let data = response.data, let pagination = response.pagination {
for result in data {
result.userDictionary = ["Description" : "Results from Cats Search"]
}
} else {
print("No Results Found")
}
}
Github
link |
Stars: 24 |
Help us keep the lights on
Dependencies
Used By
Total: 0
Releases
1.2.0 - Mar 29, 2018
Changelog
- Filters to filter requests objects (so we can on fly decide what objects to return or filter out)
- Total counts / Filtered counts
- Enabling request headers as an option
- Public/Open interfaces for classes (depending on which) so they can be inherited/visible outside of the framework
- Adding Bottle Data
- Bringing in userDictionary to models so 3rd party Devs can store custom data in GPH Models
- Swift Package Manager support
1.1.0 - Jan 23, 2018
Swift4 & Channel end-points & Bug Fixes
- Channel End-points for Stickers (will soon be deprecating Category end-points)
- Fixed serialization issue with width/height/size
- Make Asset size properties accessible from Obj-C
GPHImage
propertiesframes
width
height
gifSize
webPSize
andmp4Size
are now available in ObjC and are notInt?
butInt
with default value of 0 instead ofnil
- Updated to Swift 4
- Fixed tests
1.0.1 - Oct 20, 2017
GPHMedia
title
property added toGPHMedia
class to represent meaningful titles to represent GIFs and Stickers.
1.0.0 - Oct 20, 2017
Supported Platforms
- iOS
- macOS
- tvOS
- watchOS
End-points Supported
- Search GIFs/Stickers
- Trending GIFs/Stickers
- Translate GIFs/Stickers
- Random GIFs/Stickers
- GIF by ID
- GIFs by IDs
- Categories for GIFs
- Subcategories for GIFs
- GIFs for a Subcategory
- Term Suggestions
0.9.9 - Jun 9, 2017
Giphy Core iOS SDK v0.9.9 (Beta)
Supported Platforms
- iOS
- macOS
- tvOS
- watchOS
- Supported End-points
End-points Supported
- Search GIFs/Stickers
- Trending GIFs/Stickers
- Translate GIFs/Stickers
- Random GIFs/Stickers
- GIF by ID
- GIFs by IDs
- Categories for GIFs
- Subcategories for GIFs
- GIFs for a Subcategory
- Term Suggestions