# Loops Tools

> Includes every thing the need to be included while developing loops web pages (web apps) 
> author lishuo@mozat.com

## Quick Start

in your VUE app:
```javascript
  ...
  import LoopsTools from 'loops-tools';
  

  ...
  Vue.use(LoopsTools);
  // or
  Vue.use(LoopsTools, { env: 'production' }); // for production env
  
  // production env will use production API URL and all production settings.
    
```
install params:
- beginToForeground (when web page back to visible)
- beginToBackground (when web page hide to back)
- onDestroy (when web view begin to destroy)

wanna call an API?
```javascript
  import { api, request } from 'loops-tools';
  
  // no uid & token param needed. will auto get params from **url param** 
  // **UNLESS** you manually pass it into the **params**. that will override the url params.
  request(api.topupReward, ${params})
  .then(res => {
    ... 
    // do every thing with your result.
  })  
  
  // or
  
  api.topupReward.request(${params})
  .then(res =>{
    ...
    // same here or different code styles.
  })
```

other tools:
```javascript
  import { inapp, points } from 'loops-tools';
  
  // wanna inject a DI point?  
  inapp.di(points(${pointid}));
  
  // wanna open a app page?
  inapp.openAppPage(${pageName}});
  
  // wanna get other url params?
  import { utils } from 'loops-tools';
  
  const pageType = utils.getUrlParams('pageType');
  // multiple
  const { param1, param2 } = utils.getUrlParams('param1', param2);
```

pretty simple and all you need is focus on the page logic.

of course. if there are new APIs or features required. need to manually update the lib. 
but that also make this lib extensible and flexible. 

## Overview

Module structure: 
``` 
utils,   // include all utils. lke get url param and find, filter functions.
request, // method to request APIs.  alias for utils.request. because frequently used 
inapp,   // in APP features. like DI, open APP page etc..
api,     // APIS. 
points,  // di points
VERSION, // tools version. can see the release log to decide if this tools include requeired features.
```

### Utils Methods

#### utils.getUrlParams(paramName[s])

**Argument**
  
paramName (array of string, string) : the param names
  
**Returns**

string or object

**Example**

```
const something = utils.getUrlParams('something');

const { param1, param2 } = utils.getUrlParams(['param1', 'param2']);
```

#### utils.getMobileOperatingSystem()

**Argument**
  
**Returns**

enum['Windows Phone', 'Android', 'iOS', 'unknown']

**Example**


#### utils.getChromeVersion()

**Argument**
  
**Returns**

number of chrome version

**Example**


#### utils._

include Lodash core (~4kb)
 
_.assignIn, _.before, _.bind, _.chain, _.clone, _.compact, _.concat, _.create, _.defaults, _.defer, _.delay, _.each, _.escape, _.every, _.filter, _.find, _.flatten, _.flattenDeep, _.forEach, _.has, _.head, _.identity, _.indexOf, _.isArguments, _.isArray, _.isBoolean, _.isDate, _.isEmpty, _.isEqual, _.isFinite, _.isFunction, _.isNaN, _.isNull, _.isNumber, _.isObject, _.isRegExp, _.isString, _.isUndefined, _.iteratee, _.keys, _.last, _.map, _.matches, _.max, _.min, _.mixin, _.negate, _.noConflict, _.noop, _.once, _.pick, _.reduce, _.result, _.size, _.slice, _.some, _.sortBy, _.tap, _.thru, _.toArray, _.uniqueId, _#value, & _.values

for more information:
https://github.com/lodash/lodash/wiki/Build-Differences

### Inapp methods

https://mozat.com/confluence/pages/viewpage.action?title=Custom+URL&spaceKey=LC

#### inapp.di(diPoint: DIPoint, params: Object = {})

**Argument**

dipoint: dipoint
params: params.

**Returns**

-

**Example**
```
inapp.di(points(14012));
```


#### inapp.toast(text: String)

**Argument**

text: toast string.

**Returns**

-

**Example**
```
inapp.toast('toast test');
```

#### openAppPage(pageName: String)

**Argument**

pageName: page name.
```
page name:
mydiamond,home,mylevel,leaderboard,mytitle,topup,myprofile

unlockType
(set only when pageName == "mytitle")
// -1: default
//  0:  ‘all’
//  1: ‘broadcaster’
//  2: ‘looper ’
```

**Returns**

-

**Example**
```
inapp.openAppPage('mytitle');
```

#### openVideo(sid: String, cid: String)

**Argument**

sid: session id 
cid: channel id

**Returns**

-

**Example**
```
inapp.openVideo('v9495', '110012');
```


#### openURL(url: String, title: String)

**Argument**

url: url 
title : title

**Returns**

-

**Example**
```
inapp.openURL('http://www.google.com', 'Google');
```


### API

see code for more informations

## Points 

see code for more informations
