TestsTested | ✓ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Oct 2017 |
SwiftSwift Version | 4.0 |
SPMSupports SPM | ✗ |
Maintained by Jared Verdi.
Depends on: | |
Result | ~> 3.2 |
Decodable | ~> 0.6 |
Gramophone is a framework for interacting with the Instagram REST API, written in Swift.
It includes authentication via OAuth, and methods to make asynchronous network calls to all of Instagram's publicly available API endpoints.
Responses are parsed into concrete model objects and errors.
Setup the client, supplying your Instagram client id and redirect URI, as well as any desired scopes:
import Gramophone
let configuration = ClientConfiguration(
clientID: "{YOUR_INSTAGRAM_CLIENT_ID}",
redirectURI: "{YOUR_INSTAGRAM_REDIRECT_URI}",
scopes: [.basic, .publicContent, .comments]
)
let gramophone = Gramophone(configuration: configuration)
Authenticate using OAuth (with an in-app WKWebView
controller):
gramophone.client.authenticate(from: presentingViewController) { result in
switch result {
case .success(let response):
print("Authenticated")
case .failure(let error):
print("Failed to authenticate: \(error.localizedDescription)")
}
}
Request data using one of the API wrapper methods:
gramophone.client.myRecentMedia(options: nil) { mediaResult in
switch mediaResult {
case .success(let response):
let mediaItems = response.data.items
for media in mediaItems {
if let images = media.images, let rendition = images[.thumbnail] {
print("Media [ID: \(media.ID), url: \(rendition.url)]")
}
}
case .failure(let error):
print("Failed to load media: \(error.localizedDescription)")
}
}
See the Resources directory for the full listing of available API methods:
API Wrapper | Methods | Instagram Docs |
---|---|---|
Auth |
|
Docs |
Comments |
|
Docs |
Likes |
|
Docs |
Locations |
|
Docs |
Media |
|
Docs |
OEmbed |
|
Docs |
Relationships |
|
Docs |
Tags |
|
Docs |
Users |
|
Docs |
Gramophone makes use of the Decodable and Result libraries.
Gramophone is released under the MIT license. See LICENSE for details.
Icon created by Gan Khoon Lay from the Noun Project