1 | # @coreo/ionic-core
|
2 |
|
3 | Ionic 2+ module for integrating with Coreo.
|
4 |
|
5 | ## Installation
|
6 | ```
|
7 | npm install @coreo/ionic-core --save
|
8 | ```
|
9 |
|
10 | Update your Ionic `app.module.ts`:
|
11 | ```
|
12 | import { CoreoModule } from '@coreo/ionic-core';
|
13 | ...
|
14 | @NgModule({
|
15 | imports: [CoreoModule]
|
16 | ...
|
17 | })
|
18 | export class AppModule {}
|
19 | ```
|
20 | ### With Configuration
|
21 |
|
22 | ```
|
23 | import { CoreoModule, CoreoConfig } from '@coreo/ionic-core';
|
24 | ...
|
25 | const coreoConfig = new CoreoConfig({
|
26 | baseUrl: 'https://coreo-dev.herokuapp.com'
|
27 | });
|
28 |
|
29 |
|
30 | @NgModule({
|
31 | imports: [
|
32 | CoreoModule.forRoot(coreoConfig)
|
33 | ]
|
34 | ...
|
35 | })
|
36 | export class AppModule {}
|
37 | ```
|
38 |
|
39 | Configuration options available:
|
40 |
|
41 | - `baseUrl`: location of coreo server (leave blank to point to production Coreo server)
|
42 | - `publicUrl`: location of Coreo main site (leave blank to point to production site)
|
43 | - `projectId`: ID of project to submit to when using the `CoreoClient`. If you leave this blank, you must send it in the payload of each `CoreoClient` request.
|
44 | - `googleMapsKey`: API key to use with the Google Maps provider.
|
45 | - `ionicViewAppId`: App ID to use for Ionic View.
|
46 | - `googleWebClientId`: ID to use for Google login.
|
47 |
|
48 | ## API
|
49 |
|
50 | The following services are provided as `@Injectable()`s
|
51 | ### CoreoAuth - Authentication
|
52 |
|
53 | A thin wrapper around Ionic Native's GooglePlus and Facebook authentication.
|
54 | Ensure you have installed the relevant plugins and followed the configuration steps in the following documentation:
|
55 |
|
56 | - Google : https://ionicframework.com/docs/v2/native/google-plus/
|
57 | - Facebook : https://ionicframework.com/docs/v2/native/facebook/
|
58 |
|
59 | **NOTE** You must configure your OAuth credentials within Coreo.
|
60 | Go to Surveys > Your Survey > Credentials and add the relevant data.
|
61 |
|
62 | ```
|
63 | import { CoreoAuth, CoreoAuthResult } from '@coreo/ionic-core';
|
64 |
|
65 | @Component({
|
66 | ...
|
67 | })
|
68 | export class MyLoginComponent {
|
69 | constructor(
|
70 | private auth: CoreoAuth
|
71 | ) {}
|
72 |
|
73 | login(): Promise<CoreoAuthResult> {
|
74 | return this.auth.login('basic', { email: 'bob@mail.com', password: 'bob});
|
75 | // OR
|
76 | // const surveyId = 12;
|
77 | // return this.auth.login('google', surveyId);
|
78 | }
|
79 | }
|
80 | ```
|
81 |
|
82 | #### Methods:
|
83 | - `login(method: 'basic' | 'google' | 'facebook', params: CoreoAuthLoginOptions)`
|
84 | - `logout(): void`
|
85 |
|
86 | #### Types:
|
87 | - CoreoAuthLoginOptions - If the method is 'basic' then this is an `{email, password}` object, else it is the surveyId you are logging in to.
|
88 |
|
89 | ### CoreoUser - User
|
90 |
|
91 | #### Properties:
|
92 | - `isLoggedIn: boolean` - Flag indicating whether the user is logged in or not.
|
93 | - `id: number` - User ID
|
94 | - `email: string` - Email
|
95 | - `role: string` - Role
|
96 | - `displayName: string` - Display Name
|
97 | - `imageUrl: string` - Users' profile image URL
|
98 |
|
99 | ### Client
|
100 |
|
101 | An HTTP client for sending queries and posting data to Coreo. Handles all authentication (if the user is logged in)
|
102 |
|
103 | ```
|
104 | import { CoreoClient } from '@coreo/ionic-core';
|
105 |
|
106 | @Injectable()
|
107 | export class MyDataService {
|
108 | constructor(
|
109 | private client: CoreoClient
|
110 | ) {}
|
111 |
|
112 | getData(): Observable<any> {
|
113 | return this.client.request('/records?q=surveyId:12');
|
114 | }
|
115 | }
|
116 | ```
|
117 |
|
118 | ### Methods:
|
119 | - request(path: string, options: CoreoClientRequestOptions = {}) : Observable<any>
|
120 | - post(path: string, body?: FormData | any, options: CoreoClientRequestOptions = {}) : Observable<any>
|
121 |
|
122 | ### Types:
|
123 | - CoreoClientRequestOptions
|
124 | - `method: string` - HTTP method. Defaults to 'get'
|
125 | - `headers?: any` - An Object of HTTP headers
|
126 | - `body?: string | FormData | null`
|
127 | - `authentication?: CoreoAuthToken | false` - If false, then no authentication header is set (even if the user is logged in).
|
128 | If set to a CoreoAuthToken, this token will be used again regardless of the user's logged in token. If `authentication` is not supplied
|
129 | then the user's logged in token will be used, if logged in. |
\ | No newline at end of file |