Very simple Swift library for Foursquare API v2
Swift Ruby Objective-C
Fetching latest commit…
Cannot retrieve the latest commit at this time.

README.md

FoursquareAPIClient

Build Status

FoursquareAPIClient is very simple Swift networking library for Foursquare API v2.

Demo

Installation

From CocoaPods

First, add the following line to your Podfile:

pod 'FoursquareAPIClient'

Second, install FoursquareAPIClient into your project:

pod install

Manually

Copy all the files from the FoursquareAPIClient folder to your project.

  • FoursquareAPIClient.swift
  • FoursquareAuthClient.swift (Optional)
  • FoursquareAuthViewController.swift (Optional)

Usage

Import

import FoursquareAPIClient

Setup session

let client = FoursquareAPIClient(accessToken: "YOUR_ACCESS_TOKEN")

or

let client = FoursquareAPIClient(clientId: "YOUR_CLIENT_ID", clientSecret: "YOUR_CLIENT_SECRET")

Versioning

// Set v=YYYYMMDD param
let client = FoursquareAPIClient(accessToken: "YOUR_ACCESS_TOKEN", version: "20140723")

or

let client = FoursquareAPIClient(clientId: "YOUR_CLIENT_ID", clientSecret: "YOUR_CLIENT_SECRET”,
                                  version: "20140723”)

Search Venues

let parameter: [String: String] = [
    "ll": "35.702069,139.7753269",
    "limit": "10",
];

client.request(path: "venues/search", parameter: parameter) {
    [weak self] result in

    switch result {

    case let .success(data):
        // parse the JSON data with NSJSONSerialization or Lib like SwiftyJson
        let json = JSON(data: data) // e.g. {"meta":{"code":200},"notifications":[{"...

    case let .failure(error):
        // Error handling
        switch error {
        case let .connectionError(connectionError):
            print(connectionError)
        case let .apiError(apiError):
            print(apiError.errorType)   // e.g. endpoint_error
            print(apiError.errorDetail) // e.g. The requested path does not exist.
        }
    }
}

Check in to Venue

let parameter: [String: String] = [
    "venueId": "55b731a9498eecdfb"3854a9”,
    "ll": "37.33262674912818,-122.030451055438",
    "alt": "10”,
];

client.request(path: "checkins/add", method: .post, parameter: parameter) {
    result in

    switch result {

    case let .success(data):
        // parse the JSON data with NSJSONSerialization or Lib like SwiftyJson
        let json = JSON(data: data) // e.g. {"meta":{"code":200},"notifications":[{"...

    case let .failure(error):
        // Error handling
        switch error {
        case let .connectionError(connectionError):
            print(connectionError)
        case let .apiError(apiError):
            print(apiError.errorType)   // e.g. endpoint_error
            print(apiError.errorDetail) // e.g. The requested path does not exist.
        }
    }
}

Authorization

Setup

let client = FoursquareAuthClient(clientId: "YOUR_CLIENT_ID",
                                  callback: "YOUR_CALLBACK_URL",
                                  delegate: self)

Delegate

func foursquareAuthClientDidSucceed(accessToken: String) {
    print(accessToken)
}

func foursquareAuthClientDidFail(error: NSError) {
    print(error.description)
}

Requirements

Swift 3.0 / iOS 8.0+

Creator

Kosuke Ogawa

License

The MIT License. See License.txt for details.