Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jverdi/gramophone

Gramophone is a framework for interacting with the Instagram REST API, written in Swift.
https://github.com/jverdi/gramophone

instagram instagram-api instagram-client ios swift

Last synced: 3 months ago
JSON representation

Gramophone is a framework for interacting with the Instagram REST API, written in Swift.

Awesome Lists containing this project

README

        


Gramophone

[![Build Status](https://travis-ci.org/jverdi/Gramophone.svg?branch=master)](https://travis-ci.org/jverdi/Gramophone)
[![CocoaPods compatible](https://img.shields.io/cocoapods/v/Gramophone.svg)](#cocoapods)
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](#carthage)
[![GitHub release](https://img.shields.io/github/release/jverdi/Gramophone.svg)](https://github.com/jverdi/Gramophone/releases)
[![Swift 4.0](https://img.shields.io/badge/Swift-4.0-orange.svg)](#)
[![License](https://img.shields.io/github/license/mashape/apistatus.svg)](http://jaredverdi.mit-license.org)
[![Twitter](https://img.shields.io/badge/[email protected]?style=flat)](http://twitter.com/jverdi)

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](https://www.instagram.com/developer/clients/manage/), as well as any desired [scopes](https://www.instagram.com/developer/authorization/):

```swift
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):

```swift
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:

```swift
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](http://github.com/jverdi/Gramophone/tree/master/Source/Resources) directory for the full listing of available API methods:

| API Wrapper | Methods | Instagram Docs |
| ------------- | ------------- | ------------- |
| [Auth](http://github.com/jverdi/Gramophone/blob/master/Source/Resources/Auth.swift) |

  • ```authenticate(from:) => String```
| [Docs](https://www.instagram.com/developer/authentication/) |
| [Comments](http://github.com/jverdi/Gramophone/blob/master/Source/Resources/CommentsAPI.swift) |

  • ```comments(mediaID:) => Array```

  • ```postComment(_:mediaID:) => NoData```

  • ```deleteComment(mediaID:commentID:) => NoData```

| [Docs](https://www.instagram.com/developer/endpoints/comments) |
| [Likes](http://github.com/jverdi/Gramophone/blob/master/Source/Resources/LikesAPI.swift) |

  • ```likes(mediaID:) => >```

  • ```like(mediaID:) => NoData```

  • ```unlike(mediaID:) => NoData```

| [Docs](https://www.instagram.com/developer/endpoints/likes) |
| [Locations](http://github.com/jverdi/Gramophone/blob/master/Source/Resources/LocationsAPI.swift) |

  • ```location(ID:) => Location```

  • ```locationRecentMedia(ID:options:) => Array```

  • ```locations(latitude:longitude:distanceInMeters:) => Array```

| [Docs](https://www.instagram.com/developer/endpoints/locations) |
| [Media](http://github.com/jverdi/Gramophone/blob/master/Source/Resources/MediaAPI.swift) |

  • ```media(withID:) => Media```

  • ```media(withShortcode:) => Media```

  • ```media(latitude:longitude:distanceInMeters:) => Array```

| [Docs](https://www.instagram.com/developer/endpoints/media) |
| [OEmbed](http://github.com/jverdi/Gramophone/blob/master/Source/Resources/OEmbed.swift) |
  • ```oembed(url:) => EmbedMedia```
| [Docs](https://www.instagram.com/developer/embedding/#oembed) |
| [Relationships](http://github.com/jverdi/Gramophone/blob/master/Source/Resources/RelationshipsAPI.swift) |

  • ```myFollows() => Array```

  • ```myFollowers() => Array```

  • ```myRequests() => Array```

  • ```relationship(withUserID:) => IncomingRelationship```

  • ```followUser(withID:) => OutgoingRelationship```

  • ```unfollowUser(withID:) => OutgoingRelationship```

  • ```approveUser(withID:) => IncomingRelationship```

  • ```ignoreUser(withID:) => IncomingRelationship```

| [Docs](https://www.instagram.com/developer/endpoints/relationships) |
| [Tags](http://github.com/jverdi/Gramophone/blob/master/Source/Resources/TagsAPI.swift) |

  • ```tag(name:) => Tag```

  • ```tagRecentMedia(name:options:) => Array```

  • ```tags(query:options:) => Array```

| [Docs](https://www.instagram.com/developer/endpoints/tags) |
| [Users](http://github.com/jverdi/Gramophone/blob/master/Source/Resources/UsersAPI.swift) |

  • ```me() => User```

  • ```user(withID:) => User```

  • ```myRecentMedia(options:) => Array```

  • ```userRecentMedia(withID:options:) => Array```

  • ```myLikedMedia(options:) => Array```

  • ```users(query:options:) => Array```

| [Docs](https://www.instagram.com/developer/endpoints/users) |

## Installation

### CocoaPods

To integrate Gramophone using [CocoaPods](http://cocoapods.org), add it to your `Podfile`:

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

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

Then, run:

```bash
$ pod install
```

### Carthage

To integrate Gramophone using [Carthage](https://github.com/Carthage/Carthage), add it to your `Cartfile`:

```ogdl
github "jverdi/Gramophone" ~> 1.1
```

Then, run:

```bash
$ 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](https://github.com/Anviking/Decodable) and [Result](https://github.com/antitypical/Result) libraries.

## License

Gramophone is released under the MIT license. See [LICENSE](https://github.com/jverdi/Gramophone/blob/master/LICENSE) for details.

Icon created by Gan Khoon Lay from the Noun Project