From 83ae3b6f39bdb527dcc5ae7c1c3f5a328bf2943e Mon Sep 17 00:00:00 2001 From: crufter Date: Thu, 16 Sep 2021 11:56:07 +0000 Subject: [PATCH] Commit from GitHub Actions (Publish APIs & Clients) --- clients/go/m3o.go | 3 + clients/go/quran/quran.go | 2 +- clients/go/twitter/twitter.go | 132 ++++++++++++++++++ clients/ts/index.ts | 3 + clients/ts/package.json | 1 + clients/ts/quran/index.ts | 4 +- clients/ts/twitter/index.ts | 131 +++++++++++++++++ examples/db/create/go/createARecord.go | 4 +- examples/db/update/go/updateARecord.go | 2 +- .../timeline/curl/getATwitterTimeline.sh | 7 + .../timeline/go/getATwitterTimeline.go | 17 +++ .../timeline/node/getATwitterTimeline.js | 13 ++ 12 files changed, 313 insertions(+), 6 deletions(-) create mode 100755 clients/go/twitter/twitter.go create mode 100755 clients/ts/twitter/index.ts create mode 100755 examples/twitter/timeline/curl/getATwitterTimeline.sh create mode 100755 examples/twitter/timeline/go/getATwitterTimeline.go create mode 100755 examples/twitter/timeline/node/getATwitterTimeline.js diff --git a/clients/go/m3o.go b/clients/go/m3o.go index f1be388..c4fb7eb 100755 --- a/clients/go/m3o.go +++ b/clients/go/m3o.go @@ -28,6 +28,7 @@ import ( "github.com/micro/services/clients/go/stream" "github.com/micro/services/clients/go/thumbnail" "github.com/micro/services/clients/go/time" + "github.com/micro/services/clients/go/twitter" "github.com/micro/services/clients/go/url" "github.com/micro/services/clients/go/user" "github.com/micro/services/clients/go/weather" @@ -64,6 +65,7 @@ func NewClient(token string) *Client { StreamService: stream.NewStreamService(token), ThumbnailService: thumbnail.NewThumbnailService(token), TimeService: time.NewTimeService(token), + TwitterService: twitter.NewTwitterService(token), UrlService: url.NewUrlService(token), UserService: user.NewUserService(token), WeatherService: weather.NewWeatherService(token), @@ -100,6 +102,7 @@ type Client struct { StreamService *stream.StreamService ThumbnailService *thumbnail.ThumbnailService TimeService *time.TimeService + TwitterService *twitter.TwitterService UrlService *url.UrlService UserService *user.UserService WeatherService *weather.WeatherService diff --git a/clients/go/quran/quran.go b/clients/go/quran/quran.go index fbe5f5b..0d98d92 100755 --- a/clients/go/quran/quran.go +++ b/clients/go/quran/quran.go @@ -85,7 +85,7 @@ type Result struct { // The associated arabic text Text string `json:"text"` // The related translations to the text - Translations []Translation `json:"translations"` + Translations []Interpretation `json:"translations"` // The unique verse id across the Quran VerseId int32 `json:"verseId"` // The verse key e.g 1:1 diff --git a/clients/go/twitter/twitter.go b/clients/go/twitter/twitter.go new file mode 100755 index 0000000..358ecef --- /dev/null +++ b/clients/go/twitter/twitter.go @@ -0,0 +1,132 @@ +package twitter + +import ( + "github.com/m3o/m3o-go/client" +) + +func NewTwitterService(token string) *TwitterService { + return &TwitterService{ + client: client.NewClient(&client.Options{ + Token: token, + }), + } +} + +type TwitterService struct { + client *client.Client +} + +// Search for tweets with a simple query +func (t *TwitterService) Search(request *SearchRequest) (*SearchResponse, error) { + rsp := &SearchResponse{} + return rsp, t.client.Call("twitter", "Search", request, rsp) +} + +// Get the timeline for a given user +func (t *TwitterService) Timeline(request *TimelineRequest) (*TimelineResponse, error) { + rsp := &TimelineResponse{} + return rsp, t.client.Call("twitter", "Timeline", request, rsp) +} + +// Get the current global trending topics +func (t *TwitterService) Trends(request *TrendsRequest) (*TrendsResponse, error) { + rsp := &TrendsResponse{} + return rsp, t.client.Call("twitter", "Trends", request, rsp) +} + +// Get a user's twitter profile +func (t *TwitterService) User(request *UserRequest) (*UserResponse, error) { + rsp := &UserResponse{} + return rsp, t.client.Call("twitter", "User", request, rsp) +} + +type Profile struct { + // the account creation date + CreatedAt string `json:"createdAt"` + // the user description + Description string `json:"description"` + // the follower count + Followers int64 `json:"followers"` + // the user id + Id int64 `json:"id"` + // The user's profile picture + ImageUrl string `json:"imageUrl"` + // the user's location + Location string `json:"location"` + // display name of the user + Name string `json:"name"` + // if the account is private + Private bool `json:"private"` + // the username + Username string `json:"username"` + // if the account is verified + Verified bool `json:"verified"` +} + +type SearchRequest struct { + // number of tweets to return. default: 20 + Limit int32 `json:"limit"` + // the query to search for + Query string `json:"query"` +} + +type SearchResponse struct { + // the related tweets for the search + Tweets []Tweet `json:"tweets"` +} + +type TimelineRequest struct { + // number of tweets to return. default: 20 + Limit int32 `json:"limit"` + // the username to request the timeline for + Username string `json:"username"` +} + +type TimelineResponse struct { + // The recent tweets for the user + Tweets []Tweet `json:"tweets"` +} + +type Trend struct { + // name of the trend + Name string `json:"name"` + // the volume of tweets in last 24 hours + TweetVolume int64 `json:"tweetVolume"` + // the twitter url + Url string `json:"url"` +} + +type TrendsRequest struct { +} + +type TrendsResponse struct { + // a list of trending topics + Trends []Trend `json:"trends"` +} + +type Tweet struct { + // time of tweet + CreatedAt string `json:"createdAt"` + // number of times favourited + FavouritedCount int64 `json:"favouritedCount"` + // id of the tweet + Id int64 `json:"id"` + // number of times retweeted + RetweetedCount int64 `json:"retweetedCount"` + // text of the tweet + Text string `json:"text"` + // username of the person who tweeted + Username string `json:"username"` +} + +type UserRequest struct { + // the username to lookup + Username string `json:"username"` +} + +type UserResponse struct { + // The requested user profile + Profile *Profile `json:"profile"` + // the current user status + Status *Tweet `json:"status"` +} diff --git a/clients/ts/index.ts b/clients/ts/index.ts index b2439ee..61961ae 100755 --- a/clients/ts/index.ts +++ b/clients/ts/index.ts @@ -25,6 +25,7 @@ import * as stock from "./stock"; import * as stream from "./stream"; import * as thumbnail from "./thumbnail"; import * as time from "./time"; +import * as twitter from "./twitter"; import * as url from "./url"; import * as user from "./user"; import * as weather from "./weather"; @@ -58,6 +59,7 @@ export class Client { this.streamService = new stream.StreamService(token); this.thumbnailService = new thumbnail.ThumbnailService(token); this.timeService = new time.TimeService(token); + this.twitterService = new twitter.TwitterService(token); this.urlService = new url.UrlService(token); this.userService = new user.UserService(token); this.weatherService = new weather.WeatherService(token); @@ -90,6 +92,7 @@ export class Client { streamService: stream.StreamService; thumbnailService: thumbnail.ThumbnailService; timeService: time.TimeService; + twitterService: twitter.TwitterService; urlService: url.UrlService; userService: user.UserService; weatherService: weather.WeatherService; diff --git a/clients/ts/package.json b/clients/ts/package.json index 60809a7..c677174 100644 --- a/clients/ts/package.json +++ b/clients/ts/package.json @@ -38,6 +38,7 @@ "./test": "./dist/test/index.js", "./thumbnail": "./dist/thumbnail/index.js", "./time": "./dist/time/index.js", + "./twitter": "./dist/twitter/index.js", "./url": "./dist/url/index.js", "./user": "./dist/user/index.js", "./weather": "./dist/weather/index.js" diff --git a/clients/ts/quran/index.ts b/clients/ts/quran/index.ts index 969f465..af9b993 100755 --- a/clients/ts/quran/index.ts +++ b/clients/ts/quran/index.ts @@ -85,7 +85,7 @@ export interface Result { // The associated arabic text text?: string; // The related translations to the text - translations?: Interpretation[]; + translations?: Translation[]; // The unique verse id across the Quran verseId?: number; // The verse key e.g 1:1 @@ -159,7 +159,7 @@ export interface Verse { // The basic translation of the verse translatedText?: string; // The alternative translations for the verse - translations?: Translation[]; + translations?: Interpretation[]; // The phonetic transliteration from arabic transliteration?: string; // The individual words within the verse (Ayah) diff --git a/clients/ts/twitter/index.ts b/clients/ts/twitter/index.ts new file mode 100755 index 0000000..f03c34b --- /dev/null +++ b/clients/ts/twitter/index.ts @@ -0,0 +1,131 @@ +import * as m3o from "@m3o/m3o-node"; + +export class TwitterService { + private client: m3o.Client; + + constructor(token: string) { + this.client = new m3o.Client({ token: token }); + } + // Search for tweets with a simple query + search(request: SearchRequest): Promise { + return this.client.call( + "twitter", + "Search", + request + ) as Promise; + } + // Get the timeline for a given user + timeline(request: TimelineRequest): Promise { + return this.client.call( + "twitter", + "Timeline", + request + ) as Promise; + } + // Get the current global trending topics + trends(request: TrendsRequest): Promise { + return this.client.call( + "twitter", + "Trends", + request + ) as Promise; + } + // Get a user's twitter profile + user(request: UserRequest): Promise { + return this.client.call( + "twitter", + "User", + request + ) as Promise; + } +} + +export interface Profile { + // the account creation date + createdAt?: string; + // the user description + description?: string; + // the follower count + followers?: number; + // the user id + id?: number; + // The user's profile picture + imageUrl?: string; + // the user's location + location?: string; + // display name of the user + name?: string; + // if the account is private + private?: boolean; + // the username + username?: string; + // if the account is verified + verified?: boolean; +} + +export interface SearchRequest { + // number of tweets to return. default: 20 + limit?: number; + // the query to search for + query?: string; +} + +export interface SearchResponse { + // the related tweets for the search + tweets?: Tweet[]; +} + +export interface TimelineRequest { + // number of tweets to return. default: 20 + limit?: number; + // the username to request the timeline for + username?: string; +} + +export interface TimelineResponse { + // The recent tweets for the user + tweets?: Tweet[]; +} + +export interface Trend { + // name of the trend + name?: string; + // the volume of tweets in last 24 hours + tweetVolume?: number; + // the twitter url + url?: string; +} + +export interface TrendsRequest {} + +export interface TrendsResponse { + // a list of trending topics + trends?: Trend[]; +} + +export interface Tweet { + // time of tweet + createdAt?: string; + // number of times favourited + favouritedCount?: number; + // id of the tweet + id?: number; + // number of times retweeted + retweetedCount?: number; + // text of the tweet + text?: string; + // username of the person who tweeted + username?: string; +} + +export interface UserRequest { + // the username to lookup + username?: string; +} + +export interface UserResponse { + // The requested user profile + profile?: { [key: string]: any }; + // the current user status + status?: Tweet; +} diff --git a/examples/db/create/go/createARecord.go b/examples/db/create/go/createARecord.go index c57135b..ed2b1c4 100755 --- a/examples/db/create/go/createARecord.go +++ b/examples/db/create/go/createARecord.go @@ -11,10 +11,10 @@ func CreateArecord() { dbService := db.NewDbService(os.Getenv("MICRO_API_TOKEN")) rsp, err := dbService.Create(&db.CreateRequest{ Record: map[string]interface{}{ - "age": 42, - "isActive": true, "id": "1", "name": "Jane", + "age": 42, + "isActive": true, }, Table: "users", }) diff --git a/examples/db/update/go/updateARecord.go b/examples/db/update/go/updateARecord.go index 4c7b7e9..d1cad90 100755 --- a/examples/db/update/go/updateARecord.go +++ b/examples/db/update/go/updateARecord.go @@ -11,8 +11,8 @@ func UpdateArecord() { dbService := db.NewDbService(os.Getenv("MICRO_API_TOKEN")) rsp, err := dbService.Update(&db.UpdateRequest{ Record: map[string]interface{}{ - "age": 43, "id": "1", + "age": 43, }, Table: "users", }) diff --git a/examples/twitter/timeline/curl/getATwitterTimeline.sh b/examples/twitter/timeline/curl/getATwitterTimeline.sh new file mode 100755 index 0000000..df97c16 --- /dev/null +++ b/examples/twitter/timeline/curl/getATwitterTimeline.sh @@ -0,0 +1,7 @@ +curl "https://api.m3o.com/v1/twitter/Timeline" \ +-H "Content-Type: application/json" \ +-H "Authorization: Bearer $MICRO_API_TOKEN" \ +-d '{ + "limit": 1, + "username": "m3oservices" +}' \ No newline at end of file diff --git a/examples/twitter/timeline/go/getATwitterTimeline.go b/examples/twitter/timeline/go/getATwitterTimeline.go new file mode 100755 index 0000000..72ecdef --- /dev/null +++ b/examples/twitter/timeline/go/getATwitterTimeline.go @@ -0,0 +1,17 @@ +package example + +import ( + "fmt" + "github.com/micro/services/clients/go/twitter" + "os" +) + +// Get the timeline for a given user +func GetAtwitterTimeline() { + twitterService := twitter.NewTwitterService(os.Getenv("MICRO_API_TOKEN")) + rsp, err := twitterService.Timeline(&twitter.TimelineRequest{ + Limit: 1, + Username: "m3oservices", + }) + fmt.Println(rsp, err) +} diff --git a/examples/twitter/timeline/node/getATwitterTimeline.js b/examples/twitter/timeline/node/getATwitterTimeline.js new file mode 100755 index 0000000..e8aa0c0 --- /dev/null +++ b/examples/twitter/timeline/node/getATwitterTimeline.js @@ -0,0 +1,13 @@ +import * as twitter from "m3o/twitter"; + +// Get the timeline for a given user +async function GetAtwitterTimeline() { + let twitterService = new twitter.TwitterService(process.env.MICRO_API_TOKEN); + let rsp = await twitterService.timeline({ + limit: 1, + username: "m3oservices", + }); + console.log(rsp); +} + +await GetAtwitterTimeline();