<commit_before># selfbits-angular2-sdk

This package allows you to easily integrate the Selfbits Backend-as-Service into your Angular2 projects. Please note that you MUST have a Selfbits BaaS Account and an active Project to use the service. Check out http://baas.selfbits.io for more info.

Selfbits Backend-as-Service allows you to skip backend development and focus on what's most important for you: your user-experience.


## Features
* __auth__ - Provides Social & Basic Auth
* __database__ - Puts a ready to use database integration at your fingertips
* __file__ - Provides easy to use file storage for your App
* __user__ - Handles interaction with user data
* __device__ - Handles data from the device (Cordova only)
* __push__ - Provides Push Notifcation (Cordova only)


## Contents

- [Installation](#installation)
- [Setup](#setup)
	- [Setup via ngModule](#setup-via-ngmodule-since-rc5)
    - [Setup via bootstrap](#setup-via-boostrap-before-rc5)
- [Usage](#usage)
	- [Usage in Components](#usage-in-components)
	- [Usage in Services](#usage-in-services)
- [API Reference](#api-reference)
	- [SelfbitsAngular: auth](#selfbitsangular-auth)
		- [auth.login(authData)](#authloginauthdata)
		- [auth.signup(authData)](#authsignupauthdata)
		- [auth.social(providerName)](#authsocialprovidername)
		- [auth.unlink(providerName)](#authunlinkprovidername)
		- [auth.password(newPassword, oldPassword)](#authpasswordnewpasswordstring-oldpasswordstring)
		- [auth.logout()](#authlogout)
		- [auth.getUserId()](#authgetuserid)
		- [auth.isAuthenticated()](#authisauthenticated)
		- [auth.signupAnonymous()](#authsignupanonymous)
	- [SelfbitsAngular: database](#selfbitsangular-database)
		- [database.databaseSchema(tableName)](#databasedatabaseschematablename)
	- [SelfbitsAngular: file](#selfbitsangular-file)
		- [file.get(params)](#filegetparams)
		- [file.upload(params)](#fileuploadparams)
	- [SelfbitsAngular: user](#selfbitsangular-user)
		- [user.current()](#usercurrent)
	- [device](#selfbitsangular-device)
		- [device.sync()](#devicesync)
- [License](#license)


## Installation

```
npm install selfbits-angular2-sdk --save
```

##  Setup

### Setup via ngModule (since RC5)
```javascript

import {SelfbitsAngularModule} from 'selfbits-angular2-sdk';

const SELFBITSCONFIG = {
  /* Your App Domain */
	BASE_URL:'YourSbAppDomain',
  /* Your Selfbits App ID */
	APP_ID:'yourSbAppId',
  /* OPTIONAL: your Selfbits App Secret
     NOTE: on public clients we highly recommend to set Allowed Origins
     in your Selfbits BaaS Project Dashboard instead of using the Secret
  */  
	APP_SECTRET:'yourSbAppSecret',
};

@NgModule({
	imports: [
		/* other imports */
		SelfbitsAngularModule.initializeApp(SELFBITSCONFIG)
	],
	/*...your other providers, declarations,..*/
})
export class AppModule { }

```

### Setup via boostrap (before RC5)
```javascript

import {SelfbitsSetup, SELFBITS_PROVIDERS} from 'selfbits-angular2-sdk';

const SELFBITSCONFIG = {
  /* Your App Domain */
	BASE_URL:'YourSbAppDomain',
  /* Your Selfbits App ID */
	APP_ID:'yourSbAppId',
  /* OPTIONAL: your Selfbits App Secret
     NOTE: on public clients we highly recommend to set Allowed Origins
     in your Selfbits BaaS Project Dashboard instead of using the Secret
  */  
	APP_SECTRET:'yourSbAppSecret',
};

bootstrap(
	AppComponent,
	[
		SelfbitsSetup(SELFBITSCONFIG),
		SELFBITS_PROVIDERS
	]
);
```

## Usage

* __Note__: Our sdk is designed, so that you can consume them directly inside your components. 

### Usage in Components

```javascript

import { SelfbitsAngular } from 'selfbits-angular2-sdk';

export class LoginComponent {

  constructor(private sb:SelfbitsAngular) {}

  login(authData) {
  		this.sb.auth.login(authData).subscribe( res => {
  	        // DO SOMETHING AFTER LOGIN
  	    })
  	}
  }
}
```

### Usage in Services

Of course feel free to wrap our methods in your own services!

```javascript
import { Injectable } from '@angular/core'
import { SelfbitsAngular } from 'selfbits-angular2-sdk';

@Injectable()
export class TodoDatabaseService {

	public todo;
	
	constructor(private sb:SelfbitsAngular) {
		this.todo = this.sb.database.dataSchema('todo');
	}   
	
	createTodo(todo) {
		this.todo.post(todo)
			.map( res => { /*do something*/ return res})
			.subscribe( res => {
				console.log(res.json())
	        })
	}
}
```

## API Reference

### Always import SelfbitsAngular
```javascript
import {SelfbitsAngular} from 'selfbits-angular2-sdk';
```

### `SelfbitsAngular: auth`

- [auth.login(authData)](#auth.login)
- [auth.signup(authData)](#auth.signup)
- [auth.social(providerName)](#auth.social)
- [auth.unlink(providerName)](#auth.unlink)
- [auth.password(newPassword, oldPassword)](#auth.password)
- [auth.logout()](#auth.logout)
- [auth.getUserId()](#auth.getuserid)
- [auth.isAuthenticated()](#auth.isauthenticated)
- [auth.signupAnonymous()](#auth.signupanonymous)


### auth.login(authData)

Sign in using email and password.<commit_msg>no message<commit_after># selfbits-angular2-sdk

This package allows you to easily integrate the Selfbits Backend-as-Service into your Angular2 projects. Please note that you MUST have a Selfbits BaaS Account and an active Project to use the service. Check out http://baas.selfbits.io for more info.

Selfbits Backend-as-Service allows you to skip backend development and focus on what's most important for you: your user-experience.


## Features
* __auth__ - Provides Social & Basic Auth
* __database__ - Puts a ready to use database integration at your fingertips
* __file__ - Provides easy to use file storage for your App
* __user__ - Handles interaction with user data
* __device__ - Handles data from the device (Cordova only)
* __push__ - Provides Push Notifcation (Cordova only)


## Contents

- [Installation](#installation)
- [Setup](#setup)
	- [Setup via ngModule](#setup-via-ngmodule-since-rc5)
    - [Setup via bootstrap](#setup-via-boostrap-before-rc5)
- [Usage](#usage)
	- [Usage in Components](#usage-in-components)
	- [Usage in Services](#usage-in-services)
- [API Reference](#api-reference)
	- [SelfbitsAngular: auth](#selfbitsangular-auth)
		- [auth.login(authData)](#authloginauthdata)
		- [auth.signup(authData)](#authsignupauthdata)
		- [auth.social(providerName)](#authsocialprovidername)
		- [auth.unlink(providerName)](#authunlinkprovidername)
		- [auth.password(newPassword, oldPassword)](#authpasswordnewpasswordstring-oldpasswordstring)
		- [auth.logout()](#authlogout)
		- [auth.getUserId()](#authgetuserid)
		- [auth.isAuthenticated()](#authisauthenticated)
		- [auth.signupAnonymous()](#authsignupanonymous)
	- [SelfbitsAngular: database](#selfbitsangular-database)
		- [database.databaseSchema(tableName)](#databasedatabaseschematablename)
	- [SelfbitsAngular: file](#selfbitsangular-file)
		- [file.get(params)](#filegetparams)
		- [file.upload(params)](#fileuploadparams)
	- [SelfbitsAngular: user](#selfbitsangular-user)
		- [user.current()](#usercurrent)
	- [device](#selfbitsangular-device)
		- [device.sync()](#devicesync)
- [License](#license)


## Installation

```
npm install selfbits-angular2-sdk --save
```

##  Setup

### Setup via ngModule (since RC5)
```javascript

import {SelfbitsAngularModule} from 'selfbits-angular2-sdk';

const SELFBITSCONFIG = {
  /* Your App Domain */
	BASE_URL:'YourSbAppDomain',
  /* Your Selfbits App ID */
	APP_ID:'yourSbAppId',
  /* OPTIONAL: your Selfbits App Secret
     NOTE: on public clients we highly recommend to set Allowed Origins
     in your Selfbits BaaS Project Dashboard instead of using the Secret
  */  
	APP_SECTRET:'yourSbAppSecret',
};

@NgModule({
	imports: [
		/* other imports */
		SelfbitsAngularModule.initializeApp(SELFBITSCONFIG)
	],
	/*...your other providers, declarations,..*/
})
export class AppModule { }

```

### Setup via boostrap (before RC5)
```javascript

import {SelfbitsSetup, SELFBITS_PROVIDERS} from 'selfbits-angular2-sdk';

const SELFBITSCONFIG = {
  /* Your App Domain */
	BASE_URL:'YourSbAppDomain',
  /* Your Selfbits App ID */
	APP_ID:'yourSbAppId',
  /* OPTIONAL: your Selfbits App Secret
     NOTE: on public clients we highly recommend to set Allowed Origins
     in your Selfbits BaaS Project Dashboard instead of using the Secret
  */  
	APP_SECTRET:'yourSbAppSecret',
};

bootstrap(
	AppComponent,
	[
		SelfbitsSetup(SELFBITSCONFIG),
		SELFBITS_PROVIDERS
	]
);
```

## Usage

* __Note__: Our sdk is designed, so that you can consume them directly inside your components. 

### Usage in Components

```javascript

import { SelfbitsAngular } from 'selfbits-angular2-sdk';

export class LoginComponent {

  constructor(private sb:SelfbitsAngular) {}

  login(authData) {
  		this.sb.auth.login(authData).subscribe( res => {
  	        // DO SOMETHING AFTER LOGIN
  	    })
  	}
  }
}
```

### Usage in Services

Of course feel free to wrap our methods in your own services!

```javascript
import { Injectable } from '@angular/core'
import { SelfbitsAngular } from 'selfbits-angular2-sdk';

@Injectable()
export class TodoDatabaseService {

	public todo;
	
	constructor(private sb:SelfbitsAngular) {
		this.todo = this.sb.database.dataSchema('todo');
	}   
	
	createTodo(todo) {
		this.todo.post(todo)
			.map( res => { /*do something*/ return res})
			.subscribe( res => {
				console.log(res.json())
	        })
	}
}
```

## API Reference

### Always import SelfbitsAngular
```javascript
import {SelfbitsAngular} from 'selfbits-angular2-sdk';
```

### `SelfbitsAngular: auth`

- [auth.login(authData)](#authloginauthdata)
- [auth.signup(authData)](#authsignupauthdata)
- [auth.social(providerName)](#authsocialprovidername)
- [auth.unlink(providerName)](#authunlinkprovidername)
- [auth.password(newPassword, oldPassword)](#authpasswordnewpasswordstring-oldpasswordstring)
- [auth.logout()](#authlogout)
- [auth.getUserId()](#authgetuserid)
- [auth.isAuthenticated()](#authisauthenticated)
- [auth.signupAnonymous()](#authsignupanonymous)


### auth.login(authData)

Sign in using email and password.
{'fraction_non_alphanumeric': 0.13366683341670835, 'fraction_numerical': 0.00240120060030015, 'mean_word_length': 4.698973774230331, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1901182', 'n_tokens_mistral': 3436, 'n_tokens_neox': 3186, 'n_words': 758}