All Projects → nerdishbynature → Octokit.swift

nerdishbynature / Octokit.swift

Licence: mit
A Swift API Client for GitHub and GitHub Enterprise

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Octokit.swift

Ghapi
A delightful and complete interface to GitHub's amazing API
Stars: ✭ 187 (-42.46%)
Mutual labels:  api-client, github-api
Github
Ruby interface to GitHub API
Stars: ✭ 1,081 (+232.62%)
Mutual labels:  api-client, github-api
Githubfollows
A demo project based on MVVM architecture and material design & animations.
Stars: ✭ 272 (-16.31%)
Mutual labels:  github-api
Malsub
A Python RESTful API framework for online malware analysis and threat intelligence services.
Stars: ✭ 308 (-5.23%)
Mutual labels:  api-client
Ghcrawler
Crawl GitHub APIs and store the discovered orgs, repos, commits, ...
Stars: ✭ 293 (-9.85%)
Mutual labels:  github-api
Repository Hunter
🌹 Making GitHub more socially engaging 🎮 and fun 🍥 for all
Stars: ✭ 273 (-16%)
Mutual labels:  github-api
Simonw
https://simonwillison.net/2020/Jul/10/self-updating-profile-readme/
Stars: ✭ 297 (-8.62%)
Mutual labels:  github-api
Github cli
GitHub on your command line. Use your terminal, not the browser.
Stars: ✭ 263 (-19.08%)
Mutual labels:  github-api
Astronomer
A tool to detect illegitimate stars from bot accounts on GitHub projects
Stars: ✭ 323 (-0.62%)
Mutual labels:  github-api
Hacker Tab Extension
Browser extension to view GitHub trending projects on new tab 📈
Stars: ✭ 287 (-11.69%)
Mutual labels:  github-api
Gitify
GitHub notifications on your menu bar. Available on macOS, Windows & Linux.
Stars: ✭ 3,543 (+990.15%)
Mutual labels:  github-api
Aiodocker
Python Docker API client based on asyncio and aiohttp
Stars: ✭ 288 (-11.38%)
Mutual labels:  api-client
Hubspot Php
HubSpot PHP API Client
Stars: ✭ 273 (-16%)
Mutual labels:  api-client
Github Rs
Pure Rust bindings to the Github API
Stars: ✭ 298 (-8.31%)
Mutual labels:  github-api
Buildapks
Really quickly build APKs on handheld device (smartphone and tablet) in Amazon, Android, Chromebook, PRoot and Windows📲 See https://buildapks.github.io/docsBuildAPKs/setup to start building APKs.
Stars: ✭ 272 (-16.31%)
Mutual labels:  github-api
Node Imdb Api
A non-scraping, functional node.js interface to imdb (mirror of gitlab.com/worr/node-imdb-api)
Stars: ✭ 314 (-3.38%)
Mutual labels:  api-client
Gitlit
Platform to connect contributors and projects based on skill level and shared interests.
Stars: ✭ 265 (-18.46%)
Mutual labels:  github-api
Insomnia
The open-source, cross-platform API client for GraphQL, REST, and gRPC.
Stars: ✭ 18,969 (+5736.62%)
Mutual labels:  api-client
Shhgit
Ah shhgit! Find secrets in your code. Secrets detection for your GitHub, GitLab and Bitbucket repositories: www.shhgit.com
Stars: ✭ 3,316 (+920.31%)
Mutual labels:  github-api
Kafka Connect Github Source
Get a stream of issues and pull requests for your chosen GitHub repository
Stars: ✭ 327 (+0.62%)
Mutual labels:  github-api

Octokit.swift

Build Status CocoaPods codecov.io

Installation

import PackageDescription

let package = Package(
  name: "MyAwesomeApp",
    dependencies: [
      .package(url: "https://github.com/nerdishbynature/octokit.swift", from: "0.9.0"),
    ]
  )

Authentication

Octokit supports both, GitHub and GitHub Enterprise. Authentication is handled using Configurations.

There are two types of Configurations, TokenConfiguration and OAuthConfiguration.

TokenConfiguration

TokenConfiguration is used if you are using Access Token based Authentication (e.g. the user offered you an access token he generated on the website) or if you got an Access Token through the OAuth Flow

You can initialize a new config for github.com as follows:

let config = TokenConfiguration("YOUR_PRIVATE_GITHUB_TOKEN_HERE")

or for GitHub Enterprise

let config = TokenConfiguration("YOUR_PRIVATE_GITHUB_TOKEN_HERE", url: "https://github.example.com/api/v3/")

After you got your token you can use it with Octokit

Octokit(config).me() { response in
  switch response {
  case .success(let user):
    print(user.login as Any)
  case .failure(let error):
    print(error)
  }
}

OAuthConfiguration

OAuthConfiguration is meant to be used, if you don't have an access token already and the user has to login to your application. This also handles the OAuth flow.

You can authenticate an user for github.com as follows:

let config = OAuthConfiguration(token: "<Your Client ID>", secret: "<Your Client secret>", scopes: ["repo", "read:org"])
let url = config.authenticate()

or for GitHub Enterprise

let config = OAuthConfiguration("https://github.example.com/api/v3/", webURL: "https://github.example.com/", token: "<Your Client ID>", secret: "<Your Client secret>", scopes: ["repo", "read:org"])

After you got your config you can authenticate the user:

// AppDelegate.swift

config.authenticate()

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject?) -> Bool {
  config.handleOpenURL(url) { config in
    self.loadCurrentUser(config) // purely optional of course
  }
  return false
}

func loadCurrentUser(config: TokenConfiguration) {
  Octokit(config).me() { response in
    switch response {
    case .success(let user):
      print(user.login)
    case .failure(let error):
      print(error)
    }
  }
}

Please note that you will be given a TokenConfiguration back from the OAuth flow. You have to store the accessToken yourself. If you want to make further requests it is not necessary to do the OAuth Flow again. You can just use a TokenConfiguration.

let token = // get your token from your keychain, user defaults (not recommended) etc.
let config = TokenConfiguration(token)
Octokit(config).user(name: "octocat") { response in
  switch response {
  case .success(let user):
  	print("User login: \(user.login!)")
  case .failure(let error):
  	print("Error: \(error)")
  }
}

Users

Get a single user

let username = ... // set the username
Octokit().user(name: username) { response in
  switch response {
    case .success(let user):
      // do something with the user
    case .failure(let error):
      // handle any errors
  }
}

Get the authenticated user

Octokit().me() { response in
  switch response {
    case .success(let user):
      // do something with the user
    case .failure(let error):
      // handle any errors
  }

Repositories

Get a single repository

let (owner, name) = ("owner", "name") // replace with actual owner and name
Octokit().repository(owner, name) { response in
  switch response {
    case .success(let repository):
      // do something with the repository
    case .failure(let error):
      // handle any errors
  }
}

Get repositories of authenticated user

Octokit().repositories() { response in
  switch response {
    case .success(let repository):
      // do something
    case .failure(let error):
      // handle any errors
  }
}

Starred Repositories

Get starred repositories of some user

let username = "username"
Octokit().stars(username) { response in
  switch response {
    case .success(let repositories):
      // do something with the repositories
    case .failure(let error):
      // handle any errors
  }
}

Get starred repositories of authenticated user

Octokit().myStars() { response in
  switch response {
    case .success(let repositories):
      // do something with the repositories
    case .failure(let error):
      // handle any errors
  }
}

Follower and Following

Get followers of some user

let username = "username"
Octokit().followers(username) { response in
  switch response {
    case .success(let users):
      // do something with the users
    case .failure(let error):
      // handle any errors
  }
}

Get followers of authenticated user

Octokit().myFollowers() { response in
  switch response {
    case .success(let users):
      // do something with the users
    case .failure(let error):
      // handle any errors
  }
}

Get following of some user

let username = "username"
Octokit().following(username) { response in
  switch response {
    case .success(let users):
      // do something with the users
    case .failure(let error):
      // handle any errors
  }
}

Get following of authenticated user

Octokit().myFollowing() { response in
  switch response {
    case .success(let users):
      // do something with the users
    case .failure(let error):
      // handle any errors
  }
}

Issues

Get issues of authenticated user

Get all issues across all the authenticated user's visible repositories including owned repositories, member repositories, and organization repositories.

Octokit(config).myIssues() { response in
    switch response {
        case .success(let issues):
        // do something with the issues
    case .failure:
        // handle any errors
    }   
}

Get a single issue

let (owner, repo, number) = ("owner", "repo", 1347) // replace with actual owner, repo name, and issue number
Octokit(config).issue(owner, repository: repo, number: number) { response in
    switch response {
    case .success(let issue):
        // do something with the issue
    case .failure:
        // handle any errors
    }
}

Open a new issue

Octokit(config).postIssue("owner", repository: "repo", title: "Found a bug", body: "I'm having a problem with this.", assignee: "octocat", labels: ["bug", "duplicate"]) { response in
    switch response {
    case .success(let issue):
        // do something with the issue
    case .failure:
        // handle any errors
    }
}

Edit an existing issue

Octokit(config).patchIssue("owner", repository: "repo", number: 1347, title: "Found a bug", body: "I'm having a problem with this.", assignee: "octocat", state: .Closed) { response in
    switch response {
    case .success(let issue):
        // do something with the issue
    case .failure:
        // handle any errors
    }
}

Comment an issue

Octokit().commentIssue(owner: "octocat", repository: "Hello-World", number: 1, body: "Testing a comment") { response in
    switch response {
    case .success(let comment):
        // do something with the comment
    case .failure:
        // handle any errors
    }
}

Pull requests

Get a single pull request

Octokit().pullRequest(owner: "octocat", repository: "Hello-World", number: 1) { response in
    switch response {
        case .success(let pullRequests):
            // do something with a pull request
        case .failure:
            // handle any errors
     }
}

List a pull requests

Octokit().pullRequests(owner: "octocat", repository: "Hello-World", base: "develop", state: Openness.Open) { response in
    switch response {
        case .success(let pullRequests):
        // do something with a pull request list
        case .failure:
        // handle any errors
    }
}

Releases

Create a new release

Octokit().postRelease(owner: "octocat", repository: "Hello-World", tagName: "v1.0.0", targetCommitish: "master", name: "v1.0.0 Release", body: "The changelog of this release", prerelease: false, draft: false) { response in
	switch response {
        case .success(let release):
        // do something with the release
        case .failure:
        // handle any errors
    }
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].