diff --git a/examples/cache/README.md b/examples/cache/README.md index 8d61626..44097c1 100755 --- a/examples/cache/README.md +++ b/examples/cache/README.md @@ -4,64 +4,6 @@ An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/Cache/api](htt Endpoints: -## Increment - -Increment a value (if it's a number). If key not found it is equivalent to set. - - -[https://m3o.com/cache/api#Increment](https://m3o.com/cache/api#Increment) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/cache" -) - -// Increment a value (if it's a number). If key not found it is equivalent to set. -func IncrementAvalue() { - cacheService := cache.NewCacheService(os.Getenv("M3O_API_TOKEN")) - rsp, err := cacheService.Increment(&cache.IncrementRequest{ - Key: "counter", -Value: 2, - - }) - fmt.Println(rsp, err) - -} -``` -## Decrement - -Decrement a value (if it's a number). If key not found it is equivalent to set. - - -[https://m3o.com/cache/api#Decrement](https://m3o.com/cache/api#Decrement) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/cache" -) - -// Decrement a value (if it's a number). If key not found it is equivalent to set. -func DecrementAvalue() { - cacheService := cache.NewCacheService(os.Getenv("M3O_API_TOKEN")) - rsp, err := cacheService.Decrement(&cache.DecrementRequest{ - Key: "counter", -Value: 2, - - }) - fmt.Println(rsp, err) - -} -``` ## Set Set an item in the cache. Overwrites any existing value already set. @@ -147,3 +89,61 @@ func DeleteAvalue() { } ``` +## Increment + +Increment a value (if it's a number). If key not found it is equivalent to set. + + +[https://m3o.com/cache/api#Increment](https://m3o.com/cache/api#Increment) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/cache" +) + +// Increment a value (if it's a number). If key not found it is equivalent to set. +func IncrementAvalue() { + cacheService := cache.NewCacheService(os.Getenv("M3O_API_TOKEN")) + rsp, err := cacheService.Increment(&cache.IncrementRequest{ + Key: "counter", +Value: 2, + + }) + fmt.Println(rsp, err) + +} +``` +## Decrement + +Decrement a value (if it's a number). If key not found it is equivalent to set. + + +[https://m3o.com/cache/api#Decrement](https://m3o.com/cache/api#Decrement) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/cache" +) + +// Decrement a value (if it's a number). If key not found it is equivalent to set. +func DecrementAvalue() { + cacheService := cache.NewCacheService(os.Getenv("M3O_API_TOKEN")) + rsp, err := cacheService.Decrement(&cache.DecrementRequest{ + Key: "counter", +Value: 2, + + }) + fmt.Println(rsp, err) + +} +``` diff --git a/examples/db/README.md b/examples/db/README.md index 66a9aa3..988ce3d 100755 --- a/examples/db/README.md +++ b/examples/db/README.md @@ -36,12 +36,12 @@ Table: "users", } ``` -## Read +## Delete -Read data from a table. Lookup can be by ID or via querying any field in the record. +Delete a record in the database by id. -[https://m3o.com/db/api#Read](https://m3o.com/db/api#Read) +[https://m3o.com/db/api#Delete](https://m3o.com/db/api#Delete) ```go package example @@ -53,11 +53,11 @@ import( "go.m3o.com/db" ) -// Read data from a table. Lookup can be by ID or via querying any field in the record. -func ReadRecords() { +// Delete a record in the database by id. +func DeleteArecord() { dbService := db.NewDbService(os.Getenv("M3O_API_TOKEN")) - rsp, err := dbService.Read(&db.ReadRequest{ - Query: "age == 43", + rsp, err := dbService.Delete(&db.DeleteRequest{ + Id: "1", Table: "users", }) @@ -170,10 +170,10 @@ func CreateArecord() { dbService := db.NewDbService(os.Getenv("M3O_API_TOKEN")) rsp, err := dbService.Create(&db.CreateRequest{ Record: map[string]interface{}{ - "isActive": true, "id": "1", "name": "Jane", "age": 42, + "isActive": true, }, Table: "users", @@ -182,12 +182,12 @@ Table: "users", } ``` -## Delete +## Read -Delete a record in the database by id. +Read data from a table. Lookup can be by ID or via querying any field in the record. -[https://m3o.com/db/api#Delete](https://m3o.com/db/api#Delete) +[https://m3o.com/db/api#Read](https://m3o.com/db/api#Read) ```go package example @@ -199,11 +199,11 @@ import( "go.m3o.com/db" ) -// Delete a record in the database by id. -func DeleteArecord() { +// 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.Delete(&db.DeleteRequest{ - Id: "1", + rsp, err := dbService.Read(&db.ReadRequest{ + Query: "age == 43", Table: "users", }) diff --git a/examples/db/create/createARecord/main.go b/examples/db/create/createARecord/main.go index 886de82..81f6b1b 100755 --- a/examples/db/create/createARecord/main.go +++ b/examples/db/create/createARecord/main.go @@ -12,10 +12,10 @@ func main() { dbService := db.NewDbService(os.Getenv("M3O_API_TOKEN")) rsp, err := dbService.Create(&db.CreateRequest{ Record: map[string]interface{}{ + "isActive": true, "id": "1", "name": "Jane", "age": 42, - "isActive": true, }, Table: "users", }) diff --git a/examples/db/update/updateARecord/main.go b/examples/db/update/updateARecord/main.go index 37b63dd..f2b4cab 100755 --- a/examples/db/update/updateARecord/main.go +++ b/examples/db/update/updateARecord/main.go @@ -12,8 +12,8 @@ func main() { dbService := db.NewDbService(os.Getenv("M3O_API_TOKEN")) rsp, err := dbService.Update(&db.UpdateRequest{ Record: map[string]interface{}{ - "id": "1", "age": 43, + "id": "1", }, Table: "users", }) diff --git a/examples/event/README.md b/examples/event/README.md index bfdbd1a..346f40c 100755 --- a/examples/event/README.md +++ b/examples/event/README.md @@ -4,39 +4,6 @@ An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/Event/api](htt Endpoints: -## Publish - -Publish a event to the event stream. - - -[https://m3o.com/event/api#Publish](https://m3o.com/event/api#Publish) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/event" -) - -// Publish a event to the event stream. -func PublishAnEvent() { - eventService := event.NewEventService(os.Getenv("M3O_API_TOKEN")) - rsp, err := eventService.Publish(&event.PublishRequest{ - Message: map[string]interface{}{ - "id": "1", - "type": "signup", - "user": "john", -}, -Topic: "user", - - }) - fmt.Println(rsp, err) - -} -``` ## Consume Consume events from a given topic. @@ -106,3 +73,36 @@ func ReadEventsOnAtopic() { } ``` +## Publish + +Publish a event to the event stream. + + +[https://m3o.com/event/api#Publish](https://m3o.com/event/api#Publish) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/event" +) + +// Publish a event to the event stream. +func PublishAnEvent() { + eventService := event.NewEventService(os.Getenv("M3O_API_TOKEN")) + rsp, err := eventService.Publish(&event.PublishRequest{ + Message: map[string]interface{}{ + "id": "1", + "type": "signup", + "user": "john", +}, +Topic: "user", + + }) + fmt.Println(rsp, err) + +} +``` diff --git a/examples/forex/README.md b/examples/forex/README.md index 076f73a..2be477d 100755 --- a/examples/forex/README.md +++ b/examples/forex/README.md @@ -4,6 +4,34 @@ An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/Forex/api](htt Endpoints: +## History + +Returns the data for the previous close + + +[https://m3o.com/forex/api#History](https://m3o.com/forex/api#History) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/forex" +) + +// Returns the data for the previous close +func GetPreviousClose() { + forexService := forex.NewForexService(os.Getenv("M3O_API_TOKEN")) + rsp, err := forexService.History(&forex.HistoryRequest{ + Symbol: "GBPUSD", + + }) + fmt.Println(rsp, err) + +} +``` ## Price Get the latest price for a given forex ticker @@ -60,31 +88,3 @@ func GetAfxQuote() { } ``` -## History - -Returns the data for the previous close - - -[https://m3o.com/forex/api#History](https://m3o.com/forex/api#History) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/forex" -) - -// Returns the data for the previous close -func GetPreviousClose() { - forexService := forex.NewForexService(os.Getenv("M3O_API_TOKEN")) - rsp, err := forexService.History(&forex.HistoryRequest{ - Symbol: "GBPUSD", - - }) - fmt.Println(rsp, err) - -} -``` diff --git a/examples/function/README.md b/examples/function/README.md index 68c5eda..e427361 100755 --- a/examples/function/README.md +++ b/examples/function/README.md @@ -4,6 +4,67 @@ An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/Function/api]( Endpoints: +## 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: "my-first-func", +Project: "tests", + + }) + fmt.Println(rsp, err) + +} +``` +## Deploy + +Deploy a group of functions + + +[https://m3o.com/function/api#Deploy](https://m3o.com/function/api#Deploy) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/function" +) + +// Deploy a group of functions +func DeployAfunction() { + functionService := function.NewFunctionService(os.Getenv("M3O_API_TOKEN")) + rsp, err := functionService.Deploy(&function.DeployRequest{ + Entrypoint: "helloworld", +Name: "my-first-func", +Project: "tests", +Repo: "github.com/m3o/nodejs-function-example", +Runtime: "nodejs14", + + }) + fmt.Println(rsp, err) + +} +``` ## Call Call a function by name @@ -90,64 +151,3 @@ Project: "tests", } ``` -## 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: "my-first-func", -Project: "tests", - - }) - fmt.Println(rsp, err) - -} -``` -## Deploy - -Deploy a group of functions - - -[https://m3o.com/function/api#Deploy](https://m3o.com/function/api#Deploy) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/function" -) - -// Deploy a group of functions -func DeployAfunction() { - functionService := function.NewFunctionService(os.Getenv("M3O_API_TOKEN")) - rsp, err := functionService.Deploy(&function.DeployRequest{ - Entrypoint: "helloworld", -Name: "my-first-func", -Project: "tests", -Repo: "github.com/m3o/nodejs-function-example", -Runtime: "nodejs14", - - }) - fmt.Println(rsp, err) - -} -``` diff --git a/examples/geocoding/README.md b/examples/geocoding/README.md index ad1daf9..3ee6de8 100755 --- a/examples/geocoding/README.md +++ b/examples/geocoding/README.md @@ -4,6 +4,35 @@ An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/Geocoding/api] Endpoints: +## Reverse + +Reverse lookup an address from gps coordinates + + +[https://m3o.com/geocoding/api#Reverse](https://m3o.com/geocoding/api#Reverse) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/geocoding" +) + +// Reverse lookup an address from gps coordinates +func ReverseGeocodeLocation() { + geocodingService := geocoding.NewGeocodingService(os.Getenv("M3O_API_TOKEN")) + rsp, err := geocodingService.Reverse(&geocoding.ReverseRequest{ + Latitude: 51.5123064, +Longitude: -0.1216235, + + }) + fmt.Println(rsp, err) + +} +``` ## Lookup Lookup returns a geocoded address including normalized address and gps coordinates. All fields are optional, provide more to get more accurate results @@ -35,32 +64,3 @@ Postcode: "wc2b", } ``` -## Reverse - -Reverse lookup an address from gps coordinates - - -[https://m3o.com/geocoding/api#Reverse](https://m3o.com/geocoding/api#Reverse) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/geocoding" -) - -// Reverse lookup an address from gps coordinates -func ReverseGeocodeLocation() { - geocodingService := geocoding.NewGeocodingService(os.Getenv("M3O_API_TOKEN")) - rsp, err := geocodingService.Reverse(&geocoding.ReverseRequest{ - Latitude: 51.5123064, -Longitude: -0.1216235, - - }) - fmt.Println(rsp, err) - -} -``` diff --git a/examples/image/README.md b/examples/image/README.md index 68fa198..ae229e6 100755 --- a/examples/image/README.md +++ b/examples/image/README.md @@ -4,104 +4,6 @@ An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/Image/api](htt Endpoints: -## Upload - -Upload an image by either sending a base64 encoded image to this endpoint or a URL. -To resize an image before uploading, see the Resize endpoint. -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#Upload](https://m3o.com/image/api#Upload) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/image" -) - -// Upload an image by either sending a base64 encoded image to this endpoint or a URL. -// To resize an image before uploading, see the Resize endpoint. -// 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 UploadAbase64imageToMicrosCdn() { - imageService := image.NewImageService(os.Getenv("M3O_API_TOKEN")) - rsp, err := imageService.Upload(&image.UploadRequest{ - Base64: "data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAAx0lEQVR4nOzaMaoDMQyE4ZHj+x82vVdhwQoTkzKQEcwP5r0ihT7sbjUTeAJ4HCegXQJYfOYefOyjDuBiz3yjwJBoCIl6QZOeUjTC1Ix1IxEJXF9+0KWsf2bD4bn37OO/c/wuQ9QyRC1D1DJELUPUMkQtQ9QyRC1D1DJELUPUMkQtQ9QyRC1D1DJELUPUMkQtQ9Sa/NG94Tf3j4WBdaxudMEkn4IM2rZBA0wBrvo7aOcpj2emXvLeVt0IGm0GVXUj91mvAAAA//+V2CZl+4AKXwAAAABJRU5ErkJggg==", -Name: "cat.jpeg", - - }) - fmt.Println(rsp, err) - -} -``` -## Upload - -Upload an image by either sending a base64 encoded image to this endpoint or a URL. -To resize an image before uploading, see the Resize endpoint. -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#Upload](https://m3o.com/image/api#Upload) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/image" -) - -// Upload an image by either sending a base64 encoded image to this endpoint or a URL. -// To resize an image before uploading, see the Resize endpoint. -// 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 UploadAnImageFromAurlToMicrosCdn() { - imageService := image.NewImageService(os.Getenv("M3O_API_TOKEN")) - rsp, err := imageService.Upload(&image.UploadRequest{ - Name: "cat.jpeg", -Url: "somewebsite.com/cat.png", - - }) - fmt.Println(rsp, err) - -} -``` -## Delete - -Delete an image previously uploaded. - - -[https://m3o.com/image/api#Delete](https://m3o.com/image/api#Delete) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/image" -) - -// Delete an image previously uploaded. -func DeleteAnUploadedImage() { - imageService := image.NewImageService(os.Getenv("M3O_API_TOKEN")) - rsp, err := imageService.Delete(&image.DeleteRequest{ - Url: "https://cdn.m3ocontent.com/micro/images/micro/41e23b39-48dd-42b6-9738-79a313414bb8/cat.png", - - }) - 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. @@ -256,3 +158,101 @@ Url: "somewebsite.com/cat.png", } ``` +## Upload + +Upload an image by either sending a base64 encoded image to this endpoint or a URL. +To resize an image before uploading, see the Resize endpoint. +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#Upload](https://m3o.com/image/api#Upload) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/image" +) + +// Upload an image by either sending a base64 encoded image to this endpoint or a URL. +// To resize an image before uploading, see the Resize endpoint. +// 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 UploadAbase64imageToMicrosCdn() { + imageService := image.NewImageService(os.Getenv("M3O_API_TOKEN")) + rsp, err := imageService.Upload(&image.UploadRequest{ + Base64: "data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAAx0lEQVR4nOzaMaoDMQyE4ZHj+x82vVdhwQoTkzKQEcwP5r0ihT7sbjUTeAJ4HCegXQJYfOYefOyjDuBiz3yjwJBoCIl6QZOeUjTC1Ix1IxEJXF9+0KWsf2bD4bn37OO/c/wuQ9QyRC1D1DJELUPUMkQtQ9QyRC1D1DJELUPUMkQtQ9QyRC1D1DJELUPUMkQtQ9Sa/NG94Tf3j4WBdaxudMEkn4IM2rZBA0wBrvo7aOcpj2emXvLeVt0IGm0GVXUj91mvAAAA//+V2CZl+4AKXwAAAABJRU5ErkJggg==", +Name: "cat.jpeg", + + }) + fmt.Println(rsp, err) + +} +``` +## Upload + +Upload an image by either sending a base64 encoded image to this endpoint or a URL. +To resize an image before uploading, see the Resize endpoint. +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#Upload](https://m3o.com/image/api#Upload) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/image" +) + +// Upload an image by either sending a base64 encoded image to this endpoint or a URL. +// To resize an image before uploading, see the Resize endpoint. +// 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 UploadAnImageFromAurlToMicrosCdn() { + imageService := image.NewImageService(os.Getenv("M3O_API_TOKEN")) + rsp, err := imageService.Upload(&image.UploadRequest{ + Name: "cat.jpeg", +Url: "somewebsite.com/cat.png", + + }) + fmt.Println(rsp, err) + +} +``` +## Delete + +Delete an image previously uploaded. + + +[https://m3o.com/image/api#Delete](https://m3o.com/image/api#Delete) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/image" +) + +// Delete an image previously uploaded. +func DeleteAnUploadedImage() { + imageService := image.NewImageService(os.Getenv("M3O_API_TOKEN")) + rsp, err := imageService.Delete(&image.DeleteRequest{ + Url: "https://cdn.m3ocontent.com/micro/images/micro/41e23b39-48dd-42b6-9738-79a313414bb8/cat.png", + + }) + fmt.Println(rsp, err) + +} +``` diff --git a/examples/location/README.md b/examples/location/README.md index 83046bb..9d51b7a 100755 --- a/examples/location/README.md +++ b/examples/location/README.md @@ -4,42 +4,6 @@ An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/Location/api]( Endpoints: -## Save - -Save an entity's current position - - -[https://m3o.com/location/api#Save](https://m3o.com/location/api#Save) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/location" -) - -// Save an entity's current position -func SaveAnEntity() { - locationService := location.NewLocationService(os.Getenv("M3O_API_TOKEN")) - rsp, err := locationService.Save(&location.SaveRequest{ - Entity: &location.Entity{ - Id: "1", - Location: &location.Point{ - Latitude: 51.511061, - Longitude: -0.120022, - Timestamp: 1622802761, -}, - Type: "bike", -}, - - }) - fmt.Println(rsp, err) - -} -``` ## Read Read an entity by its ID @@ -102,3 +66,39 @@ Type: "bike", } ``` +## Save + +Save an entity's current position + + +[https://m3o.com/location/api#Save](https://m3o.com/location/api#Save) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/location" +) + +// Save an entity's current position +func SaveAnEntity() { + locationService := location.NewLocationService(os.Getenv("M3O_API_TOKEN")) + rsp, err := locationService.Save(&location.SaveRequest{ + Entity: &location.Entity{ + Id: "1", + Location: &location.Point{ + Latitude: 51.511061, + Longitude: -0.120022, + Timestamp: 1622802761, +}, + Type: "bike", +}, + + }) + fmt.Println(rsp, err) + +} +``` diff --git a/examples/notes/README.md b/examples/notes/README.md index 9b7f4c8..d3734ad 100755 --- a/examples/notes/README.md +++ b/examples/notes/README.md @@ -4,6 +4,76 @@ An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/Notes/api](htt Endpoints: +## 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 + + +[https://m3o.com/notes/api#Create](https://m3o.com/notes/api#Create) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/notes" +) + +// Create a new note +func CreateAnote() { + notesService := notes.NewNotesService(os.Getenv("M3O_API_TOKEN")) + rsp, err := notesService.Create(¬es.CreateRequest{ + Text: "This is my note", +Title: "New Note", + + }) + fmt.Println(rsp, err) + +} +``` ## Read Read a note @@ -119,73 +189,3 @@ func DeleteAnote() { } ``` -## 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 - - -[https://m3o.com/notes/api#Create](https://m3o.com/notes/api#Create) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/notes" -) - -// Create a new note -func CreateAnote() { - notesService := notes.NewNotesService(os.Getenv("M3O_API_TOKEN")) - rsp, err := notesService.Create(¬es.CreateRequest{ - Text: "This is my note", -Title: "New Note", - - }) - fmt.Println(rsp, err) - -} -``` diff --git a/examples/routing/README.md b/examples/routing/README.md index c409916..bd394b1 100755 --- a/examples/routing/README.md +++ b/examples/routing/README.md @@ -4,6 +4,41 @@ An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/Routing/api](h Endpoints: +## Eta + +Get the eta for a route from origin to destination. The eta is an estimated time based on car routes + + +[https://m3o.com/routing/api#Eta](https://m3o.com/routing/api#Eta) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/routing" +) + +// Get the eta for a route from origin to destination. The eta is an estimated time based on car routes +func EtaFromPointAtoPointB() { + routingService := routing.NewRoutingService(os.Getenv("M3O_API_TOKEN")) + rsp, err := routingService.Eta(&routing.EtaRequest{ + Destination: &routing.Point{ + Latitude: 52.529407, + Longitude: 13.397634, +}, +Origin: &routing.Point{ + Latitude: 52.517037, + Longitude: 13.38886, +}, + + }) + fmt.Println(rsp, err) + +} +``` ## Directions Turn by turn directions from a start point to an end point including maneuvers and bearings @@ -74,38 +109,3 @@ Origin: &routing.Point{ } ``` -## Eta - -Get the eta for a route from origin to destination. The eta is an estimated time based on car routes - - -[https://m3o.com/routing/api#Eta](https://m3o.com/routing/api#Eta) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/routing" -) - -// Get the eta for a route from origin to destination. The eta is an estimated time based on car routes -func EtaFromPointAtoPointB() { - routingService := routing.NewRoutingService(os.Getenv("M3O_API_TOKEN")) - rsp, err := routingService.Eta(&routing.EtaRequest{ - Destination: &routing.Point{ - Latitude: 52.529407, - Longitude: 13.397634, -}, -Origin: &routing.Point{ - Latitude: 52.517037, - Longitude: 13.38886, -}, - - }) - fmt.Println(rsp, err) - -} -``` diff --git a/examples/stream/README.md b/examples/stream/README.md index 80734bd..08f1f1a 100755 --- a/examples/stream/README.md +++ b/examples/stream/README.md @@ -4,6 +4,37 @@ An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/Stream/api](ht Endpoints: +## CreateChannel + +Create a channel with a given name and description. Channels are created automatically but +this allows you to specify a description that's persisted for the lifetime of the channel. + + +[https://m3o.com/stream/api#CreateChannel](https://m3o.com/stream/api#CreateChannel) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/stream" +) + +// Create a channel with a given name and description. Channels are created automatically but +// this allows you to specify a description that's persisted for the lifetime of the channel. +func CreateChannel() { + streamService := stream.NewStreamService(os.Getenv("M3O_API_TOKEN")) + rsp, err := streamService.CreateChannel(&stream.CreateChannelRequest{ + Description: "The channel for all things", +Name: "general", + + }) + fmt.Println(rsp, err) + +} +``` ## SendMessage Send a message to the stream. @@ -88,34 +119,3 @@ func ListChannels() { } ``` -## CreateChannel - -Create a channel with a given name and description. Channels are created automatically but -this allows you to specify a description that's persisted for the lifetime of the channel. - - -[https://m3o.com/stream/api#CreateChannel](https://m3o.com/stream/api#CreateChannel) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/stream" -) - -// Create a channel with a given name and description. Channels are created automatically but -// this allows you to specify a description that's persisted for the lifetime of the channel. -func CreateChannel() { - streamService := stream.NewStreamService(os.Getenv("M3O_API_TOKEN")) - rsp, err := streamService.CreateChannel(&stream.CreateChannelRequest{ - Description: "The channel for all things", -Name: "general", - - }) - fmt.Println(rsp, err) - -} -``` diff --git a/examples/twitter/README.md b/examples/twitter/README.md index e099911..15ebde2 100755 --- a/examples/twitter/README.md +++ b/examples/twitter/README.md @@ -4,35 +4,6 @@ An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/Twitter/api](h Endpoints: -## Timeline - -Get the timeline for a given user - - -[https://m3o.com/twitter/api#Timeline](https://m3o.com/twitter/api#Timeline) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/twitter" -) - -// Get the timeline for a given user -func GetAtwitterTimeline() { - twitterService := twitter.NewTwitterService(os.Getenv("M3O_API_TOKEN")) - rsp, err := twitterService.Timeline(&twitter.TimelineRequest{ - Limit: 1, -Username: "m3oservices", - - }) - fmt.Println(rsp, err) - -} -``` ## Search Search for tweets with a simple query @@ -116,3 +87,32 @@ func GetAusersTwitterProfile() { } ``` +## Timeline + +Get the timeline for a given user + + +[https://m3o.com/twitter/api#Timeline](https://m3o.com/twitter/api#Timeline) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/twitter" +) + +// Get the timeline for a given user +func GetAtwitterTimeline() { + twitterService := twitter.NewTwitterService(os.Getenv("M3O_API_TOKEN")) + rsp, err := twitterService.Timeline(&twitter.TimelineRequest{ + Limit: 1, +Username: "m3oservices", + + }) + fmt.Println(rsp, err) + +} +``` diff --git a/examples/user/README.md b/examples/user/README.md index 111bad0..f6e608d 100755 --- a/examples/user/README.md +++ b/examples/user/README.md @@ -4,6 +4,111 @@ An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/User/api](http Endpoints: +## 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: "sds34s34s34-s34s34-s43s43s34-s4s34s", + + }) + fmt.Println(rsp, err) + +} +``` +## SendVerificationEmail + +Send a verification email +to the user being signed up. Email from will be from 'support@m3o.com', +but you can provide the title and contents. +The verification link will be injected in to the email as a template variable, $micro_verification_link. +Example: 'Hi there, welcome onboard! Use the link below to verify your email: $micro_verification_link' +The variable will be replaced with an actual url that will look similar to this: +'https://user.m3o.com/user/verify?token=a-verification-token&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 the user being signed up. Email from will be from 'support@m3o.com', +// but you can provide the title and contents. +// The verification link will be injected in to the email as a template variable, $micro_verification_link. +// Example: 'Hi there, welcome onboard! Use the link below to verify your email: $micro_verification_link' +// The variable will be replaced with an actual url that will look similar to this: +// 'https://user.m3o.com/user/verify?token=a-verification-token&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) + +} +``` +## 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: "some-code-from-email", +ConfirmPassword: "newpass123", +NewPassword: "newpass123", + + }) + fmt.Println(rsp, err) + +} +``` ## Login Login using username or email. The response will return a new session for successful login, @@ -35,12 +140,12 @@ Password: "mySecretPass123", } ``` -## Logout +## Read -Logout a user account +Read an account by id, username or email. Only one need to be specified. -[https://m3o.com/user/api#Logout](https://m3o.com/user/api#Logout) +[https://m3o.com/user/api#Read](https://m3o.com/user/api#Read) ```go package example @@ -52,23 +157,23 @@ import( "go.m3o.com/user" ) -// Logout a user account -func LogAuserOut() { +// 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.Logout(&user.LogoutRequest{ - SessionId: "sds34s34s34-s34s34-s43s43s34-s4s34s", + rsp, err := userService.Read(&user.ReadRequest{ + Id: "usrid-1", }) fmt.Println(rsp, err) } ``` -## ReadSession +## Read -Read a session by the session id. In the event it has expired or is not found and error is returned. +Read an account by id, username or email. Only one need to be specified. -[https://m3o.com/user/api#ReadSession](https://m3o.com/user/api#ReadSession) +[https://m3o.com/user/api#Read](https://m3o.com/user/api#Read) ```go package example @@ -80,23 +185,23 @@ import( "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() { +// 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.ReadSession(&user.ReadSessionRequest{ - SessionId: "sds34s34s34-s34s34-s43s43s34-s4s34s", + rsp, err := userService.Read(&user.ReadRequest{ + Username: "usrname-1", }) fmt.Println(rsp, err) } ``` -## Create +## Read -Create a new user account. The email address and username for the account must be unique. +Read an account by id, username or email. Only one need to be specified. -[https://m3o.com/user/api#Create](https://m3o.com/user/api#Create) +[https://m3o.com/user/api#Read](https://m3o.com/user/api#Read) ```go package example @@ -108,74 +213,11 @@ import( "go.m3o.com/user" ) -// Create a new user account. The email address and username for the account must be unique. -func CreateAnAccount() { +// 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.Create(&user.CreateRequest{ + rsp, err := userService.Read(&user.ReadRequest{ Email: "joe@example.com", -Id: "usrid-1", -Password: "mySecretPass123", -Username: "usrname-1", - - }) - 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: "myEvenMoreSecretPass123", -NewPassword: "myEvenMoreSecretPass123", -OldPassword: "mySecretPass123", - - }) - 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: "some-code-from-email", -ConfirmPassword: "newpass123", -NewPassword: "newpass123", }) fmt.Println(rsp, err) @@ -270,6 +312,65 @@ func DeleteUserAccount() { }) 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: "sds34s34s34-s34s34-s43s43s34-s4s34s", + + }) + 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: "usrid-1", +Password: "mySecretPass123", +Username: "usrname-1", + + }) + fmt.Println(rsp, err) + } ``` ## Update @@ -301,12 +402,12 @@ Id: "usrid-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 @@ -318,114 +419,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: "usrid-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: "usrname-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 ReadAccountByEmail() { - userService := user.NewUserService(os.Getenv("M3O_API_TOKEN")) - rsp, err := userService.Read(&user.ReadRequest{ - Email: "joe@example.com", - - }) - fmt.Println(rsp, err) - -} -``` -## SendVerificationEmail - -Send a verification email -to the user being signed up. Email from will be from 'support@m3o.com', -but you can provide the title and contents. -The verification link will be injected in to the email as a template variable, $micro_verification_link. -Example: 'Hi there, welcome onboard! Use the link below to verify your email: $micro_verification_link' -The variable will be replaced with an actual url that will look similar to this: -'https://user.m3o.com/user/verify?token=a-verification-token&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 the user being signed up. Email from will be from 'support@m3o.com', -// but you can provide the title and contents. -// The verification link will be injected in to the email as a template variable, $micro_verification_link. -// Example: 'Hi there, welcome onboard! Use the link below to verify your email: $micro_verification_link' -// The variable will be replaced with an actual url that will look similar to this: -// 'https://user.m3o.com/user/verify?token=a-verification-token&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.UpdatePassword(&user.UpdatePasswordRequest{ + ConfirmPassword: "myEvenMoreSecretPass123", +NewPassword: "myEvenMoreSecretPass123", +OldPassword: "mySecretPass123", }) fmt.Println(rsp, err) diff --git a/examples/weather/README.md b/examples/weather/README.md index 4e71164..c29cb3d 100755 --- a/examples/weather/README.md +++ b/examples/weather/README.md @@ -4,6 +4,34 @@ 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 @@ -33,31 +61,3 @@ 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/user/user.go b/user/user.go index e09e16a..7746b20 100755 --- a/user/user.go +++ b/user/user.go @@ -237,12 +237,14 @@ type SendPasswordResetEmailResponse struct { } type SendVerificationEmailRequest struct { + // email address to send the verification code Email string `json:"email"` FailureRedirectUrl string `json:"failureRedirectUrl"` // Display name of the sender for the email. Note: the email address will still be 'support@m3o.com' FromName string `json:"fromName"` RedirectUrl string `json:"redirectUrl"` - Subject string `json:"subject"` + // subject of the email + Subject string `json:"subject"` // Text content of the email. Don't forget to include the string '$micro_verification_link' which will be replaced by the real verification link // HTML emails are not available currently. TextContent string `json:"textContent"`