From facb2a92896a3cc832750ea586a54284ed9771ca Mon Sep 17 00:00:00 2001 From: m3o-actions <> Date: Sun, 20 Feb 2022 12:36:15 +0000 Subject: [PATCH] Commit from m3o/m3o action --- comments/comments.go | 162 ++++++ examples/app/README.md | 110 ++-- examples/chat/README.md | 296 +++++----- examples/comments/README.md | 190 +++++++ .../comments/create/createAComment/main.go | 17 + .../comments/delete/deleteAComment/main.go | 17 + .../comments/events/subscribeToEvents/main.go | 30 + .../comments/list/listAllComments/main.go | 15 + examples/comments/read/readAComment/main.go | 17 + .../comments/update/updateAComment/main.go | 21 + examples/contact/README.md | 158 +++--- examples/crypto/README.md | 112 ++-- examples/db/README.md | 186 +++---- examples/email/README.md | 56 +- examples/emoji/README.md | 60 +- examples/event/README.md | 2 +- examples/function/README.md | 332 +++++------ examples/id/README.md | 54 +- examples/lists/README.md | 138 ++--- examples/location/README.md | 68 +-- examples/mq/README.md | 2 +- examples/postcode/README.md | 56 +- examples/rss/README.md | 56 +- examples/search/README.md | 174 +++--- examples/search/index/indexADocument/main.go | 2 +- examples/space/README.md | 224 ++++---- examples/stream/README.md | 54 +- examples/sunnah/README.md | 62 +-- examples/time/README.md | 54 +- examples/user/README.md | 516 +++++++++--------- examples/weather/README.md | 56 +- m3o.go | 3 + 32 files changed, 1886 insertions(+), 1414 deletions(-) create mode 100755 comments/comments.go create mode 100755 examples/comments/README.md create mode 100755 examples/comments/create/createAComment/main.go create mode 100755 examples/comments/delete/deleteAComment/main.go create mode 100755 examples/comments/events/subscribeToEvents/main.go create mode 100755 examples/comments/list/listAllComments/main.go create mode 100755 examples/comments/read/readAComment/main.go create mode 100755 examples/comments/update/updateAComment/main.go diff --git a/comments/comments.go b/comments/comments.go new file mode 100755 index 0000000..6bf5f4f --- /dev/null +++ b/comments/comments.go @@ -0,0 +1,162 @@ +package comments + +import ( + "go.m3o.com/client" +) + +type Comments interface { + Create(*CreateRequest) (*CreateResponse, error) + Delete(*DeleteRequest) (*DeleteResponse, error) + Events(*EventsRequest) (*EventsResponseStream, error) + List(*ListRequest) (*ListResponse, error) + Read(*ReadRequest) (*ReadResponse, error) + Update(*UpdateRequest) (*UpdateResponse, error) +} + +func NewCommentsService(token string) *CommentsService { + return &CommentsService{ + client: client.NewClient(&client.Options{ + Token: token, + }), + } +} + +type CommentsService struct { + client *client.Client +} + +// Create a new comment +func (t *CommentsService) Create(request *CreateRequest) (*CreateResponse, error) { + + rsp := &CreateResponse{} + return rsp, t.client.Call("comments", "Create", request, rsp) + +} + +// Delete a comment +func (t *CommentsService) Delete(request *DeleteRequest) (*DeleteResponse, error) { + + rsp := &DeleteResponse{} + return rsp, t.client.Call("comments", "Delete", request, rsp) + +} + +// Subscribe to comments events +func (t *CommentsService) Events(request *EventsRequest) (*EventsResponseStream, error) { + stream, err := t.client.Stream("comments", "Events", request) + if err != nil { + return nil, err + } + return &EventsResponseStream{ + stream: stream, + }, nil + +} + +type EventsResponseStream struct { + stream *client.Stream +} + +func (t *EventsResponseStream) Recv() (*EventsResponse, error) { + var rsp EventsResponse + if err := t.stream.Recv(&rsp); err != nil { + return nil, err + } + return &rsp, nil +} + +// List all the comments +func (t *CommentsService) List(request *ListRequest) (*ListResponse, error) { + + rsp := &ListResponse{} + return rsp, t.client.Call("comments", "List", request, rsp) + +} + +// Read a comment +func (t *CommentsService) Read(request *ReadRequest) (*ReadResponse, error) { + + rsp := &ReadResponse{} + return rsp, t.client.Call("comments", "Read", request, rsp) + +} + +// Update a comment +func (t *CommentsService) Update(request *UpdateRequest) (*UpdateResponse, error) { + + rsp := &UpdateResponse{} + return rsp, t.client.Call("comments", "Update", request, rsp) + +} + +type Comment struct { + // time at which the comment was created + Created string `json:"created"` + // unique id for the comment, generated if not specified + Id string `json:"id"` + // subject of the comment + Subject string `json:"subject"` + // text of the comment + Text string `json:"text"` + // time at which the comment was updated + Updated string `json:"updated"` +} + +type CreateRequest struct { + // comment subject + Subject string `json:"subject"` + // comment items + Text string `json:"text"` +} + +type CreateResponse struct { + // The created comment + Comment *Comment `json:"comment"` +} + +type DeleteRequest struct { + // specify the id of the comment + Id string `json:"id"` +} + +type DeleteResponse struct { + Comment *Comment `json:"comment"` +} + +type EventsRequest struct { + // optionally specify a comment id + Id string `json:"id"` +} + +type EventsResponse struct { + // the comment which the operation occured on + Comment *Comment `json:"comment"` + // the event which occured; create, delete, update + Event string `json:"event"` +} + +type ListRequest struct { +} + +type ListResponse struct { + // the comment of comments + Comments []Comment `json:"comments"` +} + +type ReadRequest struct { + // the comment id + Id string `json:"id"` +} + +type ReadResponse struct { + // The comment + Comment *Comment `json:"comment"` +} + +type UpdateRequest struct { + Comment *Comment `json:"comment"` +} + +type UpdateResponse struct { + Comment *Comment `json:"comment"` +} diff --git a/examples/app/README.md b/examples/app/README.md index 67740e7..47d0f0f 100755 --- a/examples/app/README.md +++ b/examples/app/README.md @@ -4,6 +4,61 @@ An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/app/api](https Endpoints: +## Reserve + +Reserve apps beyond the free quota. Call Run after. + + +[https://m3o.com/app/api#Reserve](https://m3o.com/app/api#Reserve) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/app" +) + +// Reserve apps beyond the free quota. Call Run after. +func ReserveAppName() { + appService := app.NewAppService(os.Getenv("M3O_API_TOKEN")) + rsp, err := appService.Reserve(&app.ReserveRequest{ + Name: "helloworld", + + }) + fmt.Println(rsp, err) + +} +``` +## List + +List all the apps + + +[https://m3o.com/app/api#List](https://m3o.com/app/api#List) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/app" +) + +// List all the apps +func ListTheApps() { + appService := app.NewAppService(os.Getenv("M3O_API_TOKEN")) + rsp, err := appService.List(&app.ListRequest{ + + }) + fmt.Println(rsp, err) + +} +``` ## Run Run an app from source @@ -175,58 +230,3 @@ func DeleteAnApp() { } ``` -## Reserve - -Reserve apps beyond the free quota. Call Run after. - - -[https://m3o.com/app/api#Reserve](https://m3o.com/app/api#Reserve) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/app" -) - -// Reserve apps beyond the free quota. Call Run after. -func ReserveAppName() { - appService := app.NewAppService(os.Getenv("M3O_API_TOKEN")) - rsp, err := appService.Reserve(&app.ReserveRequest{ - Name: "helloworld", - - }) - fmt.Println(rsp, err) - -} -``` -## List - -List all the apps - - -[https://m3o.com/app/api#List](https://m3o.com/app/api#List) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/app" -) - -// List all the apps -func ListTheApps() { - appService := app.NewAppService(os.Getenv("M3O_API_TOKEN")) - rsp, err := appService.List(&app.ListRequest{ - - }) - fmt.Println(rsp, err) - -} -``` diff --git a/examples/chat/README.md b/examples/chat/README.md index 2a63118..8f0d154 100755 --- a/examples/chat/README.md +++ b/examples/chat/README.md @@ -4,6 +4,100 @@ An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/chat/api](http Endpoints: +## Join + +Join a chat room + + +[https://m3o.com/chat/api#Join](https://m3o.com/chat/api#Join) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/chat" +) + +// Join a chat room +func JoinAroom() { + chatService := chat.NewChatService(os.Getenv("M3O_API_TOKEN")) + + stream, err := chatService.Join(&chat.JoinRequest{ + + }) + if err != nil { + fmt.Println(err) + return + } + + for { + rsp, err := stream.Recv() + if err != nil { + fmt.Println(err) + return + } + + fmt.Println(rsp) + } +} +``` +## Kick + +Kick a user from a chat room + + +[https://m3o.com/chat/api#Kick](https://m3o.com/chat/api#Kick) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/chat" +) + +// Kick a user from a chat room +func KickAuserFromAroom() { + chatService := chat.NewChatService(os.Getenv("M3O_API_TOKEN")) + rsp, err := chatService.Kick(&chat.KickRequest{ + + }) + fmt.Println(rsp, err) + +} +``` +## Leave + +Leave a chat room + + +[https://m3o.com/chat/api#Leave](https://m3o.com/chat/api#Leave) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/chat" +) + +// Leave a chat room +func LeaveAroom() { + chatService := chat.NewChatService(os.Getenv("M3O_API_TOKEN")) + rsp, err := chatService.Leave(&chat.LeaveRequest{ + + }) + fmt.Println(rsp, err) + +} +``` ## New Create a new chat room @@ -31,6 +125,60 @@ Name: "general", }) fmt.Println(rsp, err) +} +``` +## Delete + +Delete a chat room + + +[https://m3o.com/chat/api#Delete](https://m3o.com/chat/api#Delete) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/chat" +) + +// Delete a chat room +func DeleteAchat() { + chatService := chat.NewChatService(os.Getenv("M3O_API_TOKEN")) + rsp, err := chatService.Delete(&chat.DeleteRequest{ + + }) + fmt.Println(rsp, err) + +} +``` +## Invite + +Invite a user to a chat room + + +[https://m3o.com/chat/api#Invite](https://m3o.com/chat/api#Invite) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/chat" +) + +// Invite a user to a chat room +func InviteAuser() { + chatService := chat.NewChatService(os.Getenv("M3O_API_TOKEN")) + rsp, err := chatService.Invite(&chat.InviteRequest{ + + }) + fmt.Println(rsp, err) + } ``` ## Send @@ -90,73 +238,6 @@ func GetChatHistory() { }) fmt.Println(rsp, err) -} -``` -## Join - -Join a chat room - - -[https://m3o.com/chat/api#Join](https://m3o.com/chat/api#Join) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/chat" -) - -// Join a chat room -func JoinAroom() { - chatService := chat.NewChatService(os.Getenv("M3O_API_TOKEN")) - - stream, err := chatService.Join(&chat.JoinRequest{ - - }) - if err != nil { - fmt.Println(err) - return - } - - for { - rsp, err := stream.Recv() - if err != nil { - fmt.Println(err) - return - } - - fmt.Println(rsp) - } -} -``` -## Leave - -Leave a chat room - - -[https://m3o.com/chat/api#Leave](https://m3o.com/chat/api#Leave) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/chat" -) - -// Leave a chat room -func LeaveAroom() { - chatService := chat.NewChatService(os.Getenv("M3O_API_TOKEN")) - rsp, err := chatService.Leave(&chat.LeaveRequest{ - - }) - fmt.Println(rsp, err) - } ``` ## List @@ -186,84 +267,3 @@ func ListChatRooms() { } ``` -## Delete - -Delete a chat room - - -[https://m3o.com/chat/api#Delete](https://m3o.com/chat/api#Delete) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/chat" -) - -// Delete a chat room -func DeleteAchat() { - chatService := chat.NewChatService(os.Getenv("M3O_API_TOKEN")) - rsp, err := chatService.Delete(&chat.DeleteRequest{ - - }) - fmt.Println(rsp, err) - -} -``` -## Invite - -Invite a user to a chat room - - -[https://m3o.com/chat/api#Invite](https://m3o.com/chat/api#Invite) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/chat" -) - -// Invite a user to a chat room -func InviteAuser() { - chatService := chat.NewChatService(os.Getenv("M3O_API_TOKEN")) - rsp, err := chatService.Invite(&chat.InviteRequest{ - - }) - fmt.Println(rsp, err) - -} -``` -## Kick - -Kick a user from a chat room - - -[https://m3o.com/chat/api#Kick](https://m3o.com/chat/api#Kick) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/chat" -) - -// Kick a user from a chat room -func KickAuserFromAroom() { - chatService := chat.NewChatService(os.Getenv("M3O_API_TOKEN")) - rsp, err := chatService.Kick(&chat.KickRequest{ - - }) - fmt.Println(rsp, err) - -} -``` diff --git a/examples/comments/README.md b/examples/comments/README.md new file mode 100755 index 0000000..6e8311b --- /dev/null +++ b/examples/comments/README.md @@ -0,0 +1,190 @@ +# Comments + +An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/comments/api](https://m3o.com/comments/api). + +Endpoints: + +## Create + +Create a new comment + + +[https://m3o.com/comments/api#Create](https://m3o.com/comments/api#Create) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/comments" +) + +// Create a new comment +func CreateAcomment() { + commentsService := comments.NewCommentsService(os.Getenv("M3O_API_TOKEN")) + rsp, err := commentsService.Create(&comments.CreateRequest{ + Text: "This is my comment", + + }) + fmt.Println(rsp, err) + +} +``` +## Read + +Read a comment + + +[https://m3o.com/comments/api#Read](https://m3o.com/comments/api#Read) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/comments" +) + +// Read a comment +func ReadAcomment() { + commentsService := comments.NewCommentsService(os.Getenv("M3O_API_TOKEN")) + rsp, err := commentsService.Read(&comments.ReadRequest{ + Id: "63c0cdf8-2121-11ec-a881-0242e36f037a", + + }) + fmt.Println(rsp, err) + +} +``` +## List + +List all the comments + + +[https://m3o.com/comments/api#List](https://m3o.com/comments/api#List) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/comments" +) + +// List all the comments +func ListAllComments() { + commentsService := comments.NewCommentsService(os.Getenv("M3O_API_TOKEN")) + rsp, err := commentsService.List(&comments.ListRequest{ + + }) + fmt.Println(rsp, err) + +} +``` +## Update + +Update a comment + + +[https://m3o.com/comments/api#Update](https://m3o.com/comments/api#Update) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/comments" +) + +// Update a comment +func UpdateAcomment() { + commentsService := comments.NewCommentsService(os.Getenv("M3O_API_TOKEN")) + rsp, err := commentsService.Update(&comments.UpdateRequest{ + Comment: &comments.Comment{ + Id: "63c0cdf8-2121-11ec-a881-0242e36f037a", + Subject: "Update Comment", + Text: "Updated comment text", + }, + + }) + fmt.Println(rsp, err) + +} +``` +## Delete + +Delete a comment + + +[https://m3o.com/comments/api#Delete](https://m3o.com/comments/api#Delete) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/comments" +) + +// Delete a comment +func DeleteAcomment() { + commentsService := comments.NewCommentsService(os.Getenv("M3O_API_TOKEN")) + rsp, err := commentsService.Delete(&comments.DeleteRequest{ + Id: "63c0cdf8-2121-11ec-a881-0242e36f037a", + + }) + fmt.Println(rsp, err) + +} +``` +## Events + +Subscribe to comments events + + +[https://m3o.com/comments/api#Events](https://m3o.com/comments/api#Events) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/comments" +) + +// Subscribe to comments events +func SubscribeToEvents() { + commentsService := comments.NewCommentsService(os.Getenv("M3O_API_TOKEN")) + + stream, err := commentsService.Events(&comments.EventsRequest{ + Id: "63c0cdf8-2121-11ec-a881-0242e36f037a", + + }) + if err != nil { + fmt.Println(err) + return + } + + for { + rsp, err := stream.Recv() + if err != nil { + fmt.Println(err) + return + } + + fmt.Println(rsp) + } +} +``` diff --git a/examples/comments/create/createAComment/main.go b/examples/comments/create/createAComment/main.go new file mode 100755 index 0000000..a54146c --- /dev/null +++ b/examples/comments/create/createAComment/main.go @@ -0,0 +1,17 @@ +package main + +import ( + "fmt" + "os" + + "go.m3o.com/comments" +) + +// Create a new comment +func main() { + commentsService := comments.NewCommentsService(os.Getenv("M3O_API_TOKEN")) + rsp, err := commentsService.Create(&comments.CreateRequest{ + Text: "This is my comment", + }) + fmt.Println(rsp, err) +} diff --git a/examples/comments/delete/deleteAComment/main.go b/examples/comments/delete/deleteAComment/main.go new file mode 100755 index 0000000..380b618 --- /dev/null +++ b/examples/comments/delete/deleteAComment/main.go @@ -0,0 +1,17 @@ +package main + +import ( + "fmt" + "os" + + "go.m3o.com/comments" +) + +// Delete a comment +func main() { + commentsService := comments.NewCommentsService(os.Getenv("M3O_API_TOKEN")) + rsp, err := commentsService.Delete(&comments.DeleteRequest{ + Id: "63c0cdf8-2121-11ec-a881-0242e36f037a", + }) + fmt.Println(rsp, err) +} diff --git a/examples/comments/events/subscribeToEvents/main.go b/examples/comments/events/subscribeToEvents/main.go new file mode 100755 index 0000000..9084c6d --- /dev/null +++ b/examples/comments/events/subscribeToEvents/main.go @@ -0,0 +1,30 @@ +package main + +import ( + "fmt" + "os" + + "go.m3o.com/comments" +) + +// Subscribe to comments events +func main() { + commentsService := comments.NewCommentsService(os.Getenv("M3O_API_TOKEN")) + stream, err := commentsService.Events(&comments.EventsRequest{ + Id: "63c0cdf8-2121-11ec-a881-0242e36f037a", + }) + if err != nil { + fmt.Println(err) + return + } + + for { + rsp, err := stream.Recv() + if err != nil { + fmt.Println(err) + return + } + + fmt.Println(rsp) + } +} diff --git a/examples/comments/list/listAllComments/main.go b/examples/comments/list/listAllComments/main.go new file mode 100755 index 0000000..6bae3a5 --- /dev/null +++ b/examples/comments/list/listAllComments/main.go @@ -0,0 +1,15 @@ +package main + +import ( + "fmt" + "os" + + "go.m3o.com/comments" +) + +// List all the comments +func main() { + commentsService := comments.NewCommentsService(os.Getenv("M3O_API_TOKEN")) + rsp, err := commentsService.List(&comments.ListRequest{}) + fmt.Println(rsp, err) +} diff --git a/examples/comments/read/readAComment/main.go b/examples/comments/read/readAComment/main.go new file mode 100755 index 0000000..5af1144 --- /dev/null +++ b/examples/comments/read/readAComment/main.go @@ -0,0 +1,17 @@ +package main + +import ( + "fmt" + "os" + + "go.m3o.com/comments" +) + +// Read a comment +func main() { + commentsService := comments.NewCommentsService(os.Getenv("M3O_API_TOKEN")) + rsp, err := commentsService.Read(&comments.ReadRequest{ + Id: "63c0cdf8-2121-11ec-a881-0242e36f037a", + }) + fmt.Println(rsp, err) +} diff --git a/examples/comments/update/updateAComment/main.go b/examples/comments/update/updateAComment/main.go new file mode 100755 index 0000000..4bbf9e0 --- /dev/null +++ b/examples/comments/update/updateAComment/main.go @@ -0,0 +1,21 @@ +package main + +import ( + "fmt" + "os" + + "go.m3o.com/comments" +) + +// Update a comment +func main() { + commentsService := comments.NewCommentsService(os.Getenv("M3O_API_TOKEN")) + rsp, err := commentsService.Update(&comments.UpdateRequest{ + Comment: &comments.Comment{ + Id: "63c0cdf8-2121-11ec-a881-0242e36f037a", + Subject: "Update Comment", + Text: "Updated comment text", + }, + }) + fmt.Println(rsp, err) +} diff --git a/examples/contact/README.md b/examples/contact/README.md index 878f816..531c1eb 100755 --- a/examples/contact/README.md +++ b/examples/contact/README.md @@ -4,85 +4,6 @@ An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/contact/api](h Endpoints: -## Update - - - - -[https://m3o.com/contact/api#Update](https://m3o.com/contact/api#Update) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/contact" -) - -// -func UpdateAcontact() { - contactService := contact.NewContactService(os.Getenv("M3O_API_TOKEN")) - rsp, err := contactService.Update(&contact.UpdateRequest{ - Addresses: []contact.Address{ -contact.Address{ - Label: "company address", - Location: "123 street address", -}}, -Birthday: "1995-01-01", -Emails: []contact.Email{ -contact.Email{ - Address: "home@example.com", - Label: "home", -}}, -Id: "42e48a3c-6221-11ec-96d2-acde48001122", -Links: []contact.Link{ -contact.Link{ - Label: "blog", - Url: "https://blog.joe.me", -}}, -Name: "joe", -Note: "this person is very important", -Phones: []contact.Phone{ -contact.Phone{ - Label: "home", - Number: "010-12345678", -}}, - - }) - fmt.Println(rsp, err) - -} -``` -## Read - - - - -[https://m3o.com/contact/api#Read](https://m3o.com/contact/api#Read) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/contact" -) - -// -func GetAcontact() { - contactService := contact.NewContactService(os.Getenv("M3O_API_TOKEN")) - rsp, err := contactService.Read(&contact.ReadRequest{ - Id: "42e48a3c-6221-11ec-96d2-acde48001122", - - }) - fmt.Println(rsp, err) - -} -``` ## Delete @@ -217,3 +138,82 @@ contact.Phone{ } ``` +## Update + + + + +[https://m3o.com/contact/api#Update](https://m3o.com/contact/api#Update) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/contact" +) + +// +func UpdateAcontact() { + contactService := contact.NewContactService(os.Getenv("M3O_API_TOKEN")) + rsp, err := contactService.Update(&contact.UpdateRequest{ + Addresses: []contact.Address{ +contact.Address{ + Label: "company address", + Location: "123 street address", +}}, +Birthday: "1995-01-01", +Emails: []contact.Email{ +contact.Email{ + Address: "home@example.com", + Label: "home", +}}, +Id: "42e48a3c-6221-11ec-96d2-acde48001122", +Links: []contact.Link{ +contact.Link{ + Label: "blog", + Url: "https://blog.joe.me", +}}, +Name: "joe", +Note: "this person is very important", +Phones: []contact.Phone{ +contact.Phone{ + Label: "home", + Number: "010-12345678", +}}, + + }) + fmt.Println(rsp, err) + +} +``` +## Read + + + + +[https://m3o.com/contact/api#Read](https://m3o.com/contact/api#Read) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/contact" +) + +// +func GetAcontact() { + contactService := contact.NewContactService(os.Getenv("M3O_API_TOKEN")) + rsp, err := contactService.Read(&contact.ReadRequest{ + Id: "42e48a3c-6221-11ec-96d2-acde48001122", + + }) + fmt.Println(rsp, err) + +} +``` diff --git a/examples/crypto/README.md b/examples/crypto/README.md index 4f0aca0..6434fc3 100755 --- a/examples/crypto/README.md +++ b/examples/crypto/README.md @@ -4,62 +4,6 @@ An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/crypto/api](ht Endpoints: -## News - -Get news related to a currency - - -[https://m3o.com/crypto/api#News](https://m3o.com/crypto/api#News) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/crypto" -) - -// Get news related to a currency -func GetCryptocurrencyNews() { - cryptoService := crypto.NewCryptoService(os.Getenv("M3O_API_TOKEN")) - rsp, err := cryptoService.News(&crypto.NewsRequest{ - Symbol: "BTCUSD", - - }) - fmt.Println(rsp, err) - -} -``` -## Price - -Get the last price for a given crypto ticker - - -[https://m3o.com/crypto/api#Price](https://m3o.com/crypto/api#Price) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/crypto" -) - -// Get the last price for a given crypto ticker -func GetCryptocurrencyPrice() { - cryptoService := crypto.NewCryptoService(os.Getenv("M3O_API_TOKEN")) - rsp, err := cryptoService.Price(&crypto.PriceRequest{ - Symbol: "BTCUSD", - - }) - fmt.Println(rsp, err) - -} -``` ## Quote Get the last quote for a given crypto ticker @@ -116,3 +60,59 @@ func GetPreviousClose() { } ``` +## News + +Get news related to a currency + + +[https://m3o.com/crypto/api#News](https://m3o.com/crypto/api#News) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/crypto" +) + +// Get news related to a currency +func GetCryptocurrencyNews() { + cryptoService := crypto.NewCryptoService(os.Getenv("M3O_API_TOKEN")) + rsp, err := cryptoService.News(&crypto.NewsRequest{ + Symbol: "BTCUSD", + + }) + fmt.Println(rsp, err) + +} +``` +## Price + +Get the last price for a given crypto ticker + + +[https://m3o.com/crypto/api#Price](https://m3o.com/crypto/api#Price) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/crypto" +) + +// Get the last price for a given crypto ticker +func GetCryptocurrencyPrice() { + cryptoService := crypto.NewCryptoService(os.Getenv("M3O_API_TOKEN")) + rsp, err := cryptoService.Price(&crypto.PriceRequest{ + Symbol: "BTCUSD", + + }) + fmt.Println(rsp, err) + +} +``` diff --git a/examples/db/README.md b/examples/db/README.md index f44dbfb..9a5ea17 100755 --- a/examples/db/README.md +++ b/examples/db/README.md @@ -4,6 +4,63 @@ An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/db/api](https: Endpoints: +## Count + +Count records in a table + + +[https://m3o.com/db/api#Count](https://m3o.com/db/api#Count) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/db" +) + +// Count records in a table +func CountEntriesInAtable() { + dbService := db.NewDbService(os.Getenv("M3O_API_TOKEN")) + rsp, err := dbService.Count(&db.CountRequest{ + Table: "example", + + }) + fmt.Println(rsp, err) + +} +``` +## RenameTable + +Rename a table + + +[https://m3o.com/db/api#RenameTable](https://m3o.com/db/api#RenameTable) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/db" +) + +// Rename a table +func RenameTable() { + dbService := db.NewDbService(os.Getenv("M3O_API_TOKEN")) + rsp, err := dbService.RenameTable(&db.RenameTableRequest{ + From: "examples2", +To: "examples3", + + }) + fmt.Println(rsp, err) + +} +``` ## Create Create a record in the database. Optionally include an "id" field otherwise it's set automatically. @@ -68,90 +125,6 @@ Table: "example", }) fmt.Println(rsp, err) -} -``` -## Delete - -Delete a record in the database by id. - - -[https://m3o.com/db/api#Delete](https://m3o.com/db/api#Delete) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/db" -) - -// Delete a record in the database by id. -func DeleteArecord() { - dbService := db.NewDbService(os.Getenv("M3O_API_TOKEN")) - rsp, err := dbService.Delete(&db.DeleteRequest{ - Id: "1", -Table: "example", - - }) - fmt.Println(rsp, err) - -} -``` -## Count - -Count records in a table - - -[https://m3o.com/db/api#Count](https://m3o.com/db/api#Count) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/db" -) - -// Count records in a table -func CountEntriesInAtable() { - dbService := db.NewDbService(os.Getenv("M3O_API_TOKEN")) - rsp, err := dbService.Count(&db.CountRequest{ - Table: "example", - - }) - fmt.Println(rsp, err) - -} -``` -## ListTables - -List tables in the DB - - -[https://m3o.com/db/api#ListTables](https://m3o.com/db/api#ListTables) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/db" -) - -// List tables in the DB -func ListTables() { - dbService := db.NewDbService(os.Getenv("M3O_API_TOKEN")) - rsp, err := dbService.ListTables(&db.ListTablesRequest{ - - }) - fmt.Println(rsp, err) - } ``` ## Read @@ -181,6 +154,35 @@ Table: "example", }) fmt.Println(rsp, err) +} +``` +## Delete + +Delete a record in the database by id. + + +[https://m3o.com/db/api#Delete](https://m3o.com/db/api#Delete) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/db" +) + +// Delete a record in the database by id. +func DeleteArecord() { + dbService := db.NewDbService(os.Getenv("M3O_API_TOKEN")) + rsp, err := dbService.Delete(&db.DeleteRequest{ + Id: "1", +Table: "example", + + }) + fmt.Println(rsp, err) + } ``` ## Truncate @@ -239,12 +241,12 @@ func DropTable() { } ``` -## RenameTable +## ListTables -Rename a table +List tables in the DB -[https://m3o.com/db/api#RenameTable](https://m3o.com/db/api#RenameTable) +[https://m3o.com/db/api#ListTables](https://m3o.com/db/api#ListTables) ```go package example @@ -256,13 +258,11 @@ import( "go.m3o.com/db" ) -// Rename a table -func RenameTable() { +// List tables in the DB +func ListTables() { dbService := db.NewDbService(os.Getenv("M3O_API_TOKEN")) - rsp, err := dbService.RenameTable(&db.RenameTableRequest{ - From: "examples2", -To: "examples3", - + rsp, err := dbService.ListTables(&db.ListTablesRequest{ + }) fmt.Println(rsp, err) diff --git a/examples/email/README.md b/examples/email/README.md index 8e6afcf..b04ca45 100755 --- a/examples/email/README.md +++ b/examples/email/README.md @@ -4,6 +4,34 @@ An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/email/api](htt Endpoints: +## Validate + +Validate an email address format + + +[https://m3o.com/email/api#Validate](https://m3o.com/email/api#Validate) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/email" +) + +// Validate an email address format +func ValidateEmail() { + emailService := email.NewEmailService(os.Getenv("M3O_API_TOKEN")) + rsp, err := emailService.Validate(&email.ValidateRequest{ + Address: "joe@example.com", + + }) + fmt.Println(rsp, err) + +} +``` ## Send Send an email by passing in from, to, subject, and a text or html body @@ -64,31 +92,3 @@ func ParseEmail() { } ``` -## Validate - -Validate an email address format - - -[https://m3o.com/email/api#Validate](https://m3o.com/email/api#Validate) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/email" -) - -// Validate an email address format -func ValidateEmail() { - emailService := email.NewEmailService(os.Getenv("M3O_API_TOKEN")) - rsp, err := emailService.Validate(&email.ValidateRequest{ - Address: "joe@example.com", - - }) - fmt.Println(rsp, err) - -} -``` diff --git a/examples/emoji/README.md b/examples/emoji/README.md index e461cd8..dc735fb 100755 --- a/examples/emoji/README.md +++ b/examples/emoji/README.md @@ -4,36 +4,6 @@ An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/emoji/api](htt Endpoints: -## Print - -Print text and renders the emojis with aliases e.g -let's grab a :beer: becomes let's grab a 🍺 - - -[https://m3o.com/emoji/api#Print](https://m3o.com/emoji/api#Print) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/emoji" -) - -// Print text and renders the emojis with aliases e.g -// let's grab a :beer: becomes let's grab a 🍺 -func PrintTextIncludingEmoji() { - emojiService := emoji.NewEmojiService(os.Getenv("M3O_API_TOKEN")) - rsp, err := emojiService.Print(&emoji.PrintRequest{ - Text: "let's grab a :beer:", - - }) - fmt.Println(rsp, err) - -} -``` ## Find Find an emoji by its alias e.g :beer: @@ -89,3 +59,33 @@ func GetFlagByCountryCode() { } ``` +## Print + +Print text and renders the emojis with aliases e.g +let's grab a :beer: becomes let's grab a 🍺 + + +[https://m3o.com/emoji/api#Print](https://m3o.com/emoji/api#Print) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/emoji" +) + +// Print text and renders the emojis with aliases e.g +// let's grab a :beer: becomes let's grab a 🍺 +func PrintTextIncludingEmoji() { + emojiService := emoji.NewEmojiService(os.Getenv("M3O_API_TOKEN")) + rsp, err := emojiService.Print(&emoji.PrintRequest{ + Text: "let's grab a :beer:", + + }) + fmt.Println(rsp, err) + +} +``` diff --git a/examples/event/README.md b/examples/event/README.md index c8f6f43..a478169 100755 --- a/examples/event/README.md +++ b/examples/event/README.md @@ -26,9 +26,9 @@ func PublishAnEvent() { eventService := event.NewEventService(os.Getenv("M3O_API_TOKEN")) rsp, err := eventService.Publish(&event.PublishRequest{ Message: map[string]interface{}{ + "user": "john", "id": "1", "type": "signup", - "user": "john", }, Topic: "user", diff --git a/examples/function/README.md b/examples/function/README.md index 0f61247..c05f0ae 100755 --- a/examples/function/README.md +++ b/examples/function/README.md @@ -4,34 +4,6 @@ An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/function/api]( Endpoints: -## Proxy - -Return the backend url for proxying - - -[https://m3o.com/function/api#Proxy](https://m3o.com/function/api#Proxy) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/function" -) - -// Return the backend url for proxying -func ProxyUrl() { - functionService := function.NewFunctionService(os.Getenv("M3O_API_TOKEN")) - rsp, err := functionService.Proxy(&function.ProxyRequest{ - Id: "helloworld", - - }) - fmt.Println(rsp, err) - -} -``` ## Deploy Deploy a group of functions @@ -64,6 +36,172 @@ Subfolder: "examples/go-function", }) fmt.Println(rsp, err) +} +``` +## List + +List all the deployed functions + + +[https://m3o.com/function/api#List](https://m3o.com/function/api#List) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/function" +) + +// List all the deployed functions +func ListFunctions() { + functionService := function.NewFunctionService(os.Getenv("M3O_API_TOKEN")) + rsp, err := functionService.List(&function.ListRequest{ + + }) + fmt.Println(rsp, err) + +} +``` +## Delete + +Delete a function by name + + +[https://m3o.com/function/api#Delete](https://m3o.com/function/api#Delete) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/function" +) + +// Delete a function by name +func DeleteAfunction() { + functionService := function.NewFunctionService(os.Getenv("M3O_API_TOKEN")) + rsp, err := functionService.Delete(&function.DeleteRequest{ + Name: "helloworld", + + }) + fmt.Println(rsp, err) + +} +``` +## Describe + +Get the info for a deployed function + + +[https://m3o.com/function/api#Describe](https://m3o.com/function/api#Describe) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/function" +) + +// Get the info for a deployed function +func DescribeFunctionStatus() { + functionService := function.NewFunctionService(os.Getenv("M3O_API_TOKEN")) + rsp, err := functionService.Describe(&function.DescribeRequest{ + Name: "helloworld", + + }) + fmt.Println(rsp, err) + +} +``` +## Regions + +Return a list of supported regions + + +[https://m3o.com/function/api#Regions](https://m3o.com/function/api#Regions) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/function" +) + +// Return a list of supported regions +func ListRegions() { + functionService := function.NewFunctionService(os.Getenv("M3O_API_TOKEN")) + rsp, err := functionService.Regions(&function.RegionsRequest{ + + }) + fmt.Println(rsp, err) + +} +``` +## Reserve + +Reserve function names and resources beyond free quota + + +[https://m3o.com/function/api#Reserve](https://m3o.com/function/api#Reserve) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/function" +) + +// Reserve function names and resources beyond free quota +func ReserveAfunction() { + functionService := function.NewFunctionService(os.Getenv("M3O_API_TOKEN")) + rsp, err := functionService.Reserve(&function.ReserveRequest{ + Name: "helloworld", + + }) + fmt.Println(rsp, err) + +} +``` +## Proxy + +Return the backend url for proxying + + +[https://m3o.com/function/api#Proxy](https://m3o.com/function/api#Proxy) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/function" +) + +// Return the backend url for proxying +func ProxyUrl() { + functionService := function.NewFunctionService(os.Getenv("M3O_API_TOKEN")) + rsp, err := functionService.Proxy(&function.ProxyRequest{ + Id: "helloworld", + + }) + fmt.Println(rsp, err) + } ``` ## Update @@ -125,141 +263,3 @@ Request: map[string]interface{}{ } ``` -## Describe - -Get the info for a deployed function - - -[https://m3o.com/function/api#Describe](https://m3o.com/function/api#Describe) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/function" -) - -// Get the info for a deployed function -func DescribeFunctionStatus() { - functionService := function.NewFunctionService(os.Getenv("M3O_API_TOKEN")) - rsp, err := functionService.Describe(&function.DescribeRequest{ - Name: "helloworld", - - }) - fmt.Println(rsp, err) - -} -``` -## List - -List all the deployed functions - - -[https://m3o.com/function/api#List](https://m3o.com/function/api#List) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/function" -) - -// List all the deployed functions -func ListFunctions() { - functionService := function.NewFunctionService(os.Getenv("M3O_API_TOKEN")) - rsp, err := functionService.List(&function.ListRequest{ - - }) - fmt.Println(rsp, err) - -} -``` -## Delete - -Delete a function by name - - -[https://m3o.com/function/api#Delete](https://m3o.com/function/api#Delete) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/function" -) - -// Delete a function by name -func DeleteAfunction() { - functionService := function.NewFunctionService(os.Getenv("M3O_API_TOKEN")) - rsp, err := functionService.Delete(&function.DeleteRequest{ - Name: "helloworld", - - }) - fmt.Println(rsp, err) - -} -``` -## Regions - -Return a list of supported regions - - -[https://m3o.com/function/api#Regions](https://m3o.com/function/api#Regions) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/function" -) - -// Return a list of supported regions -func ListRegions() { - functionService := function.NewFunctionService(os.Getenv("M3O_API_TOKEN")) - rsp, err := functionService.Regions(&function.RegionsRequest{ - - }) - fmt.Println(rsp, err) - -} -``` -## Reserve - -Reserve function names and resources beyond free quota - - -[https://m3o.com/function/api#Reserve](https://m3o.com/function/api#Reserve) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/function" -) - -// Reserve function names and resources beyond free quota -func ReserveAfunction() { - functionService := function.NewFunctionService(os.Getenv("M3O_API_TOKEN")) - rsp, err := functionService.Reserve(&function.ReserveRequest{ - Name: "helloworld", - - }) - fmt.Println(rsp, err) - -} -``` diff --git a/examples/id/README.md b/examples/id/README.md index eb26228..8013667 100755 --- a/examples/id/README.md +++ b/examples/id/README.md @@ -4,6 +4,33 @@ An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/id/api](https: Endpoints: +## Types + +List the types of IDs available. No query params needed. + + +[https://m3o.com/id/api#Types](https://m3o.com/id/api#Types) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/id" +) + +// List the types of IDs available. No query params needed. +func ListTheTypesOfIdsAvailable() { + idService := id.NewIdService(os.Getenv("M3O_API_TOKEN")) + rsp, err := idService.Types(&id.TypesRequest{ + + }) + fmt.Println(rsp, err) + +} +``` ## Generate Generate a unique ID. Defaults to uuid. @@ -116,30 +143,3 @@ func GenerateAbigflakeId() { } ``` -## Types - -List the types of IDs available. No query params needed. - - -[https://m3o.com/id/api#Types](https://m3o.com/id/api#Types) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/id" -) - -// List the types of IDs available. No query params needed. -func ListTheTypesOfIdsAvailable() { - idService := id.NewIdService(os.Getenv("M3O_API_TOKEN")) - rsp, err := idService.Types(&id.TypesRequest{ - - }) - fmt.Println(rsp, err) - -} -``` diff --git a/examples/lists/README.md b/examples/lists/README.md index 7fe9884..e794d73 100755 --- a/examples/lists/README.md +++ b/examples/lists/README.md @@ -4,6 +4,75 @@ An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/lists/api](htt Endpoints: +## Delete + +Delete a list + + +[https://m3o.com/lists/api#Delete](https://m3o.com/lists/api#Delete) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/lists" +) + +// Delete a list +func DeleteAlist() { + listsService := lists.NewListsService(os.Getenv("M3O_API_TOKEN")) + rsp, err := listsService.Delete(&lists.DeleteRequest{ + Id: "63c0cdf8-2121-11ec-a881-0242e36f037a", + + }) + fmt.Println(rsp, err) + +} +``` +## Events + +Subscribe to lists events + + +[https://m3o.com/lists/api#Events](https://m3o.com/lists/api#Events) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/lists" +) + +// Subscribe to lists events +func SubscribeToEvents() { + listsService := lists.NewListsService(os.Getenv("M3O_API_TOKEN")) + + stream, err := listsService.Events(&lists.EventsRequest{ + Id: "63c0cdf8-2121-11ec-a881-0242e36f037a", + + }) + if err != nil { + fmt.Println(err) + return + } + + for { + rsp, err := stream.Recv() + if err != nil { + fmt.Println(err) + return + } + + fmt.Println(rsp) + } +} +``` ## Create Create a new list @@ -116,72 +185,3 @@ func UpdateAlist() { } ``` -## Delete - -Delete a list - - -[https://m3o.com/lists/api#Delete](https://m3o.com/lists/api#Delete) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/lists" -) - -// Delete a list -func DeleteAlist() { - listsService := lists.NewListsService(os.Getenv("M3O_API_TOKEN")) - rsp, err := listsService.Delete(&lists.DeleteRequest{ - Id: "63c0cdf8-2121-11ec-a881-0242e36f037a", - - }) - fmt.Println(rsp, err) - -} -``` -## Events - -Subscribe to lists events - - -[https://m3o.com/lists/api#Events](https://m3o.com/lists/api#Events) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/lists" -) - -// Subscribe to lists events -func SubscribeToEvents() { - listsService := lists.NewListsService(os.Getenv("M3O_API_TOKEN")) - - stream, err := listsService.Events(&lists.EventsRequest{ - Id: "63c0cdf8-2121-11ec-a881-0242e36f037a", - - }) - if err != nil { - fmt.Println(err) - return - } - - for { - rsp, err := stream.Recv() - if err != nil { - fmt.Println(err) - return - } - - fmt.Println(rsp) - } -} -``` diff --git a/examples/location/README.md b/examples/location/README.md index 17f0150..78700e1 100755 --- a/examples/location/README.md +++ b/examples/location/README.md @@ -4,40 +4,6 @@ An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/location/api]( Endpoints: -## Search - -Search for entities in a given radius - - -[https://m3o.com/location/api#Search](https://m3o.com/location/api#Search) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/location" -) - -// Search for entities in a given radius -func SearchForLocations() { - locationService := location.NewLocationService(os.Getenv("M3O_API_TOKEN")) - rsp, err := locationService.Search(&location.SearchRequest{ - Center: &location.Point{ - Latitude: 51.511061, - Longitude: -0.120022, - }, -NumEntities: 10, -Radius: 100, -Type: "bike", - - }) - fmt.Println(rsp, err) - -} -``` ## Save Save an entity's current position @@ -102,3 +68,37 @@ func GetLocationById() { } ``` +## Search + +Search for entities in a given radius + + +[https://m3o.com/location/api#Search](https://m3o.com/location/api#Search) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/location" +) + +// Search for entities in a given radius +func SearchForLocations() { + locationService := location.NewLocationService(os.Getenv("M3O_API_TOKEN")) + rsp, err := locationService.Search(&location.SearchRequest{ + Center: &location.Point{ + Latitude: 51.511061, + Longitude: -0.120022, + }, +NumEntities: 10, +Radius: 100, +Type: "bike", + + }) + fmt.Println(rsp, err) + +} +``` diff --git a/examples/mq/README.md b/examples/mq/README.md index 8f18a93..1582975 100755 --- a/examples/mq/README.md +++ b/examples/mq/README.md @@ -26,9 +26,9 @@ func PublishAmessage() { mqService := mq.NewMqService(os.Getenv("M3O_API_TOKEN")) rsp, err := mqService.Publish(&mq.PublishRequest{ Message: map[string]interface{}{ - "user": "john", "id": "1", "type": "signup", + "user": "john", }, Topic: "events", diff --git a/examples/postcode/README.md b/examples/postcode/README.md index a497f9c..ee2ea3c 100755 --- a/examples/postcode/README.md +++ b/examples/postcode/README.md @@ -4,6 +4,34 @@ An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/postcode/api]( Endpoints: +## Validate + +Validate a postcode. + + +[https://m3o.com/postcode/api#Validate](https://m3o.com/postcode/api#Validate) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/postcode" +) + +// Validate a postcode. +func ReturnArandomPostcodeAndItsInformation() { + postcodeService := postcode.NewPostcodeService(os.Getenv("M3O_API_TOKEN")) + rsp, err := postcodeService.Validate(&postcode.ValidateRequest{ + Postcode: "SW1A 2AA", + + }) + fmt.Println(rsp, err) + +} +``` ## Lookup Lookup a postcode to retrieve the related region, county, etc @@ -59,31 +87,3 @@ func ReturnArandomPostcodeAndItsInformation() { } ``` -## Validate - -Validate a postcode. - - -[https://m3o.com/postcode/api#Validate](https://m3o.com/postcode/api#Validate) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/postcode" -) - -// Validate a postcode. -func ReturnArandomPostcodeAndItsInformation() { - postcodeService := postcode.NewPostcodeService(os.Getenv("M3O_API_TOKEN")) - rsp, err := postcodeService.Validate(&postcode.ValidateRequest{ - Postcode: "SW1A 2AA", - - }) - fmt.Println(rsp, err) - -} -``` diff --git a/examples/rss/README.md b/examples/rss/README.md index d95588d..5cda3e4 100755 --- a/examples/rss/README.md +++ b/examples/rss/README.md @@ -4,34 +4,6 @@ An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/rss/api](https Endpoints: -## Remove - -Remove an RSS feed by name - - -[https://m3o.com/rss/api#Remove](https://m3o.com/rss/api#Remove) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/rss" -) - -// Remove an RSS feed by name -func RemoveAfeed() { - rssService := rss.NewRssService(os.Getenv("M3O_API_TOKEN")) - rsp, err := rssService.Remove(&rss.RemoveRequest{ - Name: "bbc", - - }) - fmt.Println(rsp, err) - -} -``` ## Add Add a new RSS feed with a name, url, and category @@ -117,3 +89,31 @@ func ListRssFeeds() { } ``` +## Remove + +Remove an RSS feed by name + + +[https://m3o.com/rss/api#Remove](https://m3o.com/rss/api#Remove) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/rss" +) + +// Remove an RSS feed by name +func RemoveAfeed() { + rssService := rss.NewRssService(os.Getenv("M3O_API_TOKEN")) + rsp, err := rssService.Remove(&rss.RemoveRequest{ + Name: "bbc", + + }) + fmt.Println(rsp, err) + +} +``` diff --git a/examples/search/README.md b/examples/search/README.md index 7b98f95..99af5ee 100755 --- a/examples/search/README.md +++ b/examples/search/README.md @@ -4,93 +4,6 @@ An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/search/api](ht Endpoints: -## Search - -Search for documents in a given in index - - -[https://m3o.com/search/api#Search](https://m3o.com/search/api#Search) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/search" -) - -// Search for documents in a given in index -func SearchForAdocument() { - searchService := search.NewSearchService(os.Getenv("M3O_API_TOKEN")) - rsp, err := searchService.Search(&search.SearchRequest{ - Index: "customers", -Query: "name == 'John'", - - }) - fmt.Println(rsp, err) - -} -``` -## Search - -Search for documents in a given in index - - -[https://m3o.com/search/api#Search](https://m3o.com/search/api#Search) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/search" -) - -// Search for documents in a given in index -func SearchOnMultipleFieldsand() { - searchService := search.NewSearchService(os.Getenv("M3O_API_TOKEN")) - rsp, err := searchService.Search(&search.SearchRequest{ - Index: "customers", -Query: "name == 'John' AND starsign == 'Leo'", - - }) - fmt.Println(rsp, err) - -} -``` -## Search - -Search for documents in a given in index - - -[https://m3o.com/search/api#Search](https://m3o.com/search/api#Search) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/search" -) - -// Search for documents in a given in index -func SearchOnMultipleFieldsor() { - searchService := search.NewSearchService(os.Getenv("M3O_API_TOKEN")) - rsp, err := searchService.Search(&search.SearchRequest{ - Index: "customers", -Query: "name == 'John' OR name == 'Jane'", - - }) - fmt.Println(rsp, err) - -} -``` ## Delete Delete a document given its ID @@ -212,3 +125,90 @@ Index: "customers", } ``` +## Search + +Search for documents in a given in index + + +[https://m3o.com/search/api#Search](https://m3o.com/search/api#Search) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/search" +) + +// Search for documents in a given in index +func SearchForAdocument() { + searchService := search.NewSearchService(os.Getenv("M3O_API_TOKEN")) + rsp, err := searchService.Search(&search.SearchRequest{ + Index: "customers", +Query: "name == 'John'", + + }) + fmt.Println(rsp, err) + +} +``` +## Search + +Search for documents in a given in index + + +[https://m3o.com/search/api#Search](https://m3o.com/search/api#Search) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/search" +) + +// Search for documents in a given in index +func SearchOnMultipleFieldsand() { + searchService := search.NewSearchService(os.Getenv("M3O_API_TOKEN")) + rsp, err := searchService.Search(&search.SearchRequest{ + Index: "customers", +Query: "name == 'John' AND starsign == 'Leo'", + + }) + fmt.Println(rsp, err) + +} +``` +## Search + +Search for documents in a given in index + + +[https://m3o.com/search/api#Search](https://m3o.com/search/api#Search) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/search" +) + +// Search for documents in a given in index +func SearchOnMultipleFieldsor() { + searchService := search.NewSearchService(os.Getenv("M3O_API_TOKEN")) + rsp, err := searchService.Search(&search.SearchRequest{ + Index: "customers", +Query: "name == 'John' OR name == 'Jane'", + + }) + fmt.Println(rsp, err) + +} +``` diff --git a/examples/search/index/indexADocument/main.go b/examples/search/index/indexADocument/main.go index b81496d..81df17a 100755 --- a/examples/search/index/indexADocument/main.go +++ b/examples/search/index/indexADocument/main.go @@ -13,9 +13,9 @@ func main() { rsp, err := searchService.Index(&search.IndexRequest{ Document: &search.Document{ Contents: map[string]interface{}{ + "name": "John Doe", "age": 37, "starsign": "Leo", - "name": "John Doe", }, Id: "1234", }, diff --git a/examples/space/README.md b/examples/space/README.md index caa0bf5..d40b142 100755 --- a/examples/space/README.md +++ b/examples/space/README.md @@ -4,6 +4,118 @@ An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/space/api](htt Endpoints: +## List + +List the objects in space + + +[https://m3o.com/space/api#List](https://m3o.com/space/api#List) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/space" +) + +// List the objects in space +func ListObjectsWithPrefix() { + spaceService := space.NewSpaceService(os.Getenv("M3O_API_TOKEN")) + rsp, err := spaceService.List(&space.ListRequest{ + Prefix: "images/", + + }) + fmt.Println(rsp, err) + +} +``` +## Head + +Retrieve meta information about an object + + +[https://m3o.com/space/api#Head](https://m3o.com/space/api#Head) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/space" +) + +// Retrieve meta information about an object +func HeadAnObject() { + spaceService := space.NewSpaceService(os.Getenv("M3O_API_TOKEN")) + rsp, err := spaceService.Head(&space.HeadRequest{ + Name: "images/file.jpg", + + }) + fmt.Println(rsp, err) + +} +``` +## Read + +Read an object in space + + +[https://m3o.com/space/api#Read](https://m3o.com/space/api#Read) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/space" +) + +// Read an object in space +func ReadAnObject() { + spaceService := space.NewSpaceService(os.Getenv("M3O_API_TOKEN")) + rsp, err := spaceService.Read(&space.ReadRequest{ + Name: "images/file.jpg", + + }) + fmt.Println(rsp, err) + +} +``` +## Download + +Download an object via a presigned url + + +[https://m3o.com/space/api#Download](https://m3o.com/space/api#Download) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/space" +) + +// Download an object via a presigned url +func DownloadAnObject() { + spaceService := space.NewSpaceService(os.Getenv("M3O_API_TOKEN")) + rsp, err := spaceService.Download(&space.DownloadRequest{ + Name: "images/file.jpg", + + }) + fmt.Println(rsp, err) + +} +``` ## Upload Upload a large object (> 10MB). Returns a time limited presigned URL to be used for uploading the object @@ -120,115 +232,3 @@ func DeleteAnObject() { } ``` -## List - -List the objects in space - - -[https://m3o.com/space/api#List](https://m3o.com/space/api#List) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/space" -) - -// List the objects in space -func ListObjectsWithPrefix() { - spaceService := space.NewSpaceService(os.Getenv("M3O_API_TOKEN")) - rsp, err := spaceService.List(&space.ListRequest{ - Prefix: "images/", - - }) - fmt.Println(rsp, err) - -} -``` -## Head - -Retrieve meta information about an object - - -[https://m3o.com/space/api#Head](https://m3o.com/space/api#Head) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/space" -) - -// Retrieve meta information about an object -func HeadAnObject() { - spaceService := space.NewSpaceService(os.Getenv("M3O_API_TOKEN")) - rsp, err := spaceService.Head(&space.HeadRequest{ - Name: "images/file.jpg", - - }) - fmt.Println(rsp, err) - -} -``` -## Read - -Read an object in space - - -[https://m3o.com/space/api#Read](https://m3o.com/space/api#Read) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/space" -) - -// Read an object in space -func ReadAnObject() { - spaceService := space.NewSpaceService(os.Getenv("M3O_API_TOKEN")) - rsp, err := spaceService.Read(&space.ReadRequest{ - Name: "images/file.jpg", - - }) - fmt.Println(rsp, err) - -} -``` -## Download - -Download an object via a presigned url - - -[https://m3o.com/space/api#Download](https://m3o.com/space/api#Download) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/space" -) - -// Download an object via a presigned url -func DownloadAnObject() { - spaceService := space.NewSpaceService(os.Getenv("M3O_API_TOKEN")) - rsp, err := spaceService.Download(&space.DownloadRequest{ - Name: "images/file.jpg", - - }) - fmt.Println(rsp, err) - -} -``` diff --git a/examples/stream/README.md b/examples/stream/README.md index 232026e..d35da4f 100755 --- a/examples/stream/README.md +++ b/examples/stream/README.md @@ -4,6 +4,33 @@ An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/stream/api](ht Endpoints: +## ListChannels + +List all the active channels + + +[https://m3o.com/stream/api#ListChannels](https://m3o.com/stream/api#ListChannels) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/stream" +) + +// List all the active channels +func ListChannels() { + streamService := stream.NewStreamService(os.Getenv("M3O_API_TOKEN")) + rsp, err := streamService.ListChannels(&stream.ListChannelsRequest{ + + }) + fmt.Println(rsp, err) + +} +``` ## CreateChannel Create a channel with a given name and description. Channels are created automatically but @@ -92,30 +119,3 @@ func ListMessages() { } ``` -## ListChannels - -List all the active channels - - -[https://m3o.com/stream/api#ListChannels](https://m3o.com/stream/api#ListChannels) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/stream" -) - -// List all the active channels -func ListChannels() { - streamService := stream.NewStreamService(os.Getenv("M3O_API_TOKEN")) - rsp, err := streamService.ListChannels(&stream.ListChannelsRequest{ - - }) - fmt.Println(rsp, err) - -} -``` diff --git a/examples/sunnah/README.md b/examples/sunnah/README.md index d2d603b..fbe4416 100755 --- a/examples/sunnah/README.md +++ b/examples/sunnah/README.md @@ -4,6 +4,37 @@ An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/sunnah/api](ht Endpoints: +## Hadiths + +Hadiths returns a list of hadiths and their corresponding text for a +given book within a collection. + + +[https://m3o.com/sunnah/api#Hadiths](https://m3o.com/sunnah/api#Hadiths) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/sunnah" +) + +// Hadiths returns a list of hadiths and their corresponding text for a +// given book within a collection. +func ListTheHadithsInAbook() { + sunnahService := sunnah.NewSunnahService(os.Getenv("M3O_API_TOKEN")) + rsp, err := sunnahService.Hadiths(&sunnah.HadithsRequest{ + Book: 1, +Collection: "bukhari", + + }) + fmt.Println(rsp, err) + +} +``` ## Collections Get a list of available collections. A collection is @@ -92,34 +123,3 @@ Collection: "bukhari", } ``` -## Hadiths - -Hadiths returns a list of hadiths and their corresponding text for a -given book within a collection. - - -[https://m3o.com/sunnah/api#Hadiths](https://m3o.com/sunnah/api#Hadiths) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/sunnah" -) - -// Hadiths returns a list of hadiths and their corresponding text for a -// given book within a collection. -func ListTheHadithsInAbook() { - sunnahService := sunnah.NewSunnahService(os.Getenv("M3O_API_TOKEN")) - rsp, err := sunnahService.Hadiths(&sunnah.HadithsRequest{ - Book: 1, -Collection: "bukhari", - - }) - fmt.Println(rsp, err) - -} -``` diff --git a/examples/time/README.md b/examples/time/README.md index 9aad631..c0626b7 100755 --- a/examples/time/README.md +++ b/examples/time/README.md @@ -4,33 +4,6 @@ An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/time/api](http Endpoints: -## Now - -Get the current time - - -[https://m3o.com/time/api#Now](https://m3o.com/time/api#Now) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/time" -) - -// Get the current time -func ReturnsCurrentTimeOptionallyWithLocation() { - timeService := time.NewTimeService(os.Getenv("M3O_API_TOKEN")) - rsp, err := timeService.Now(&time.NowRequest{ - - }) - fmt.Println(rsp, err) - -} -``` ## Zone Get the timezone info for a specific location @@ -59,3 +32,30 @@ func GetTheTimezoneInfoForAspecificLocation() { } ``` +## Now + +Get the current time + + +[https://m3o.com/time/api#Now](https://m3o.com/time/api#Now) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/time" +) + +// Get the current time +func ReturnsCurrentTimeOptionallyWithLocation() { + timeService := time.NewTimeService(os.Getenv("M3O_API_TOKEN")) + rsp, err := timeService.Now(&time.NowRequest{ + + }) + fmt.Println(rsp, err) + +} +``` diff --git a/examples/user/README.md b/examples/user/README.md index 4ebdd82..0b4e4e9 100755 --- a/examples/user/README.md +++ b/examples/user/README.md @@ -4,34 +4,6 @@ An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/user/api](http Endpoints: -## Delete - -Delete an account by id - - -[https://m3o.com/user/api#Delete](https://m3o.com/user/api#Delete) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/user" -) - -// Delete an account by id -func DeleteUserAccount() { - userService := user.NewUserService(os.Getenv("M3O_API_TOKEN")) - rsp, err := userService.Delete(&user.DeleteRequest{ - Id: "8b98acbe-0b6a-4d66-a414-5ffbf666786f", - - }) - fmt.Println(rsp, err) - -} -``` ## Login Login using username or email. The response will return a new session for successful login, @@ -63,12 +35,15 @@ Password: "Password1", } ``` -## List +## VerifyToken -List all users. Returns a paged list of results +Check whether the token attached to MagicLink is valid or not. +Ideally, you need to call this endpoint from your http request +handler that handles the endpoint which is specified in the +SendMagicLink request. -[https://m3o.com/user/api#List](https://m3o.com/user/api#List) +[https://m3o.com/user/api#VerifyToken](https://m3o.com/user/api#VerifyToken) ```go package example @@ -80,59 +55,14 @@ import( "go.m3o.com/user" ) -// List all users. Returns a paged list of results -func ListAllUsers() { +// Check whether the token attached to MagicLink is valid or not. +// Ideally, you need to call this endpoint from your http request +// handler that handles the endpoint which is specified in the +// SendMagicLink request. +func VerifyAtoken() { userService := user.NewUserService(os.Getenv("M3O_API_TOKEN")) - rsp, err := userService.List(&user.ListRequest{ - Limit: 100, -Offset: 0, - - }) - fmt.Println(rsp, err) - -} -``` -## SendVerificationEmail - -Send a verification email to a user. -Email "from" will be 'noreply@email.m3ocontent.com'. -The verification link will be injected in the email -as a template variable, $micro_verification_link e.g -'Welcome to M3O! Use the link below to verify your email: $micro_verification_link' -The variable will be replaced with a url similar to: -'https://user.m3o.com/user/verify?token=a-verification-token&redirectUrl=your-redir-url' - - -[https://m3o.com/user/api#SendVerificationEmail](https://m3o.com/user/api#SendVerificationEmail) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/user" -) - -// Send a verification email to a user. -// Email "from" will be 'noreply@email.m3ocontent.com'. -// The verification link will be injected in the email -// as a template variable, $micro_verification_link e.g -// 'Welcome to M3O! Use the link below to verify your email: $micro_verification_link' -// The variable will be replaced with a url similar to: -// 'https://user.m3o.com/user/verify?token=a-verification-token&redirectUrl=your-redir-url' -func SendVerificationEmail() { - userService := user.NewUserService(os.Getenv("M3O_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`, + rsp, err := userService.VerifyToken(&user.VerifyTokenRequest{ + Token: "EdsUiidouJJJLldjlloofUiorkojflsWWdld", }) fmt.Println(rsp, err) @@ -167,159 +97,6 @@ Username: "joe", }) fmt.Println(rsp, err) -} -``` -## VerifyEmail - -Verify the email address of an account from a token sent in an email to the user. - - -[https://m3o.com/user/api#VerifyEmail](https://m3o.com/user/api#VerifyEmail) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/user" -) - -// Verify the email address of an account from a token sent in an email to the user. -func VerifyEmail() { - userService := user.NewUserService(os.Getenv("M3O_API_TOKEN")) - rsp, err := userService.VerifyEmail(&user.VerifyEmailRequest{ - Token: "012345", - - }) - fmt.Println(rsp, err) - -} -``` -## ReadSession - -Read a session by the session id. In the event it has expired or is not found and error is returned. - - -[https://m3o.com/user/api#ReadSession](https://m3o.com/user/api#ReadSession) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/user" -) - -// Read a session by the session id. In the event it has expired or is not found and error is returned. -func ReadAsessionByTheSessionId() { - userService := user.NewUserService(os.Getenv("M3O_API_TOKEN")) - rsp, err := userService.ReadSession(&user.ReadSessionRequest{ - SessionId: "df91a612-5b24-4634-99ff-240220ab8f55", - - }) - fmt.Println(rsp, err) - -} -``` -## SendMagicLink - -Login using email only - Passwordless - - -[https://m3o.com/user/api#SendMagicLink](https://m3o.com/user/api#SendMagicLink) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/user" -) - -// Login using email only - Passwordless -func SendAmagicLink() { - userService := user.NewUserService(os.Getenv("M3O_API_TOKEN")) - rsp, err := userService.SendMagicLink(&user.SendMagicLinkRequest{ - Address: "www.example.com", -Email: "joe@example.com", -Endpoint: "verifytoken", -FromName: "Awesome Dot Com", -Subject: "MagicLink to access your account", -TextContent: `Hi there, - -Click here to access your account $micro_verification_link`, - - }) - fmt.Println(rsp, err) - -} -``` -## Create - -Create a new user account. The email address and username for the account must be unique. - - -[https://m3o.com/user/api#Create](https://m3o.com/user/api#Create) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/user" -) - -// Create a new user account. The email address and username for the account must be unique. -func CreateAnAccount() { - userService := user.NewUserService(os.Getenv("M3O_API_TOKEN")) - rsp, err := userService.Create(&user.CreateRequest{ - Email: "joe@example.com", -Id: "user-1", -Password: "Password1", -Username: "joe", - - }) - fmt.Println(rsp, err) - -} -``` -## UpdatePassword - -Update the account password - - -[https://m3o.com/user/api#UpdatePassword](https://m3o.com/user/api#UpdatePassword) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/user" -) - -// Update the account password -func UpdateTheAccountPassword() { - userService := user.NewUserService(os.Getenv("M3O_API_TOKEN")) - rsp, err := userService.UpdatePassword(&user.UpdatePasswordRequest{ - ConfirmPassword: "Password2", -NewPassword: "Password2", -OldPassword: "Password1", -UserId: "user-1", - - }) - fmt.Println(rsp, err) - } ``` ## Read @@ -404,6 +181,143 @@ func ReadAccountByEmail() { }) fmt.Println(rsp, err) +} +``` +## ResetPassword + +Reset password with the code sent by the "SendPasswordResetEmail" endpoint. + + +[https://m3o.com/user/api#ResetPassword](https://m3o.com/user/api#ResetPassword) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/user" +) + +// Reset password with the code sent by the "SendPasswordResetEmail" endpoint. +func ResetPassword() { + userService := user.NewUserService(os.Getenv("M3O_API_TOKEN")) + rsp, err := userService.ResetPassword(&user.ResetPasswordRequest{ + Code: "012345", +ConfirmPassword: "NewPassword1", +Email: "joe@example.com", +NewPassword: "NewPassword1", + + }) + fmt.Println(rsp, err) + +} +``` +## Delete + +Delete an account by id + + +[https://m3o.com/user/api#Delete](https://m3o.com/user/api#Delete) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/user" +) + +// Delete an account by id +func DeleteUserAccount() { + userService := user.NewUserService(os.Getenv("M3O_API_TOKEN")) + rsp, err := userService.Delete(&user.DeleteRequest{ + Id: "8b98acbe-0b6a-4d66-a414-5ffbf666786f", + + }) + fmt.Println(rsp, err) + +} +``` +## UpdatePassword + +Update the account password + + +[https://m3o.com/user/api#UpdatePassword](https://m3o.com/user/api#UpdatePassword) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/user" +) + +// Update the account password +func UpdateTheAccountPassword() { + userService := user.NewUserService(os.Getenv("M3O_API_TOKEN")) + rsp, err := userService.UpdatePassword(&user.UpdatePasswordRequest{ + ConfirmPassword: "Password2", +NewPassword: "Password2", +OldPassword: "Password1", +UserId: "user-1", + + }) + fmt.Println(rsp, err) + +} +``` +## SendVerificationEmail + +Send a verification email to a user. +Email "from" will be 'noreply@email.m3ocontent.com'. +The verification link will be injected in the email +as a template variable, $micro_verification_link e.g +'Welcome to M3O! Use the link below to verify your email: $micro_verification_link' +The variable will be replaced with a url similar to: +'https://user.m3o.com/user/verify?token=a-verification-token&redirectUrl=your-redir-url' + + +[https://m3o.com/user/api#SendVerificationEmail](https://m3o.com/user/api#SendVerificationEmail) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/user" +) + +// Send a verification email to a user. +// Email "from" will be 'noreply@email.m3ocontent.com'. +// The verification link will be injected in the email +// as a template variable, $micro_verification_link e.g +// 'Welcome to M3O! Use the link below to verify your email: $micro_verification_link' +// The variable will be replaced with a url similar to: +// 'https://user.m3o.com/user/verify?token=a-verification-token&redirectUrl=your-redir-url' +func SendVerificationEmail() { + userService := user.NewUserService(os.Getenv("M3O_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) + } ``` ## SendPasswordResetEmail @@ -440,12 +354,12 @@ TextContent: `Hi there, } ``` -## ResetPassword +## VerifyEmail -Reset password with the code sent by the "SendPasswordResetEmail" endpoint. +Verify the email address of an account from a token sent in an email to the user. -[https://m3o.com/user/api#ResetPassword](https://m3o.com/user/api#ResetPassword) +[https://m3o.com/user/api#VerifyEmail](https://m3o.com/user/api#VerifyEmail) ```go package example @@ -457,14 +371,77 @@ import( "go.m3o.com/user" ) -// Reset password with the code sent by the "SendPasswordResetEmail" endpoint. -func ResetPassword() { +// Verify the email address of an account from a token sent in an email to the user. +func VerifyEmail() { userService := user.NewUserService(os.Getenv("M3O_API_TOKEN")) - rsp, err := userService.ResetPassword(&user.ResetPasswordRequest{ - Code: "012345", -ConfirmPassword: "NewPassword1", + rsp, err := userService.VerifyEmail(&user.VerifyEmailRequest{ + Token: "012345", + + }) + fmt.Println(rsp, err) + +} +``` +## SendMagicLink + +Login using email only - Passwordless + + +[https://m3o.com/user/api#SendMagicLink](https://m3o.com/user/api#SendMagicLink) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/user" +) + +// Login using email only - Passwordless +func SendAmagicLink() { + userService := user.NewUserService(os.Getenv("M3O_API_TOKEN")) + rsp, err := userService.SendMagicLink(&user.SendMagicLinkRequest{ + Address: "www.example.com", Email: "joe@example.com", -NewPassword: "NewPassword1", +Endpoint: "verifytoken", +FromName: "Awesome Dot Com", +Subject: "MagicLink to access your account", +TextContent: `Hi there, + +Click here to access your account $micro_verification_link`, + + }) + fmt.Println(rsp, err) + +} +``` +## Create + +Create a new user account. The email address and username for the account must be unique. + + +[https://m3o.com/user/api#Create](https://m3o.com/user/api#Create) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/user" +) + +// Create a new user account. The email address and username for the account must be unique. +func CreateAnAccount() { + userService := user.NewUserService(os.Getenv("M3O_API_TOKEN")) + rsp, err := userService.Create(&user.CreateRequest{ + Email: "joe@example.com", +Id: "user-1", +Password: "Password1", +Username: "joe", }) fmt.Println(rsp, err) @@ -499,15 +476,12 @@ func LogAuserOut() { } ``` -## VerifyToken +## ReadSession -Check whether the token attached to MagicLink is valid or not. -Ideally, you need to call this endpoint from your http request -handler that handles the endpoint which is specified in the -SendMagicLink request. +Read a session by the session id. In the event it has expired or is not found and error is returned. -[https://m3o.com/user/api#VerifyToken](https://m3o.com/user/api#VerifyToken) +[https://m3o.com/user/api#ReadSession](https://m3o.com/user/api#ReadSession) ```go package example @@ -519,14 +493,40 @@ import( "go.m3o.com/user" ) -// Check whether the token attached to MagicLink is valid or not. -// Ideally, you need to call this endpoint from your http request -// handler that handles the endpoint which is specified in the -// SendMagicLink request. -func VerifyAtoken() { +// Read a session by the session id. In the event it has expired or is not found and error is returned. +func ReadAsessionByTheSessionId() { userService := user.NewUserService(os.Getenv("M3O_API_TOKEN")) - rsp, err := userService.VerifyToken(&user.VerifyTokenRequest{ - Token: "EdsUiidouJJJLldjlloofUiorkojflsWWdld", + rsp, err := userService.ReadSession(&user.ReadSessionRequest{ + SessionId: "df91a612-5b24-4634-99ff-240220ab8f55", + + }) + fmt.Println(rsp, err) + +} +``` +## List + +List all users. Returns a paged list of results + + +[https://m3o.com/user/api#List](https://m3o.com/user/api#List) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/user" +) + +// List all users. Returns a paged list of results +func ListAllUsers() { + userService := user.NewUserService(os.Getenv("M3O_API_TOKEN")) + rsp, err := userService.List(&user.ListRequest{ + Limit: 100, +Offset: 0, }) fmt.Println(rsp, err) diff --git a/examples/weather/README.md b/examples/weather/README.md index 4fa715b..43c5660 100755 --- a/examples/weather/README.md +++ b/examples/weather/README.md @@ -4,34 +4,6 @@ An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/weather/api](h Endpoints: -## Now - -Get the current weather report for a location by postcode, city, zip code, ip address - - -[https://m3o.com/weather/api#Now](https://m3o.com/weather/api#Now) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/weather" -) - -// Get the current weather report for a location by postcode, city, zip code, ip address -func GetCurrentWeather() { - weatherService := weather.NewWeatherService(os.Getenv("M3O_API_TOKEN")) - rsp, err := weatherService.Now(&weather.NowRequest{ - Location: "london", - - }) - fmt.Println(rsp, err) - -} -``` ## Forecast Get the weather forecast for the next 1-10 days @@ -61,3 +33,31 @@ Location: "London", } ``` +## Now + +Get the current weather report for a location by postcode, city, zip code, ip address + + +[https://m3o.com/weather/api#Now](https://m3o.com/weather/api#Now) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/weather" +) + +// Get the current weather report for a location by postcode, city, zip code, ip address +func GetCurrentWeather() { + weatherService := weather.NewWeatherService(os.Getenv("M3O_API_TOKEN")) + rsp, err := weatherService.Now(&weather.NowRequest{ + Location: "london", + + }) + fmt.Println(rsp, err) + +} +``` diff --git a/m3o.go b/m3o.go index 63ccfd9..eb9e766 100755 --- a/m3o.go +++ b/m3o.go @@ -8,6 +8,7 @@ import ( "go.m3o.com/cache" "go.m3o.com/carbon" "go.m3o.com/chat" + "go.m3o.com/comments" "go.m3o.com/contact" "go.m3o.com/crypto" "go.m3o.com/currency" @@ -75,6 +76,7 @@ func NewClient(token string) *Client { CacheService: cache.NewCacheService(token), CarbonService: carbon.NewCarbonService(token), ChatService: chat.NewChatService(token), + CommentsService: comments.NewCommentsService(token), ContactService: contact.NewContactService(token), CryptoService: crypto.NewCryptoService(token), CurrencyService: currency.NewCurrencyService(token), @@ -142,6 +144,7 @@ type Client struct { CacheService *cache.CacheService CarbonService *carbon.CarbonService ChatService *chat.ChatService + CommentsService *comments.CommentsService ContactService *contact.ContactService CryptoService *crypto.CryptoService CurrencyService *currency.CurrencyService