|
@@ -1,19 +1,22 @@
|
|
|
-import { Injectable } from '@angular/core';
|
|
|
-import { HttpClient } from '@angular/common/http';
|
|
|
-import { Storage } from '@ionic/storage';
|
|
|
-import Twit from 'twit';
|
|
|
-
|
|
|
+import { Injectable } from "@angular/core";
|
|
|
+import { HttpClient } from "@angular/common/http";
|
|
|
+import { Storage } from "@ionic/storage";
|
|
|
+import Twit from "twit";
|
|
|
|
|
|
@Injectable()
|
|
|
export class TwitterApiProvider {
|
|
|
- consumer_key: string = 'UxZkbKotkr8Uc6seupnaZ1kDE';
|
|
|
- consumer_secret: string = 'fEAas8iugR60FOEXsFG0iajq6oyfIIXRBVMlTgWxBd1stWIKHq';
|
|
|
+ consumer_key: string = "UxZkbKotkr8Uc6seupnaZ1kDE";
|
|
|
+ consumer_secret: string =
|
|
|
+ "fEAas8iugR60FOEXsFG0iajq6oyfIIXRBVMlTgWxBd1stWIKHq";
|
|
|
access_token_key: string;
|
|
|
access_token_secret: string;
|
|
|
client;
|
|
|
|
|
|
constructor(public http: HttpClient, private storage: Storage) {
|
|
|
- Promise.all([this.storage.get('accessTokenKey'), this.storage.get('accessTokenSecret')]).then(values => {
|
|
|
+ Promise.all([
|
|
|
+ this.storage.get("accessTokenKey"),
|
|
|
+ this.storage.get("accessTokenSecret")
|
|
|
+ ]).then(values => {
|
|
|
this.access_token_key = values[0];
|
|
|
this.access_token_secret = values[1];
|
|
|
this.initApi();
|
|
@@ -26,100 +29,63 @@ export class TwitterApiProvider {
|
|
|
consumer_secret: this.consumer_secret,
|
|
|
access_token: this.access_token_key,
|
|
|
access_token_secret: this.access_token_secret,
|
|
|
- timeout_ms: 60 * 1000, // optional HTTP request timeout to apply to all requests.
|
|
|
- })
|
|
|
+ timeout_ms: 60 * 1000 // optional HTTP request timeout to apply to all requests.
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
- public fetchHomeFeed() {
|
|
|
- return this.client.get('statuses/home_timeline', { count: 10, include_entities: true, tweet_mode: "extended" })
|
|
|
- .then(res => {
|
|
|
- console.log(res);
|
|
|
- return res;
|
|
|
- })
|
|
|
- .catch(err => {
|
|
|
- console.log(err);
|
|
|
- });
|
|
|
+ public async fetchHomeFeed() {
|
|
|
+ return await this.client.get("statuses/home_timeline", {
|
|
|
+ count: 10,
|
|
|
+ include_entities: true,
|
|
|
+ tweet_mode: "extended"
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
- public fetchHomeFeedSince(id) {
|
|
|
- return this.client.get('statuses/home_timeline', { max_id: id, count: 15, include_entities: true, tweet_mode: "extended" })
|
|
|
- .then(res => {
|
|
|
- return res;
|
|
|
- })
|
|
|
- .catch(err => {
|
|
|
- console.log(err);
|
|
|
- });
|
|
|
+ public async fetchHomeFeedSince(id) {
|
|
|
+ return await this.client.get("statuses/home_timeline", {
|
|
|
+ max_id: id,
|
|
|
+ count: 15,
|
|
|
+ include_entities: true,
|
|
|
+ tweet_mode: "extended"
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
- public fetchUser(userId) {
|
|
|
- return this.client.get('users/lookup', { user_id: userId })
|
|
|
- .then(res => {
|
|
|
- return res.data[0];
|
|
|
- })
|
|
|
- .catch(err => {
|
|
|
- console.log(err);
|
|
|
- });
|
|
|
+ public async fetchUser(userId) {
|
|
|
+ const res = await this.client.get("users/lookup", { user_id: userId });
|
|
|
+ return res.data[0];
|
|
|
}
|
|
|
|
|
|
- public fetchUserTimeline(userId) {
|
|
|
- return this.client.get('statuses/user_timeline', { user_id: userId, include_entities: true, tweet_mode: "extended" })
|
|
|
- .then(res => {
|
|
|
- console.log(res.data);
|
|
|
- return res.data;
|
|
|
- })
|
|
|
- .catch(err => {
|
|
|
- console.log(err);
|
|
|
- });
|
|
|
+ public async fetchUserTimeline(userId) {
|
|
|
+ const res = await this.client.get("statuses/user_timeline", {
|
|
|
+ user_id: userId,
|
|
|
+ include_entities: true,
|
|
|
+ tweet_mode: "extended"
|
|
|
+ });
|
|
|
+ return res.data;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- public fetchUserTimelineSince(userId, maxId) {
|
|
|
- return this.client.get('statuses/user_timeline', { user_id: userId, max_id: maxId, include_entities: true, tweet_mode: "extended" })
|
|
|
- .then(res => {
|
|
|
- return res.data;
|
|
|
- })
|
|
|
- .catch(err => {
|
|
|
- console.log(err);
|
|
|
- });
|
|
|
+ public async fetchUserTimelineSince(userId, maxId) {
|
|
|
+ return await this.client.get("statuses/user_timeline", {
|
|
|
+ user_id: userId,
|
|
|
+ max_id: maxId,
|
|
|
+ include_entities: true,
|
|
|
+ tweet_mode: "extended"
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
- public destroyFriendship(userId) {
|
|
|
- return this.client.post('friendships/destroy', { user_id: userId })
|
|
|
- .then(res => {
|
|
|
- return res;
|
|
|
- })
|
|
|
- .catch(err => {
|
|
|
- console.log(err);
|
|
|
- });
|
|
|
+ public async destroyFriendship(userId) {
|
|
|
+ return await this.client.post("friendships/destroy", { user_id: userId });
|
|
|
}
|
|
|
|
|
|
- public muteUser(userId) {
|
|
|
- return this.client.post('mutes/users/create', { user_id: userId })
|
|
|
- .then(res => {
|
|
|
- return res;
|
|
|
- })
|
|
|
- .catch(err => {
|
|
|
- console.log(err);
|
|
|
- });
|
|
|
+ public async muteUser(userId) {
|
|
|
+ return await this.client.post("mutes/users/create", { user_id: userId });
|
|
|
}
|
|
|
-
|
|
|
- public blockUser(userId) {
|
|
|
- return this.client.post('blocks/create', { user_id: userId })
|
|
|
- .then(res => {
|
|
|
- return res;
|
|
|
- })
|
|
|
- .catch(err => {
|
|
|
- console.log(err);
|
|
|
- });
|
|
|
+
|
|
|
+ public async blockUser(userId) {
|
|
|
+ return await this.client.post("blocks/create", { user_id: userId });
|
|
|
}
|
|
|
|
|
|
- public tweet(status) {
|
|
|
- return this.client.post('statuses/update', { status: status})
|
|
|
- .then(res => {
|
|
|
- return res;
|
|
|
- })
|
|
|
- .catch(err => {
|
|
|
- console.log(err);
|
|
|
- });
|
|
|
+ public async tweet(status) {
|
|
|
+ return await this.client.post("statuses/update", { status: status });
|
|
|
}
|
|
|
}
|