import BaseHttpApi from './BaseHttpApi' ; import HttpApiRequest from './HttpApiRequest' ; import AuthTokens from '../types/AuthTokens' ; import GraphQLRequest from './GraphQLRequest' ; import { AuthAPIError } from '../types/Errors' ; /**
 * This class will make specific requests to the facebook API utilizing their sick http logic implemented by BaseFacebookHttpApi.
 */ export default class HttpApi extends BaseHttpApi { see QFacebookHttpApi param email param password async auth ( email , password ) { return this . post ( new HttpApiRequest ( { url : 'https://b-api.facebook.com/method/auth.login' , method : 'auth.login' , friendlyName : 'authenticate' , params : { email , password } } ) ) . then ( res => { if ( ! res . access_token ) { const error = new AuthAPIError ( res . error_msg ) ; error . code = res . error_code ; error . errorData = JSON . parse ( res . error_data ) ; error . requestArgs = res . request_args . reduce ( ( prev , current ) => ( { ... prev , [ current . key ] : current . value } ) , { } ) ; throw error ; } this . token = res . access_token ; return res ; } ) ; } see QFacebookHttpApi async userQuery ( userId ) { return this . post ( new GraphQLRequest ( { name : 'UsersQuery' , params : { '0' : [ userId ] , '1' : true } } ) ) ; } see QFacebookHttpApi async usersQuery ( userIds ) { return this . post ( new GraphQLRequest ( { name : 'FetchContactsFullQuery' , params : { '0' : userIds , '1' : userIds . length } } ) ) ; } see QFacebookHttpApi param userIds param cursor async usersQueryAfter ( userIds , cursor ) { return this . post ( new GraphQLRequest ( { name : 'FetchContactsFullWithAfterQuery' , params : { '0' : userIds , '1' : cursor , '2' : userIds . length } } ) ) ; } see QFacebookHttpApi param userId param deltaCursor async usersQueryDelta ( userId , deltaCursor ) { return this . post ( new GraphQLRequest ( { name : 'FetchContactsDeltaQuery' , params : { '0' : deltaCursor , '1' : [ userId ] , '2' : '500' } } ) ) ; } see QFacebookHttpApi async threadListQuery ( count ) { return this . post ( new GraphQLRequest ( { name : 'ThreadListQuery' , params : { '11' : 'true' , '23' : count , '3' : 'false' , '27' : 'false' , '5' : 'false' , '10' : 'false' , '17' : 20 , '18' : 880 , '19' : 220 , '20' : 138 , '31' : '3' } } ) ) ; } param threadId see facebook-api . c async threadQuery ( threadId ) { return this . post ( new GraphQLRequest ( { name : 'ThreadQuery' , params : { '0' : [ threadId ] , '10' : false , '11' : false , '13' : true } } ) ) ; } async threadMessagesQuery ( threadId , count ) { return this . post ( new GraphQLRequest ( { name : 'ThreadQuery' , params : { '0' : [ threadId ] , '11' : true , '12' : count } } ) ) ; } async querySeqId ( ) { return this . post ( new GraphQLRequest ( { name : 'SeqIdQuery' , params : { '1' : '0' } } ) ) ; } see QFacebookHttpApi param unreadCount async unreadThreadListQuery ( unreadCount ) { return this . post ( new GraphQLRequest ( { name : 'UnreadThreadListQuery' , params : { '1' : unreadCount , '2' : true , '12' : true , '13' : false } } ) ) ; } param mid param aid async getAttachment ( mid , aid ) { return this . post ( new HttpApiRequest ( { url : 'https://api.facebook.com/method/messaging.getAttachment' , method : 'messaging.getAttachment' , friendlyName : '' , params : { mid , aid } } ) ) ; } param stickerId getSticker ( stickerId ) { return this . post ( new GraphQLRequest ( { name : 'FetchStickersWithPreviewsQuery' , params : { '0' : [ stickerId ] } } ) ) ; } }