Github API V3 Swifty Wrapper

Overview

GithubPilot - Github API V3 Swifty Wrapper

Build Status

This is a Swift Github API Wrapper, it could make your life a little easier if you want to make an App with Github's wonderful data.

Installation

CocoaPods

Add a Podfile to your project, then edit it by adding:

use_frameworks!
pod 'GithubPilot', '~>1.0.3'

then, run the following command:

$ pod install

From now on you should use {Project}.xcworkspace to open your project

Before You start

Setup Your developer applications

Go to your Github homepage, tap your avatar -> Setting, on your left choose Applications -> Developer applications, then you should tap register a new OAuth application on your top right side.

Remember you should use a custom Authorization callback URL, which will be used later, eg. FunnyGithubTest://random After registration, you could get your Client ID and Client Secret.

Setup Your Project

To allow your user to be re-directed back to your app after OAuth dance, you'll need to associate a custom URL scheme with your app.

Open your Xcode then open Info.plist of your project. copy and paste following code to your Info.plist source code.

  <key>CFBundleURLTypes</key>
  <array>
      <dict>
          <key>CFBundleURLSchemes</key>
          <array>
              <string>your.custom.scheme(eg. FunnyGithubTest)</string>
          </array>
      <dict>
  <array>

Usage

Authentication

First, add import GithubPilot at the top of your AppDelegate. You could then add application(_: didFinishLaunchingWithOptions:) with following to authenticate your client. You also should take care of scope parameter that your client will use, refer to Github Scope

Github.setupClientID("YourClientID", clientSecret: "YourClientSecret", scope: ["user", "repo"], redirectURI: "YourCustomCallBackURL")
Github.authenticate()

Second, add following code to your AppDelegate to get Github access token

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool 
{
    Github.requestAccessToken(url)
    return true
}

Used in Code

Users

Get the authenticated user

if let client = Github.authorizedClient {
        client.users.getAuthenticatedUser().response({ user, requestError in
            if let me = user {
                print(me.description)
            } else {
                print(requestError?.description)
            }
        })
}

Get a user with username

if let client = Github.authorizedClient {
        client.users.getUser(username: "onevcat").response({ (githubUser, error) -> Void in
            if let user = githubUser {
                print(user.description)
            } else {
                print(error?.description)
            }
        })
}

Get a page of users from since id

if let client = Github.authorizedClient {
        client.users.getAllUsers("1209").response({ (httpResponse, users, requestError) -> Void in
            if let response = httpResponse {
                // next `since` id
                print("Since   :\(response)")
            }
            if let result = users {
                for user in result {
                    print(user.description)
                }
            } else {
                print(requestError?.description)
            }
        })
}

Repositories

Get repositories of authenticated user

if let client = Github.authorizedClient {
        client.repos.getAuthenticatedUserRepos().response({ (result, error) -> Void in
            if let repos = result {
                print(repos.count)
                for i in repos {
                    print(i.name)
                    print(i.stargazersCount)
                }
            }
            if let requestError = error {
                print(requestError.description)
            }
        })
}

Get a repo by repo name and repo owner name

if let client = Github.authorizedClient {
        client.repos.getRepo("Yep", owner: "CatchChat").response({ (result, error) -> Void in
            if let repo = result {
                print(repo.name)
            }
            if let requestError = error {
                print(requestError.description)
            }
        })
}

Get repos belong to a user

if let client = Github.authorizedClient {
    client.repos.getRepoFrom(owner: "onevcat").response({ (nextPage, result, error) -> Void in
        if let page = nextPage {
            print("Next Page is \(page)")
        }
        if let repos = result {
            print(repos.count)
            for r in repos {
                print(r.name)
                print(r.stargazersCount)
            }
        }
        if let requestError = error {
            print(requestError.description)
        }
    })
}

Events

Get received events for a user

if let client = Github.authorizedClient {
    client.events.getReceivedEventsForUser("someUser", page: "1").response({ (nextpage, results, error) -> Void in
        if let events = results {
            // New events
        }
    })
}

Example

You could refer to one of my project GitPocket as an example.

Credits

SwiftyDropbox

Future Work

There all tons of other API I haven't implementated, like Search. I will continuously make this repo better. Welcome to pull request and open issues.

You might also like...
Another network wrapper for URLSession. Built to be simple, small and easy to create tests at the network layer of your application.
Another network wrapper for URLSession. Built to be simple, small and easy to create tests at the network layer of your application.

