Skip to content

Pinoccio/library-objc-pinoccio

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 

Repository files navigation

client-objc-pinoccio

Objective C library for Pinoccio

How to

  1. Download the zip here
  2. Drag the Pinoccio header and class file into your iOS project, Copy to project directory if needed, and add to your iOS app's target.
  3. Add the header to whatever class you need to use the API in, like so;
#import "Pinoccio.h"

Functions, basic usage.

Initializing library

PinoccioAPI *pinoccioAPI = [[PinoccioAPI alloc] init]; // this also initializes the keychain wrapper

Setting login email and password

[pinoccioAPI setPinoccioEmail:@"foo@bar.com"];
[pinoccioAPI setPinoccioPassword:@"foobarbaz123"];

Logging in (changed API) This uses the set email and password stored in the keychain.

[pinoccioAPI loginWithCompletion:^(NSString *generatedToken, BOOL isOK) {
    if (isOK){
        token = generatedToken; // token is a NSString
        isLoggedIn = YES; // isLoggedIn is global bool and to be checked if already logged in
    }else {
        NSLog(@"Username or password is incorrect!");
    }

}

Logging in. Required arguments: email, password (Depredicated)

NSString *token; // This and the bool can be a global variable that can be used anywhere in the class, the example demos this.
BOOL isLoggedIn;

pinoccioAPI loginWithCredentials:@"dylan@pinocc.io" password:@"Password2014" withCompletion:^(NSString *generatedToken, BOOL isOK) {
    if (isOK){
        token = generatedToken;
        isLoggedIn = YES;
    }else {
        NSLog(@"Username or password is incorrect!");
    }
}];

Logging out. Required arguments: token

[pinoccioAPI logoutWithToken:token withCompletion:^(BOOL isOK) {
    if (isOK) {
        [[[UIAlertView alloc] initWithTitle:@"Success!" message:@"You're logged out :D" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil] show];
    }else {
        // Make sure you're logging out a token that is valid
    }
}];

Get array of troops for account. Required arguments: token

[pinoccioAPI troopWithToken:token withCompletion:^(NSArray *troops, BOOL isOK) {
    if (isOK) {
        // Do something with troops
    }else {
        NSLog(@"Data is nil/null, check if user is logged in and token is valid.");
    }
}];

Get array of scouts in troop. Required arguments: TroopID, token

[pinoccioAPI scoutsWithTroopID:1 withToken:token withCompletion:^(NSArray *scoutArray, BOOL isOK) {
    if (isOK) {
        // Do something with scoutArray
    }else {
        NSLog(@"Data is nil/null, check if user is logged in and token is valid.");
    }
}];

Toggle led, pass bool true/false for led on/off. Required arguments: ScoutID, TroopID, token

[pinoccioAPI led:YES withScoutID:selectedScout withTroopID:selectedTroop withToken:token withCompletion:^(BOOL isOK) {
    if (isOK) {
        // If the function reaches here, the LED was toggled.
    }
}];

Send a bitlash command

[pinoccioAPI sendBitlash:@"print temperature.f" withScoutID:selectedScout withTroopID:selectedTroop withToken:token withCompletion:^(NSDictionary *returnedJSON, BOOL isOK) {
    if (isOK) {
        // Do something with returnedJSON, the reply is the object "reply"
        NSLog(@"%@",returnedJSON[@"reply"]);
    }
}];