Nuxeo iOS SDK

Meetup - Nuxeo Tech Talk


Created by Arnaud Kervern / @arnaudke

Fork me github.com/akervern/ios-meetup-reveal.js

Basic Nuxeo Concepts

Non exhaustive...

Document hierarchy

Every document has a parent, except Root.

Document metadata

{
    "properties": {
        "dc:creator": "akervern", // field creator from dublincore schema
            "dc:nature": "comics",
            "dc:contributors": ["akervern"],
            "dc:created": "tomorrow",
            "dc:description": "A very nice description",
            ...
    }
}

REST API

CRUD our documents

Automation

Like OSX Automator

Plug me with Nuxeo

... said another app, one day.

JavaScript / NodeJS client

client.operation('Document.GetChildren')
.input('doc:/')
.execute(function(error, children) {
        if (error) {
        // something went wrong
        throw error;
        }

        // do something with children
        });

Java


import org.nuxeo.ecm.automation.client.model.documents;
import org.nuxeo.ecm.automation.client.Session;

public static void main(String[] args) throws Exception {
    HttpAutomationClient client = new HttpAutomationClient(
            "http://localhost:8080/nuxeo/site/automation");

        Session session = client.getSession("Administrator", "Administrator");
        Documents docs = (Documents) session.newRequest("Document.Query").set(
                "query", "SELECT * FROM Document").execute();
        System.out.println(docs);

        client.shutdown();
}

PHP

$client = new PhpAutomationClient('http://localhost:8080/nuxeo/site/automation');

$session = $client->getSession('Administrator','Administrator');

$answer = $session->newRequest("Blob.Attach")->set('params', 'document', $path)
->loadBlob($blob, $blobtype)
->sendRequest();

Android

ctx.getServerConfig().setLogin("jdoe");
ctx.getServerConfig().setPassword("secret");
ctx.getServerConfig().setServerBaseUrl("http://10.0.2.2:8080/nuxeo/");

if (ctx.getNetworkStatus().isNuxeoServerReachable()) {
    Document doc = (Document) ctx.getSession().newRequest("Document.Fetch").set("value", docRef).execute();
}

And much more...

Nuxeo clients: http://doc.nuxeo.com/x/oIf1

Mobile work

Nuxeo Android

github.com/nuxeo/nuxeo-android/

API client

Simple layout exposition

Offline actions stack

Built with Droid4Me from Smart&Soft

Nuxeo Web Mobile

github.com/nuxeo/nuxeo-web-mobile/

Mobile oriented website (jQuery Mobile)

Basic mobile front-end

Document files preview

Native app using Apache Cordova (iOS & Android)

Let’s try with a real iOS library

Objective-C...


returnType (^blockName)(parameterTypes) = ^returnType(parameters) {...};

- (void)someMethodThatTakesABlock:(returnType (^)(parameterTypes))blockName;

[someObject someMethodThatTakesABlock: ^returnType (parameters) {...}];

typedef returnType (^TypeName)(parameterTypes);
TypeName blockName = ^returnType(parameters) {...};

Need help.

Smart&Soft

Making an iOS Lib?

How can we do that?!

How to deploy an app for testing?

TesflightApp

testflightapp.com

Share your builds with your testers

Testers won’t need any dev certificates

Users rights on per build releases

How to continuously test it?

Facebook XCTool

github.com/facebook/xctool

qa.nuxeo.org/jenkins/job/nuxeo-sdk-ios-master/

Runs the same as xcodebuild

... but with a human readable output.

pouet

… or a jUnit XML Output to be ingested by Jenkins

How do Objective-C devs include a library into their project?

CocoaPods

http://cocoapods.org/

Dependency manager

Podfile sample

$ cat Podfile
platform :ios, '7.0'
pod 'JSONKit',       '~> 1.4'
pod 'Reachability',  ‘>= 3.0'

$ pod install

Nuxeo's Cocoapods Specs Repository

github.com/nuxeo/cocoapods-specs

$ pod repo add Nuxeo https://github.com/nuxeo/cocoapods-specs

HTTP? JSON? Best practice…

trying our best.

ASIHTTPRequest

vs

AFNetworking

Which will win Nuxeo's HTTP battle?

AFNetworking

new mainstream http lib

ASIHTTPRequest

dead project?

better caching integration

JSON Serializer / Deserializer

JSONKit? TouchJSON? NSJSON*?

With Object mapping it should be better…

Foundation NSJSONSerialization

Nuxeo SDK iOS in practice

NUXJSONSerializer / NUXJSONMapper

I'll save you the Headache

Property mapping introspection

#import "NUXEntity.h"
@interface NUXDocument : NUXEntity

#pragma mark -
#pragma mark Somewhere else

[[NUXJSONMapper sharedMapper] registerEntityClass:[NUXDocument class]];
NUXDocument *myDoc =
[NUXJSONSerializer entityWithData:someData error:&error];

NUXSession

Holding Nuxeo’s URL and credentials.

A shared session, configured with .plist file.

REST request

NUXRequest

Built for our REST API

Adaptor, Category, Schema, HTTP Method, HTTP header, …


NUXRequest *request = [[NUXRequest alloc] initWithSession:session];
[request addURLSegment:@"path/default-domain/workspaces"];
[request addSchema:@"file"];

[session startRequestSynchronous:request withCompletionBlock:^{
    NSDictionary *json = [request responseJSONWithError:nil];
    XCTAssertEqualObjects(@"/default-domain/workspaces", [json valueForKey:@"path"]); }
failureBlock:^{
                 XCTFail(@"Request should not fail: %@", request.responseMessage);
             }];

Easy to instantiate using requests category

#import "NUXSession+requests.h"

NUXRequest *request = [session requestQuery:
@"select * from Document where ecm:mixinType = 'SuperSpace'"];

Automation Request

NUXAutomationRequest

Built for our Automation API

Chain parameters, Chain Input (file or document), Context variables


- (NUXAutomationRequest *)requestImportFile:(NSString *)file withParent:(NSString *)documentRef {
    NUXAutomationRequest *request = [self requestOperation:@"FileManager.Import"];

    [request addContextValue:documentRef forKey:@"currentDocument"];
    [request setInputFile:file];

    return request;
}

Much more ...

  • Blob LRU cache
  • Hierarchical cache
  • Document cache
  • ...

Thank you

Questions during beers?

Made with Slides.com