ng-rec-api
v1.0.0
Published
An Angular 2+ Api Interface
Downloads
3
Readme
REC Barcelona (Angular 2+ API)
A little api interface for REC Barcelona.
!! WARNING !! THIS LIBRARY IS IN BETA, USE AT YOUR OWN RISK
Table Of Content
Installing
Using npm:
npm install ng-rec-api -s
Setting Up
Setting up is as easy as any other Angular library, just import the module and add it to the AppModule imports.
// app.module.ts
import { RecApiModule, REC_APP_CONFIG } from 'ng-rec-api';
@NgModule({
imports: [
RecApiModule
],
providers: [
{
provide: REC_APP_CONFIG,
useValue: {
url: "https://api.rec.barcelona.com",
client_id: "...",
client_secret: "...",
grant_type: 'client_credentials',
}
},
]
})
export class AppModule {
}
You must also provide
REC_APP_CONFIG
, containing the url and client credentials
Usage
Using it is also pretty simple, just import the service and start using it.
Note:
Some calls have various versions available.
rec.auth.token({ ... }, 'v1'); rec.auth.tokenV1({ ... }); rec.auth.tokenV2({ ... }); rec.auth.tokenV3({ ... });
Example:
// app.component.ts
import { RecApiService, TokenSet } from '../packages/rec-api';
export class AppComponent {
constructor(
private rec: RecApiService
){
rec.oauth.clientToken('v2')
.subscribe(
(token: TokenSet) => {
/**
* `persistToken` saves token to localStorage with a name
* can be later retrieved via `restoreToken`
*/
rec.auth.persistToken('app', token);
let appToken = rec.auth.restoreToken('app');
},
(error) => {
console.error(error.message);
}
);
}
}
API
List of methods by version:
auth
loggedIn : boolean
persistToken: TokenSet
restoreToken: TokenSet
oauth
token(data: AuthTokenData, version: 'v1' | 'v2' | 'v3'): Observable<Response>
registerUser(data: RegisterUserData): Observable<Response>
validateUserPhone(dni: string, code: string): Observable<Response>
clientToken(): Observable<Response>
userToken(data: UserTokenData): Observable<Response>
getToken(): TokenSet
status
Returns status
user
account(): Observable<User>
update(data: any): Observable<any>
saveKyc(data: any): Observable<any>
exchangers(): Observable<any>
uploadFile(file: File): Observable<any>
profileImage(url): Observable<any>
settings(): Observable<any>
phoneList(): Observable<any>
publicPhone(public: boolean): Observable<any>
changePin(pin, repin, security_answer): Observable<any>
securityQuestion(): Observable<any>
setActiveGroup(group_id): Observable<any>
transactions(offset, limit, day): Observable<any>
transactionsPerDay(day: string | number, offset: number, limit: number): Observable<any>
createNewGroup(data: CreateGroupData): Observable<any>
Security:otp(): Observable<any>
request2faCode(): Observable<any>
validate2faCode(pin): Observable<any>
show2faCode(pin): Observable<any>
deactivate2faCode(pin): Observable<any>
getRecoveryCode(dni: string, phone: string, secret: string): Observable<any>
recoverPassword(code: string | number, password: string, repassword: string): Observable<any>
group
groups
group
update
users
creditCards
deleteCard
addCreditCard
updateLocation
bankAccount
addBankAccount
deleteBankAccount
offers
addOffer
editOffer
deleteOffer
categories
addCategory
products
addProduct
deleteProducts
transaction
getVendorData
recharge
map
list
search