mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-20 22:45:09 +00:00
Commit from GitHub Actions (Generate Clients & Examples)
This commit is contained in:
53
clients/go/event/event.go
Executable file
53
clients/go/event/event.go
Executable file
@@ -0,0 +1,53 @@
|
|||||||
|
package event
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/m3o/m3o-go/client"
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewEventService(token string) *EventService {
|
||||||
|
return &EventService{
|
||||||
|
client: client.NewClient(&client.Options{
|
||||||
|
Token: token,
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type EventService struct {
|
||||||
|
client *client.Client
|
||||||
|
}
|
||||||
|
|
||||||
|
// Publish a message to the event. Specify a topic to group messages for a specific topic.
|
||||||
|
func (t *EventService) Publish(request *PublishRequest) (*PublishResponse, error) {
|
||||||
|
rsp := &PublishResponse{}
|
||||||
|
return rsp, t.client.Call("event", "Publish", request, rsp)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Subscribe to messages for a given topic.
|
||||||
|
func (t *EventService) Subscribe(request *SubscribeRequest) (*SubscribeResponse, error) {
|
||||||
|
rsp := &SubscribeResponse{}
|
||||||
|
return rsp, t.client.Call("event", "Subscribe", request, rsp)
|
||||||
|
}
|
||||||
|
|
||||||
|
type PublishRequest struct {
|
||||||
|
// The json message to publish
|
||||||
|
Message map[string]interface{} `json:"message"`
|
||||||
|
// The topic to publish to
|
||||||
|
Topic string `json:"topic"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type PublishResponse struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
type SubscribeRequest struct {
|
||||||
|
// Optional group for the subscription
|
||||||
|
Group string `json:"group"`
|
||||||
|
// The topic to subscribe to
|
||||||
|
Topic string `json:"topic"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type SubscribeResponse struct {
|
||||||
|
// The next json message on the topic
|
||||||
|
Message map[string]interface{} `json:"message"`
|
||||||
|
// The topic subscribed to
|
||||||
|
Topic string `json:"topic"`
|
||||||
|
}
|
||||||
@@ -10,6 +10,7 @@ import (
|
|||||||
"github.com/micro/services/clients/go/email"
|
"github.com/micro/services/clients/go/email"
|
||||||
"github.com/micro/services/clients/go/emoji"
|
"github.com/micro/services/clients/go/emoji"
|
||||||
"github.com/micro/services/clients/go/evchargers"
|
"github.com/micro/services/clients/go/evchargers"
|
||||||
|
"github.com/micro/services/clients/go/event"
|
||||||
"github.com/micro/services/clients/go/file"
|
"github.com/micro/services/clients/go/file"
|
||||||
"github.com/micro/services/clients/go/forex"
|
"github.com/micro/services/clients/go/forex"
|
||||||
"github.com/micro/services/clients/go/function"
|
"github.com/micro/services/clients/go/function"
|
||||||
@@ -58,6 +59,7 @@ func NewClient(token string) *Client {
|
|||||||
EmailService: email.NewEmailService(token),
|
EmailService: email.NewEmailService(token),
|
||||||
EmojiService: emoji.NewEmojiService(token),
|
EmojiService: emoji.NewEmojiService(token),
|
||||||
EvchargersService: evchargers.NewEvchargersService(token),
|
EvchargersService: evchargers.NewEvchargersService(token),
|
||||||
|
EventService: event.NewEventService(token),
|
||||||
FileService: file.NewFileService(token),
|
FileService: file.NewFileService(token),
|
||||||
ForexService: forex.NewForexService(token),
|
ForexService: forex.NewForexService(token),
|
||||||
FunctionService: function.NewFunctionService(token),
|
FunctionService: function.NewFunctionService(token),
|
||||||
@@ -106,6 +108,7 @@ type Client struct {
|
|||||||
EmailService *email.EmailService
|
EmailService *email.EmailService
|
||||||
EmojiService *emoji.EmojiService
|
EmojiService *emoji.EmojiService
|
||||||
EvchargersService *evchargers.EvchargersService
|
EvchargersService *evchargers.EvchargersService
|
||||||
|
EventService *event.EventService
|
||||||
FileService *file.FileService
|
FileService *file.FileService
|
||||||
ForexService *forex.ForexService
|
ForexService *forex.ForexService
|
||||||
FunctionService *function.FunctionService
|
FunctionService *function.FunctionService
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ func (t *NotesService) Delete(request *DeleteRequest) (*DeleteResponse, error) {
|
|||||||
return rsp, t.client.Call("notes", "Delete", request, rsp)
|
return rsp, t.client.Call("notes", "Delete", request, rsp)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Specify the note to events
|
// Subscribe to notes events
|
||||||
func (t *NotesService) Events(request *EventsRequest) (*EventsResponse, error) {
|
func (t *NotesService) Events(request *EventsRequest) (*EventsResponse, error) {
|
||||||
rsp := &EventsResponse{}
|
rsp := &EventsResponse{}
|
||||||
return rsp, t.client.Call("notes", "Events", request, rsp)
|
return rsp, t.client.Call("notes", "Events", request, rsp)
|
||||||
|
|||||||
1
clients/ts/.gitignore
vendored
1
clients/ts/.gitignore
vendored
@@ -21,6 +21,7 @@ db
|
|||||||
email
|
email
|
||||||
emoji
|
emoji
|
||||||
evchargers
|
evchargers
|
||||||
|
event
|
||||||
file
|
file
|
||||||
forex
|
forex
|
||||||
function
|
function
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import * as db from "./db";
|
|||||||
import * as email from "./email";
|
import * as email from "./email";
|
||||||
import * as emoji from "./emoji";
|
import * as emoji from "./emoji";
|
||||||
import * as evchargers from "./evchargers";
|
import * as evchargers from "./evchargers";
|
||||||
|
import * as event from "./event";
|
||||||
import * as file from "./file";
|
import * as file from "./file";
|
||||||
import * as forex from "./forex";
|
import * as forex from "./forex";
|
||||||
import * as fx from "./function";
|
import * as fx from "./function";
|
||||||
@@ -52,6 +53,7 @@ export class Client {
|
|||||||
this.emailService = new email.EmailService(token);
|
this.emailService = new email.EmailService(token);
|
||||||
this.emojiService = new emoji.EmojiService(token);
|
this.emojiService = new emoji.EmojiService(token);
|
||||||
this.evchargersService = new evchargers.EvchargersService(token);
|
this.evchargersService = new evchargers.EvchargersService(token);
|
||||||
|
this.eventService = new event.EventService(token);
|
||||||
this.fileService = new file.FileService(token);
|
this.fileService = new file.FileService(token);
|
||||||
this.forexService = new forex.ForexService(token);
|
this.forexService = new forex.ForexService(token);
|
||||||
this.functionService = new fx.FunctionService(token);
|
this.functionService = new fx.FunctionService(token);
|
||||||
@@ -96,6 +98,7 @@ export class Client {
|
|||||||
emailService: email.EmailService;
|
emailService: email.EmailService;
|
||||||
emojiService: emoji.EmojiService;
|
emojiService: emoji.EmojiService;
|
||||||
evchargersService: evchargers.EvchargersService;
|
evchargersService: evchargers.EvchargersService;
|
||||||
|
eventService: event.EventService;
|
||||||
fileService: file.FileService;
|
fileService: file.FileService;
|
||||||
forexService: forex.ForexService;
|
forexService: forex.ForexService;
|
||||||
functionService: fx.FunctionService;
|
functionService: fx.FunctionService;
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
"email",
|
"email",
|
||||||
"emoji",
|
"emoji",
|
||||||
"evchargers",
|
"evchargers",
|
||||||
|
"event",
|
||||||
"file",
|
"file",
|
||||||
"forex",
|
"forex",
|
||||||
"function",
|
"function",
|
||||||
@@ -76,5 +77,5 @@
|
|||||||
"prepare": "npm run build"
|
"prepare": "npm run build"
|
||||||
},
|
},
|
||||||
"types": "index.d.ts",
|
"types": "index.d.ts",
|
||||||
"version": "1.0.597"
|
"version": "1.0.599"
|
||||||
}
|
}
|
||||||
@@ -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",
|
||||||
})
|
})
|
||||||
|
|||||||
11
examples/event/publish/curl/publishAMessage.sh
Executable file
11
examples/event/publish/curl/publishAMessage.sh
Executable file
@@ -0,0 +1,11 @@
|
|||||||
|
curl "https://api.m3o.com/v1/event/Publish" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-H "Authorization: Bearer $MICRO_API_TOKEN" \
|
||||||
|
-d '{
|
||||||
|
"message": {
|
||||||
|
"id": "1",
|
||||||
|
"type": "signup",
|
||||||
|
"user": "john"
|
||||||
|
},
|
||||||
|
"topic": "user"
|
||||||
|
}'
|
||||||
22
examples/event/publish/go/publishAMessage.go
Executable file
22
examples/event/publish/go/publishAMessage.go
Executable file
@@ -0,0 +1,22 @@
|
|||||||
|
package example
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/micro/services/clients/go/event"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Publish a message to the event. Specify a topic to group messages for a specific topic.
|
||||||
|
func PublishAmessage() {
|
||||||
|
eventService := event.NewEventService(os.Getenv("MICRO_API_TOKEN"))
|
||||||
|
rsp, err := eventService.Publish(&event.PublishRequest{
|
||||||
|
Message: map[string]interface{}{
|
||||||
|
"id": "1",
|
||||||
|
"type": "signup",
|
||||||
|
"user": "john",
|
||||||
|
},
|
||||||
|
Topic: "user",
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
17
examples/event/publish/node/publishAMessage.js
Executable file
17
examples/event/publish/node/publishAMessage.js
Executable file
@@ -0,0 +1,17 @@
|
|||||||
|
const { EventService } = require("m3o/event");
|
||||||
|
|
||||||
|
// Publish a message to the event. Specify a topic to group messages for a specific topic.
|
||||||
|
async function publishAmessage() {
|
||||||
|
let eventService = new EventService(process.env.MICRO_API_TOKEN);
|
||||||
|
let rsp = await eventService.publish({
|
||||||
|
message: {
|
||||||
|
id: "1",
|
||||||
|
type: "signup",
|
||||||
|
user: "john",
|
||||||
|
},
|
||||||
|
topic: "user",
|
||||||
|
});
|
||||||
|
console.log(rsp);
|
||||||
|
}
|
||||||
|
|
||||||
|
publishAmessage();
|
||||||
6
examples/event/subscribe/curl/subscribeToATopic.sh
Executable file
6
examples/event/subscribe/curl/subscribeToATopic.sh
Executable file
@@ -0,0 +1,6 @@
|
|||||||
|
curl "https://api.m3o.com/v1/event/Subscribe" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-H "Authorization: Bearer $MICRO_API_TOKEN" \
|
||||||
|
-d '{
|
||||||
|
"topic": "user"
|
||||||
|
}'
|
||||||
17
examples/event/subscribe/go/subscribeToATopic.go
Executable file
17
examples/event/subscribe/go/subscribeToATopic.go
Executable file
@@ -0,0 +1,17 @@
|
|||||||
|
package example
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/micro/services/clients/go/event"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Subscribe to messages for a given topic.
|
||||||
|
func SubscribeToAtopic() {
|
||||||
|
eventService := event.NewEventService(os.Getenv("MICRO_API_TOKEN"))
|
||||||
|
rsp, err := eventService.Subscribe(&event.SubscribeRequest{
|
||||||
|
Topic: "user",
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
12
examples/event/subscribe/node/subscribeToATopic.js
Executable file
12
examples/event/subscribe/node/subscribeToATopic.js
Executable file
@@ -0,0 +1,12 @@
|
|||||||
|
const { EventService } = require("m3o/event");
|
||||||
|
|
||||||
|
// Subscribe to messages for a given topic.
|
||||||
|
async function subscribeToAtopic() {
|
||||||
|
let eventService = new EventService(process.env.MICRO_API_TOKEN);
|
||||||
|
let rsp = await eventService.subscribe({
|
||||||
|
topic: "user",
|
||||||
|
});
|
||||||
|
console.log(rsp);
|
||||||
|
}
|
||||||
|
|
||||||
|
subscribeToAtopic();
|
||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
"github.com/micro/services/clients/go/notes"
|
"github.com/micro/services/clients/go/notes"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Specify the note to events
|
// Subscribe to notes events
|
||||||
func SubscribeToEvents() {
|
func SubscribeToEvents() {
|
||||||
notesService := notes.NewNotesService(os.Getenv("MICRO_API_TOKEN"))
|
notesService := notes.NewNotesService(os.Getenv("MICRO_API_TOKEN"))
|
||||||
rsp, err := notesService.Events(¬es.EventsRequest{
|
rsp, err := notesService.Events(¬es.EventsRequest{
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
const { NotesService } = require("m3o/notes");
|
const { NotesService } = require("m3o/notes");
|
||||||
|
|
||||||
// Specify the note to events
|
// Subscribe to notes events
|
||||||
async function subscribeToEvents() {
|
async function subscribeToEvents() {
|
||||||
let notesService = new NotesService(process.env.MICRO_API_TOKEN);
|
let notesService = new NotesService(process.env.MICRO_API_TOKEN);
|
||||||
let rsp = await notesService.events({
|
let rsp = await notesService.events({
|
||||||
|
|||||||
Reference in New Issue
Block a user