GithubHelp home page GithubHelp logo

banshchikov / tanukikit Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nerdishbynature/tanukikit

0.0 2.0 0.0 155 KB

A Swift API Client for GitLab.com, GitLab CE and GitLab EE

License: MIT License

Ruby 6.26% Makefile 0.62% Swift 92.75% Objective-C 0.37%

tanukikit's Introduction

TanukiKit

Build Status codecov.io

A Swift 2.0 API Client for the GitLab API.

Name

The name derives from the GitLab logo which is an abstraction of an japanese racoon dog subspecies named Tanuki. Too bad GitLabKit was already taken.

Authentication

TanukiKit supports both, GitLab Cloud and self hosted GitLab. 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 gitlab.com as follows:

let config = TokenConfiguration("12345")

or for self hosted installations

let config = PrivateTokenConfiguration("12345", url: "https://gitlab.example.com/api/v3/")

After you got your token you can use it with TanukiKit

TanukiKit(config).me() { response in
  switch response {
  case .Success(let user):
    println(user.login)
  case .Failure(let error):
    println(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.Please not that the redirectURI are completely arbitrary and are only necessary because GitLab does not support redirect URIs like git2go://gitlab_oauth. When logging in you should present a UIWebView and look for your redirectURI being called.

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

let config = OAuthConfiguration(token: "<Your Client ID>", secret: "<Your Client secret>", redirect_uri: "https://oauth.example.com/gitlab_oauth")
config.authenticate()

or for self hosted installations

let config = OAuthConfiguration("https://gitlab.example.com/api/v3/", webURL: "https://gitlab.example.com/", token: "<Your Client ID>", redirect_uri: "https://oauth.example.com/gitlab_oauth")

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) {
  TanukiKit(config).me() { response in
    switch response {
    case .Success(let user):
      println(user.login)
    case .Failure(let error):
      println(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)
TanukiKit(config).user("tanuki") { response in
  switch response {
  case .Success(let user):
    println(user.login)
  case .Failure(let error):
    println(error)
  }
}

Users

Get the authenticated user

TanukiKit().me() { response in
  switch response {
    case .Success(let user):
      // do something with the user
    case .Failure(let error):
      // handle any errors
  }

Repositories

Get repositories of authenticated user

TanukiKit().repositories() { response in
  switch response {
    case .Success(let repositories):
      // do something
    case .Failure(let error):
      // handle any errors
  }
}

tanukikit's People

Contributors

pietbrauer avatar tiferrei avatar 1ec5 avatar

Watchers

James Cloos avatar Andrey Banshchikov avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.