Latest 1.1
Homepage https://github.com/jverdi/Gramophone
License MIT
Platforms ios 9.0
Dependencies Result, Decodable
Authors

Gramophone

Build Status
CocoaPods compatible
Carthage compatible
GitHub release
Swift 4.0
License
Twitter

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

Installation

CocoaPods

To integrate Gramophone using CocoaPods, add it to your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!

target '{YOUR_TARGET}' do
    pod 'Gramophone', '~> 1.1'
end

Then, run:

$ pod install

Carthage

To integrate Gramophone using Carthage, add it to your Cartfile:

github "jverdi/Gramophone" ~> 1.1

Then, run:

$ carthage update --platform iOS

and drag the built Gramophone.framework, Decodable.framework, and Result.framework into your Xcode project’s Embedded Binaries from Carthage/Build/iOS.

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

Latest podspec

{
    "name": "Gramophone",
    "version": "1.1",
    "summary": "Gramophone is a swifty wrapper of the Instagram API",
    "homepage": "https://github.com/jverdi/Gramophone",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Jared Verdi": "[email protected]"
    },
    "social_media_url": "http://twitter.com/jverdi",
    "source": {
        "git": "https://github.com/jverdi/Gramophone.git",
        "tag": "1.1"
    },
    "source_files": [
        "Source/*.swift",
        "Source/Client/*.swift",
        "Source/Model/*.swift",
        "Source/Resources/*.swift"
    ],
    "platforms": {
        "ios": "9.0"
    },
    "dependencies": {
        "Result": [
            "~> 3.2"
        ],
        "Decodable": [
            "~> 0.6"
        ]
    },
    "pushed_with_swift_version": "4.0"
}

Pin It on Pinterest

Share This