Commit from GitHub Actions (Publish APIs & Clients)

This commit is contained in:
crufter
2021-09-16 11:56:07 +00:00
parent d4d9c1c176
commit 83ae3b6f39
12 changed files with 313 additions and 6 deletions

View File

@@ -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

View File

@@ -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

132
clients/go/twitter/twitter.go Executable file
View File

@@ -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"`
}

View File

@@ -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;

View File

@@ -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"

View File

@@ -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)

131
clients/ts/twitter/index.ts Executable file
View File

@@ -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<SearchResponse> {
return this.client.call(
"twitter",
"Search",
request
) as Promise<SearchResponse>;
}
// Get the timeline for a given user
timeline(request: TimelineRequest): Promise<TimelineResponse> {
return this.client.call(
"twitter",
"Timeline",
request
) as Promise<TimelineResponse>;
}
// Get the current global trending topics
trends(request: TrendsRequest): Promise<TrendsResponse> {
return this.client.call(
"twitter",
"Trends",
request
) as Promise<TrendsResponse>;
}
// Get a user's twitter profile
user(request: UserRequest): Promise<UserResponse> {
return this.client.call(
"twitter",
"User",
request
) as Promise<UserResponse>;
}
}
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;
}

View File

@@ -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",
})

View File

@@ -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",
})

View File

@@ -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"
}'

View File

@@ -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)
}

View File

@@ -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();