iamatjs v0.3.0
#IamatJS
###Install dependencies npm install
###Build client: browserify src/iamat.js --s IamatJS > dist/iamat.js
###Test for errors (open in browser): test/iamat.html
###Build app + client: browserify src/main.js -o dist/main.js
###Test app (open in browser): test/main.html
###Build client & app + client: browserify src/main.js -o dist/main.js && browserify src/iamat.js --s IamatJS > dist/iamat.js
###Build client & app + client (the 'cool' way) npm run Build
##Shorthand Usage
IamatJS.connect({atcodeName: 'test'})
.then(function (status) {
// 0: disconnected, 1: connected, 2: reconnecting, 3:connection lost
console.log('connection status: ', status);
});
##Basic Usage
// listen to connection updates
IamatJS.getConnection()
.on('update', function (connectionModel, status) {
// 0: disconnected, 1: connected, 2: reconnecting, 3:connection lost
console.log('connection status: ', status);
//console.log('connection status: ', connectionModel.getStatus());
});
// load metadata, then load atcode information and then connect
IamatJS.getMetadata().load('test')
.then(function () {
IamatJS.getAtcode().load('test')
.then(function () {
IamatJS.getConnection().connect();
});
});
#API
- set(opts): sets IamatJS parameters
- baseUrl (optional): set base url to connect to (procotol + '://' + host + ':' + port)
- connect(opts): sets IamatJS parameters and returns a Promise that resolves to socket connection status update
- baseUrl (optional): set base url to connect to (procotol + '://' + host + ':' + port)
- atcodeName (required): set atcodeName to connect to
###Metadata
IamatJS.getMetadata()
- loadAtcodes(atcodes: Array: String): returns a promise that resolves to load
- user data
- atcodes list with respective atcode data
- load(tag: String): (alias to loadTag)
- loadTag(tag: String): returns a promise that resolves to load
- user data
- atcodes list with respective atcode data
- get(atcodeName: String): returns a metadata atcode item that corresponds to the specified atcodeName or null
- getAll(): returns the list of metadada atcodes or an empty array
- getRaw(): returns original json data or null
- getStatus(): returns a reference to the status of the last load call
- 0: no data has been requested
- 200: data requested success
- 400: data requested error
- getTag(): returns the specified tag (only gets set when the load call was successful)
- getUser(): returns the metadata user item
###Metadata User Item
IamatJS.getMetadata().getUser()
- createUser(data: Object): returns a promise that resolves to creating a new user (our backend handles merging sessions and not duplicating users) with the data (required - only one: facebook, twitter, linkedin or google data objects)
- getAnonymous(): returns bool to reference if user is anonymous
- getFacebook(): returns bool to reference if user is logged into facebook
- getGoogle(): returns bool to reference if user is logged into google
- getId(): return metadata user item unique identifier
- getName(): return metadata user item name
- getPhotoUrl(): return metadata user item photo url
- getLinkedIn(): returns bool to reference if user is logged into linkedin
- getTwitter(): returns bool to reference if user is logged into twitter
- getRaw(): returns original json data
- logout(): returns a promise that resolves to the user loggin out (will disconnect from atcode if connection had been established)
####Publisher methods The Metadata User Item object inherits from Observable, so it exposes a method on. It notifies the following events through such interface:
- update: metadata user item information data changed
###Metadata Atcode Item
IamatJS.getMetadata().get('some-atcodeName');
IamatJS.getMetadata().getAll(); // Array of Atcode Items
- getAtcodeName(): returns the atcode atcodeName
- getBanner(): returns a metadata atcode banner item
- getContext(): returns a metadata atcode context item
- getLogo(): returns the atcode logo (media item image) or nullObject
- getRaw(): returns original json data
- getRequiredSocialLogins(): returns a metadata required social logins item
- getVersion(): returns the atcode version
###Metadata Atcode Banner Item
aMetadataAtcodeItem.getBanner()
- getBackgroundColor(): returns string to reference a hex color
- getBannerFull(): returns the banner image (media item image) or nullObject
- getBannerTile(): returns the banner image tile (media item image) or nullObject
- getTextColor(): returns string to reference a hex color or null
- getRaw(): returns original json data
###Metadata Atcode Context Item
aMetadataAtcodeItem.getContext()
- getRaw(): returns original json data
####Publisher methods The Metadata Atcode Context Item object inherits from Observable, so it exposes a method on. It notifies the following events through such interface:
- update: context information data changed
###Metadata Atcode Required Social Logins Item
aMetadataAtcodeItem.getRequiredSocialLogins()
- getFacebook(): returns bool to reference if facebook login is accepted
- getGoogle(): returns bool to reference if google login is accepted
- getLinkedIn(): returns bool to reference if linkedin login is accepted
- getRaw(): returns original json data
- getTwitter(): returns bool to reference if twitter login is accepted
- getSkip(): returns bool to reference if login can be skipped
- isLoginRequired(): returns bool to reference if login is mandatory
###Atcode
IamatJS.getAtcode()
- load(atcode: String): returns a promise that resolves to atcode information data
- getConfig(): returns config json data or empty json object
- getAbout(): returns about string or empty string
- getAgenda(): returns agenda json data or empty agenda json object
- getAtcodeName(): returns atcodeName string
- getLogo(): returns atcode logo (media item image) or nullObject
- getMap(): returns map json data or empty map json object
- getMedia(): returns media json data or empty array
- getMenu(): returns menu json data or empty array
- getPlan(): returns map json data or empty plan json object
- getPeople(): returns people json data or empty array
- getRaw(): returns original json data
- getStyles(): returns style json data or empty json object
- getTOS(): returns tos json data or empty string
####Publisher methods The media object inherits from Observable, so it exposes a method on. It notifies the following events through such interface:
- update: atcode information data changed (it is advisable to listen to specific models to subscribe to atomic/modular updates)
###Connection
IamatJS.getConnection()
- connect(): executes a sockect connection (listen to event update to receive status)
- disconnect(): destroys the sockect connection (if any) (listen to event update to receive status)
- getOffset(): returns offset time with server clock
- getStatus(): returns connection status
- 0: disconnected
- 1: connected
- 2: reconnecting
- 3:connection lost
####Publisher methods The media object inherits from Observable, so it exposes a method on. It notifies the following events through such interface:
- update: connection status changed
###Shout
IamatJS.getShout()
- shout(event: String, data: Object): sends a shout event via sockect connection (different events will require different data)
- sh_text_command
- text: String
- sh_text_command
###Sections
IamatJS.getSections()
- get(id: String): return a section item with unique identifier id or section item null if none was found with such identifier
- getAll(): returns the array of section items sorted by items order
- getAllInclude(included: Bool (default true)): returns the array of section items sorted by items order filtered to included or not included sections in menu
- getLandingSection(): returns the section item set as the landing section
###Section Item
IamatJS.getSections().get('some-id');
IamatJS.getSections().getAll(); // Array of Section Items
IamatJS.getSections().getAllIncluded(true or false); // Array of filtered Section Items
- getId(): returns the item's unique identifier
- getImage(): returns the item's image (media item image) or nullObject
- getInclude(): returns the item's include in menu property
- getRaw(): returns original json data
- getSlug(): returns the item's unique identifier in slug case
- getStart(): returns the item's property that defines it as landing section
- getTitle(): returns the item's title
- getType(): returns the item's type
- static
- HTML
- HTMLList
- youtube
- favoriteRecipes
- feed
- fixture
- iframe
- recipes
- separator
- Videos
- getOrder(): returns the item's order
###History
IamatJS.getHistory()
- get(id: String): returns the history item that corresponds to the specified unique identifier or null
- getAll(): returns an array of history items
- initialFetch(howMany: int (optional), room: String (optional)): returns a Promise that resolves to the initial load of history items
- load(howMany: int (optional), room: String (optional)): returns a Promise that resolves to the load of history items
- setRoom(): sets the room filter
####Publisher methods The media object inherits from Observable, so it exposes a method on. It notifies the following events through such interface:
- update: new items have been added to the list of history items (occurs both via socket or via load)
- event: new items have arrived via socket
###History Item
IamatJS.getHistory().get('some-id');
IamatJS.getHistory().getAll(); // Array of Section Items
- getContent(): returns a promise that resolves once the item's content has been loaded. Items that need to load content:
- sh_html
- getData(): returns the item's data
- getEvent(): returns the item's event
- getId(): returns the item's unique identifier
- getRaw(): returns original json data
- getTime(): returns the item's time
###History Item Poll
- getEvent(): returns the item's event
- sh_poll2
- poll_answered_response2
- poll_final_response2
- setAnswer(responseIndex: int): send an answer to the poll
- update(data: Object): update the item's data
###History Item Featured Item
- getEvent(): returns the item's event
- sh_featured_item
###History Item Tweet Action
- getEvent(): returns the item's event
- sh_tweet_action
###History Item Text
- getEvent(): returns the item's event
- sh_text_command
###History Item Image
- getEvent(): returns the item's event
- sh_img
###History Item Ad Image with link
- getEvent(): returns the item's event
- sh_ad_img_link
###History Item Html
- getEvent(): returns the item's event
- sh_html
###History Item Media
- getEvent(): returns the item's event
- sh_media
###History Item Post
- getEvent(): returns the item's event
- sh_post
####How to:
var receivedEvent = function (historyModel, historyItem) {
console.log('Received event');
// all 3 access the item
console.log('Item:', historyItem, historyModel.get(historyItem.getId()), IamatJS.getHistory().get(historyItem.getId()));
console.log('Item id:', historyItem.getId());
console.log('Item event:', historyItem.getEvent());
console.log('Item data:', historyItem.getRaw());
historyItem.getContent().then(function (content) {
console.log('Item content:', content);
});
};
IamatJS.getHistory().on('event', receivedEvent);
###Ranking
IamatJS.getRanking()
- getAll(): returns the array of ranking items
- getRaw(): returns the original json of ranking items
- load(): returns a promise that resolves once the ranking data has been loaded. Returns an array of ranking items.
###Ranking Item
IamatJS.getRanking().load().then(function (rankingItems) {
rankingItems; // Array of Ranking Items
IamatJS.getRanking().getAll() // Array of Ranking Items
});
- getId(): returns the item's unique identifier
- getName(): returns the item's name
- getPhoto(): returns the item's image (media item image)
- getPoints(): returns the item's points
- getPosition(): returns the item's position
- getRaw(): returns original json data
###Markers
IamatJS.getMarkers()
- get(id: String): returns a marker item with the unique identifier if it exists || null
- getAll(): returns the array of marker items
- getRaw(): returns the original json of marker items
- load(): returns a promise that resolves once the markers data has been loaded. Returns an array of marker items.
###Marker Item
IamatJS.getMarkers().load().then(function (markerItems) {
markerItems; // Array of Marker Items
IamatJS.getMarkers().getAll() // Array of Marker Items
});
- getFilter(): returns the item's filter value
- getFrom(): returns the item's from value
- getHistory(): returns the item's history (make sure to call this after using the load method)
- getId(): returns the item's unique identifier
- getName(): returns the item's name value
- getRoom(): returns the item's room value
- getTill(): returns the item's till value
- getRaw(): returns original json data
- getRawHistory(): returns original json data for the item's history
- load(): returns a promise that resolves one the item's history data has been loaded. Returns an array of history items.
// assuming markerItem
markerItem.load().then(function (history) {
console.log('MarkerItem History data raw: ', markerItem.getRawHistory());
console.log('MarkerItem History data: ', markerItem.getHistory());
console.log('MarkerItem History data: ', history);
});
###People
IamatJS.getPeople()
- get(id: String): return the people item that refers to the unique id
- getAll(): returns the array of people items
- getRaw(): returns the original json of people items
####Publisher methods The people object inherits from Observable, so it exposes a method on. It notifies the following events through such interface:
- update: data has changed
###People Item
IamatJS.getPeople().get('some-id');
IamatJS.getPeople().getAll(); // Array of People Items
- getBio(): returns the item's bio
- getCompany(): returns the item's company
- getId(): returns the item's unique identifier
- getName(): returns the item's name
- getPhot(): return the item's image (media item image)
- getPosition(): returns the item's position
- getRaw(): returns original json data
- getTwitter(): returns the item's twitter
###VOD
IamatJS.getVOD()
- get(id: String): return a promise that resolves to null if there is no marker referenced by the provided id or an array (could be empty) of history items