blob: 50e7c5372414d2ee2da49dc83bab24e5b040f926 [file] [log] [blame]
{
"name": "AmbrosusSDK",
"version": "2.0.3",
"summary": "Fetches Assets and Events from the Ambrosus Network (AMB-NET) and makes it easy to build interfaces.",
"swift_version": "4.2",
"description": "# AmbrosusSDK\n\n[![Version](https://img.shields.io/cocoapods/v/AmbrosusSDK.svg?style=flat)](http://cocoapods.org/pods/AmbrosusSDK)\n[![License](https://img.shields.io/cocoapods/l/AmbrosusSDK.svg?style=flat)](http://cocoapods.org/pods/AmbrosusSDK)\n[![Platform](https://img.shields.io/cocoapods/p/AmbrosusSDK.svg?style=flat)](http://cocoapods.org/pods/AmbrosusSDK)\n\n- [AmbrosusSDK](#AmbrosusSDK)\n * [Integration](#integration)\n * [Overview](#overview)\n * [Usage](#usage)\n * [Usage (Objective-C)](#usage-objective-c)\n \n- [Sample Application (Ambrosus Viewer)](#sample-application-ambrosus-viewer)\n * [Ambrosus Viewer Support](#ambrosus-viewer-support)\n * [Sample Symbologies](#sample-symbologies)\n\nThe AmbrosusSDK for iOS makes it easy for iOS App Developers to get back data from the [Ambrosus API](https://ambrosus.docs.apiary.io) (AMB-NET), and build their own interfaces for displaying Assets and Events.\n\n* Supports iOS 10+\n* Supports Objective-C and Swift 4.2+\n* Supports Xcode 10.1+\n\n### Integration\n\nTo start using the SDK you can add the following to your Podfile:\n\n```ruby\npod 'AmbrosusSDK'\n```\n\nYou can also download or clone this repository and import the AmbrosusSDK manually if not using Cocoapods, all of the code is contained in the top level \"AmbrosusSDK\" folder.\n\n### Overview\n\nThe SDK is composed of three main files all contained within the \"AmbrosusSDK\" folder:\n\n`AMBNetwork.swift` \n\nThe interface layer which makes network requests to the Ambrosus API such as fetching assets, events, and images associated with assets and Events\n\n`AMBDataStore.swift`\n\nA singleton caching layer, you can insert assets into it using `AMBDataStore.sharedInstance.assetStore.insert(:)` or events using `AMBDataStore.sharedInstance.eventsStore.insert(_:)`, saving assets and events in here will make them easy to fetch later, and also improve network performance when requesting already stored assets and events from `AMBNetwork`. It also will cache images downloaded using `AMBNetwork.requestImage(_:)` calls.\n\nModels\n\nDefines the two main data models, `AMBAsset` and `AMBEvent` these are the objects which Asset and Event details screens can be built with. To see an example of these structures being used see the AmbrosusViewer example project included with this repository.\n\n`AMBScanViewController.swift`\n\nBuilt-in scanner. There are 2 types for scanning events and assets and for scanning private keys (login)\nSupports all necessary types as 1d or 2d codes (Symbologies).\n\n### Usage\n\nTo start using the Ambrosus SDK within a Swift file first import it:\n```swift\nimport AmbrosusSDK\n```\n\nTo get back an asset from the API you can make a call like the following:\n\n```swift\nAMBNetwork.requestAsset(fromId: \"0x602023f73ab25f0c95a3cf4e92c9cb2f4c9c09dbd3ca6e167d362de6e7f1eeae\", completion: { asset, error in\n guard let asset = asset else {\n NSLog(\"asset failed to unwrap (error ?? \"\")\")\n return\n }\n // Use unwrapped Asset here\n})\n```\n\nA single Asset in the AmbrosusSDK has many events associated with it, to get back all events associated with an asset you can make a call like the following:\n\n```swift\nAMBNetwork.requestEvents(fromAssetId: \"0x602023f73ab25f0c95a3cf4e92c9cb2f4c9c09dbd3ca6e167d362de6e7f1eeae\") { events, error in\n guard let events = events else {\n NSLog(\"Failed to return events (error ?? \"\")\")\n return\n }\n // Use unwrapped events here\n}\n```\n\nTo get back an asset along with all of its events, and store the information in the `AMBDataStore` this can be done as follows:\n\n```swift\nAMBNetwork.requestAsset(fromId: \"0x602023f73ab25f0c95a3cf4e92c9cb2f4c9c09dbd3ca6e167d362de6e7f1eeae\", completion: { asset, error in\n guard let asset = asset else {\n NSLog(\"asset failed to unwrap (error ?? \"\")\")\n return\n }\n AMBDataStore.sharedInstance.assetStore.insert(asset)\n\n AMBNetwork.requestEvents(fromAssetId: asset.id, completion: { events, error in\n guard let events = events else {\n print(\"events failed to unwrap (error ?? \"\")\")\n return\n }\n AMBDataStore.sharedInstance.eventStore.insert(events)\n })\n})\n```\n\nOnce the asset along with its events are stored in the `AMBDataStore` they can then be accessed like so:\n```swift\nlet assetId = \"0x602023f73ab25f0c95a3cf4e92c9cb2f4c9c09dbd3ca6e167d362de6e7f1eeae\"\nlet asset = AMBDataStore.sharedInstance.assetStore.fetch(withAssetId: assetId)\nlet events = AMBDataStore.sharedInstance.eventStore.fetchEvents(forAssetId: assetId)\n```\n\nTo create assets and events, you must have an Ambrosus account with the `create_entity` permission and know your public key and private key. Your private key will be used for client-side signing. Start by configuring the `AMBWeb3Manager` with your private key:\n\n```swift\nlet privateKey = \"[YOUR_PRIVATE_KEY]\"\nlet publicKey = \"[YOUR_PUBLIC_KEY]\"\nAMBWeb3Manager.sharedInstance.setAccount(withPrivateKey: privateKey)\n```\n\nOnce you have your private key set you can now create assets and events using `AMBNetwork`:\n```swift\nAMBNetwork.createAsset(createdBy: publicKey) { (asset, error) in\n guard let assetId = asset?.id else {\n NSLog(error ?? \"Error, no Asset created\")\n return\n }\n let eventData = [\n [\"type\": \"ambrosus.asset.info\",\n \"name\": \"Organic Figs ((Int(arc4random_uniform(300))) count)\",\n \"assetType\": \"ambrosus.assetTypes.batch\",\n \"images\": [\n \"default\": [\"url\": \"http://limitlessapps.net/images/AmberAssets/figs.png\"]\n ]\n ]\n ]\n\n AMBNetwork.createEvent(assetId: assetId, createdBy: publicKey, data: eventData) { (event, error) in\n guard let event = event else {\n NSLog(error ?? \"Error, no Event created\")\n return\n }\n\n // Do something with unwrapped event here\n print(event.description)\n }\n}\n```\nThe AmbrosusSDK has a built-in Scanner: `AMBScanViewController` \n\nTo start scanning codes your view controller needs to use `AMBScanViewControllerDelegate`. After a code is scanned it will execute the delegate method:\n\n```swift\nfunc scanner(_ controller: AMBScanViewController, didCaptureCode code: String, type: String, codeResult: @escaping (Bool) -> Void) {\n // Do something with the code here\n}\n```\n* `code` - code what you scanned.\n* `type` - type of 1d or 2d code.\n* `codeResult` - callback for success or erorr scan result to reload scanner if smth goes wrong.\n\nTo set up the scanner add the following to the `viewWillAppear` method:\n```swift\nscanner = AMBScanViewController()\nscanner?.delegate = self\nscanner?.setup(with: self, scannerType: .entity)\n```\nscannerType - has 2 states :\n 1. `.entity` - for scan assets and events.\n 2. `.account` - for scan private keys.\n \nTo remove the scanner add the following to `viewWillDisappear`:\n```swift\nscanner?.delegate = nil\nscanner?.stop()\n```\n\n### Usage (Objective-C)\n\nThe Ambrosus SDK is also fully compatible with Objective-C, you can import the SDK by adding the following to the top of your implementation file:\n```objective-c\n@import AmbrosusSDK;\n```\n\nTo fetch an asset as well as its events in Objective-C and store the data in `AMBDataStore` you can do the following:\n\n```objective-c\nNSString *assetId = @\"0x602023f73ab25f0c95a3cf4e92c9cb2f4c9c09dbd3ca6e167d362de6e7f1eeae\";\n[AMBNetwork requestAssetFromId:assetId completion:^(AMBAsset * _Nullable asset) {\n if (!asset) {\n return;\n }\n [[[AMBDataStore sharedInstance] assetStore] insert:asset];\n\n [AMBNetwork requestEventsFromAssetId:assetId completion:^(NSArray<AMBEvent *> * _Nullable events) {\n if (!events) {\n return;\n }\n [[[AMBDataStore sharedInstance] eventStore] insert:events];\n }];\n}];\n```\n\n## Sample Application (Ambrosus Viewer)\n\nThe included example application, Ambrosus Viewer includes a scanner that is capable of scanning 1d and 2d codes and displaying details about an associated asset and its events from AMB-NET. In App you can login with your private key and create assets and events. It comes packaged with several sample assets and events as well. The app also contains Asset Details and Event Details screens which demonstrate using the SDK to build a fully featured iOS application for viewing data stored on AMB-NET.\n\n### Ambrosus Viewer Support\n\n* Supports iPhone 5S and above, iPad 5th Generation and above, iPod Touch 6th Generation and Above.\n* Minimum iOS Version 11\n* Requires Camera permission enabled in order to scan codes\n* Capable of scanning codes with the following symbologies:\n * UPCE, UPC12, EAN8, EAN13, CODE 39, CODE 128, ITF, QR, DATAMATRIX, AZTEC\n\n### Sample Symbologies\n\nTo see details about sample assets with the Ambrosus Viewer, scan any of the following codes from the app:\n\n|   EAN-8   |   EAN-13   |     QR     |\n| --------- | ---------------------------------- | ---------- |\n| &emsp;&emsp;![EAN-8 Sample](https://i.imgur.com/m7QZIaS.png) | &emsp;&emsp;![EAN-13 Sample](https://i.imgur.com/1HXwtPr.png) | &emsp;&emsp;![QR Sample](https://i.imgur.com/JfEUGo8.png)&emsp;&emsp;\n| <a href=\"https://gateway-test.ambrosus.com/events?data[type]=ambrosus.asset.identifier&data[identifiers.ean8]=96385074\" target=\"_blank\">Generic Asset</a>&emsp; | <a href=\"https://gateway-test.ambrosus.com/events?data[type]=ambrosus.asset.identifier&data[identifiers.ean13]=6942507312009\" target=\"_blank\">Guernsey Cow</a>&emsp;&emsp; | &emsp;&emsp;&emsp;&emsp;<a href=\"https://gateway-test.ambrosus.com/assets/0x4c289b68b5bb1a098a4aa622b84d6f523e02fc9346a3a0a99efdfd8a96ba56df\" target=\"_blank\">Ibuprofen Batch 200mg</a>&emsp;&emsp;\n\n### Account Scanner Sample\n\n![Account QR Sample](https://www.scandit.com/wp-content/themes/bridge-child/wbq_barcode_gen.php?symbology=qr&value=type%3Dambrosus.account%26account%3D0x8536eBc067457602FfC92B89B55501b54bcf5049&size=100&ec=L)\n\nAdd account (*ERC20 address:* 0x8536eBc067457602FfC92B89B55501b54bcf5049)",
"homepage": "https://github.com/ambrosus/sdk-ios",
"license": {
"type": "MIT",
"file": "LICENSE"
},
"authors": {
"ambrosus": "tech@ambrosus.com"
},
"source": {
"git": "https://github.com/ambrosus/sdk-ios.git",
"tag": "v.2.0.3"
},
"platforms": {
"ios": "10.0"
},
"source_files": "AmbrosusSDK/**/*"
}