diff --git a/examples/db/README.md b/examples/db/README.md index bd0ee60..2f824ab 100755 --- a/examples/db/README.md +++ b/examples/db/README.md @@ -26,10 +26,10 @@ func CreateArecord() { dbService := db.NewDbService(os.Getenv("M3O_API_TOKEN")) rsp, err := dbService.Create(&db.CreateRequest{ Record: map[string]interface{}{ + "id": "1", "name": "Jane", "age": 42, "isActive": true, - "id": "1", }, Table: "users", @@ -60,14 +60,99 @@ func UpdateArecord() { dbService := db.NewDbService(os.Getenv("M3O_API_TOKEN")) rsp, err := dbService.Update(&db.UpdateRequest{ Record: map[string]interface{}{ - "age": 43, "id": "1", + "age": 43, }, Table: "users", }) 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 + +Read data from a table. Lookup can be by ID or via querying any field in the record. + + +[https://m3o.com/db/api#Read](https://m3o.com/db/api#Read) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/db" +) + +// Read data from a table. Lookup can be by ID or via querying any field in the record. +func ReadRecords() { + dbService := db.NewDbService(os.Getenv("M3O_API_TOKEN")) + rsp, err := dbService.Read(&db.ReadRequest{ + Query: "age == 43", +Table: "users", + + }) + 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: "users", + + }) + fmt.Println(rsp, err) + } ``` ## Truncate @@ -96,6 +181,34 @@ func TruncateTable() { }) fmt.Println(rsp, err) +} +``` +## DropTable + +Drop a table in the DB + + +[https://m3o.com/db/api#DropTable](https://m3o.com/db/api#DropTable) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/db" +) + +// Drop a table in the DB +func DropTable() { + dbService := db.NewDbService(os.Getenv("M3O_API_TOKEN")) + rsp, err := dbService.DropTable(&db.DropTableRequest{ + Table: "users", + + }) + fmt.Println(rsp, err) + } ``` ## Count @@ -155,116 +268,3 @@ To: "events_backup", } ``` -## Read - -Read data from a table. Lookup can be by ID or via querying any field in the record. - - -[https://m3o.com/db/api#Read](https://m3o.com/db/api#Read) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/db" -) - -// Read data from a table. Lookup can be by ID or via querying any field in the record. -func ReadRecords() { - dbService := db.NewDbService(os.Getenv("M3O_API_TOKEN")) - rsp, err := dbService.Read(&db.ReadRequest{ - Query: "age == 43", -Table: "users", - - }) - 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: "users", - - }) - fmt.Println(rsp, err) - -} -``` -## DropTable - -Drop a table in the DB - - -[https://m3o.com/db/api#DropTable](https://m3o.com/db/api#DropTable) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/db" -) - -// Drop a table in the DB -func DropTable() { - dbService := db.NewDbService(os.Getenv("M3O_API_TOKEN")) - rsp, err := dbService.DropTable(&db.DropTableRequest{ - Table: "users", - - }) - 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) - -} -``` diff --git a/examples/emoji/README.md b/examples/emoji/README.md index 272d9a9..d2a4c7f 100755 --- a/examples/emoji/README.md +++ b/examples/emoji/README.md @@ -4,6 +4,61 @@ An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/Emoji/api](htt Endpoints: +## Find + +Find an emoji by its alias e.g :beer: + + +[https://m3o.com/emoji/api#Find](https://m3o.com/emoji/api#Find) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/emoji" +) + +// Find an emoji by its alias e.g :beer: +func FindEmoji() { + emojiService := emoji.NewEmojiService(os.Getenv("M3O_API_TOKEN")) + rsp, err := emojiService.Find(&emoji.FindRequest{ + Alias: ":beer:", + + }) + fmt.Println(rsp, err) + +} +``` +## Flag + +Get the flag for a country. Requires country code e.g GB for great britain + + +[https://m3o.com/emoji/api#Flag](https://m3o.com/emoji/api#Flag) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/emoji" +) + +// Get the flag for a country. Requires country code e.g GB for great britain +func GetFlagByCountryCode() { + emojiService := emoji.NewEmojiService(os.Getenv("M3O_API_TOKEN")) + rsp, err := emojiService.Flag(&emoji.FlagRequest{ + + }) + fmt.Println(rsp, err) + +} +``` ## Print Print text and renders the emojis with aliases e.g @@ -64,58 +119,3 @@ To: "+44782669123", } ``` -## Find - -Find an emoji by its alias e.g :beer: - - -[https://m3o.com/emoji/api#Find](https://m3o.com/emoji/api#Find) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/emoji" -) - -// Find an emoji by its alias e.g :beer: -func FindEmoji() { - emojiService := emoji.NewEmojiService(os.Getenv("M3O_API_TOKEN")) - rsp, err := emojiService.Find(&emoji.FindRequest{ - Alias: ":beer:", - - }) - fmt.Println(rsp, err) - -} -``` -## Flag - -Get the flag for a country. Requires country code e.g GB for great britain - - -[https://m3o.com/emoji/api#Flag](https://m3o.com/emoji/api#Flag) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/emoji" -) - -// Get the flag for a country. Requires country code e.g GB for great britain -func GetFlagByCountryCode() { - emojiService := emoji.NewEmojiService(os.Getenv("M3O_API_TOKEN")) - rsp, err := emojiService.Flag(&emoji.FlagRequest{ - - }) - fmt.Println(rsp, err) - -} -``` diff --git a/examples/event/README.md b/examples/event/README.md index 1278ca7..cb93c29 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{}{ - "type": "signup", "user": "john", "id": "1", + "type": "signup", }, Topic: "user", diff --git a/examples/file/README.md b/examples/file/README.md index 6b3ff5e..600798e 100755 --- a/examples/file/README.md +++ b/examples/file/README.md @@ -4,38 +4,6 @@ An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/File/api](http Endpoints: -## Save - -Save a file - - -[https://m3o.com/file/api#Save](https://m3o.com/file/api#Save) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/file" -) - -// Save a file -func SaveFile() { - fileService := file.NewFileService(os.Getenv("M3O_API_TOKEN")) - rsp, err := fileService.Save(&file.SaveRequest{ - File: &file.Record{ - Content: "file content example", - Path: "/document/text-files/file.txt", - Project: "examples", - }, - - }) - fmt.Println(rsp, err) - -} -``` ## List List files by their project and optionally a path. @@ -122,3 +90,35 @@ Project: "examples", } ``` +## Save + +Save a file + + +[https://m3o.com/file/api#Save](https://m3o.com/file/api#Save) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/file" +) + +// Save a file +func SaveFile() { + fileService := file.NewFileService(os.Getenv("M3O_API_TOKEN")) + rsp, err := fileService.Save(&file.SaveRequest{ + File: &file.Record{ + Content: "file content example", + Path: "/document/text-files/file.txt", + Project: "examples", + }, + + }) + fmt.Println(rsp, err) + +} +``` diff --git a/examples/helloworld/README.md b/examples/helloworld/README.md index 8f0aa43..3593fb7 100755 --- a/examples/helloworld/README.md +++ b/examples/helloworld/README.md @@ -4,34 +4,6 @@ An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/Helloworld/api Endpoints: -## Call - -Call returns a personalised "Hello $name" response - - -[https://m3o.com/helloworld/api#Call](https://m3o.com/helloworld/api#Call) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/helloworld" -) - -// Call returns a personalised "Hello $name" response -func CallTheHelloworldService() { - helloworldService := helloworld.NewHelloworldService(os.Getenv("M3O_API_TOKEN")) - rsp, err := helloworldService.Call(&helloworld.CallRequest{ - Name: "John", - - }) - fmt.Println(rsp, err) - -} -``` ## Stream Stream returns a stream of "Hello $name" responses @@ -74,3 +46,31 @@ Name: "John", } } ``` +## Call + +Call returns a personalised "Hello $name" response + + +[https://m3o.com/helloworld/api#Call](https://m3o.com/helloworld/api#Call) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/helloworld" +) + +// Call returns a personalised "Hello $name" response +func CallTheHelloworldService() { + helloworldService := helloworld.NewHelloworldService(os.Getenv("M3O_API_TOKEN")) + rsp, err := helloworldService.Call(&helloworld.CallRequest{ + Name: "John", + + }) + fmt.Println(rsp, err) + +} +``` diff --git a/examples/holidays/README.md b/examples/holidays/README.md index 22e8fcd..c0b9f00 100755 --- a/examples/holidays/README.md +++ b/examples/holidays/README.md @@ -4,6 +4,33 @@ An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/Holidays/api]( Endpoints: +## Countries + +Get the list of countries that are supported by this API + + +[https://m3o.com/holidays/api#Countries](https://m3o.com/holidays/api#Countries) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/holidays" +) + +// Get the list of countries that are supported by this API +func ListCountries() { + holidaysService := holidays.NewHolidaysService(os.Getenv("M3O_API_TOKEN")) + rsp, err := holidaysService.Countries(&holidays.CountriesRequest{ + + }) + fmt.Println(rsp, err) + +} +``` ## List List the holiday dates for a given country and year @@ -32,30 +59,3 @@ func GetHolidays() { } ``` -## Countries - -Get the list of countries that are supported by this API - - -[https://m3o.com/holidays/api#Countries](https://m3o.com/holidays/api#Countries) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/holidays" -) - -// Get the list of countries that are supported by this API -func ListCountries() { - holidaysService := holidays.NewHolidaysService(os.Getenv("M3O_API_TOKEN")) - rsp, err := holidaysService.Countries(&holidays.CountriesRequest{ - - }) - fmt.Println(rsp, err) - -} -``` diff --git a/examples/image/README.md b/examples/image/README.md index 017aa39..ae229e6 100755 --- a/examples/image/README.md +++ b/examples/image/README.md @@ -4,6 +4,125 @@ An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/Image/api](htt Endpoints: +## Resize + +Resize an image on the fly without storing it (by sending and receiving a base64 encoded image), or resize and upload depending on parameters. +If one of width or height is 0, the image aspect ratio is preserved. +Optional cropping. +To use the file parameter you need to send the request as a multipart/form-data rather than the usual application/json +with each parameter as a form field. + + +[https://m3o.com/image/api#Resize](https://m3o.com/image/api#Resize) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/image" +) + +// Resize an image on the fly without storing it (by sending and receiving a base64 encoded image), or resize and upload depending on parameters. +// If one of width or height is 0, the image aspect ratio is preserved. +// Optional cropping. +// To use the file parameter you need to send the request as a multipart/form-data rather than the usual application/json +// with each parameter as a form field. +func Base64toHostedImage() { + imageService := image.NewImageService(os.Getenv("M3O_API_TOKEN")) + rsp, err := imageService.Resize(&image.ResizeRequest{ + Base64: "data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==", +Height: 100, +Name: "cat.png", +Width: 100, + + }) + fmt.Println(rsp, err) + +} +``` +## Resize + +Resize an image on the fly without storing it (by sending and receiving a base64 encoded image), or resize and upload depending on parameters. +If one of width or height is 0, the image aspect ratio is preserved. +Optional cropping. +To use the file parameter you need to send the request as a multipart/form-data rather than the usual application/json +with each parameter as a form field. + + +[https://m3o.com/image/api#Resize](https://m3o.com/image/api#Resize) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/image" +) + +// Resize an image on the fly without storing it (by sending and receiving a base64 encoded image), or resize and upload depending on parameters. +// If one of width or height is 0, the image aspect ratio is preserved. +// Optional cropping. +// To use the file parameter you need to send the request as a multipart/form-data rather than the usual application/json +// with each parameter as a form field. +func Base64toBase64image() { + imageService := image.NewImageService(os.Getenv("M3O_API_TOKEN")) + rsp, err := imageService.Resize(&image.ResizeRequest{ + Base64: "data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==", +Height: 100, +Width: 100, + + }) + fmt.Println(rsp, err) + +} +``` +## Resize + +Resize an image on the fly without storing it (by sending and receiving a base64 encoded image), or resize and upload depending on parameters. +If one of width or height is 0, the image aspect ratio is preserved. +Optional cropping. +To use the file parameter you need to send the request as a multipart/form-data rather than the usual application/json +with each parameter as a form field. + + +[https://m3o.com/image/api#Resize](https://m3o.com/image/api#Resize) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/image" +) + +// Resize an image on the fly without storing it (by sending and receiving a base64 encoded image), or resize and upload depending on parameters. +// If one of width or height is 0, the image aspect ratio is preserved. +// Optional cropping. +// To use the file parameter you need to send the request as a multipart/form-data rather than the usual application/json +// with each parameter as a form field. +func Base64toBase64imageWithCropping() { + imageService := image.NewImageService(os.Getenv("M3O_API_TOKEN")) + rsp, err := imageService.Resize(&image.ResizeRequest{ + Base64: "data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==", +CropOptions: &image.CropOptions{ + Height: 50, + Width: 50, +}, +Height: 100, +Width: 100, + + }) + fmt.Println(rsp, err) + +} +``` ## Convert Convert an image from one format (jpeg, png etc.) to an other either on the fly (from base64 to base64), @@ -137,122 +256,3 @@ func DeleteAnUploadedImage() { } ``` -## Resize - -Resize an image on the fly without storing it (by sending and receiving a base64 encoded image), or resize and upload depending on parameters. -If one of width or height is 0, the image aspect ratio is preserved. -Optional cropping. -To use the file parameter you need to send the request as a multipart/form-data rather than the usual application/json -with each parameter as a form field. - - -[https://m3o.com/image/api#Resize](https://m3o.com/image/api#Resize) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/image" -) - -// Resize an image on the fly without storing it (by sending and receiving a base64 encoded image), or resize and upload depending on parameters. -// If one of width or height is 0, the image aspect ratio is preserved. -// Optional cropping. -// To use the file parameter you need to send the request as a multipart/form-data rather than the usual application/json -// with each parameter as a form field. -func Base64toHostedImage() { - imageService := image.NewImageService(os.Getenv("M3O_API_TOKEN")) - rsp, err := imageService.Resize(&image.ResizeRequest{ - Base64: "data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==", -Height: 100, -Name: "cat.png", -Width: 100, - - }) - fmt.Println(rsp, err) - -} -``` -## Resize - -Resize an image on the fly without storing it (by sending and receiving a base64 encoded image), or resize and upload depending on parameters. -If one of width or height is 0, the image aspect ratio is preserved. -Optional cropping. -To use the file parameter you need to send the request as a multipart/form-data rather than the usual application/json -with each parameter as a form field. - - -[https://m3o.com/image/api#Resize](https://m3o.com/image/api#Resize) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/image" -) - -// Resize an image on the fly without storing it (by sending and receiving a base64 encoded image), or resize and upload depending on parameters. -// If one of width or height is 0, the image aspect ratio is preserved. -// Optional cropping. -// To use the file parameter you need to send the request as a multipart/form-data rather than the usual application/json -// with each parameter as a form field. -func Base64toBase64image() { - imageService := image.NewImageService(os.Getenv("M3O_API_TOKEN")) - rsp, err := imageService.Resize(&image.ResizeRequest{ - Base64: "data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==", -Height: 100, -Width: 100, - - }) - fmt.Println(rsp, err) - -} -``` -## Resize - -Resize an image on the fly without storing it (by sending and receiving a base64 encoded image), or resize and upload depending on parameters. -If one of width or height is 0, the image aspect ratio is preserved. -Optional cropping. -To use the file parameter you need to send the request as a multipart/form-data rather than the usual application/json -with each parameter as a form field. - - -[https://m3o.com/image/api#Resize](https://m3o.com/image/api#Resize) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/image" -) - -// Resize an image on the fly without storing it (by sending and receiving a base64 encoded image), or resize and upload depending on parameters. -// If one of width or height is 0, the image aspect ratio is preserved. -// Optional cropping. -// To use the file parameter you need to send the request as a multipart/form-data rather than the usual application/json -// with each parameter as a form field. -func Base64toBase64imageWithCropping() { - imageService := image.NewImageService(os.Getenv("M3O_API_TOKEN")) - rsp, err := imageService.Resize(&image.ResizeRequest{ - Base64: "data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==", -CropOptions: &image.CropOptions{ - Height: 50, - Width: 50, -}, -Height: 100, -Width: 100, - - }) - fmt.Println(rsp, err) - -} -``` diff --git a/examples/mq/README.md b/examples/mq/README.md index 10f108b..e9efd8f 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/news/README.md b/examples/news/README.md new file mode 100755 index 0000000..a48f30a --- /dev/null +++ b/examples/news/README.md @@ -0,0 +1,36 @@ +# News + +An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/News/api](https://m3o.com/News/api). + +Endpoints: + +## Headlines + + + + +[https://m3o.com/news/api#Headlines](https://m3o.com/news/api#Headlines) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/news" +) + +// +func GetNewsHeadlines() { + newsService := news.NewNewsService(os.Getenv("M3O_API_TOKEN")) + rsp, err := newsService.Headlines(&news.HeadlinesRequest{ + Date: "2021-11-24", +Language: "en", +Locale: "us", + + }) + fmt.Println(rsp, err) + +} +``` diff --git a/examples/news/headlines/getNewsHeadlines/main.go b/examples/news/headlines/getNewsHeadlines/main.go new file mode 100755 index 0000000..f5a9e98 --- /dev/null +++ b/examples/news/headlines/getNewsHeadlines/main.go @@ -0,0 +1,20 @@ +package main + +import ( + "fmt" + "os" + + "go.m3o.com/news" +) + +// +func main() { + newsService := news.NewNewsService(os.Getenv("M3O_API_TOKEN")) + rsp, err := newsService.Headlines(&news.HeadlinesRequest{ + Date: "2021-11-24", + Language: "en", + Locale: "us", + }) + fmt.Println(rsp, err) + +} diff --git a/examples/notes/README.md b/examples/notes/README.md index 04d20a1..3d9f237 100755 --- a/examples/notes/README.md +++ b/examples/notes/README.md @@ -4,75 +4,6 @@ An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/Notes/api](htt Endpoints: -## Delete - -Delete a note - - -[https://m3o.com/notes/api#Delete](https://m3o.com/notes/api#Delete) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/notes" -) - -// Delete a note -func DeleteAnote() { - notesService := notes.NewNotesService(os.Getenv("M3O_API_TOKEN")) - rsp, err := notesService.Delete(¬es.DeleteRequest{ - Id: "63c0cdf8-2121-11ec-a881-0242e36f037a", - - }) - fmt.Println(rsp, err) - -} -``` -## Events - -Subscribe to notes events - - -[https://m3o.com/notes/api#Events](https://m3o.com/notes/api#Events) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/notes" -) - -// Subscribe to notes events -func SubscribeToEvents() { - notesService := notes.NewNotesService(os.Getenv("M3O_API_TOKEN")) - - stream, err := notesService.Events(¬es.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 note @@ -189,3 +120,72 @@ func UpdateAnote() { } ``` +## Delete + +Delete a note + + +[https://m3o.com/notes/api#Delete](https://m3o.com/notes/api#Delete) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/notes" +) + +// Delete a note +func DeleteAnote() { + notesService := notes.NewNotesService(os.Getenv("M3O_API_TOKEN")) + rsp, err := notesService.Delete(¬es.DeleteRequest{ + Id: "63c0cdf8-2121-11ec-a881-0242e36f037a", + + }) + fmt.Println(rsp, err) + +} +``` +## Events + +Subscribe to notes events + + +[https://m3o.com/notes/api#Events](https://m3o.com/notes/api#Events) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/notes" +) + +// Subscribe to notes events +func SubscribeToEvents() { + notesService := notes.NewNotesService(os.Getenv("M3O_API_TOKEN")) + + stream, err := notesService.Events(¬es.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/postcode/README.md b/examples/postcode/README.md index cccb09a..675099b 100755 --- a/examples/postcode/README.md +++ b/examples/postcode/README.md @@ -4,34 +4,6 @@ An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/Postcode/api]( Endpoints: -## Lookup - -Lookup a postcode to retrieve the related region, county, etc - - -[https://m3o.com/postcode/api#Lookup](https://m3o.com/postcode/api#Lookup) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/postcode" -) - -// Lookup a postcode to retrieve the related region, county, etc -func LookupPostcode() { - postcodeService := postcode.NewPostcodeService(os.Getenv("M3O_API_TOKEN")) - rsp, err := postcodeService.Lookup(&postcode.LookupRequest{ - Postcode: "SW1A 2AA", - - }) - fmt.Println(rsp, err) - -} -``` ## Random Return a random postcode and its related info @@ -87,3 +59,31 @@ func ReturnArandomPostcodeAndItsInformation() { } ``` +## Lookup + +Lookup a postcode to retrieve the related region, county, etc + + +[https://m3o.com/postcode/api#Lookup](https://m3o.com/postcode/api#Lookup) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/postcode" +) + +// Lookup a postcode to retrieve the related region, county, etc +func LookupPostcode() { + postcodeService := postcode.NewPostcodeService(os.Getenv("M3O_API_TOKEN")) + rsp, err := postcodeService.Lookup(&postcode.LookupRequest{ + Postcode: "SW1A 2AA", + + }) + fmt.Println(rsp, err) + +} +``` diff --git a/examples/quran/README.md b/examples/quran/README.md index 5f43d60..ee61912 100755 --- a/examples/quran/README.md +++ b/examples/quran/README.md @@ -4,6 +4,38 @@ An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/Quran/api](htt Endpoints: +## Verses + +Lookup the verses (ayahs) for a chapter including +translation, interpretation and breakdown by individual +words. + + +[https://m3o.com/quran/api#Verses](https://m3o.com/quran/api#Verses) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/quran" +) + +// Lookup the verses (ayahs) for a chapter including +// translation, interpretation and breakdown by individual +// words. +func GetVersesOfAchapter() { + quranService := quran.NewQuranService(os.Getenv("M3O_API_TOKEN")) + rsp, err := quranService.Verses(&quran.VersesRequest{ + Chapter: 1, + + }) + fmt.Println(rsp, err) + +} +``` ## Search Search the Quran for any form of query or questions @@ -88,35 +120,3 @@ func GetChapterSummary() { } ``` -## Verses - -Lookup the verses (ayahs) for a chapter including -translation, interpretation and breakdown by individual -words. - - -[https://m3o.com/quran/api#Verses](https://m3o.com/quran/api#Verses) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/quran" -) - -// Lookup the verses (ayahs) for a chapter including -// translation, interpretation and breakdown by individual -// words. -func GetVersesOfAchapter() { - quranService := quran.NewQuranService(os.Getenv("M3O_API_TOKEN")) - rsp, err := quranService.Verses(&quran.VersesRequest{ - Chapter: 1, - - }) - fmt.Println(rsp, err) - -} -``` diff --git a/examples/stock/README.md b/examples/stock/README.md index 4983276..3090684 100755 --- a/examples/stock/README.md +++ b/examples/stock/README.md @@ -4,6 +4,63 @@ An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/Stock/api](htt Endpoints: +## Quote + +Get the last quote for the stock + + +[https://m3o.com/stock/api#Quote](https://m3o.com/stock/api#Quote) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/stock" +) + +// Get the last quote for the stock +func GetAstockQuote() { + stockService := stock.NewStockService(os.Getenv("M3O_API_TOKEN")) + rsp, err := stockService.Quote(&stock.QuoteRequest{ + Symbol: "AAPL", + + }) + fmt.Println(rsp, err) + +} +``` +## History + +Get the historic open-close for a given day + + +[https://m3o.com/stock/api#History](https://m3o.com/stock/api#History) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/stock" +) + +// Get the historic open-close for a given day +func GetHistoricData() { + stockService := stock.NewStockService(os.Getenv("M3O_API_TOKEN")) + rsp, err := stockService.History(&stock.HistoryRequest{ + Date: "2020-10-01", +Stock: "AAPL", + + }) + fmt.Println(rsp, err) + +} +``` ## OrderBook Get the historic order book and each trade by timestamp @@ -64,60 +121,3 @@ func GetAstockPrice() { } ``` -## Quote - -Get the last quote for the stock - - -[https://m3o.com/stock/api#Quote](https://m3o.com/stock/api#Quote) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/stock" -) - -// Get the last quote for the stock -func GetAstockQuote() { - stockService := stock.NewStockService(os.Getenv("M3O_API_TOKEN")) - rsp, err := stockService.Quote(&stock.QuoteRequest{ - Symbol: "AAPL", - - }) - fmt.Println(rsp, err) - -} -``` -## History - -Get the historic open-close for a given day - - -[https://m3o.com/stock/api#History](https://m3o.com/stock/api#History) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/stock" -) - -// Get the historic open-close for a given day -func GetHistoricData() { - stockService := stock.NewStockService(os.Getenv("M3O_API_TOKEN")) - rsp, err := stockService.History(&stock.HistoryRequest{ - Date: "2020-10-01", -Stock: "AAPL", - - }) - fmt.Println(rsp, err) - -} -``` diff --git a/examples/sunnah/README.md b/examples/sunnah/README.md index 0b5cf6e..7b24889 100755 --- a/examples/sunnah/README.md +++ b/examples/sunnah/README.md @@ -4,35 +4,6 @@ An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/Sunnah/api](ht Endpoints: -## Collections - -Get a list of available collections. A collection is -a compilation of hadiths collected and written by an author. - - -[https://m3o.com/sunnah/api#Collections](https://m3o.com/sunnah/api#Collections) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/sunnah" -) - -// Get a list of available collections. A collection is -// a compilation of hadiths collected and written by an author. -func ListAvailableCollections() { - sunnahService := sunnah.NewSunnahService(os.Getenv("M3O_API_TOKEN")) - rsp, err := sunnahService.Collections(&sunnah.CollectionsRequest{ - - }) - fmt.Println(rsp, err) - -} -``` ## Books Get a list of books from within a collection. A book can contain many chapters @@ -123,3 +94,32 @@ Collection: "bukhari", } ``` +## Collections + +Get a list of available collections. A collection is +a compilation of hadiths collected and written by an author. + + +[https://m3o.com/sunnah/api#Collections](https://m3o.com/sunnah/api#Collections) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/sunnah" +) + +// Get a list of available collections. A collection is +// a compilation of hadiths collected and written by an author. +func ListAvailableCollections() { + sunnahService := sunnah.NewSunnahService(os.Getenv("M3O_API_TOKEN")) + rsp, err := sunnahService.Collections(&sunnah.CollectionsRequest{ + + }) + fmt.Println(rsp, err) + +} +``` diff --git a/examples/user/README.md b/examples/user/README.md index d02b5a2..3546f25 100755 --- a/examples/user/README.md +++ b/examples/user/README.md @@ -4,13 +4,12 @@ An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/User/api](http Endpoints: -## Login +## Create -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 +Create a new user account. The email address and username for the account must be unique. -[https://m3o.com/user/api#Login](https://m3o.com/user/api#Login) +[https://m3o.com/user/api#Create](https://m3o.com/user/api#Create) ```go package example @@ -22,25 +21,26 @@ import( "go.m3o.com/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 -func LogAuserIn() { +// 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.Login(&user.LoginRequest{ + rsp, err := userService.Create(&user.CreateRequest{ Email: "joe@example.com", +Id: "user-1", Password: "Password1", +Username: "joe", }) fmt.Println(rsp, err) } ``` -## UpdatePassword +## Read -Update the account password +Read an account by id, username or email. Only one need to be specified. -[https://m3o.com/user/api#UpdatePassword](https://m3o.com/user/api#UpdatePassword) +[https://m3o.com/user/api#Read](https://m3o.com/user/api#Read) ```go package example @@ -52,13 +52,67 @@ import( "go.m3o.com/user" ) -// Update the account password -func UpdateTheAccountPassword() { +// Read an account by id, username or email. Only one need to be specified. +func ReadAnAccountById() { userService := user.NewUserService(os.Getenv("M3O_API_TOKEN")) - rsp, err := userService.UpdatePassword(&user.UpdatePasswordRequest{ - ConfirmPassword: "Password2", -NewPassword: "Password2", -OldPassword: "Password1", + rsp, err := userService.Read(&user.ReadRequest{ + Id: "user-1", + + }) + fmt.Println(rsp, err) + +} +``` +## Read + +Read an account by id, username or email. Only one need to be specified. + + +[https://m3o.com/user/api#Read](https://m3o.com/user/api#Read) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/user" +) + +// Read an account by id, username or email. Only one need to be specified. +func ReadAccountByUsernameOrEmail() { + userService := user.NewUserService(os.Getenv("M3O_API_TOKEN")) + rsp, err := userService.Read(&user.ReadRequest{ + Username: "joe", + + }) + fmt.Println(rsp, err) + +} +``` +## Read + +Read an account by id, username or email. Only one need to be specified. + + +[https://m3o.com/user/api#Read](https://m3o.com/user/api#Read) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/user" +) + +// Read an account by id, username or email. Only one need to be specified. +func ReadAccountByEmail() { + userService := user.NewUserService(os.Getenv("M3O_API_TOKEN")) + rsp, err := userService.Read(&user.ReadRequest{ + Email: "joe@example.com", }) fmt.Println(rsp, err) @@ -167,65 +221,6 @@ func DeleteUserAccount() { }) fmt.Println(rsp, err) -} -``` -## ResetPassword - -Reset password with the code sent by the "SendPasswordResetEmail" endoint. - - -[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" endoint. -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) - -} -``` -## Logout - -Logout a user account - - -[https://m3o.com/user/api#Logout](https://m3o.com/user/api#Logout) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/user" -) - -// Logout a user account -func LogAuserOut() { - userService := user.NewUserService(os.Getenv("M3O_API_TOKEN")) - rsp, err := userService.Logout(&user.LogoutRequest{ - SessionId: "df91a612-5b24-4634-99ff-240220ab8f55", - - }) - fmt.Println(rsp, err) - } ``` ## ReadSession @@ -254,66 +249,6 @@ func ReadAsessionByTheSessionId() { }) 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) - -} -``` -## 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) - } ``` ## Update @@ -345,12 +280,12 @@ Id: "user-1", } ``` -## Read +## UpdatePassword -Read an account by id, username or email. Only one need to be specified. +Update the account password -[https://m3o.com/user/api#Read](https://m3o.com/user/api#Read) +[https://m3o.com/user/api#UpdatePassword](https://m3o.com/user/api#UpdatePassword) ```go package example @@ -362,67 +297,13 @@ import( "go.m3o.com/user" ) -// Read an account by id, username or email. Only one need to be specified. -func ReadAnAccountById() { +// Update the account password +func UpdateTheAccountPassword() { userService := user.NewUserService(os.Getenv("M3O_API_TOKEN")) - rsp, err := userService.Read(&user.ReadRequest{ - Id: "user-1", - - }) - fmt.Println(rsp, err) - -} -``` -## Read - -Read an account by id, username or email. Only one need to be specified. - - -[https://m3o.com/user/api#Read](https://m3o.com/user/api#Read) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/user" -) - -// Read an account by id, username or email. Only one need to be specified. -func ReadAccountByUsernameOrEmail() { - userService := user.NewUserService(os.Getenv("M3O_API_TOKEN")) - rsp, err := userService.Read(&user.ReadRequest{ - Username: "joe", - - }) - fmt.Println(rsp, err) - -} -``` -## Read - -Read an account by id, username or email. Only one need to be specified. - - -[https://m3o.com/user/api#Read](https://m3o.com/user/api#Read) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/user" -) - -// Read an account by id, username or email. Only one need to be specified. -func ReadAccountByEmail() { - userService := user.NewUserService(os.Getenv("M3O_API_TOKEN")) - rsp, err := userService.Read(&user.ReadRequest{ - Email: "joe@example.com", + rsp, err := userService.UpdatePassword(&user.UpdatePasswordRequest{ + ConfirmPassword: "Password2", +NewPassword: "Password2", +OldPassword: "Password1", }) fmt.Println(rsp, err) @@ -463,3 +344,122 @@ TextContent: `Hi there, } ``` +## ResetPassword + +Reset password with the code sent by the "SendPasswordResetEmail" endoint. + + +[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" endoint. +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) + +} +``` +## Login + +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 + + +[https://m3o.com/user/api#Login](https://m3o.com/user/api#Login) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/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 +func LogAuserIn() { + userService := user.NewUserService(os.Getenv("M3O_API_TOKEN")) + rsp, err := userService.Login(&user.LoginRequest{ + Email: "joe@example.com", +Password: "Password1", + + }) + fmt.Println(rsp, err) + +} +``` +## Logout + +Logout a user account + + +[https://m3o.com/user/api#Logout](https://m3o.com/user/api#Logout) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/user" +) + +// Logout a user account +func LogAuserOut() { + userService := user.NewUserService(os.Getenv("M3O_API_TOKEN")) + rsp, err := userService.Logout(&user.LogoutRequest{ + 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/m3o.go b/m3o.go index 8fad007..bca8d74 100755 --- a/m3o.go +++ b/m3o.go @@ -24,6 +24,7 @@ import ( "go.m3o.com/ip" "go.m3o.com/location" "go.m3o.com/mq" + "go.m3o.com/news" "go.m3o.com/notes" "go.m3o.com/otp" "go.m3o.com/postcode" @@ -75,6 +76,7 @@ func NewClient(token string) *Client { IpService: ip.NewIpService(token), LocationService: location.NewLocationService(token), MqService: mq.NewMqService(token), + NewsService: news.NewNewsService(token), NotesService: notes.NewNotesService(token), OtpService: otp.NewOtpService(token), PostcodeService: postcode.NewPostcodeService(token), @@ -126,6 +128,7 @@ type Client struct { IpService *ip.IpService LocationService *location.LocationService MqService *mq.MqService + NewsService *news.NewsService NotesService *notes.NotesService OtpService *otp.OtpService PostcodeService *postcode.PostcodeService diff --git a/news/news.go b/news/news.go new file mode 100755 index 0000000..bc7c453 --- /dev/null +++ b/news/news.go @@ -0,0 +1,65 @@ +package news + +import ( + "go.m3o.com/client" +) + +func NewNewsService(token string) *NewsService { + return &NewsService{ + client: client.NewClient(&client.Options{ + Token: token, + }), + } +} + +type NewsService struct { + client *client.Client +} + +// +func (t *NewsService) Headlines(request *HeadlinesRequest) (*HeadlinesResponse, error) { + + rsp := &HeadlinesResponse{} + return rsp, t.client.Call("news", "Headlines", request, rsp) + +} + +type Article struct { + // categories + Categories []string `json:"categories"` + // article description + Description string `json:"description"` + // article id + Id string `json:"id"` + // image url + ImageUrl string `json:"image_url"` + // related keywords + Keywords string `json:"keywords"` + // the article language + Language string `json:"language"` + // the locale + Locale string `json:"locale"` + // time it was published + PublishedAt string `json:"published_at"` + // first 60 characters of article body + Snippet string `json:"snippet"` + // source of news + Source string `json:"source"` + // article title + Title string `json:"title"` + // url of the article + Url string `json:"url"` +} + +type HeadlinesRequest struct { + // date published on in YYYY-MM-DD format + Date string `json:"date"` + // comma separated list of languages to retrieve in e.g en,es + Language string `json:"language"` + // comma separated list of countries to include e.g us,ca + Locale string `json:"locale"` +} + +type HeadlinesResponse struct { + Articles []Article `json:"articles"` +}