Code Monkey home page Code Monkey logo

off-sdk-ios's Introduction

GitHub GitHub GitHub GitHub GitHub Open Source Helpers

Open Food Facts iOS SDK

An easy to use framework for building iOS apps for the open food facts api. More features will be added soon this is just an initial start...

Install using cocoapods

pod 'OpenFoodFactsSDK', :git => 'https://github.com/keegho/off-sdk-ios.git'

Install using carthage

Install Homebrew

$ brew update
$ brew install carthage

Create Cartfile in your project root folder and add this to it.

github "keegho/off-sdk-ios"

Then in your terminal project root folder type.

carthage update

Now make sure to drag-and-drop the built frameworks into your Xcode project and import them in the source files that require them.

How to use the SDK?

Example Read:

import OpenFoodFactsSDK
//In the AppDelegate.swift setup your enviroment and url prefix
    private let off = OFF()

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

        off.enviroment = .production   //.production . testing  //Default production
        off.lanugageUrl = .fr          //.world .fr .ar .de     //Default world
        
        return true
    }

//Then in the ViewController
import OpenFoodFactsSDK

private let off = OFF() 
private var item = OFFProduct()

override func viewDidLoad() {
    super.viewDidLoad()
    
    //Call get product closure function
    off.getProduct(code: "737628064502") { (product, message) in
            if product != nil {
                item = product!
                print(item?.genericName ?? "NO PRODUCT NAME")
            } else {
                print(message ?? "NO MESSAGE")
            }
     }
}

Example Write:

import OpenFoodFactsSDK
//In the AppDelegate.swift setup your enviroment and url prefix
    private let off = OFF()

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

        off.enviroment = .production   //.production . testing  //Default production
        off.lanugageUrl = .fr          //.world .fr .ar .de     //Default world
        off.username = "foo"           // username needed when editing
        off.password = "bar"           // password needed when editing
        
        return true
    }

//Then in the ViewController
import OpenFoodFactsSDK

private let off = OFF() 
private var item = OFFProduct()

override func viewDidLoad() {
    super.viewDidLoad()
    
        item.code = "1"
        item.genericName = "Golden Virginia Tobacco"
        item.productName = "Golden Virginia Classic"
        item.brandsText = "Golden Viginia"
        item.labelsText = "Causes Death, Die young"
        item.quantity = "50g"
    
    //Call add product closure function
    off.addProduct(product: item) { (status, msg) in
            switch status {
            case .success:
                print("ADDED")
            case .failure:
                print("NOT ADDED")
                
            }
     }
}

off-sdk-ios's People

Contributors

keegho avatar

Watchers

 avatar  avatar

Forkers

mihaelamj

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.