mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-19 14:05:23 +00:00
Generate clients (#206)
This commit is contained in:
9
examples/user/create/curl/createAnAccount.sh
Executable file
9
examples/user/create/curl/createAnAccount.sh
Executable file
@@ -0,0 +1,9 @@
|
||||
curl "https://api.m3o.com/v1/user/Create" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $MICRO_API_TOKEN" \
|
||||
-d '{
|
||||
"email": "joe@example.com",
|
||||
"id": "usrid-1",
|
||||
"password": "mySecretPass123",
|
||||
"username": "usrname-1"
|
||||
}'
|
||||
19
examples/user/create/go/createAnAccount.go
Executable file
19
examples/user/create/go/createAnAccount.go
Executable file
@@ -0,0 +1,19 @@
|
||||
package example
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/micro/services/clients/go/user"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Create a new user account. The email address and username for the account must be unique.
|
||||
func CreateAnAccount() {
|
||||
userService := user.NewUserService(os.Getenv("MICRO_API_TOKEN"))
|
||||
rsp, err := userService.Create(&user.CreateRequest{
|
||||
Email: "joe@example.com",
|
||||
Id: "usrid-1",
|
||||
Password: "mySecretPass123",
|
||||
Username: "usrname-1",
|
||||
})
|
||||
fmt.Println(rsp, err)
|
||||
}
|
||||
15
examples/user/create/node/createAnAccount.js
Executable file
15
examples/user/create/node/createAnAccount.js
Executable file
@@ -0,0 +1,15 @@
|
||||
import * as user from "m3o/user";
|
||||
|
||||
// Create a new user account. The email address and username for the account must be unique.
|
||||
async function CreateAnAccount() {
|
||||
let userService = new user.UserService(process.env.MICRO_API_TOKEN);
|
||||
let rsp = await userService.create({
|
||||
email: "joe@example.com",
|
||||
id: "usrid-1",
|
||||
password: "mySecretPass123",
|
||||
username: "usrname-1",
|
||||
});
|
||||
console.log(rsp);
|
||||
}
|
||||
|
||||
await CreateAnAccount();
|
||||
6
examples/user/delete/curl/deleteUserAccount.sh
Executable file
6
examples/user/delete/curl/deleteUserAccount.sh
Executable file
@@ -0,0 +1,6 @@
|
||||
curl "https://api.m3o.com/v1/user/Delete" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $MICRO_API_TOKEN" \
|
||||
-d '{
|
||||
"id": "fdf34f34f34-f34f34-f43f43f34-f4f34f"
|
||||
}'
|
||||
16
examples/user/delete/go/deleteUserAccount.go
Executable file
16
examples/user/delete/go/deleteUserAccount.go
Executable file
@@ -0,0 +1,16 @@
|
||||
package example
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/micro/services/clients/go/user"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Delete an account by id
|
||||
func DeleteUserAccount() {
|
||||
userService := user.NewUserService(os.Getenv("MICRO_API_TOKEN"))
|
||||
rsp, err := userService.Delete(&user.DeleteRequest{
|
||||
Id: "fdf34f34f34-f34f34-f43f43f34-f4f34f",
|
||||
})
|
||||
fmt.Println(rsp, err)
|
||||
}
|
||||
12
examples/user/delete/node/deleteUserAccount.js
Executable file
12
examples/user/delete/node/deleteUserAccount.js
Executable file
@@ -0,0 +1,12 @@
|
||||
import * as user from "m3o/user";
|
||||
|
||||
// Delete an account by id
|
||||
async function DeleteUserAccount() {
|
||||
let userService = new user.UserService(process.env.MICRO_API_TOKEN);
|
||||
let rsp = await userService.delete({
|
||||
id: "fdf34f34f34-f34f34-f43f43f34-f4f34f",
|
||||
});
|
||||
console.log(rsp);
|
||||
}
|
||||
|
||||
await DeleteUserAccount();
|
||||
7
examples/user/login/curl/logAUserIn.sh
Executable file
7
examples/user/login/curl/logAUserIn.sh
Executable file
@@ -0,0 +1,7 @@
|
||||
curl "https://api.m3o.com/v1/user/Login" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $MICRO_API_TOKEN" \
|
||||
-d '{
|
||||
"email": "joe@example.com",
|
||||
"password": "mySecretPass123"
|
||||
}'
|
||||
18
examples/user/login/go/logAUserIn.go
Executable file
18
examples/user/login/go/logAUserIn.go
Executable file
@@ -0,0 +1,18 @@
|
||||
package example
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/micro/services/clients/go/user"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Login using username or email. The response will return a new session for successful login,
|
||||
// 401 in the case of login failure and 500 for any other error
|
||||
func LogAuserIn() {
|
||||
userService := user.NewUserService(os.Getenv("MICRO_API_TOKEN"))
|
||||
rsp, err := userService.Login(&user.LoginRequest{
|
||||
Email: "joe@example.com",
|
||||
Password: "mySecretPass123",
|
||||
})
|
||||
fmt.Println(rsp, err)
|
||||
}
|
||||
14
examples/user/login/node/logAUserIn.js
Executable file
14
examples/user/login/node/logAUserIn.js
Executable file
@@ -0,0 +1,14 @@
|
||||
import * as user from "m3o/user";
|
||||
|
||||
// Login using username or email. The response will return a new session for successful login,
|
||||
// 401 in the case of login failure and 500 for any other error
|
||||
async function LogAuserIn() {
|
||||
let userService = new user.UserService(process.env.MICRO_API_TOKEN);
|
||||
let rsp = await userService.login({
|
||||
email: "joe@example.com",
|
||||
password: "mySecretPass123",
|
||||
});
|
||||
console.log(rsp);
|
||||
}
|
||||
|
||||
await LogAuserIn();
|
||||
6
examples/user/logout/curl/logAUserOut.sh
Executable file
6
examples/user/logout/curl/logAUserOut.sh
Executable file
@@ -0,0 +1,6 @@
|
||||
curl "https://api.m3o.com/v1/user/Logout" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $MICRO_API_TOKEN" \
|
||||
-d '{
|
||||
"sessionId": "sds34s34s34-s34s34-s43s43s34-s4s34s"
|
||||
}'
|
||||
16
examples/user/logout/go/logAUserOut.go
Executable file
16
examples/user/logout/go/logAUserOut.go
Executable file
@@ -0,0 +1,16 @@
|
||||
package example
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/micro/services/clients/go/user"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Logout a user account
|
||||
func LogAuserOut() {
|
||||
userService := user.NewUserService(os.Getenv("MICRO_API_TOKEN"))
|
||||
rsp, err := userService.Logout(&user.LogoutRequest{
|
||||
SessionId: "sds34s34s34-s34s34-s43s43s34-s4s34s",
|
||||
})
|
||||
fmt.Println(rsp, err)
|
||||
}
|
||||
12
examples/user/logout/node/logAUserOut.js
Executable file
12
examples/user/logout/node/logAUserOut.js
Executable file
@@ -0,0 +1,12 @@
|
||||
import * as user from "m3o/user";
|
||||
|
||||
// Logout a user account
|
||||
async function LogAuserOut() {
|
||||
let userService = new user.UserService(process.env.MICRO_API_TOKEN);
|
||||
let rsp = await userService.logout({
|
||||
sessionId: "sds34s34s34-s34s34-s43s43s34-s4s34s",
|
||||
});
|
||||
console.log(rsp);
|
||||
}
|
||||
|
||||
await LogAuserOut();
|
||||
6
examples/user/read/curl/readAccountByEmail.sh
Executable file
6
examples/user/read/curl/readAccountByEmail.sh
Executable file
@@ -0,0 +1,6 @@
|
||||
curl "https://api.m3o.com/v1/user/Read" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $MICRO_API_TOKEN" \
|
||||
-d '{
|
||||
"email": "joe@example.com"
|
||||
}'
|
||||
6
examples/user/read/curl/readAccountByUsernameOrEmail.sh
Executable file
6
examples/user/read/curl/readAccountByUsernameOrEmail.sh
Executable file
@@ -0,0 +1,6 @@
|
||||
curl "https://api.m3o.com/v1/user/Read" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $MICRO_API_TOKEN" \
|
||||
-d '{
|
||||
"username": "usrname-1"
|
||||
}'
|
||||
6
examples/user/read/curl/readAnAccountById.sh
Executable file
6
examples/user/read/curl/readAnAccountById.sh
Executable file
@@ -0,0 +1,6 @@
|
||||
curl "https://api.m3o.com/v1/user/Read" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $MICRO_API_TOKEN" \
|
||||
-d '{
|
||||
"id": "usrid-1"
|
||||
}'
|
||||
16
examples/user/read/go/readAccountByEmail.go
Executable file
16
examples/user/read/go/readAccountByEmail.go
Executable file
@@ -0,0 +1,16 @@
|
||||
package example
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/micro/services/clients/go/user"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Read an account by id, username or email. Only one need to be specified.
|
||||
func ReadAccountByEmail() {
|
||||
userService := user.NewUserService(os.Getenv("MICRO_API_TOKEN"))
|
||||
rsp, err := userService.Read(&user.ReadRequest{
|
||||
Email: "joe@example.com",
|
||||
})
|
||||
fmt.Println(rsp, err)
|
||||
}
|
||||
16
examples/user/read/go/readAccountByUsernameOrEmail.go
Executable file
16
examples/user/read/go/readAccountByUsernameOrEmail.go
Executable file
@@ -0,0 +1,16 @@
|
||||
package example
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/micro/services/clients/go/user"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Read an account by id, username or email. Only one need to be specified.
|
||||
func ReadAccountByUsernameOrEmail() {
|
||||
userService := user.NewUserService(os.Getenv("MICRO_API_TOKEN"))
|
||||
rsp, err := userService.Read(&user.ReadRequest{
|
||||
Username: "usrname-1",
|
||||
})
|
||||
fmt.Println(rsp, err)
|
||||
}
|
||||
16
examples/user/read/go/readAnAccountById.go
Executable file
16
examples/user/read/go/readAnAccountById.go
Executable file
@@ -0,0 +1,16 @@
|
||||
package example
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/micro/services/clients/go/user"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Read an account by id, username or email. Only one need to be specified.
|
||||
func ReadAnAccountById() {
|
||||
userService := user.NewUserService(os.Getenv("MICRO_API_TOKEN"))
|
||||
rsp, err := userService.Read(&user.ReadRequest{
|
||||
Id: "usrid-1",
|
||||
})
|
||||
fmt.Println(rsp, err)
|
||||
}
|
||||
12
examples/user/read/node/readAccountByEmail.js
Executable file
12
examples/user/read/node/readAccountByEmail.js
Executable file
@@ -0,0 +1,12 @@
|
||||
import * as user from "m3o/user";
|
||||
|
||||
// Read an account by id, username or email. Only one need to be specified.
|
||||
async function ReadAccountByEmail() {
|
||||
let userService = new user.UserService(process.env.MICRO_API_TOKEN);
|
||||
let rsp = await userService.read({
|
||||
email: "joe@example.com",
|
||||
});
|
||||
console.log(rsp);
|
||||
}
|
||||
|
||||
await ReadAccountByEmail();
|
||||
12
examples/user/read/node/readAccountByUsernameOrEmail.js
Executable file
12
examples/user/read/node/readAccountByUsernameOrEmail.js
Executable file
@@ -0,0 +1,12 @@
|
||||
import * as user from "m3o/user";
|
||||
|
||||
// Read an account by id, username or email. Only one need to be specified.
|
||||
async function ReadAccountByUsernameOrEmail() {
|
||||
let userService = new user.UserService(process.env.MICRO_API_TOKEN);
|
||||
let rsp = await userService.read({
|
||||
username: "usrname-1",
|
||||
});
|
||||
console.log(rsp);
|
||||
}
|
||||
|
||||
await ReadAccountByUsernameOrEmail();
|
||||
12
examples/user/read/node/readAnAccountById.js
Executable file
12
examples/user/read/node/readAnAccountById.js
Executable file
@@ -0,0 +1,12 @@
|
||||
import * as user from "m3o/user";
|
||||
|
||||
// Read an account by id, username or email. Only one need to be specified.
|
||||
async function ReadAnAccountById() {
|
||||
let userService = new user.UserService(process.env.MICRO_API_TOKEN);
|
||||
let rsp = await userService.read({
|
||||
id: "usrid-1",
|
||||
});
|
||||
console.log(rsp);
|
||||
}
|
||||
|
||||
await ReadAnAccountById();
|
||||
11
examples/user/sendVerificationEmail/curl/sendVerificationEmail.sh
Executable file
11
examples/user/sendVerificationEmail/curl/sendVerificationEmail.sh
Executable file
@@ -0,0 +1,11 @@
|
||||
curl "https://api.m3o.com/v1/user/SendVerificationEmail" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $MICRO_API_TOKEN" \
|
||||
-d '{
|
||||
"email": "joe@example.com",
|
||||
"failureRedirectUrl": "https://m3o.com/verification-failed",
|
||||
"fromName": "Awesome Dot Com",
|
||||
"redirectUrl": "https://m3o.com",
|
||||
"subject": "Email verification",
|
||||
"textContent": "Hi there,\n\nPlease verify your email by clicking this link: $micro_verification_link"
|
||||
}'
|
||||
29
examples/user/sendVerificationEmail/go/sendVerificationEmail.go
Executable file
29
examples/user/sendVerificationEmail/go/sendVerificationEmail.go
Executable file
@@ -0,0 +1,29 @@
|
||||
package example
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/micro/services/clients/go/user"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Send a verification email
|
||||
// to the user being signed up. Email from will be from 'support@m3o.com',
|
||||
// but you can provide the title and contents.
|
||||
// The verification link will be injected in to the email as a template variable, $micro_verification_link.
|
||||
// Example: 'Hi there, welcome onboard! Use the link below to verify your email: $micro_verification_link'
|
||||
// The variable will be replaced with an actual url that will look similar to this:
|
||||
// 'https://user.m3o.com/user/verify?token=a-verification-token&rediretUrl=your-redir-url'
|
||||
func SendVerificationEmail() {
|
||||
userService := user.NewUserService(os.Getenv("MICRO_API_TOKEN"))
|
||||
rsp, err := userService.SendVerificationEmail(&user.SendVerificationEmailRequest{
|
||||
Email: "joe@example.com",
|
||||
FailureRedirectUrl: "https://m3o.com/verification-failed",
|
||||
FromName: "Awesome Dot Com",
|
||||
RedirectUrl: "https://m3o.com",
|
||||
Subject: "Email verification",
|
||||
TextContent: `Hi there,
|
||||
|
||||
Please verify your email by clicking this link: $micro_verification_link`,
|
||||
})
|
||||
fmt.Println(rsp, err)
|
||||
}
|
||||
24
examples/user/sendVerificationEmail/node/sendVerificationEmail.js
Executable file
24
examples/user/sendVerificationEmail/node/sendVerificationEmail.js
Executable file
@@ -0,0 +1,24 @@
|
||||
import * as user from "m3o/user";
|
||||
|
||||
// Send a verification email
|
||||
// to the user being signed up. Email from will be from 'support@m3o.com',
|
||||
// but you can provide the title and contents.
|
||||
// The verification link will be injected in to the email as a template variable, $micro_verification_link.
|
||||
// Example: 'Hi there, welcome onboard! Use the link below to verify your email: $micro_verification_link'
|
||||
// The variable will be replaced with an actual url that will look similar to this:
|
||||
// 'https://user.m3o.com/user/verify?token=a-verification-token&rediretUrl=your-redir-url'
|
||||
async function SendVerificationEmail() {
|
||||
let userService = new user.UserService(process.env.MICRO_API_TOKEN);
|
||||
let rsp = await userService.sendVerificationEmail({
|
||||
email: "joe@example.com",
|
||||
failureRedirectUrl: "https://m3o.com/verification-failed",
|
||||
fromName: "Awesome Dot Com",
|
||||
redirectUrl: "https://m3o.com",
|
||||
subject: "Email verification",
|
||||
textContent:
|
||||
"Hi there,\n\nPlease verify your email by clicking this link: $micro_verification_link",
|
||||
});
|
||||
console.log(rsp);
|
||||
}
|
||||
|
||||
await SendVerificationEmail();
|
||||
Reference in New Issue
Block a user