CocoaPods trunk is moving to be read-only. Read more on the blog, there are 19 months to go.
TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Oct 2016 |
SPMSupports SPM | ✗ |
Maintained by Matias Seijas.
GiphySwift allows you to interact with the Giphy API on iOS
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.
For development purposes you can use Giphy’s Public Beta Key
Giphy.configure(with: .publicKey)
For production purposes you will need to specify your private access key
Giphy.configure(with: .private(key: "dc6zaTOxFJmzC"))
There are five different endpoint through which you can request Gifs:
You can read more about Giphy’s endpoints here.
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)
}
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)
}
}
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)
}
}
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)
}
}
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)
}
}
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)
}
}
There are four different endpoint through which you can request Stickers:
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)
}
}
Matias Seijas
Mail: [email protected]
Website: mseijas.com
Twitter: @mseijas_
GiphySwift is available under the MIT license. See the LICENSE file for more info.