Latest 0.6.3
Homepage https://github.com/nerdishbynature/trashcankit
License MIT
Platforms ios 8.0, osx 10.10, watchos 2.0, tvos 9.0, requires ARC
Dependencies NBNRequestKit
Authors

Build Status
codecov.io

A Swift 2.0 API Client for Bitbuckets 2.0 API.

Name

The name derives from how I, Piet Brauer, see the Bitbucket logo everytime I look at it and maybe my experience working with the API.

Authentication

TrashCanKit supports both, Bitbucket Cloud and Bitbucket 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 bitbucket.com as follows:

let config = TokenConfiguration(token: "12345")

or for Bitbucket Enterprise

let config = TokenConfiguration("https://bitbucket.example.com/api/2.0/", token: "12345")

After you got your token you can use it with TrashCanKit

TrashCanKit(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.

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

let config = OAuthConfiguration(token: "<Your Client ID>", secret: "<Your Client secret>", scopes: []) // Scopes are not supported by the API yet
config.authenticate()

or for Bitbucket Enterprise

let config = OAuthConfiguration("https://bitbucket.example.com/api/v3/", webURL: "https://bitbucket.example.com/", token: "<Your Client ID>", secret: "<Your Client secret>", scopes: []) // Scopes are not supported by the API yet

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

Users

Get a single user

let username = ... // set the username
TrashCanKit().user(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

TrashCanKit().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

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

Get repository

TrashCanKit().repository("nerdishbynature", name: "octokit.swift") { response in
  switch response {
    case .Success(let repository):
      // do something
    case .Failure(let error):
      // handle any errors
  }
}

Latest podspec

{
    "name": "TrashCanKit",
    "version": "0.6.3",
    "summary": "A Swift API Client for Bitbucket.org",
    "description": "You are looking at the A Swift API Client for GitHub and GitHub Enterprise.nThis is very unofficial and not maintained by Github.",
    "homepage": "https://github.com/nerdishbynature/trashcankit",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Piet Brauer": "[email protected]"
    },
    "source": {
        "git": "https://github.com/nerdishbynature/trashcankit.git",
        "tag": "0.6.3"
    },
    "social_media_url": "https://twitter.com/pietbrauer",
    "module_name": "TrashCanKit",
    "dependencies": {
        "NBNRequestKit": [
            "~> 2.0"
        ]
    },
    "requires_arc": true,
    "source_files": "TrashCanKit/*.swift",
    "platforms": {
        "ios": "8.0",
        "osx": "10.10",
        "watchos": "2.0",
        "tvos": "9.0"
    },
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This