message: Use apiCall to avoid code duplicity
diff: @@ -47,15 +47,21 @@ export class FacebookAPI {
  * @param method HTTP method, for example POST, GET, DELETE or PUT.
  * @param payload An object to be sent as parameters to the API call.
  */
  - public async callAPI(path: string, method: string = 'POST', payload: any): Promise<any> {
  + public async callAPI(path: string, method: string = 'POST', payload: any, query: any): Promise<any> {
  let proof = this.getAppSecretProof(this.token, this.secret);
  + let queryString = '?';
  +
  + for(const key in query) {
  + queryString = queryString + `${key}=${query[key]}&`;
  + }
  +
  return new Promise((resolve, reject) => {
  request({
  method: method,
  json: true,
  body: payload,
  - uri: 'https://' + this.api_host + '/' + this.api_version + path + '?access_token=' + this.token + '&appsecret_proof=' + proof
  + uri: 'https://' + this.api_host + '/' + this.api_version + path + queryString + 'access_token=' + this.token + '&appsecret_proof=' + proof
  }, (err, res, body) => {
  if (err) {
  reject(err);
  @@ -69,7 +75,7 @@ export class FacebookAPI {
  }
  /**
  - *
  + * Make get to a path with a query
  *
  * @param {string} path
  * @param {*} query
  @@ -77,59 +83,19 @@ export class FacebookAPI {
  * @memberof FacebookAPI
  */
  public async get(path: string, query: any): Promise<any> {
  - let proof = this.getAppSecretProof(this.token, this.secret);
  -
  - let queryString = '?';
  -
  - for(const key in query) {
  - queryString = queryString + `${key}=${query[key]}&`;
  - }
  -
  - return new Promise((resolve, reject) => {
  - request({
  - method: 'GET',
  - json: true,
  - body: {},
  - uri: 'https://' + this.api_host + '/' + this.api_version + path + queryString + 'access_token=' + this.token + '&appsecret_proof=' + proof
  - }, (err, res, body) => {
  - if (err) {
  - reject(err);
  - } else if (body.error) {
  - reject(body.error.message);
  - } else {
  - resolve(body);
  - }
  - });
  - });
  + return this.callAPI(path, 'GET', {}, query);
  }
  /**
  - * Make a post to a path with a body
  + * Make post to a path with a body
  *
  * @param {string} path
  * @param {*} body
  * @returns {Promise<any>}
  * @memberof FacebookAPI
  */
  - public async post(path: string, body: any): Promise<any> {
  - let proof = this.getAppSecretProof(this.token, this.secret);
  -
  - return new Promise((resolve, reject) => {
  - request({
  - method: 'POST',
  - json: true,
  - body,
  - uri: 'https://' + this.api_host + '/' + this.api_version + path + '?access_token=' + this.token + '&appsecret_proof=' + proof
  - }, (err, res, body) => {
  - if (err) {
  - reject(err);
  - } else if (body.error) {
  - reject(body.error.message);
  - } else {
  - resolve(body);
  - }
  - });
  - });
  + public async post(path: string, body: any, query: any): Promise<any> {
  + return this.callAPI(path, 'POST', body, query);
  }
  /**
  