Latest 1.5.1
Homepage https://github.com/octoblu/MeshbluKit
License MIT
Platforms ios 8.0, requires ARC
Dependencies Alamofire, SwiftyJSON
Authors

Version
License
Platform

Usage

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

Installation

MeshbluKit is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "MeshbluKit"

API

Is device registered?

isNotRegistered() -> Bool

Set Credentials

setCredentials(uuid: String, token: String)

Claim Device

claimDevice(uuid: String, handler: (Result<JSON, NSError>) -> ())

Get Devices

devices(options: [String: AnyObject], handler: (Result<JSON, NSError>) -> ())

Delete Device

deleteDevice(uuid: String, handler: (Result<JSON, NSError>) -> ())

Get Data

getData(uuid: String, options: [String: AnyObject], handler: (Result<JSON, NSError>) -> ())

Send Data Message

data(uuid: String, message: [String: AnyObject], handler: (Result<JSON, NSError>) -> ())

Send Message

message(message: [String: AnyObject], handler: (Result<JSON, NSError>) -> ())

Generate New Session Token

generateToken(uuid: String, handler: (Result<JSON, NSError>) -> ())

Reset Token

resetToken(uuid: String, handler: (Result<JSON, NSError>) -> ())

Update

update(uuid: String, properties: [String: AnyObject], handler: (Result<JSON, NSError>) -> ())
// OR
update(properties: [String: AnyObject], handler: (Result<JSON, NSError>) -> ())

Update Dangerously

updateDangerously(uuid: String, properties: [String: AnyObject], handler: (Result<JSON, NSError>) -> ())

Register Device

register(device: [String: AnyObject], handler: (Result<JSON, NSError>) -> ())

Get PublicKey

getPublicKey(uuid: String, handler: (Result<JSON, NSError>) -> ())

Who am i?

whoami(handler: (Result<JSON, NSError>) -> ())

Usage:

import Foundation
import MeshbluKit

class MeshbluExample : AnyObject {
  var meshbluHttp: MeshbluHttp

  init(meshbluConfig: [String: AnyObject]){
    self.meshbluHttp = MeshbluHttp(meshbluConfig: meshbluConfig)
    let uuid = meshbluConfig["uuid"] as? String
    let token = meshbluConfig["token"] as? String
    if uuid != nil && token != nil {
      self.meshbluHttp.setCredentials(uuid!, token: token!)
    }
  }

  init(meshbluHttp: MeshbluHttp) {
    self.meshbluHttp = meshbluHttp
  }

  func getMeshbluClient() -> MeshbluHttp {
    return self.meshbluHttp
  }

  func register() {
    let device = [
      "type": "device:ios-device", // Set your own device type
      "online" : "true"
    ]

    self.meshbluHttp.register(device) { (result) -> () in
      switch result {
      case let .Failure(error):
        println("Failed to register")
      case let .Success(success):
        let json = success.value
        let uuid = json["uuid"].stringValue
        let token = json["token"].stringValue
        println("Register device: uuid: (uuid) and token: (token)")

        self.meshbluHttp.setCredentials(uuid, token: token)
      }
    }
  }

  func sendMessage(payload: [String: AnyObject], handler: (Result<JSON, NSError>) -> ()){
    var message : [String: AnyObject] = [
      "devices" : ["*"],
      "payload" : payload,
      "topic" : "some-topic"
    ]

    self.meshbluHttp.message(message) {
      (result) -> () in
      handler(result)
      println("Message Sent: (message)")
    }
  }
}

Author

Sqrt of Octoblu, [email protected]

License

MeshbluKit is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "MeshbluKit",
    "version": "1.5.1",
    "summary": "Objective-C / Swift Meshblu Client Library",
    "description": "Objective-C / Swift Meshblu Client Library to easily connect Meshblu to iOS",
    "homepage": "https://github.com/octoblu/MeshbluKit",
    "license": "MIT",
    "authors": {
        "Sqrt of Octoblu": "[email protected]"
    },
    "source": {
        "git": "https://github.com/octoblu/MeshbluKit.git",
        "tag": "1.5.1"
    },
    "platforms": {
        "ios": "8.0"
    },
    "requires_arc": true,
    "source_files": "Pod/Classes/**/*",
    "resource_bundles": {
        "MeshbluKit": [
            "Pod/Assets/*.png"
        ]
    },
    "dependencies": {
        "Alamofire": [
            "~> 2.0.2"
        ],
        "SwiftyJSON": [
            "~> 2.3.0"
        ]
    }
}

Pin It on Pinterest

Share This