Skip to content

Instantly share code, notes, and snippets.

@hamedbaatour
Created August 6, 2019 09:27
Show Gist options
  • Save hamedbaatour/e3188872575eeece4d74cef78acbfd06 to your computer and use it in GitHub Desktop.
Save hamedbaatour/e3188872575eeece4d74cef78acbfd06 to your computer and use it in GitHub Desktop.
import {Injectable} from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {filter, first, map} from 'rxjs/operators';
@Injectable({
providedIn: 'root'
})
export class TwitterService {
constructor(public http: HttpClient) {
}
fetchTweets(city) {
return this.http.post('https://336e847e.ngrok.io/minimus-weather/us-central1/tweets', {
data: {q: `${city} Weather`}
}).pipe(
first(),
map((res: any) => res && res.result ? res.result.statuses : []),
filter((tweets: any) => tweets.map(tweet => tweet.text && tweet.text.match(/weather/g))),
map((tweets: any) => tweets.map(tweet => ({
text: tweet.text,
date: tweet.created_at,
user: {
name: tweet.user.name,
photo: tweet.user.profile_image_url_https,
handle: tweet.user.screen_name
}
}))),
map((tweets: any) => tweets.slice(0, 4)));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment