Gramophone 1.1

Gramophone 1.1

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.

Usage

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
  • authenticate(from:) => String
Docs
Comments
  • comments(mediaID:) => Array<Comment>
  • postComment(_:mediaID:) => NoData
  • deleteComment(mediaID:commentID:) => NoData
Docs
Likes
  • likes(mediaID:) => <Array<Like>>
  • like(mediaID:) => NoData
  • unlike(mediaID:) => NoData
Docs
Locations
  • location(ID:) => Location
  • locationRecentMedia(ID:options:) => Array<Media>
  • locations(latitude:longitude:distanceInMeters:) => Array<Location>
Docs
Media
  • media(withID:) => Media
  • media(withShortcode:) => Media
  • media(latitude:longitude:distanceInMeters:) => Array<Media>
Docs
OEmbed
  • oembed(url:) => EmbedMedia
Docs
Relationships
  • myFollows() => Array<User>
  • myFollowers() => Array<User>
  • myRequests() => Array<User>
  • relationship(withUserID:) => IncomingRelationship
  • followUser(withID:) => OutgoingRelationship
  • unfollowUser(withID:) => OutgoingRelationship
  • approveUser(withID:) => IncomingRelationship
  • ignoreUser(withID:) => IncomingRelationship
Docs
Tags
  • tag(name:) => Tag
  • tagRecentMedia(name:options:) => Array<Media>
  • tags(query:options:) => Array<Tag>
Docs
Users
  • me() => User
  • user(withID:) => User
  • myRecentMedia(options:) => Array<Media>
  • userRecentMedia(withID:options:) => Array<Media>
  • myLikedMedia(options:) => Array<Media>
  • users(query:options:) => Array<User>
Docs

Dependencies

Gramophone makes use of the Decodable and Result libraries.

License

Gramophone is released under the MIT license. See LICENSE for details.

Icon created by Gan Khoon Lay from the Noun Project