mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-20 06:25:07 +00:00
Commit from GitHub Actions (Generate Clients & Examples)
This commit is contained in:
@@ -34,6 +34,7 @@ import (
|
|||||||
"github.com/micro/services/clients/go/rss"
|
"github.com/micro/services/clients/go/rss"
|
||||||
"github.com/micro/services/clients/go/sentiment"
|
"github.com/micro/services/clients/go/sentiment"
|
||||||
"github.com/micro/services/clients/go/sms"
|
"github.com/micro/services/clients/go/sms"
|
||||||
|
"github.com/micro/services/clients/go/spam"
|
||||||
"github.com/micro/services/clients/go/stock"
|
"github.com/micro/services/clients/go/stock"
|
||||||
"github.com/micro/services/clients/go/stream"
|
"github.com/micro/services/clients/go/stream"
|
||||||
"github.com/micro/services/clients/go/sunnah"
|
"github.com/micro/services/clients/go/sunnah"
|
||||||
@@ -84,6 +85,7 @@ func NewClient(token string) *Client {
|
|||||||
RssService: rss.NewRssService(token),
|
RssService: rss.NewRssService(token),
|
||||||
SentimentService: sentiment.NewSentimentService(token),
|
SentimentService: sentiment.NewSentimentService(token),
|
||||||
SmsService: sms.NewSmsService(token),
|
SmsService: sms.NewSmsService(token),
|
||||||
|
SpamService: spam.NewSpamService(token),
|
||||||
StockService: stock.NewStockService(token),
|
StockService: stock.NewStockService(token),
|
||||||
StreamService: stream.NewStreamService(token),
|
StreamService: stream.NewStreamService(token),
|
||||||
SunnahService: sunnah.NewSunnahService(token),
|
SunnahService: sunnah.NewSunnahService(token),
|
||||||
@@ -134,6 +136,7 @@ type Client struct {
|
|||||||
RssService *rss.RssService
|
RssService *rss.RssService
|
||||||
SentimentService *sentiment.SentimentService
|
SentimentService *sentiment.SentimentService
|
||||||
SmsService *sms.SmsService
|
SmsService *sms.SmsService
|
||||||
|
SpamService *spam.SpamService
|
||||||
StockService *stock.StockService
|
StockService *stock.StockService
|
||||||
StreamService *stream.StreamService
|
StreamService *stream.StreamService
|
||||||
SunnahService *sunnah.SunnahService
|
SunnahService *sunnah.SunnahService
|
||||||
|
|||||||
43
clients/go/spam/spam.go
Executable file
43
clients/go/spam/spam.go
Executable file
@@ -0,0 +1,43 @@
|
|||||||
|
package spam
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/micro/micro-go/client"
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewSpamService(token string) *SpamService {
|
||||||
|
return &SpamService{
|
||||||
|
client: client.NewClient(&client.Options{
|
||||||
|
Token: token,
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type SpamService struct {
|
||||||
|
client *client.Client
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check whether an email is likely to be spam based on its attributes
|
||||||
|
func (t *SpamService) Classify(request *ClassifyRequest) (*ClassifyResponse, error) {
|
||||||
|
rsp := &ClassifyResponse{}
|
||||||
|
return rsp, t.client.Call("spam", "Classify", request, rsp)
|
||||||
|
}
|
||||||
|
|
||||||
|
type ClassifyRequest struct {
|
||||||
|
// The body of the email
|
||||||
|
EmailBody string `json:"emailBody"`
|
||||||
|
// The email address it has been sent from
|
||||||
|
From string `json:"from"`
|
||||||
|
// The subject of the email
|
||||||
|
Subject string `json:"subject"`
|
||||||
|
// The email address it is being sent to
|
||||||
|
To string `json:"to"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ClassifyResponse struct {
|
||||||
|
// The rules that have contributed to this score
|
||||||
|
Details []string `json:"details"`
|
||||||
|
// Is it spam? Returns true if its score is > 5
|
||||||
|
IsSpam bool `json:"isSpam"`
|
||||||
|
// The score evaluated for this email. A higher number means it is more likely to be spam
|
||||||
|
Score float64 `json:"score"`
|
||||||
|
}
|
||||||
1
clients/ts/.gitignore
vendored
1
clients/ts/.gitignore
vendored
@@ -46,6 +46,7 @@ routing
|
|||||||
rss
|
rss
|
||||||
sentiment
|
sentiment
|
||||||
sms
|
sms
|
||||||
|
spam
|
||||||
stock
|
stock
|
||||||
stream
|
stream
|
||||||
sunnah
|
sunnah
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import * as routing from "./routing";
|
|||||||
import * as rss from "./rss";
|
import * as rss from "./rss";
|
||||||
import * as sentiment from "./sentiment";
|
import * as sentiment from "./sentiment";
|
||||||
import * as sms from "./sms";
|
import * as sms from "./sms";
|
||||||
|
import * as spam from "./spam";
|
||||||
import * as stock from "./stock";
|
import * as stock from "./stock";
|
||||||
import * as stream from "./stream";
|
import * as stream from "./stream";
|
||||||
import * as sunnah from "./sunnah";
|
import * as sunnah from "./sunnah";
|
||||||
@@ -78,6 +79,7 @@ export class Client {
|
|||||||
this.rssService = new rss.RssService(token);
|
this.rssService = new rss.RssService(token);
|
||||||
this.sentimentService = new sentiment.SentimentService(token);
|
this.sentimentService = new sentiment.SentimentService(token);
|
||||||
this.smsService = new sms.SmsService(token);
|
this.smsService = new sms.SmsService(token);
|
||||||
|
this.spamService = new spam.SpamService(token);
|
||||||
this.stockService = new stock.StockService(token);
|
this.stockService = new stock.StockService(token);
|
||||||
this.streamService = new stream.StreamService(token);
|
this.streamService = new stream.StreamService(token);
|
||||||
this.sunnahService = new sunnah.SunnahService(token);
|
this.sunnahService = new sunnah.SunnahService(token);
|
||||||
@@ -124,6 +126,7 @@ export class Client {
|
|||||||
rssService: rss.RssService;
|
rssService: rss.RssService;
|
||||||
sentimentService: sentiment.SentimentService;
|
sentimentService: sentiment.SentimentService;
|
||||||
smsService: sms.SmsService;
|
smsService: sms.SmsService;
|
||||||
|
spamService: spam.SpamService;
|
||||||
stockService: stock.StockService;
|
stockService: stock.StockService;
|
||||||
streamService: stream.StreamService;
|
streamService: stream.StreamService;
|
||||||
sunnahService: sunnah.SunnahService;
|
sunnahService: sunnah.SunnahService;
|
||||||
|
|||||||
@@ -51,6 +51,7 @@
|
|||||||
"rss",
|
"rss",
|
||||||
"sentiment",
|
"sentiment",
|
||||||
"sms",
|
"sms",
|
||||||
|
"spam",
|
||||||
"stock",
|
"stock",
|
||||||
"stream",
|
"stream",
|
||||||
"sunnah",
|
"sunnah",
|
||||||
@@ -78,5 +79,5 @@
|
|||||||
"prepare": "npm run build"
|
"prepare": "npm run build"
|
||||||
},
|
},
|
||||||
"types": "index.d.ts",
|
"types": "index.d.ts",
|
||||||
"version": "1.0.717"
|
"version": "1.0.734"
|
||||||
}
|
}
|
||||||
@@ -12,10 +12,10 @@ func CreateArecord() {
|
|||||||
dbService := db.NewDbService(os.Getenv("MICRO_API_TOKEN"))
|
dbService := db.NewDbService(os.Getenv("MICRO_API_TOKEN"))
|
||||||
rsp, err := dbService.Create(&db.CreateRequest{
|
rsp, err := dbService.Create(&db.CreateRequest{
|
||||||
Record: map[string]interface{}{
|
Record: map[string]interface{}{
|
||||||
"id": "1",
|
|
||||||
"name": "Jane",
|
"name": "Jane",
|
||||||
"age": 42,
|
"age": 42,
|
||||||
"isActive": true,
|
"isActive": true,
|
||||||
|
"id": "1",
|
||||||
},
|
},
|
||||||
Table: "users",
|
Table: "users",
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ func UpdateArecord() {
|
|||||||
dbService := db.NewDbService(os.Getenv("MICRO_API_TOKEN"))
|
dbService := db.NewDbService(os.Getenv("MICRO_API_TOKEN"))
|
||||||
rsp, err := dbService.Update(&db.UpdateRequest{
|
rsp, err := dbService.Update(&db.UpdateRequest{
|
||||||
Record: map[string]interface{}{
|
Record: map[string]interface{}{
|
||||||
"id": "1",
|
|
||||||
"age": 43,
|
"age": 43,
|
||||||
|
"id": "1",
|
||||||
},
|
},
|
||||||
Table: "users",
|
Table: "users",
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -12,9 +12,9 @@ func PublishAnEvent() {
|
|||||||
eventService := event.NewEventService(os.Getenv("MICRO_API_TOKEN"))
|
eventService := event.NewEventService(os.Getenv("MICRO_API_TOKEN"))
|
||||||
rsp, err := eventService.Publish(&event.PublishRequest{
|
rsp, err := eventService.Publish(&event.PublishRequest{
|
||||||
Message: map[string]interface{}{
|
Message: map[string]interface{}{
|
||||||
"type": "signup",
|
|
||||||
"user": "john",
|
"user": "john",
|
||||||
"id": "1",
|
"id": "1",
|
||||||
|
"type": "signup",
|
||||||
},
|
},
|
||||||
Topic: "user",
|
Topic: "user",
|
||||||
})
|
})
|
||||||
|
|||||||
9
examples/spam/classify/curl/classifyAnEmail.sh
Executable file
9
examples/spam/classify/curl/classifyAnEmail.sh
Executable file
@@ -0,0 +1,9 @@
|
|||||||
|
curl "http://localhost:8080/spam/Classify" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-H "Authorization: Bearer $MICRO_API_TOKEN" \
|
||||||
|
-d '{
|
||||||
|
"email_body": "Hi there,\n\nWelcome to M3O.\n\nThanks\nM3O team",
|
||||||
|
"from": "noreply@m3o.com",
|
||||||
|
"subject": "Welcome",
|
||||||
|
"to": "hello@example.com"
|
||||||
|
}'
|
||||||
19
examples/spam/classify/go/classifyAnEmail.go
Executable file
19
examples/spam/classify/go/classifyAnEmail.go
Executable file
@@ -0,0 +1,19 @@
|
|||||||
|
package example
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/micro/services/clients/go/spam"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Check whether an email is likely to be spam based on its attributes
|
||||||
|
func ClassifyAnEmail() {
|
||||||
|
spamService := spam.NewSpamService(os.Getenv("MICRO_API_TOKEN"))
|
||||||
|
rsp, err := spamService.Classify(&spam.ClassifyRequest{
|
||||||
|
From: "noreply@m3o.com",
|
||||||
|
Subject: "Welcome",
|
||||||
|
To: "hello@example.com",
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
15
examples/spam/classify/node/classifyAnEmail.js
Executable file
15
examples/spam/classify/node/classifyAnEmail.js
Executable file
@@ -0,0 +1,15 @@
|
|||||||
|
const { SpamService } = require("m3o/spam");
|
||||||
|
|
||||||
|
// Check whether an email is likely to be spam based on its attributes
|
||||||
|
async function classifyAnEmail() {
|
||||||
|
let spamService = new SpamService(process.env.MICRO_API_TOKEN);
|
||||||
|
let rsp = await spamService.classify({
|
||||||
|
email_body: "Hi there,\n\nWelcome to M3O.\n\nThanks\nM3O team",
|
||||||
|
from: "noreply@m3o.com",
|
||||||
|
subject: "Welcome",
|
||||||
|
to: "hello@example.com",
|
||||||
|
});
|
||||||
|
console.log(rsp);
|
||||||
|
}
|
||||||
|
|
||||||
|
classifyAnEmail();
|
||||||
Reference in New Issue
Block a user