btn52396 / FatSecretSwift

A framework built to help use the FatSecret API in swift

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

FatSecretSwift

FatSecretSwift is a Framework built to help connect to the FatSecret REST api. Currently the framework supports foods.search and food.get.

Requirements

  • iOS 12

Installation

FatSecretSwift is currently only available by adding it as a submodule to your project.

git submodule add https://github.com/NicholasBellucci/FatSecretSwift.git

Usage

First step is to initialize your personal credentials. In the demo project this is done in the App Delegate but you can do this wherever you want so long as it is done before your API request.

import FatSecretSwift

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    enum Constants {
        static let apiKey = ""
        static let apiSecret = ""
    }

    var window: UIWindow?


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

        FatSecretCredentials.setConsumerKey(Constants.apiKey)
        FatSecretCredentials.setSharedSecret(Constants.apiSecret)

        return true
    }
}

Once this has been done requests can be made by initializing the FatSecretClient.

let fatSecretClient = FatSecretClient()

Models

All Codable structs can be found in the Models folder.

Search

fatSecretClient.searchFood(name: "Hotdog") { search in
    print(search.foods)
}

Get Food

fatSecretClient.getFood(id: "16758") { food in
    print(food)
}

Author

Nicholas Bellucci, nickdbellucci@gmail.com

License

FatSecretSwift is available under the MIT license.

About

A framework built to help use the FatSecret API in swift


Languages

Language:Swift 96.8%Language:Objective-C 3.2%