diff --git a/examples/notes/README.md b/examples/notes/README.md index 7ebdf0d..81a5075 100755 --- a/examples/notes/README.md +++ b/examples/notes/README.md @@ -4,6 +4,32 @@ An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/Notes/api](htt Endpoints: +## List + +List all the notes + + +[https://m3o.com/notes/api#List](https://m3o.com/notes/api#List) + +```go +package example + +import( + "fmt" + "os" + + "go.m3o.com/notes" +) + +// List all the notes +func ListAllNotes() { + notesService := notes.NewNotesService(os.Getenv("M3O_API_TOKEN")) + rsp, err := notesService.List(¬es.ListRequest{ + + }) + fmt.Println(rsp, err) +} +``` ## Update Update a note @@ -144,29 +170,3 @@ func ReadAnote() { fmt.Println(rsp, err) } ``` -## List - -List all the notes - - -[https://m3o.com/notes/api#List](https://m3o.com/notes/api#List) - -```go -package example - -import( - "fmt" - "os" - - "go.m3o.com/notes" -) - -// List all the notes -func ListAllNotes() { - notesService := notes.NewNotesService(os.Getenv("M3O_API_TOKEN")) - rsp, err := notesService.List(¬es.ListRequest{ - - }) - fmt.Println(rsp, err) -} -``` diff --git a/examples/notes/create/createANote/main.go b/examples/notes/create/createANote/main.go index 56ab7ca..92aecbf 100755 --- a/examples/notes/create/createANote/main.go +++ b/examples/notes/create/createANote/main.go @@ -15,4 +15,5 @@ func main() { Title: "New Note", }) fmt.Println(rsp, err) + } diff --git a/examples/notes/delete/deleteANote/main.go b/examples/notes/delete/deleteANote/main.go index a102cb0..edff5b7 100755 --- a/examples/notes/delete/deleteANote/main.go +++ b/examples/notes/delete/deleteANote/main.go @@ -14,4 +14,5 @@ func main() { Id: "63c0cdf8-2121-11ec-a881-0242e36f037a", }) fmt.Println(rsp, err) + } diff --git a/examples/notes/events/subscribeToEvents/main.go b/examples/notes/events/subscribeToEvents/main.go index c9008bc..4f67395 100755 --- a/examples/notes/events/subscribeToEvents/main.go +++ b/examples/notes/events/subscribeToEvents/main.go @@ -10,8 +10,22 @@ import ( // Subscribe to notes events func main() { notesService := notes.NewNotesService(os.Getenv("M3O_API_TOKEN")) - rsp, err := notesService.Events(¬es.EventsRequest{ + + stream, err := notesService.Events(¬es.EventsRequest{ Id: "63c0cdf8-2121-11ec-a881-0242e36f037a", }) - fmt.Println(rsp, err) + 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/notes/list/listAllNotes/main.go b/examples/notes/list/listAllNotes/main.go index 9fc1dca..0c89c17 100755 --- a/examples/notes/list/listAllNotes/main.go +++ b/examples/notes/list/listAllNotes/main.go @@ -12,4 +12,5 @@ func main() { notesService := notes.NewNotesService(os.Getenv("M3O_API_TOKEN")) rsp, err := notesService.List(¬es.ListRequest{}) fmt.Println(rsp, err) + } diff --git a/examples/notes/read/readANote/main.go b/examples/notes/read/readANote/main.go index 8c292bf..7068056 100755 --- a/examples/notes/read/readANote/main.go +++ b/examples/notes/read/readANote/main.go @@ -14,4 +14,5 @@ func main() { Id: "63c0cdf8-2121-11ec-a881-0242e36f037a", }) fmt.Println(rsp, err) + } diff --git a/examples/notes/update/updateANote/main.go b/examples/notes/update/updateANote/main.go index c2fbc16..3f3bbe4 100755 --- a/examples/notes/update/updateANote/main.go +++ b/examples/notes/update/updateANote/main.go @@ -18,4 +18,5 @@ func main() { }, }) fmt.Println(rsp, err) + } diff --git a/m3o.go b/m3o.go index 20bc035..fe52eb1 100755 --- a/m3o.go +++ b/m3o.go @@ -1,148 +1,19 @@ package m3o import ( - "go.m3o.com/address" - "go.m3o.com/answer" - "go.m3o.com/cache" - "go.m3o.com/crypto" - "go.m3o.com/currency" - "go.m3o.com/db" - "go.m3o.com/email" - "go.m3o.com/emoji" - "go.m3o.com/evchargers" - "go.m3o.com/event" - "go.m3o.com/file" - "go.m3o.com/forex" - "go.m3o.com/function" - "go.m3o.com/geocoding" - "go.m3o.com/gifs" - "go.m3o.com/google" - "go.m3o.com/helloworld" - "go.m3o.com/holidays" - "go.m3o.com/id" - "go.m3o.com/image" - "go.m3o.com/ip" - "go.m3o.com/location" - "go.m3o.com/mq" "go.m3o.com/notes" - "go.m3o.com/otp" - "go.m3o.com/postcode" - "go.m3o.com/prayer" - "go.m3o.com/qr" - "go.m3o.com/quran" - "go.m3o.com/routing" - "go.m3o.com/rss" - "go.m3o.com/sentiment" - "go.m3o.com/sms" - "go.m3o.com/stock" - "go.m3o.com/stream" - "go.m3o.com/sunnah" - "go.m3o.com/thumbnail" - "go.m3o.com/time" - "go.m3o.com/twitter" - "go.m3o.com/url" - "go.m3o.com/user" - "go.m3o.com/vehicle" - "go.m3o.com/weather" - "go.m3o.com/youtube" ) func NewClient(token string) *Client { return &Client{ token: token, - AddressService: address.NewAddressService(token), - AnswerService: answer.NewAnswerService(token), - CacheService: cache.NewCacheService(token), - CryptoService: crypto.NewCryptoService(token), - CurrencyService: currency.NewCurrencyService(token), - DbService: db.NewDbService(token), - EmailService: email.NewEmailService(token), - EmojiService: emoji.NewEmojiService(token), - EvchargersService: evchargers.NewEvchargersService(token), - EventService: event.NewEventService(token), - FileService: file.NewFileService(token), - ForexService: forex.NewForexService(token), - FunctionService: function.NewFunctionService(token), - GeocodingService: geocoding.NewGeocodingService(token), - GifsService: gifs.NewGifsService(token), - GoogleService: google.NewGoogleService(token), - HelloworldService: helloworld.NewHelloworldService(token), - HolidaysService: holidays.NewHolidaysService(token), - IdService: id.NewIdService(token), - ImageService: image.NewImageService(token), - IpService: ip.NewIpService(token), - LocationService: location.NewLocationService(token), - MqService: mq.NewMqService(token), - NotesService: notes.NewNotesService(token), - OtpService: otp.NewOtpService(token), - PostcodeService: postcode.NewPostcodeService(token), - PrayerService: prayer.NewPrayerService(token), - QrService: qr.NewQrService(token), - QuranService: quran.NewQuranService(token), - RoutingService: routing.NewRoutingService(token), - RssService: rss.NewRssService(token), - SentimentService: sentiment.NewSentimentService(token), - SmsService: sms.NewSmsService(token), - StockService: stock.NewStockService(token), - StreamService: stream.NewStreamService(token), - SunnahService: sunnah.NewSunnahService(token), - ThumbnailService: thumbnail.NewThumbnailService(token), - TimeService: time.NewTimeService(token), - TwitterService: twitter.NewTwitterService(token), - UrlService: url.NewUrlService(token), - UserService: user.NewUserService(token), - VehicleService: vehicle.NewVehicleService(token), - WeatherService: weather.NewWeatherService(token), - YoutubeService: youtube.NewYoutubeService(token), + NotesService: notes.NewNotesService(token), } } type Client struct { token string - AddressService *address.AddressService - AnswerService *answer.AnswerService - CacheService *cache.CacheService - CryptoService *crypto.CryptoService - CurrencyService *currency.CurrencyService - DbService *db.DbService - EmailService *email.EmailService - EmojiService *emoji.EmojiService - EvchargersService *evchargers.EvchargersService - EventService *event.EventService - FileService *file.FileService - ForexService *forex.ForexService - FunctionService *function.FunctionService - GeocodingService *geocoding.GeocodingService - GifsService *gifs.GifsService - GoogleService *google.GoogleService - HelloworldService *helloworld.HelloworldService - HolidaysService *holidays.HolidaysService - IdService *id.IdService - ImageService *image.ImageService - IpService *ip.IpService - LocationService *location.LocationService - MqService *mq.MqService - NotesService *notes.NotesService - OtpService *otp.OtpService - PostcodeService *postcode.PostcodeService - PrayerService *prayer.PrayerService - QrService *qr.QrService - QuranService *quran.QuranService - RoutingService *routing.RoutingService - RssService *rss.RssService - SentimentService *sentiment.SentimentService - SmsService *sms.SmsService - StockService *stock.StockService - StreamService *stream.StreamService - SunnahService *sunnah.SunnahService - ThumbnailService *thumbnail.ThumbnailService - TimeService *time.TimeService - TwitterService *twitter.TwitterService - UrlService *url.UrlService - UserService *user.UserService - VehicleService *vehicle.VehicleService - WeatherService *weather.WeatherService - YoutubeService *youtube.YoutubeService + NotesService *notes.NotesService } diff --git a/notes/notes.go b/notes/notes.go index c036e07..5e2e157 100755 --- a/notes/notes.go +++ b/notes/notes.go @@ -18,38 +18,66 @@ type NotesService struct { // Create a new note func (t *NotesService) Create(request *CreateRequest) (*CreateResponse, error) { + rsp := &CreateResponse{} return rsp, t.client.Call("notes", "Create", request, rsp) + } // Delete a note func (t *NotesService) Delete(request *DeleteRequest) (*DeleteResponse, error) { + rsp := &DeleteResponse{} return rsp, t.client.Call("notes", "Delete", request, rsp) + } // Subscribe to notes events -func (t *NotesService) Events(request *EventsRequest) (*EventsResponse, error) { - rsp := &EventsResponse{} - return rsp, t.client.Call("notes", "Events", request, rsp) +func (t *NotesService) Events(request *EventsRequest) (*EventsResponseStream, error) { + stream, err := t.client.Stream("notes", "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 notes func (t *NotesService) List(request *ListRequest) (*ListResponse, error) { + rsp := &ListResponse{} return rsp, t.client.Call("notes", "List", request, rsp) + } // Read a note func (t *NotesService) Read(request *ReadRequest) (*ReadResponse, error) { + rsp := &ReadResponse{} return rsp, t.client.Call("notes", "Read", request, rsp) + } // Update a note func (t *NotesService) Update(request *UpdateRequest) (*UpdateResponse, error) { + rsp := &UpdateResponse{} return rsp, t.client.Call("notes", "Update", request, rsp) + } type CreateRequest struct {