Another network wrapper for URLSession. Built to be simple, small and easy to create tests at the network layer of your application. Install Carthage

A testable RxSwift wrapper around MultipeerConnectivity

A testable RxSwift wrapper around MultipeerConnectivity

Easy to use CFNetwork wrapper for HTTP requests, Objective-C, Mac OS X and iPhone

ASIHTTPRequest is an easy to use wrapper around the CFNetwork API that makes some of the more tedious aspects of communicating with web servers easier

A custom wrapper over AFNetworking library that we use inside RC extensively

AFNetworkingHelper A very simple wrapper over the most amazing networking library for objective C, AFNetworking. We extensively use it inside RC and i

Easy HTTP Networking in Swift a NSURLSession wrapper with image caching support
Easy HTTP Networking in Swift a NSURLSession wrapper with image caching support

Networking was born out of the necessity of having a simple networking library that doesn't have crazy programming abstractions or uses the latest rea

AsyncWebSocketClient - A package that contains a client behaving as a wrapper for the URLSessionWebSocketTask

(WORK IN PROGRESS) AsyncWebSocketClient This is a package that contains a client

A glorious Swift wrapper around NSNotificationCenter

Kugel A glorious Swift wrapper around NSNotificationCenter. ⚠️ Deprecated ⚠️ This library is deprecated and will not be maintained anymore. With Swift

A Combine-style wrapper around Network's NWConnection with a UDP protocol

A Combine-style wrapper around Network's NWConnection with a UDP protocol

🌸 Powerful Codable API requests builder and manager for iOS.
🌸 Powerful Codable API requests builder and manager for iOS.

This lib is about network requests with blackjack, roulette and craps! Using it you will be able to convert your massive API layer code into an awesom

Owner
Yansong Li
iOS developer, Machine Learning Advocator
Yansong Li
A modern Swift wrapper for Instagram Private API.

Swiftagram is a wrapper for Instagram Private API, written entirely in (modern) Swift. Instagram's official APIs, both the Instagram Basic Display API

Stefano Bertagno 217 Dec 27, 2022
iw03-JerryZhongJ created by GitHub Classroom

iw03 请基于模板工程,为https://itsc.nju.edu.cn开发一个iOS客户端。 功能要求如下: App界面设计见模板工程的Main Storyboard,首届面通过tab bar controller分为5个栏目 前4个分别对应网站4个信息栏目(如下),下载list.htm内容并将

null 0 Nov 15, 2021
hw1-SaniyeToy created by GitHub Classroom

hw1-SaniyeToy Fibonacci Case This application finds fibonacci numbers between 75

null 0 Jan 19, 2022
hw2-sadikcoban created by GitHub Classroom

Homework 2 Arkadaşlar selamlar! Acı çekeceğiniz ama bolca öğreneceğiniz haftanın ödevi için sizlerden: 2 adet ekran oluşturup (View controller ve view

null 0 Dec 25, 2021
GitHub iOS client in RxSwift and MVVM-C clean architecture

GitHub iOS client in RxSwift and MVVM-C clean architecture. FlutterHub - Flutter version available at an early stage KotlinHub - Android version is co

Khoren Markosyan 2.7k Jan 7, 2023
GitTime is GitHub Tracking App. Using ReactorKit, RxSwift, Moya.

GitTime Feature Activity: GitHub Contributions graph & Event lists Trending: Trending Repositories & Developers Buddys: Show your buddy's contribution

Kanz 58 Dec 7, 2022
APIProvider - API Provider Package for easier API management inspired by abstraction

APIProvider Using APIProvider you can easily communicate with all API endpoints

null 1 Apr 21, 2022
📱📲 A wrapper for the MultipeerConnectivity framework for automatic offline data transmission between devices

A wrapper for Apple's MultipeerConnectivity framework for offline data transmission between Apple devices. This framework makes it easy to automatical

Wilson Ding 197 Nov 2, 2022
Thin wrapper around NSURLSession in swift. Simplifies HTTP requests.

SwiftHTTP SwiftHTTP is a thin wrapper around NSURLSession in Swift to simplify HTTP requests. Features Convenient Closure APIs Simple Queue Support Pa

Dalton 1.9k Dec 7, 2022
Http Request wrapper written in Swift

Net Net is a HttpRequest wrapper written in Swift Features GET, POST, PUT, DELETE method Powerful request params: nested params, number, string, dic,

Le Van Nghia 304 Jun 29, 2022