mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-11 19:04:35 +00:00
Generate clients (#206)
This commit is contained in:
40
.github/workflows/publish.yml
vendored
40
.github/workflows/publish.yml
vendored
@@ -1,7 +1,5 @@
|
||||
name: Publish APIs & Clients
|
||||
on:
|
||||
push:
|
||||
branches: [master]
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
docs:
|
||||
@@ -57,6 +55,7 @@ jobs:
|
||||
|
||||
- name: Generate openapi spec and publish the api
|
||||
working-directory: services
|
||||
if: github.ref == 'refs/heads/master'
|
||||
run: |
|
||||
go run cmd/publisher/main.go .
|
||||
env:
|
||||
@@ -66,33 +65,22 @@ jobs:
|
||||
env:
|
||||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
run: |
|
||||
pwd
|
||||
cd cmd/clients;
|
||||
go install;
|
||||
cd ../..;
|
||||
clients .
|
||||
|
||||
- uses: EndBug/add-and-commit@v7
|
||||
with:
|
||||
cwd: './services'
|
||||
|
||||
- name: npm install
|
||||
working-directory: services
|
||||
if: github.ref == 'refs/heads/master'
|
||||
run: |
|
||||
git status
|
||||
cd clients/ts;
|
||||
npm install
|
||||
npm run build
|
||||
|
||||
# publish to github first under micro/services
|
||||
# .npmrc has settings for it
|
||||
- uses: JS-DevTools/npm-publish@v1
|
||||
#if: github.ref == 'refs/heads/master'
|
||||
with:
|
||||
access: public
|
||||
package: services/clients/ts/package.json
|
||||
token: ${{ secrets.NPM_TOKEN }}
|
||||
|
||||
# publish to npm m3o/services
|
||||
- name: Change npm settings
|
||||
working-directory: services
|
||||
run: |
|
||||
rm clients/ts/.npmrc
|
||||
sed -i 's/micro/m3o/g' clients/ts/package.json
|
||||
|
||||
- uses: JS-DevTools/npm-publish@v1
|
||||
#if: github.ref == 'refs/heads/master'
|
||||
with:
|
||||
access: public
|
||||
package: services/clients/ts/package.json
|
||||
token: ${{ secrets.NPM_SITE_TOKEN }}
|
||||
npm publish --access public
|
||||
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -3,3 +3,5 @@ api-*.json
|
||||
redoc-static.html
|
||||
!docs
|
||||
node_modules
|
||||
postman.json
|
||||
.npmrc
|
||||
|
||||
57
clients/go/address/address.go
Executable file
57
clients/go/address/address.go
Executable file
@@ -0,0 +1,57 @@
|
||||
package address
|
||||
|
||||
import (
|
||||
"github.com/m3o/m3o-go/client"
|
||||
)
|
||||
|
||||
func NewAddressService(token string) *AddressService {
|
||||
return &AddressService{
|
||||
client: client.NewClient(&client.Options{
|
||||
Token: token,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
type AddressService struct {
|
||||
client *client.Client
|
||||
}
|
||||
|
||||
// Lookup a list of UK addresses by postcode
|
||||
func (t *AddressService) LookupPostcode(request *LookupPostcodeRequest) (*LookupPostcodeResponse, error) {
|
||||
rsp := &LookupPostcodeResponse{}
|
||||
return rsp, t.client.Call("address", "LookupPostcode", request, rsp)
|
||||
}
|
||||
|
||||
type LookupPostcodeRequest struct {
|
||||
// UK postcode e.g SW1A 2AA
|
||||
Postcode string `json:"postcode"`
|
||||
}
|
||||
|
||||
type LookupPostcodeResponse struct {
|
||||
Addresses []Record `json:"addresses"`
|
||||
}
|
||||
|
||||
type Record struct {
|
||||
// building name
|
||||
BuildingName string `json:"buildingName"`
|
||||
// the county
|
||||
County string `json:"county"`
|
||||
// line one of address
|
||||
LineOne string `json:"lineOne"`
|
||||
// line two of address
|
||||
LineTwo string `json:"lineTwo"`
|
||||
// dependent locality
|
||||
Locality string `json:"locality"`
|
||||
// organisation if present
|
||||
Organisation string `json:"organisation"`
|
||||
// the postcode
|
||||
Postcode string `json:"postcode"`
|
||||
// the premise
|
||||
Premise string `json:"premise"`
|
||||
// street name
|
||||
Street string `json:"street"`
|
||||
// the complete address
|
||||
Summary string `json:"summary"`
|
||||
// post town
|
||||
Town string `json:"town"`
|
||||
}
|
||||
37
clients/go/answer/answer.go
Executable file
37
clients/go/answer/answer.go
Executable file
@@ -0,0 +1,37 @@
|
||||
package answer
|
||||
|
||||
import (
|
||||
"github.com/m3o/m3o-go/client"
|
||||
)
|
||||
|
||||
func NewAnswerService(token string) *AnswerService {
|
||||
return &AnswerService{
|
||||
client: client.NewClient(&client.Options{
|
||||
Token: token,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
type AnswerService struct {
|
||||
client *client.Client
|
||||
}
|
||||
|
||||
// Ask a question and receive an instant answer
|
||||
func (t *AnswerService) Question(request *QuestionRequest) (*QuestionResponse, error) {
|
||||
rsp := &QuestionResponse{}
|
||||
return rsp, t.client.Call("answer", "Question", request, rsp)
|
||||
}
|
||||
|
||||
type QuestionRequest struct {
|
||||
// the question to answer
|
||||
Query string `json:"query"`
|
||||
}
|
||||
|
||||
type QuestionResponse struct {
|
||||
// the answer to your question
|
||||
Answer string `json:"answer"`
|
||||
// any related image
|
||||
Image string `json:"image"`
|
||||
// a related url
|
||||
Url string `json:"url"`
|
||||
}
|
||||
113
clients/go/cache/cache.go
vendored
Executable file
113
clients/go/cache/cache.go
vendored
Executable file
@@ -0,0 +1,113 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
"github.com/m3o/m3o-go/client"
|
||||
)
|
||||
|
||||
func NewCacheService(token string) *CacheService {
|
||||
return &CacheService{
|
||||
client: client.NewClient(&client.Options{
|
||||
Token: token,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
type CacheService struct {
|
||||
client *client.Client
|
||||
}
|
||||
|
||||
// Decrement a value (if it's a number)
|
||||
func (t *CacheService) Decrement(request *DecrementRequest) (*DecrementResponse, error) {
|
||||
rsp := &DecrementResponse{}
|
||||
return rsp, t.client.Call("cache", "Decrement", request, rsp)
|
||||
}
|
||||
|
||||
// Delete a value from the cache
|
||||
func (t *CacheService) Delete(request *DeleteRequest) (*DeleteResponse, error) {
|
||||
rsp := &DeleteResponse{}
|
||||
return rsp, t.client.Call("cache", "Delete", request, rsp)
|
||||
}
|
||||
|
||||
// Get an item from the cache by key
|
||||
func (t *CacheService) Get(request *GetRequest) (*GetResponse, error) {
|
||||
rsp := &GetResponse{}
|
||||
return rsp, t.client.Call("cache", "Get", request, rsp)
|
||||
}
|
||||
|
||||
// Increment a value (if it's a number)
|
||||
func (t *CacheService) Increment(request *IncrementRequest) (*IncrementResponse, error) {
|
||||
rsp := &IncrementResponse{}
|
||||
return rsp, t.client.Call("cache", "Increment", request, rsp)
|
||||
}
|
||||
|
||||
// Set an item in the cache. Overwrites any existing value already set.
|
||||
func (t *CacheService) Set(request *SetRequest) (*SetResponse, error) {
|
||||
rsp := &SetResponse{}
|
||||
return rsp, t.client.Call("cache", "Set", request, rsp)
|
||||
}
|
||||
|
||||
type DecrementRequest struct {
|
||||
// The key to decrement
|
||||
Key string `json:"key"`
|
||||
// The amount to decrement the value by
|
||||
Value int64 `json:"value"`
|
||||
}
|
||||
|
||||
type DecrementResponse struct {
|
||||
// The key decremented
|
||||
Key string `json:"key"`
|
||||
// The new value
|
||||
Value int64 `json:"value"`
|
||||
}
|
||||
|
||||
type DeleteRequest struct {
|
||||
// The key to delete
|
||||
Key string `json:"key"`
|
||||
}
|
||||
|
||||
type DeleteResponse struct {
|
||||
// Returns "ok" if successful
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
type GetRequest struct {
|
||||
// The key to retrieve
|
||||
Key string `json:"key"`
|
||||
}
|
||||
|
||||
type GetResponse struct {
|
||||
// The key
|
||||
Key string `json:"key"`
|
||||
// Time to live in seconds
|
||||
Ttl int64 `json:"ttl"`
|
||||
// The value
|
||||
Value string `json:"value"`
|
||||
}
|
||||
|
||||
type IncrementRequest struct {
|
||||
// The key to increment
|
||||
Key string `json:"key"`
|
||||
// The amount to increment the value by
|
||||
Value int64 `json:"value"`
|
||||
}
|
||||
|
||||
type IncrementResponse struct {
|
||||
// The key incremented
|
||||
Key string `json:"key"`
|
||||
// The new value
|
||||
Value int64 `json:"value"`
|
||||
}
|
||||
|
||||
type SetRequest struct {
|
||||
// The key to update
|
||||
Key string `json:"key"`
|
||||
// Time to live in seconds
|
||||
Ttl int64 `json:"ttl"`
|
||||
// The value to set
|
||||
Value string `json:"value"`
|
||||
}
|
||||
|
||||
type SetResponse struct {
|
||||
// Returns "ok" if successful
|
||||
Status string `json:"status"`
|
||||
}
|
||||
120
clients/go/crypto/crypto.go
Executable file
120
clients/go/crypto/crypto.go
Executable file
@@ -0,0 +1,120 @@
|
||||
package crypto
|
||||
|
||||
import (
|
||||
"github.com/m3o/m3o-go/client"
|
||||
)
|
||||
|
||||
func NewCryptoService(token string) *CryptoService {
|
||||
return &CryptoService{
|
||||
client: client.NewClient(&client.Options{
|
||||
Token: token,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
type CryptoService struct {
|
||||
client *client.Client
|
||||
}
|
||||
|
||||
// Returns the history for the previous close
|
||||
func (t *CryptoService) History(request *HistoryRequest) (*HistoryResponse, error) {
|
||||
rsp := &HistoryResponse{}
|
||||
return rsp, t.client.Call("crypto", "History", request, rsp)
|
||||
}
|
||||
|
||||
// Get news related to a currency
|
||||
func (t *CryptoService) News(request *NewsRequest) (*NewsResponse, error) {
|
||||
rsp := &NewsResponse{}
|
||||
return rsp, t.client.Call("crypto", "News", request, rsp)
|
||||
}
|
||||
|
||||
// Get the last price for a given crypto ticker
|
||||
func (t *CryptoService) Price(request *PriceRequest) (*PriceResponse, error) {
|
||||
rsp := &PriceResponse{}
|
||||
return rsp, t.client.Call("crypto", "Price", request, rsp)
|
||||
}
|
||||
|
||||
// Get the last quote for a given crypto ticker
|
||||
func (t *CryptoService) Quote(request *QuoteRequest) (*QuoteResponse, error) {
|
||||
rsp := &QuoteResponse{}
|
||||
return rsp, t.client.Call("crypto", "Quote", request, rsp)
|
||||
}
|
||||
|
||||
type Article struct {
|
||||
// the date published
|
||||
Date string `json:"date"`
|
||||
// its description
|
||||
Description string `json:"description"`
|
||||
// the source
|
||||
Source string `json:"source"`
|
||||
// title of the article
|
||||
Title string `json:"title"`
|
||||
// the source url
|
||||
Url string `json:"url"`
|
||||
}
|
||||
|
||||
type HistoryRequest struct {
|
||||
// the crypto symbol e.g BTCUSD
|
||||
Symbol string `json:"symbol"`
|
||||
}
|
||||
|
||||
type HistoryResponse struct {
|
||||
// the close price
|
||||
Close float64 `json:"close"`
|
||||
// the date
|
||||
Date string `json:"date"`
|
||||
// the peak price
|
||||
High float64 `json:"high"`
|
||||
// the low price
|
||||
Low float64 `json:"low"`
|
||||
// the open price
|
||||
Open float64 `json:"open"`
|
||||
// the crypto symbol
|
||||
Symbol string `json:"symbol"`
|
||||
// the volume
|
||||
Volume float64 `json:"volume"`
|
||||
}
|
||||
|
||||
type NewsRequest struct {
|
||||
// cryptocurrency ticker to request news for e.g BTC
|
||||
Symbol string `json:"symbol"`
|
||||
}
|
||||
|
||||
type NewsResponse struct {
|
||||
// list of articles
|
||||
Articles []Article `json:"articles"`
|
||||
// symbol requested for
|
||||
Symbol string `json:"symbol"`
|
||||
}
|
||||
|
||||
type PriceRequest struct {
|
||||
// the crypto symbol e.g BTCUSD
|
||||
Symbol string `json:"symbol"`
|
||||
}
|
||||
|
||||
type PriceResponse struct {
|
||||
// the last price
|
||||
Price float64 `json:"price"`
|
||||
// the crypto symbol e.g BTCUSD
|
||||
Symbol string `json:"symbol"`
|
||||
}
|
||||
|
||||
type QuoteRequest struct {
|
||||
// the crypto symbol e.g BTCUSD
|
||||
Symbol string `json:"symbol"`
|
||||
}
|
||||
|
||||
type QuoteResponse struct {
|
||||
// the asking price
|
||||
AskPrice float64 `json:"askPrice"`
|
||||
// the ask size
|
||||
AskSize float64 `json:"askSize"`
|
||||
// the bidding price
|
||||
BidPrice float64 `json:"bidPrice"`
|
||||
// the bid size
|
||||
BidSize float64 `json:"bidSize"`
|
||||
// the crypto symbol
|
||||
Symbol string `json:"symbol"`
|
||||
// the UTC timestamp of the quote
|
||||
Timestamp string `json:"timestamp"`
|
||||
}
|
||||
103
clients/go/currency/currency.go
Executable file
103
clients/go/currency/currency.go
Executable file
@@ -0,0 +1,103 @@
|
||||
package currency
|
||||
|
||||
import (
|
||||
"github.com/m3o/m3o-go/client"
|
||||
)
|
||||
|
||||
func NewCurrencyService(token string) *CurrencyService {
|
||||
return &CurrencyService{
|
||||
client: client.NewClient(&client.Options{
|
||||
Token: token,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
type CurrencyService struct {
|
||||
client *client.Client
|
||||
}
|
||||
|
||||
// Codes returns the supported currency codes for the API
|
||||
func (t *CurrencyService) Codes(request *CodesRequest) (*CodesResponse, error) {
|
||||
rsp := &CodesResponse{}
|
||||
return rsp, t.client.Call("currency", "Codes", request, rsp)
|
||||
}
|
||||
|
||||
// Convert returns the currency conversion rate between two pairs e.g USD/GBP
|
||||
func (t *CurrencyService) Convert(request *ConvertRequest) (*ConvertResponse, error) {
|
||||
rsp := &ConvertResponse{}
|
||||
return rsp, t.client.Call("currency", "Convert", request, rsp)
|
||||
}
|
||||
|
||||
// Returns the historic rates for a currency on a given date
|
||||
func (t *CurrencyService) History(request *HistoryRequest) (*HistoryResponse, error) {
|
||||
rsp := &HistoryResponse{}
|
||||
return rsp, t.client.Call("currency", "History", request, rsp)
|
||||
}
|
||||
|
||||
// Rates returns the currency rates for a given code e.g USD
|
||||
func (t *CurrencyService) Rates(request *RatesRequest) (*RatesResponse, error) {
|
||||
rsp := &RatesResponse{}
|
||||
return rsp, t.client.Call("currency", "Rates", request, rsp)
|
||||
}
|
||||
|
||||
type Code struct {
|
||||
// e.g United States Dollar
|
||||
Currency string `json:"currency"`
|
||||
// e.g USD
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type CodesRequest struct {
|
||||
}
|
||||
|
||||
type CodesResponse struct {
|
||||
Codes []Code `json:"codes"`
|
||||
}
|
||||
|
||||
type ConvertRequest struct {
|
||||
// optional amount to convert e.g 10.0
|
||||
Amount float64 `json:"amount"`
|
||||
// base code to convert from e.g USD
|
||||
From string `json:"from"`
|
||||
// target code to convert to e.g GBP
|
||||
To string `json:"to"`
|
||||
}
|
||||
|
||||
type ConvertResponse struct {
|
||||
// converted amount e.g 7.10
|
||||
Amount float64 `json:"amount"`
|
||||
// the base code e.g USD
|
||||
From string `json:"from"`
|
||||
// conversion rate e.g 0.71
|
||||
Rate float64 `json:"rate"`
|
||||
// the target code e.g GBP
|
||||
To string `json:"to"`
|
||||
}
|
||||
|
||||
type HistoryRequest struct {
|
||||
// currency code e.g USD
|
||||
Code string `json:"code"`
|
||||
// date formatted as YYYY-MM-DD
|
||||
Date string `json:"date"`
|
||||
}
|
||||
|
||||
type HistoryResponse struct {
|
||||
// The code of the request
|
||||
Code string `json:"code"`
|
||||
// The date requested
|
||||
Date string `json:"date"`
|
||||
// The rate for the day as code:rate
|
||||
Rates map[string]float64 `json:"rates"`
|
||||
}
|
||||
|
||||
type RatesRequest struct {
|
||||
// The currency code to get rates for e.g USD
|
||||
Code string `json:"code"`
|
||||
}
|
||||
|
||||
type RatesResponse struct {
|
||||
// The code requested e.g USD
|
||||
Code string `json:"code"`
|
||||
// The rates for the given code as key-value pairs code:rate
|
||||
Rates map[string]float64 `json:"rates"`
|
||||
}
|
||||
117
clients/go/db/db.go
Executable file
117
clients/go/db/db.go
Executable file
@@ -0,0 +1,117 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"github.com/m3o/m3o-go/client"
|
||||
)
|
||||
|
||||
func NewDbService(token string) *DbService {
|
||||
return &DbService{
|
||||
client: client.NewClient(&client.Options{
|
||||
Token: token,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
type DbService struct {
|
||||
client *client.Client
|
||||
}
|
||||
|
||||
// Create a record in the database. Optionally include an "id" field otherwise it's set automatically.
|
||||
func (t *DbService) Create(request *CreateRequest) (*CreateResponse, error) {
|
||||
rsp := &CreateResponse{}
|
||||
return rsp, t.client.Call("db", "Create", request, rsp)
|
||||
}
|
||||
|
||||
// Delete a record in the database by id.
|
||||
func (t *DbService) Delete(request *DeleteRequest) (*DeleteResponse, error) {
|
||||
rsp := &DeleteResponse{}
|
||||
return rsp, t.client.Call("db", "Delete", request, rsp)
|
||||
}
|
||||
|
||||
// Read data from a table. Lookup can be by ID or via querying any field in the record.
|
||||
func (t *DbService) Read(request *ReadRequest) (*ReadResponse, error) {
|
||||
rsp := &ReadResponse{}
|
||||
return rsp, t.client.Call("db", "Read", request, rsp)
|
||||
}
|
||||
|
||||
// Truncate the records in a table
|
||||
func (t *DbService) Truncate(request *TruncateRequest) (*TruncateResponse, error) {
|
||||
rsp := &TruncateResponse{}
|
||||
return rsp, t.client.Call("db", "Truncate", request, rsp)
|
||||
}
|
||||
|
||||
// Update a record in the database. Include an "id" in the record to update.
|
||||
func (t *DbService) Update(request *UpdateRequest) (*UpdateResponse, error) {
|
||||
rsp := &UpdateResponse{}
|
||||
return rsp, t.client.Call("db", "Update", request, rsp)
|
||||
}
|
||||
|
||||
type CreateRequest struct {
|
||||
// JSON encoded record or records (can be array or object)
|
||||
Record map[string]interface{} `json:"record"`
|
||||
// Optional table name. Defaults to 'default'
|
||||
Table string `json:"table"`
|
||||
}
|
||||
|
||||
type CreateResponse struct {
|
||||
// The id of the record (either specified or automatically created)
|
||||
Id string `json:"id"`
|
||||
}
|
||||
|
||||
type DeleteRequest struct {
|
||||
// id of the record
|
||||
Id string `json:"id"`
|
||||
// Optional table name. Defaults to 'default'
|
||||
Table string `json:"table"`
|
||||
}
|
||||
|
||||
type DeleteResponse struct {
|
||||
}
|
||||
|
||||
type ReadRequest struct {
|
||||
// Read by id. Equivalent to 'id == "your-id"'
|
||||
Id string `json:"id"`
|
||||
// Maximum number of records to return. Default limit is 25.
|
||||
// Maximum limit is 1000. Anything higher will return an error.
|
||||
Limit int32 `json:"limit"`
|
||||
Offset int32 `json:"offset"`
|
||||
// 'asc' (default), 'desc'
|
||||
Order string `json:"order"`
|
||||
// field name to order by
|
||||
OrderBy string `json:"orderBy"`
|
||||
// Examples: 'age >= 18', 'age >= 18 and verified == true'
|
||||
// Comparison operators: '==', '!=', '<', '>', '<=', '>='
|
||||
// Logical operator: 'and'
|
||||
// Dot access is supported, eg: 'user.age == 11'
|
||||
// Accessing list elements is not supported yet.
|
||||
Query string `json:"query"`
|
||||
// Optional table name. Defaults to 'default'
|
||||
Table string `json:"table"`
|
||||
}
|
||||
|
||||
type ReadResponse struct {
|
||||
// JSON encoded records
|
||||
Records []map[string]interface{} `json:"records"`
|
||||
}
|
||||
|
||||
type TruncateRequest struct {
|
||||
// Optional table name. Defaults to 'default'
|
||||
Table string `json:"table"`
|
||||
}
|
||||
|
||||
type TruncateResponse struct {
|
||||
// The table truncated
|
||||
Table string `json:"table"`
|
||||
}
|
||||
|
||||
type UpdateRequest struct {
|
||||
// The id of the record. If not specified it is inferred from the 'id' field of the record
|
||||
Id string `json:"id"`
|
||||
// record, JSON object
|
||||
Record map[string]interface{} `json:"record"`
|
||||
// Optional table name. Defaults to 'default'
|
||||
Table string `json:"table"`
|
||||
}
|
||||
|
||||
type UpdateResponse struct {
|
||||
}
|
||||
41
clients/go/email/email.go
Executable file
41
clients/go/email/email.go
Executable file
@@ -0,0 +1,41 @@
|
||||
package email
|
||||
|
||||
import (
|
||||
"github.com/m3o/m3o-go/client"
|
||||
)
|
||||
|
||||
func NewEmailService(token string) *EmailService {
|
||||
return &EmailService{
|
||||
client: client.NewClient(&client.Options{
|
||||
Token: token,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
type EmailService struct {
|
||||
client *client.Client
|
||||
}
|
||||
|
||||
// Send an email by passing in from, to, subject, and a text or html body
|
||||
func (t *EmailService) Send(request *SendRequest) (*SendResponse, error) {
|
||||
rsp := &SendResponse{}
|
||||
return rsp, t.client.Call("email", "Send", request, rsp)
|
||||
}
|
||||
|
||||
type SendRequest struct {
|
||||
// the display name of the sender
|
||||
From string `json:"from"`
|
||||
// the html body
|
||||
HtmlBody string `json:"htmlBody"`
|
||||
// an optional reply to email address
|
||||
ReplyTo string `json:"replyTo"`
|
||||
// the email subject
|
||||
Subject string `json:"subject"`
|
||||
// the text body
|
||||
TextBody string `json:"textBody"`
|
||||
// the email address of the recipient
|
||||
To string `json:"to"`
|
||||
}
|
||||
|
||||
type SendResponse struct {
|
||||
}
|
||||
86
clients/go/emoji/emoji.go
Executable file
86
clients/go/emoji/emoji.go
Executable file
@@ -0,0 +1,86 @@
|
||||
package emoji
|
||||
|
||||
import (
|
||||
"github.com/m3o/m3o-go/client"
|
||||
)
|
||||
|
||||
func NewEmojiService(token string) *EmojiService {
|
||||
return &EmojiService{
|
||||
client: client.NewClient(&client.Options{
|
||||
Token: token,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
type EmojiService struct {
|
||||
client *client.Client
|
||||
}
|
||||
|
||||
// Find an emoji by its alias e.g :beer:
|
||||
func (t *EmojiService) Find(request *FindRequest) (*FindResponse, error) {
|
||||
rsp := &FindResponse{}
|
||||
return rsp, t.client.Call("emoji", "Find", request, rsp)
|
||||
}
|
||||
|
||||
// Get the flag for a country. Requires country code e.g GB for great britain
|
||||
func (t *EmojiService) Flag(request *FlagRequest) (*FlagResponse, error) {
|
||||
rsp := &FlagResponse{}
|
||||
return rsp, t.client.Call("emoji", "Flag", request, rsp)
|
||||
}
|
||||
|
||||
// Print text and renders the emojis with aliases e.g
|
||||
// let's grab a :beer: becomes let's grab a 🍺
|
||||
func (t *EmojiService) Print(request *PrintRequest) (*PrintResponse, error) {
|
||||
rsp := &PrintResponse{}
|
||||
return rsp, t.client.Call("emoji", "Print", request, rsp)
|
||||
}
|
||||
|
||||
// Send an emoji to anyone via SMS. Messages are sent in the form '<message> Sent from <from>'
|
||||
func (t *EmojiService) Send(request *SendRequest) (*SendResponse, error) {
|
||||
rsp := &SendResponse{}
|
||||
return rsp, t.client.Call("emoji", "Send", request, rsp)
|
||||
}
|
||||
|
||||
type FindRequest struct {
|
||||
// the alias code e.g :beer:
|
||||
Alias string `json:"alias"`
|
||||
}
|
||||
|
||||
type FindResponse struct {
|
||||
// the unicode emoji 🍺
|
||||
Emoji string `json:"emoji"`
|
||||
}
|
||||
|
||||
type FlagRequest struct {
|
||||
// country code e.g GB
|
||||
Code string `json:"code"`
|
||||
}
|
||||
|
||||
type FlagResponse struct {
|
||||
// the emoji flag
|
||||
Flag string `json:"flag"`
|
||||
}
|
||||
|
||||
type PrintRequest struct {
|
||||
// text including any alias e.g let's grab a :beer:
|
||||
Text string `json:"text"`
|
||||
}
|
||||
|
||||
type PrintResponse struct {
|
||||
// text with rendered emojis
|
||||
Text string `json:"text"`
|
||||
}
|
||||
|
||||
type SendRequest struct {
|
||||
// the name of the sender from e.g Alice
|
||||
From string `json:"from"`
|
||||
// message to send including emoji aliases
|
||||
Message string `json:"message"`
|
||||
// phone number to send to (including international dialing code)
|
||||
To string `json:"to"`
|
||||
}
|
||||
|
||||
type SendResponse struct {
|
||||
// whether or not it succeeded
|
||||
Success bool `json:"success"`
|
||||
}
|
||||
107
clients/go/file/file.go
Executable file
107
clients/go/file/file.go
Executable file
@@ -0,0 +1,107 @@
|
||||
package file
|
||||
|
||||
import (
|
||||
"github.com/m3o/m3o-go/client"
|
||||
)
|
||||
|
||||
func NewFileService(token string) *FileService {
|
||||
return &FileService{
|
||||
client: client.NewClient(&client.Options{
|
||||
Token: token,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
type FileService struct {
|
||||
client *client.Client
|
||||
}
|
||||
|
||||
// Delete a file by project name/path
|
||||
func (t *FileService) Delete(request *DeleteRequest) (*DeleteResponse, error) {
|
||||
rsp := &DeleteResponse{}
|
||||
return rsp, t.client.Call("file", "Delete", request, rsp)
|
||||
}
|
||||
|
||||
// List files by their project and optionally a path.
|
||||
func (t *FileService) List(request *ListRequest) (*ListResponse, error) {
|
||||
rsp := &ListResponse{}
|
||||
return rsp, t.client.Call("file", "List", request, rsp)
|
||||
}
|
||||
|
||||
// Read a file by path
|
||||
func (t *FileService) Read(request *ReadRequest) (*ReadResponse, error) {
|
||||
rsp := &ReadResponse{}
|
||||
return rsp, t.client.Call("file", "Read", request, rsp)
|
||||
}
|
||||
|
||||
// Save a file
|
||||
func (t *FileService) Save(request *SaveRequest) (*SaveResponse, error) {
|
||||
rsp := &SaveResponse{}
|
||||
return rsp, t.client.Call("file", "Save", request, rsp)
|
||||
}
|
||||
|
||||
type BatchSaveRequest struct {
|
||||
Files []Record `json:"files"`
|
||||
}
|
||||
|
||||
type BatchSaveResponse struct {
|
||||
}
|
||||
|
||||
type DeleteRequest struct {
|
||||
// Path to the file
|
||||
Path string `json:"path"`
|
||||
// The project name
|
||||
Project string `json:"project"`
|
||||
}
|
||||
|
||||
type DeleteResponse struct {
|
||||
}
|
||||
|
||||
type ListRequest struct {
|
||||
// Defaults to '/', ie. lists all files in a project.
|
||||
// Supply path to a folder if you want to list
|
||||
// files inside that folder
|
||||
// eg. '/docs'
|
||||
Path string `json:"path"`
|
||||
// Project, required for listing.
|
||||
Project string `json:"project"`
|
||||
}
|
||||
|
||||
type ListResponse struct {
|
||||
Files []Record `json:"files"`
|
||||
}
|
||||
|
||||
type ReadRequest struct {
|
||||
// Path to the file
|
||||
Path string `json:"path"`
|
||||
// Project name
|
||||
Project string `json:"project"`
|
||||
}
|
||||
|
||||
type ReadResponse struct {
|
||||
// Returns the file
|
||||
File *Record `json:"file"`
|
||||
}
|
||||
|
||||
type Record struct {
|
||||
// File contents
|
||||
Content string `json:"content"`
|
||||
// Time the file was created e.g 2021-05-20T13:37:21Z
|
||||
Created string `json:"created"`
|
||||
// Any other associated metadata as a map of key-value pairs
|
||||
Metadata map[string]string `json:"metadata"`
|
||||
// Path to file or folder eg. '/documents/text-files/file.txt'.
|
||||
Path string `json:"path"`
|
||||
// A custom project to group files
|
||||
// eg. file-of-mywebsite.com
|
||||
Project string `json:"project"`
|
||||
// Time the file was updated e.g 2021-05-20T13:37:21Z
|
||||
Updated string `json:"updated"`
|
||||
}
|
||||
|
||||
type SaveRequest struct {
|
||||
File *Record `json:"file"`
|
||||
}
|
||||
|
||||
type SaveResponse struct {
|
||||
}
|
||||
85
clients/go/forex/forex.go
Executable file
85
clients/go/forex/forex.go
Executable file
@@ -0,0 +1,85 @@
|
||||
package forex
|
||||
|
||||
import (
|
||||
"github.com/m3o/m3o-go/client"
|
||||
)
|
||||
|
||||
func NewForexService(token string) *ForexService {
|
||||
return &ForexService{
|
||||
client: client.NewClient(&client.Options{
|
||||
Token: token,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
type ForexService struct {
|
||||
client *client.Client
|
||||
}
|
||||
|
||||
// Returns the data for the previous close
|
||||
func (t *ForexService) History(request *HistoryRequest) (*HistoryResponse, error) {
|
||||
rsp := &HistoryResponse{}
|
||||
return rsp, t.client.Call("forex", "History", request, rsp)
|
||||
}
|
||||
|
||||
// Get the latest price for a given forex ticker
|
||||
func (t *ForexService) Price(request *PriceRequest) (*PriceResponse, error) {
|
||||
rsp := &PriceResponse{}
|
||||
return rsp, t.client.Call("forex", "Price", request, rsp)
|
||||
}
|
||||
|
||||
// Get the latest quote for the forex
|
||||
func (t *ForexService) Quote(request *QuoteRequest) (*QuoteResponse, error) {
|
||||
rsp := &QuoteResponse{}
|
||||
return rsp, t.client.Call("forex", "Quote", request, rsp)
|
||||
}
|
||||
|
||||
type HistoryRequest struct {
|
||||
// the forex symbol e.g GBPUSD
|
||||
Symbol string `json:"symbol"`
|
||||
}
|
||||
|
||||
type HistoryResponse struct {
|
||||
// the close price
|
||||
Close float64 `json:"close"`
|
||||
// the date
|
||||
Date string `json:"date"`
|
||||
// the peak price
|
||||
High float64 `json:"high"`
|
||||
// the low price
|
||||
Low float64 `json:"low"`
|
||||
// the open price
|
||||
Open float64 `json:"open"`
|
||||
// the forex symbol
|
||||
Symbol string `json:"symbol"`
|
||||
// the volume
|
||||
Volume float64 `json:"volume"`
|
||||
}
|
||||
|
||||
type PriceRequest struct {
|
||||
// forex symbol e.g GBPUSD
|
||||
Symbol string `json:"symbol"`
|
||||
}
|
||||
|
||||
type PriceResponse struct {
|
||||
// the last price
|
||||
Price float64 `json:"price"`
|
||||
// the forex symbol e.g GBPUSD
|
||||
Symbol string `json:"symbol"`
|
||||
}
|
||||
|
||||
type QuoteRequest struct {
|
||||
// the forex symbol e.g GBPUSD
|
||||
Symbol string `json:"symbol"`
|
||||
}
|
||||
|
||||
type QuoteResponse struct {
|
||||
// the asking price
|
||||
AskPrice float64 `json:"askPrice"`
|
||||
// the bidding price
|
||||
BidPrice float64 `json:"bidPrice"`
|
||||
// the forex symbol
|
||||
Symbol string `json:"symbol"`
|
||||
// the UTC timestamp of the quote
|
||||
Timestamp string `json:"timestamp"`
|
||||
}
|
||||
64
clients/go/geocoding/geocoding.go
Executable file
64
clients/go/geocoding/geocoding.go
Executable file
@@ -0,0 +1,64 @@
|
||||
package geocoding
|
||||
|
||||
import (
|
||||
"github.com/m3o/m3o-go/client"
|
||||
)
|
||||
|
||||
func NewGeocodingService(token string) *GeocodingService {
|
||||
return &GeocodingService{
|
||||
client: client.NewClient(&client.Options{
|
||||
Token: token,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
type GeocodingService struct {
|
||||
client *client.Client
|
||||
}
|
||||
|
||||
// Lookup returns a geocoded address including normalized address and gps coordinates. All fields are optional, provide more to get more accurate results
|
||||
func (t *GeocodingService) Lookup(request *LookupRequest) (*LookupResponse, error) {
|
||||
rsp := &LookupResponse{}
|
||||
return rsp, t.client.Call("geocoding", "Lookup", request, rsp)
|
||||
}
|
||||
|
||||
// Reverse lookup an address from gps coordinates
|
||||
func (t *GeocodingService) Reverse(request *ReverseRequest) (*ReverseResponse, error) {
|
||||
rsp := &ReverseResponse{}
|
||||
return rsp, t.client.Call("geocoding", "Reverse", request, rsp)
|
||||
}
|
||||
|
||||
type Address struct {
|
||||
City string `json:"city"`
|
||||
Country string `json:"country"`
|
||||
LineOne string `json:"lineOne"`
|
||||
LineTwo string `json:"lineTwo"`
|
||||
Postcode string `json:"postcode"`
|
||||
}
|
||||
|
||||
type Location struct {
|
||||
Latitude float64 `json:"latitude"`
|
||||
Longitude float64 `json:"longitude"`
|
||||
}
|
||||
|
||||
type LookupRequest struct {
|
||||
Address string `json:"address"`
|
||||
City string `json:"city"`
|
||||
Country string `json:"country"`
|
||||
Postcode string `json:"postcode"`
|
||||
}
|
||||
|
||||
type LookupResponse struct {
|
||||
Address *Address `json:"address"`
|
||||
Location *Location `json:"location"`
|
||||
}
|
||||
|
||||
type ReverseRequest struct {
|
||||
Latitude float64 `json:"latitude"`
|
||||
Longitude float64 `json:"longitude"`
|
||||
}
|
||||
|
||||
type ReverseResponse struct {
|
||||
Address *Address `json:"address"`
|
||||
Location *Location `json:"location"`
|
||||
}
|
||||
47
clients/go/helloworld/helloworld.go
Executable file
47
clients/go/helloworld/helloworld.go
Executable file
@@ -0,0 +1,47 @@
|
||||
package helloworld
|
||||
|
||||
import (
|
||||
"github.com/m3o/m3o-go/client"
|
||||
)
|
||||
|
||||
func NewHelloworldService(token string) *HelloworldService {
|
||||
return &HelloworldService{
|
||||
client: client.NewClient(&client.Options{
|
||||
Token: token,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
type HelloworldService struct {
|
||||
client *client.Client
|
||||
}
|
||||
|
||||
// Call returns a personalised "Hello $name" response
|
||||
func (t *HelloworldService) Call(request *CallRequest) (*CallResponse, error) {
|
||||
rsp := &CallResponse{}
|
||||
return rsp, t.client.Call("helloworld", "Call", request, rsp)
|
||||
}
|
||||
|
||||
// Stream returns a stream of "Hello $name" responses
|
||||
func (t *HelloworldService) Stream(request *StreamRequest) (*StreamResponse, error) {
|
||||
rsp := &StreamResponse{}
|
||||
return rsp, t.client.Call("helloworld", "Stream", request, rsp)
|
||||
}
|
||||
|
||||
type CallRequest struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type CallResponse struct {
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
type StreamRequest struct {
|
||||
// the number of messages to send back
|
||||
Messages int64 `json:"messages"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type StreamResponse struct {
|
||||
Message string `json:"message"`
|
||||
}
|
||||
48
clients/go/id/id.go
Executable file
48
clients/go/id/id.go
Executable file
@@ -0,0 +1,48 @@
|
||||
package id
|
||||
|
||||
import (
|
||||
"github.com/m3o/m3o-go/client"
|
||||
)
|
||||
|
||||
func NewIdService(token string) *IdService {
|
||||
return &IdService{
|
||||
client: client.NewClient(&client.Options{
|
||||
Token: token,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
type IdService struct {
|
||||
client *client.Client
|
||||
}
|
||||
|
||||
// Generate a unique ID. Defaults to uuid.
|
||||
func (t *IdService) Generate(request *GenerateRequest) (*GenerateResponse, error) {
|
||||
rsp := &GenerateResponse{}
|
||||
return rsp, t.client.Call("id", "Generate", request, rsp)
|
||||
}
|
||||
|
||||
// List the types of IDs available. No query params needed.
|
||||
func (t *IdService) Types(request *TypesRequest) (*TypesResponse, error) {
|
||||
rsp := &TypesResponse{}
|
||||
return rsp, t.client.Call("id", "Types", request, rsp)
|
||||
}
|
||||
|
||||
type GenerateRequest struct {
|
||||
// type of id e.g uuid, shortid, snowflake (64 bit), bigflake (128 bit)
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
type GenerateResponse struct {
|
||||
// the unique id generated
|
||||
Id string `json:"id"`
|
||||
// the type of id generated
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
type TypesRequest struct {
|
||||
}
|
||||
|
||||
type TypesResponse struct {
|
||||
Types []string `json:"types"`
|
||||
}
|
||||
115
clients/go/image/image.go
Executable file
115
clients/go/image/image.go
Executable file
@@ -0,0 +1,115 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"github.com/m3o/m3o-go/client"
|
||||
)
|
||||
|
||||
func NewImageService(token string) *ImageService {
|
||||
return &ImageService{
|
||||
client: client.NewClient(&client.Options{
|
||||
Token: token,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
type ImageService struct {
|
||||
client *client.Client
|
||||
}
|
||||
|
||||
// Convert an image from one format (jpeg, png etc.) to an other either on the fly (from base64 to base64),
|
||||
// or by uploading the conversion result.
|
||||
func (t *ImageService) Convert(request *ConvertRequest) (*ConvertResponse, error) {
|
||||
rsp := &ConvertResponse{}
|
||||
return rsp, t.client.Call("image", "Convert", request, rsp)
|
||||
}
|
||||
|
||||
// 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.
|
||||
func (t *ImageService) Resize(request *ResizeRequest) (*ResizeResponse, error) {
|
||||
rsp := &ResizeResponse{}
|
||||
return rsp, t.client.Call("image", "Resize", request, rsp)
|
||||
}
|
||||
|
||||
// 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.
|
||||
func (t *ImageService) Upload(request *UploadRequest) (*UploadResponse, error) {
|
||||
rsp := &UploadResponse{}
|
||||
return rsp, t.client.Call("image", "Upload", request, rsp)
|
||||
}
|
||||
|
||||
type ConvertRequest struct {
|
||||
// base64 encoded image to resize,
|
||||
// ie. "data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="
|
||||
Base64 string `json:"base64"`
|
||||
// output name of the image including extension, ie. "cat.png"
|
||||
Name string `json:"name"`
|
||||
// make output a URL and not a base64 response
|
||||
OutputUrl bool `json:"outputUrl"`
|
||||
// url of the image to resize
|
||||
Url string `json:"url"`
|
||||
}
|
||||
|
||||
type ConvertResponse struct {
|
||||
Base64 string `json:"base64"`
|
||||
Url string `json:"url"`
|
||||
}
|
||||
|
||||
type CropOptions struct {
|
||||
// Crop anchor point: "top", "top left", "top right",
|
||||
// "left", "center", "right"
|
||||
// "bottom left", "bottom", "bottom right".
|
||||
// Optional. Defaults to center.
|
||||
Anchor string `json:"anchor"`
|
||||
// height to crop to
|
||||
Height int32 `json:"height"`
|
||||
// width to crop to
|
||||
Width int32 `json:"width"`
|
||||
}
|
||||
|
||||
type Point struct {
|
||||
X int32 `json:"x"`
|
||||
Y int32 `json:"y"`
|
||||
}
|
||||
|
||||
type Rectangle struct {
|
||||
Max *Point `json:"max"`
|
||||
Min *Point `json:"min"`
|
||||
}
|
||||
|
||||
type ResizeRequest struct {
|
||||
// base64 encoded image to resize,
|
||||
// ie. "data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="
|
||||
Base64 string `json:"base64"`
|
||||
// optional crop options
|
||||
// if provided, after resize, the image
|
||||
// will be cropped
|
||||
CropOptions *CropOptions `json:"cropOptions"`
|
||||
Height int64 `json:"height"`
|
||||
// output name of the image including extension, ie. "cat.png"
|
||||
Name string `json:"name"`
|
||||
// make output a URL and not a base64 response
|
||||
OutputUrl bool `json:"outputUrl"`
|
||||
// url of the image to resize
|
||||
Url string `json:"url"`
|
||||
Width int64 `json:"width"`
|
||||
}
|
||||
|
||||
type ResizeResponse struct {
|
||||
Base64 string `json:"base64"`
|
||||
Url string `json:"url"`
|
||||
}
|
||||
|
||||
type UploadRequest struct {
|
||||
// Base64 encoded image to upload,
|
||||
// ie. "data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="
|
||||
Base64 string `json:"base64"`
|
||||
// Output name of the image including extension, ie. "cat.png"
|
||||
Name string `json:"name"`
|
||||
// URL of the image to upload
|
||||
Url string `json:"url"`
|
||||
}
|
||||
|
||||
type UploadResponse struct {
|
||||
Url string `json:"url"`
|
||||
}
|
||||
47
clients/go/ip/ip.go
Executable file
47
clients/go/ip/ip.go
Executable file
@@ -0,0 +1,47 @@
|
||||
package ip
|
||||
|
||||
import (
|
||||
"github.com/m3o/m3o-go/client"
|
||||
)
|
||||
|
||||
func NewIpService(token string) *IpService {
|
||||
return &IpService{
|
||||
client: client.NewClient(&client.Options{
|
||||
Token: token,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
type IpService struct {
|
||||
client *client.Client
|
||||
}
|
||||
|
||||
// Lookup the geolocation information for an IP address
|
||||
func (t *IpService) Lookup(request *LookupRequest) (*LookupResponse, error) {
|
||||
rsp := &LookupResponse{}
|
||||
return rsp, t.client.Call("ip", "Lookup", request, rsp)
|
||||
}
|
||||
|
||||
type LookupRequest struct {
|
||||
// IP to lookup
|
||||
Ip string `json:"ip"`
|
||||
}
|
||||
|
||||
type LookupResponse struct {
|
||||
// Autonomous system number
|
||||
Asn int32 `json:"asn"`
|
||||
// Name of the city
|
||||
City string `json:"city"`
|
||||
// Name of the continent
|
||||
Continent string `json:"continent"`
|
||||
// Name of the country
|
||||
Country string `json:"country"`
|
||||
// IP of the query
|
||||
Ip string `json:"ip"`
|
||||
// Latitude e.g 52.523219
|
||||
Latitude float64 `json:"latitude"`
|
||||
// Longitude e.g 13.428555
|
||||
Longitude float64 `json:"longitude"`
|
||||
// Timezone e.g Europe/Rome
|
||||
Timezone string `json:"timezone"`
|
||||
}
|
||||
78
clients/go/location/location.go
Executable file
78
clients/go/location/location.go
Executable file
@@ -0,0 +1,78 @@
|
||||
package location
|
||||
|
||||
import (
|
||||
"github.com/m3o/m3o-go/client"
|
||||
)
|
||||
|
||||
func NewLocationService(token string) *LocationService {
|
||||
return &LocationService{
|
||||
client: client.NewClient(&client.Options{
|
||||
Token: token,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
type LocationService struct {
|
||||
client *client.Client
|
||||
}
|
||||
|
||||
// Read an entity by its ID
|
||||
func (t *LocationService) Read(request *ReadRequest) (*ReadResponse, error) {
|
||||
rsp := &ReadResponse{}
|
||||
return rsp, t.client.Call("location", "Read", request, rsp)
|
||||
}
|
||||
|
||||
// Save an entity's current position
|
||||
func (t *LocationService) Save(request *SaveRequest) (*SaveResponse, error) {
|
||||
rsp := &SaveResponse{}
|
||||
return rsp, t.client.Call("location", "Save", request, rsp)
|
||||
}
|
||||
|
||||
// Search for entities in a given radius
|
||||
func (t *LocationService) Search(request *SearchRequest) (*SearchResponse, error) {
|
||||
rsp := &SearchResponse{}
|
||||
return rsp, t.client.Call("location", "Search", request, rsp)
|
||||
}
|
||||
|
||||
type Entity struct {
|
||||
Id string `json:"id"`
|
||||
Location *Point `json:"location"`
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
type Point struct {
|
||||
Latitude float64 `json:"latitude"`
|
||||
Longitude float64 `json:"longitude"`
|
||||
Timestamp int64 `json:"timestamp"`
|
||||
}
|
||||
|
||||
type ReadRequest struct {
|
||||
// the entity id
|
||||
Id string `json:"id"`
|
||||
}
|
||||
|
||||
type ReadResponse struct {
|
||||
Entity *Entity `json:"entity"`
|
||||
}
|
||||
|
||||
type SaveRequest struct {
|
||||
Entity *Entity `json:"entity"`
|
||||
}
|
||||
|
||||
type SaveResponse struct {
|
||||
}
|
||||
|
||||
type SearchRequest struct {
|
||||
// Central position to search from
|
||||
Center *Point `json:"center"`
|
||||
// Maximum number of entities to return
|
||||
NumEntities int64 `json:"numEntities"`
|
||||
// radius in meters
|
||||
Radius float64 `json:"radius"`
|
||||
// type of entities to filter
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
type SearchResponse struct {
|
||||
Entities []Entity `json:"entities"`
|
||||
}
|
||||
106
clients/go/m3o.go
Executable file
106
clients/go/m3o.go
Executable file
@@ -0,0 +1,106 @@
|
||||
package m3o
|
||||
|
||||
import (
|
||||
"github.com/micro/services/clients/go/address"
|
||||
"github.com/micro/services/clients/go/answer"
|
||||
"github.com/micro/services/clients/go/cache"
|
||||
"github.com/micro/services/clients/go/crypto"
|
||||
"github.com/micro/services/clients/go/currency"
|
||||
"github.com/micro/services/clients/go/db"
|
||||
"github.com/micro/services/clients/go/email"
|
||||
"github.com/micro/services/clients/go/emoji"
|
||||
"github.com/micro/services/clients/go/file"
|
||||
"github.com/micro/services/clients/go/forex"
|
||||
"github.com/micro/services/clients/go/geocoding"
|
||||
"github.com/micro/services/clients/go/helloworld"
|
||||
"github.com/micro/services/clients/go/id"
|
||||
"github.com/micro/services/clients/go/image"
|
||||
"github.com/micro/services/clients/go/ip"
|
||||
"github.com/micro/services/clients/go/location"
|
||||
"github.com/micro/services/clients/go/otp"
|
||||
"github.com/micro/services/clients/go/postcode"
|
||||
"github.com/micro/services/clients/go/quran"
|
||||
"github.com/micro/services/clients/go/routing"
|
||||
"github.com/micro/services/clients/go/rss"
|
||||
"github.com/micro/services/clients/go/sentiment"
|
||||
"github.com/micro/services/clients/go/sms"
|
||||
"github.com/micro/services/clients/go/stock"
|
||||
"github.com/micro/services/clients/go/stream"
|
||||
"github.com/micro/services/clients/go/thumbnail"
|
||||
"github.com/micro/services/clients/go/time"
|
||||
"github.com/micro/services/clients/go/url"
|
||||
"github.com/micro/services/clients/go/user"
|
||||
"github.com/micro/services/clients/go/weather"
|
||||
)
|
||||
|
||||
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),
|
||||
FileService: file.NewFileService(token),
|
||||
ForexService: forex.NewForexService(token),
|
||||
GeocodingService: geocoding.NewGeocodingService(token),
|
||||
HelloworldService: helloworld.NewHelloworldService(token),
|
||||
IdService: id.NewIdService(token),
|
||||
ImageService: image.NewImageService(token),
|
||||
IpService: ip.NewIpService(token),
|
||||
LocationService: location.NewLocationService(token),
|
||||
OtpService: otp.NewOtpService(token),
|
||||
PostcodeService: postcode.NewPostcodeService(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),
|
||||
ThumbnailService: thumbnail.NewThumbnailService(token),
|
||||
TimeService: time.NewTimeService(token),
|
||||
UrlService: url.NewUrlService(token),
|
||||
UserService: user.NewUserService(token),
|
||||
WeatherService: weather.NewWeatherService(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
|
||||
FileService *file.FileService
|
||||
ForexService *forex.ForexService
|
||||
GeocodingService *geocoding.GeocodingService
|
||||
HelloworldService *helloworld.HelloworldService
|
||||
IdService *id.IdService
|
||||
ImageService *image.ImageService
|
||||
IpService *ip.IpService
|
||||
LocationService *location.LocationService
|
||||
OtpService *otp.OtpService
|
||||
PostcodeService *postcode.PostcodeService
|
||||
QuranService *quran.QuranService
|
||||
RoutingService *routing.RoutingService
|
||||
RssService *rss.RssService
|
||||
SentimentService *sentiment.SentimentService
|
||||
SmsService *sms.SmsService
|
||||
StockService *stock.StockService
|
||||
StreamService *stream.StreamService
|
||||
ThumbnailService *thumbnail.ThumbnailService
|
||||
TimeService *time.TimeService
|
||||
UrlService *url.UrlService
|
||||
UserService *user.UserService
|
||||
WeatherService *weather.WeatherService
|
||||
}
|
||||
55
clients/go/otp/otp.go
Executable file
55
clients/go/otp/otp.go
Executable file
@@ -0,0 +1,55 @@
|
||||
package otp
|
||||
|
||||
import (
|
||||
"github.com/m3o/m3o-go/client"
|
||||
)
|
||||
|
||||
func NewOtpService(token string) *OtpService {
|
||||
return &OtpService{
|
||||
client: client.NewClient(&client.Options{
|
||||
Token: token,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
type OtpService struct {
|
||||
client *client.Client
|
||||
}
|
||||
|
||||
// Generate an OTP (one time pass) code
|
||||
func (t *OtpService) Generate(request *GenerateRequest) (*GenerateResponse, error) {
|
||||
rsp := &GenerateResponse{}
|
||||
return rsp, t.client.Call("otp", "Generate", request, rsp)
|
||||
}
|
||||
|
||||
// Validate the OTP code
|
||||
func (t *OtpService) Validate(request *ValidateRequest) (*ValidateResponse, error) {
|
||||
rsp := &ValidateResponse{}
|
||||
return rsp, t.client.Call("otp", "Validate", request, rsp)
|
||||
}
|
||||
|
||||
type GenerateRequest struct {
|
||||
// expiration in seconds (default: 60)
|
||||
Expiry int64 `json:"expiry"`
|
||||
// unique id, email or user to generate an OTP for
|
||||
Id string `json:"id"`
|
||||
// number of characters (default: 6)
|
||||
Size int64 `json:"size"`
|
||||
}
|
||||
|
||||
type GenerateResponse struct {
|
||||
// one time pass code
|
||||
Code string `json:"code"`
|
||||
}
|
||||
|
||||
type ValidateRequest struct {
|
||||
// one time pass code to validate
|
||||
Code string `json:"code"`
|
||||
// unique id, email or user for which the code was generated
|
||||
Id string `json:"id"`
|
||||
}
|
||||
|
||||
type ValidateResponse struct {
|
||||
// returns true if the code is valid for the ID
|
||||
Success bool `json:"success"`
|
||||
}
|
||||
87
clients/go/postcode/postcode.go
Executable file
87
clients/go/postcode/postcode.go
Executable file
@@ -0,0 +1,87 @@
|
||||
package postcode
|
||||
|
||||
import (
|
||||
"github.com/m3o/m3o-go/client"
|
||||
)
|
||||
|
||||
func NewPostcodeService(token string) *PostcodeService {
|
||||
return &PostcodeService{
|
||||
client: client.NewClient(&client.Options{
|
||||
Token: token,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
type PostcodeService struct {
|
||||
client *client.Client
|
||||
}
|
||||
|
||||
// Lookup a postcode to retrieve the related region, county, etc
|
||||
func (t *PostcodeService) Lookup(request *LookupRequest) (*LookupResponse, error) {
|
||||
rsp := &LookupResponse{}
|
||||
return rsp, t.client.Call("postcode", "Lookup", request, rsp)
|
||||
}
|
||||
|
||||
// Return a random postcode and its related info
|
||||
func (t *PostcodeService) Random(request *RandomRequest) (*RandomResponse, error) {
|
||||
rsp := &RandomResponse{}
|
||||
return rsp, t.client.Call("postcode", "Random", request, rsp)
|
||||
}
|
||||
|
||||
// Validate a postcode.
|
||||
func (t *PostcodeService) Validate(request *ValidateRequest) (*ValidateResponse, error) {
|
||||
rsp := &ValidateResponse{}
|
||||
return rsp, t.client.Call("postcode", "Validate", request, rsp)
|
||||
}
|
||||
|
||||
type LookupRequest struct {
|
||||
// UK postcode e.g SW1A 2AA
|
||||
Postcode string `json:"postcode"`
|
||||
}
|
||||
|
||||
type LookupResponse struct {
|
||||
// country e.g United Kingdom
|
||||
Country string `json:"country"`
|
||||
// e.g Westminster
|
||||
District string `json:"district"`
|
||||
// e.g 51.50354
|
||||
Latitude float64 `json:"latitude"`
|
||||
// e.g -0.127695
|
||||
Longitude float64 `json:"longitude"`
|
||||
// UK postcode e.g SW1A 2AA
|
||||
Postcode string `json:"postcode"`
|
||||
// related region e.g London
|
||||
Region string `json:"region"`
|
||||
// e.g St James's
|
||||
Ward string `json:"ward"`
|
||||
}
|
||||
|
||||
type RandomRequest struct {
|
||||
}
|
||||
|
||||
type RandomResponse struct {
|
||||
// country e.g United Kingdom
|
||||
Country string `json:"country"`
|
||||
// e.g Westminster
|
||||
District string `json:"district"`
|
||||
// e.g 51.50354
|
||||
Latitude float64 `json:"latitude"`
|
||||
// e.g -0.127695
|
||||
Longitude float64 `json:"longitude"`
|
||||
// UK postcode e.g SW1A 2AA
|
||||
Postcode string `json:"postcode"`
|
||||
// related region e.g London
|
||||
Region string `json:"region"`
|
||||
// e.g St James's
|
||||
Ward string `json:"ward"`
|
||||
}
|
||||
|
||||
type ValidateRequest struct {
|
||||
// UK postcode e.g SW1A 2AA
|
||||
Postcode string `json:"postcode"`
|
||||
}
|
||||
|
||||
type ValidateResponse struct {
|
||||
// Is the postcode valid (true) or not (false)
|
||||
Valid bool `json:"valid"`
|
||||
}
|
||||
216
clients/go/quran/quran.go
Executable file
216
clients/go/quran/quran.go
Executable file
@@ -0,0 +1,216 @@
|
||||
package quran
|
||||
|
||||
import (
|
||||
"github.com/m3o/m3o-go/client"
|
||||
)
|
||||
|
||||
func NewQuranService(token string) *QuranService {
|
||||
return &QuranService{
|
||||
client: client.NewClient(&client.Options{
|
||||
Token: token,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
type QuranService struct {
|
||||
client *client.Client
|
||||
}
|
||||
|
||||
// List the Chapters (surahs) of the Quran
|
||||
func (t *QuranService) Chapters(request *ChaptersRequest) (*ChaptersResponse, error) {
|
||||
rsp := &ChaptersResponse{}
|
||||
return rsp, t.client.Call("quran", "Chapters", request, rsp)
|
||||
}
|
||||
|
||||
// Search the Quran for any form of query or questions
|
||||
func (t *QuranService) Search(request *SearchRequest) (*SearchResponse, error) {
|
||||
rsp := &SearchResponse{}
|
||||
return rsp, t.client.Call("quran", "Search", request, rsp)
|
||||
}
|
||||
|
||||
// Get a summary for a given chapter (surah)
|
||||
func (t *QuranService) Summary(request *SummaryRequest) (*SummaryResponse, error) {
|
||||
rsp := &SummaryResponse{}
|
||||
return rsp, t.client.Call("quran", "Summary", request, rsp)
|
||||
}
|
||||
|
||||
// Lookup the verses (ayahs) for a chapter
|
||||
func (t *QuranService) Verses(request *VersesRequest) (*VersesResponse, error) {
|
||||
rsp := &VersesResponse{}
|
||||
return rsp, t.client.Call("quran", "Verses", request, rsp)
|
||||
}
|
||||
|
||||
type Chapter struct {
|
||||
// The arabic name of the chapter
|
||||
ArabicName string `json:"arabicName"`
|
||||
// The complex name of the chapter
|
||||
ComplexName string `json:"complexName"`
|
||||
// The id of the chapter as a number e.g 1
|
||||
Id int32 `json:"id"`
|
||||
// The simple name of the chapter
|
||||
Name string `json:"name"`
|
||||
// The pages from and to e.g 1, 1
|
||||
Pages []int32 `json:"pages"`
|
||||
// Should the chapter start with bismillah
|
||||
PrefixBismillah bool `json:"prefixBismillah"`
|
||||
// The order in which it was revealed
|
||||
RevelationOrder int32 `json:"revelationOrder"`
|
||||
// The place of revelation
|
||||
RevelationPlace string `json:"revelationPlace"`
|
||||
// The translated name
|
||||
TranslatedName string `json:"translatedName"`
|
||||
// The number of verses in the chapter
|
||||
Verses int32 `json:"verses"`
|
||||
}
|
||||
|
||||
type ChaptersRequest struct {
|
||||
// Specify the language e.g en
|
||||
Language string `json:"language"`
|
||||
}
|
||||
|
||||
type ChaptersResponse struct {
|
||||
Chapters []Chapter `json:"chapters"`
|
||||
}
|
||||
|
||||
type Interpretation struct {
|
||||
// The unique id of the interpretation
|
||||
Id int32 `json:"id"`
|
||||
// The source of the interpretation
|
||||
Source string `json:"source"`
|
||||
// The translated text
|
||||
Text string `json:"text"`
|
||||
}
|
||||
|
||||
type Result struct {
|
||||
// The associated arabic text
|
||||
Text string `json:"text"`
|
||||
// The related translations to the text
|
||||
Translations []Translation `json:"translations"`
|
||||
// The unique verse id across the Quran
|
||||
VerseId int32 `json:"verseId"`
|
||||
// The verse key e.g 1:1
|
||||
VerseKey string `json:"verseKey"`
|
||||
}
|
||||
|
||||
type SearchRequest struct {
|
||||
// The language for translation
|
||||
Language string `json:"language"`
|
||||
// The number of results to return
|
||||
Limit int32 `json:"limit"`
|
||||
// The pagination number
|
||||
Page int32 `json:"page"`
|
||||
// The query to ask
|
||||
Query string `json:"query"`
|
||||
}
|
||||
|
||||
type SearchResponse struct {
|
||||
// The current page
|
||||
Page int32 `json:"page"`
|
||||
// The question asked
|
||||
Query string `json:"query"`
|
||||
// The results for the query
|
||||
Results []Result `json:"results"`
|
||||
// The total pages
|
||||
TotalPages int32 `json:"totalPages"`
|
||||
// The total results returned
|
||||
TotalResults int32 `json:"totalResults"`
|
||||
}
|
||||
|
||||
type SummaryRequest struct {
|
||||
// The chapter id e.g 1
|
||||
Chapter int32 `json:"chapter"`
|
||||
// Specify the language e.g en
|
||||
Language string `json:"language"`
|
||||
}
|
||||
|
||||
type SummaryResponse struct {
|
||||
// The chapter id
|
||||
Chapter int32 `json:"chapter"`
|
||||
// The source of the summary
|
||||
Source string `json:"source"`
|
||||
// The short summary for the chapter
|
||||
Summary string `json:"summary"`
|
||||
// The full description for the chapter
|
||||
Text string `json:"text"`
|
||||
}
|
||||
|
||||
type Translation struct {
|
||||
// The unique id of the translation
|
||||
Id int32 `json:"id"`
|
||||
// The source of the translation
|
||||
Source string `json:"source"`
|
||||
// The translated text
|
||||
Text string `json:"text"`
|
||||
}
|
||||
|
||||
type Verse struct {
|
||||
// The unique id of the verse in the whole book
|
||||
Id int32 `json:"id"`
|
||||
// The interpretations of the verse
|
||||
Interpretations []Translation `json:"interpretations"`
|
||||
// The key of this verse (chapter:verse) e.g 1:1
|
||||
Key string `json:"key"`
|
||||
// The verse number in this chapter
|
||||
Number int32 `json:"number"`
|
||||
// The page of the Quran this verse is on
|
||||
Page int32 `json:"page"`
|
||||
// The arabic text for this verse
|
||||
Text string `json:"text"`
|
||||
// The basic translation of the verse
|
||||
TranslatedText string `json:"translatedText"`
|
||||
// The alternative translations for the verse
|
||||
Translations []Translation `json:"translations"`
|
||||
// The phonetic transliteration from arabic
|
||||
Transliteration string `json:"transliteration"`
|
||||
// The individual words within the verse (Ayah)
|
||||
Words []Word `json:"words"`
|
||||
}
|
||||
|
||||
type VersesRequest struct {
|
||||
// The chapter id to retrieve
|
||||
Chapter int32 `json:"chapter"`
|
||||
// Return the interpretation (tafsir)
|
||||
Interpret bool `json:"interpret"`
|
||||
// The language of translation
|
||||
Language string `json:"language"`
|
||||
// The verses per page
|
||||
Limit int32 `json:"limit"`
|
||||
// The page number to request
|
||||
Page int32 `json:"page"`
|
||||
// Return alternate translations
|
||||
Translate bool `json:"translate"`
|
||||
// Return the individual words with the verses
|
||||
Words bool `json:"words"`
|
||||
}
|
||||
|
||||
type VersesResponse struct {
|
||||
// The chapter requested
|
||||
Chapter int32 `json:"chapter"`
|
||||
// The page requested
|
||||
Page int32 `json:"page"`
|
||||
// The total pages
|
||||
TotalPages int32 `json:"totalPages"`
|
||||
// The verses on the page
|
||||
Verses []Verse `json:"verses"`
|
||||
}
|
||||
|
||||
type Word struct {
|
||||
// The character type e.g word, end
|
||||
CharType string `json:"charType"`
|
||||
// The QCF v2 font code
|
||||
Code string `json:"code"`
|
||||
// The id of the word within the verse
|
||||
Id int32 `json:"id"`
|
||||
// The line number
|
||||
Line int32 `json:"line"`
|
||||
// The page number
|
||||
Page int32 `json:"page"`
|
||||
// The position of the word
|
||||
Position int32 `json:"position"`
|
||||
// The arabic text for this word
|
||||
Text string `json:"text"`
|
||||
// The translated text
|
||||
Translation string `json:"translation"`
|
||||
// The transliteration text
|
||||
Transliteration string `json:"transliteration"`
|
||||
}
|
||||
129
clients/go/routing/routing.go
Executable file
129
clients/go/routing/routing.go
Executable file
@@ -0,0 +1,129 @@
|
||||
package routing
|
||||
|
||||
import (
|
||||
"github.com/m3o/m3o-go/client"
|
||||
)
|
||||
|
||||
func NewRoutingService(token string) *RoutingService {
|
||||
return &RoutingService{
|
||||
client: client.NewClient(&client.Options{
|
||||
Token: token,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
type RoutingService struct {
|
||||
client *client.Client
|
||||
}
|
||||
|
||||
// Turn by turn directions from a start point to an end point including maneuvers and bearings
|
||||
func (t *RoutingService) Directions(request *DirectionsRequest) (*DirectionsResponse, error) {
|
||||
rsp := &DirectionsResponse{}
|
||||
return rsp, t.client.Call("routing", "Directions", request, rsp)
|
||||
}
|
||||
|
||||
// Get the eta for a route from origin to destination. The eta is an estimated time based on car routes
|
||||
func (t *RoutingService) Eta(request *EtaRequest) (*EtaResponse, error) {
|
||||
rsp := &EtaResponse{}
|
||||
return rsp, t.client.Call("routing", "Eta", request, rsp)
|
||||
}
|
||||
|
||||
// Retrieve a route as a simple list of gps points along with total distance and estimated duration
|
||||
func (t *RoutingService) Route(request *RouteRequest) (*RouteResponse, error) {
|
||||
rsp := &RouteResponse{}
|
||||
return rsp, t.client.Call("routing", "Route", request, rsp)
|
||||
}
|
||||
|
||||
type Direction struct {
|
||||
// distance to travel in meters
|
||||
Distance float64 `json:"distance"`
|
||||
// duration to travel in seconds
|
||||
Duration float64 `json:"duration"`
|
||||
// human readable instruction
|
||||
Instruction string `json:"instruction"`
|
||||
// intersections on route
|
||||
Intersections []Intersection `json:"intersections"`
|
||||
// maneuver to take
|
||||
Maneuver *Maneuver `json:"maneuver"`
|
||||
// street name or location
|
||||
Name string `json:"name"`
|
||||
// alternative reference
|
||||
Reference string `json:"reference"`
|
||||
}
|
||||
|
||||
type DirectionsRequest struct {
|
||||
// The destination of the journey
|
||||
Destination *Point `json:"destination"`
|
||||
// The staring point for the journey
|
||||
Origin *Point `json:"origin"`
|
||||
}
|
||||
|
||||
type DirectionsResponse struct {
|
||||
// Turn by turn directions
|
||||
Directions []Direction `json:"directions"`
|
||||
// Estimated distance of the route in meters
|
||||
Distance float64 `json:"distance"`
|
||||
// Estimated duration of the route in seconds
|
||||
Duration float64 `json:"duration"`
|
||||
// The waypoints on the route
|
||||
Waypoints []Waypoint `json:"waypoints"`
|
||||
}
|
||||
|
||||
type EtaRequest struct {
|
||||
// The end point for the eta calculation
|
||||
Destination *Point `json:"destination"`
|
||||
// The starting point for the eta calculation
|
||||
Origin *Point `json:"origin"`
|
||||
// speed in kilometers
|
||||
Speed float64 `json:"speed"`
|
||||
// type of transport. Only "car" is supported currently.
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
type EtaResponse struct {
|
||||
// eta in seconds
|
||||
Duration float64 `json:"duration"`
|
||||
}
|
||||
|
||||
type Intersection struct {
|
||||
Bearings []float64 `json:"bearings"`
|
||||
Location *Point `json:"location"`
|
||||
}
|
||||
|
||||
type Maneuver struct {
|
||||
Action string `json:"action"`
|
||||
BearingAfter float64 `json:"bearingAfter"`
|
||||
BearingBefore float64 `json:"bearingBefore"`
|
||||
Direction string `json:"direction"`
|
||||
Location *Point `json:"location"`
|
||||
}
|
||||
|
||||
type Point struct {
|
||||
// Lat e.g 52.523219
|
||||
Latitude float64 `json:"latitude"`
|
||||
// Long e.g 13.428555
|
||||
Longitude float64 `json:"longitude"`
|
||||
}
|
||||
|
||||
type RouteRequest struct {
|
||||
// Point of destination for the trip
|
||||
Destination *Point `json:"destination"`
|
||||
// Point of origin for the trip
|
||||
Origin *Point `json:"origin"`
|
||||
}
|
||||
|
||||
type RouteResponse struct {
|
||||
// estimated distance in meters
|
||||
Distance float64 `json:"distance"`
|
||||
// estimated duration in seconds
|
||||
Duration float64 `json:"duration"`
|
||||
// waypoints on the route
|
||||
Waypoints []Waypoint `json:"waypoints"`
|
||||
}
|
||||
|
||||
type Waypoint struct {
|
||||
// gps point coordinates
|
||||
Location *Point `json:"location"`
|
||||
// street name or related reference
|
||||
Name string `json:"name"`
|
||||
}
|
||||
114
clients/go/rss/rss.go
Executable file
114
clients/go/rss/rss.go
Executable file
@@ -0,0 +1,114 @@
|
||||
package rss
|
||||
|
||||
import (
|
||||
"github.com/m3o/m3o-go/client"
|
||||
)
|
||||
|
||||
func NewRssService(token string) *RssService {
|
||||
return &RssService{
|
||||
client: client.NewClient(&client.Options{
|
||||
Token: token,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
type RssService struct {
|
||||
client *client.Client
|
||||
}
|
||||
|
||||
// Add a new RSS feed with a name, url, and category
|
||||
func (t *RssService) Add(request *AddRequest) (*AddResponse, error) {
|
||||
rsp := &AddResponse{}
|
||||
return rsp, t.client.Call("rss", "Add", request, rsp)
|
||||
}
|
||||
|
||||
// Get an RSS feed by name. If no name is given, all feeds are returned. Default limit is 25 entries.
|
||||
func (t *RssService) Feed(request *FeedRequest) (*FeedResponse, error) {
|
||||
rsp := &FeedResponse{}
|
||||
return rsp, t.client.Call("rss", "Feed", request, rsp)
|
||||
}
|
||||
|
||||
// List the saved RSS fields
|
||||
func (t *RssService) List(request *ListRequest) (*ListResponse, error) {
|
||||
rsp := &ListResponse{}
|
||||
return rsp, t.client.Call("rss", "List", request, rsp)
|
||||
}
|
||||
|
||||
// Remove an RSS feed by name
|
||||
func (t *RssService) Remove(request *RemoveRequest) (*RemoveResponse, error) {
|
||||
rsp := &RemoveResponse{}
|
||||
return rsp, t.client.Call("rss", "Remove", request, rsp)
|
||||
}
|
||||
|
||||
type AddRequest struct {
|
||||
// category to add e.g news
|
||||
Category string `json:"category"`
|
||||
// rss feed name
|
||||
// eg. a16z
|
||||
Name string `json:"name"`
|
||||
// rss feed url
|
||||
// eg. http://a16z.com/feed/
|
||||
Url string `json:"url"`
|
||||
}
|
||||
|
||||
type AddResponse struct {
|
||||
}
|
||||
|
||||
type Entry struct {
|
||||
// article content
|
||||
Content string `json:"content"`
|
||||
// data of the entry
|
||||
Date string `json:"date"`
|
||||
// the rss feed where it came from
|
||||
Feed string `json:"feed"`
|
||||
// unique id of the entry
|
||||
Id string `json:"id"`
|
||||
// rss feed url of the entry
|
||||
Link string `json:"link"`
|
||||
// article summary
|
||||
Summary string `json:"summary"`
|
||||
// title of the entry
|
||||
Title string `json:"title"`
|
||||
}
|
||||
|
||||
type Feed struct {
|
||||
// category of the feed e.g news
|
||||
Category string `json:"category"`
|
||||
// unique id
|
||||
Id string `json:"id"`
|
||||
// rss feed name
|
||||
// eg. a16z
|
||||
Name string `json:"name"`
|
||||
// rss feed url
|
||||
// eg. http://a16z.com/feed/
|
||||
Url string `json:"url"`
|
||||
}
|
||||
|
||||
type FeedRequest struct {
|
||||
// limit entries returned
|
||||
Limit int64 `json:"limit"`
|
||||
// rss feed name
|
||||
Name string `json:"name"`
|
||||
// offset entries
|
||||
Offset int64 `json:"offset"`
|
||||
}
|
||||
|
||||
type FeedResponse struct {
|
||||
Entries []Entry `json:"entries"`
|
||||
}
|
||||
|
||||
type ListRequest struct {
|
||||
}
|
||||
|
||||
type ListResponse struct {
|
||||
Feeds []Feed `json:"feeds"`
|
||||
}
|
||||
|
||||
type RemoveRequest struct {
|
||||
// rss feed name
|
||||
// eg. a16z
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type RemoveResponse struct {
|
||||
}
|
||||
35
clients/go/sentiment/sentiment.go
Executable file
35
clients/go/sentiment/sentiment.go
Executable file
@@ -0,0 +1,35 @@
|
||||
package sentiment
|
||||
|
||||
import (
|
||||
"github.com/m3o/m3o-go/client"
|
||||
)
|
||||
|
||||
func NewSentimentService(token string) *SentimentService {
|
||||
return &SentimentService{
|
||||
client: client.NewClient(&client.Options{
|
||||
Token: token,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
type SentimentService struct {
|
||||
client *client.Client
|
||||
}
|
||||
|
||||
// Analyze and score a piece of text
|
||||
func (t *SentimentService) Analyze(request *AnalyzeRequest) (*AnalyzeResponse, error) {
|
||||
rsp := &AnalyzeResponse{}
|
||||
return rsp, t.client.Call("sentiment", "Analyze", request, rsp)
|
||||
}
|
||||
|
||||
type AnalyzeRequest struct {
|
||||
// The language. Defaults to english.
|
||||
Lang string `json:"lang"`
|
||||
// The text to analyze
|
||||
Text string `json:"text"`
|
||||
}
|
||||
|
||||
type AnalyzeResponse struct {
|
||||
// The score of the text {positive is 1, negative is 0}
|
||||
Score float64 `json:"score"`
|
||||
}
|
||||
39
clients/go/sms/sms.go
Executable file
39
clients/go/sms/sms.go
Executable file
@@ -0,0 +1,39 @@
|
||||
package sms
|
||||
|
||||
import (
|
||||
"github.com/m3o/m3o-go/client"
|
||||
)
|
||||
|
||||
func NewSmsService(token string) *SmsService {
|
||||
return &SmsService{
|
||||
client: client.NewClient(&client.Options{
|
||||
Token: token,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
type SmsService struct {
|
||||
client *client.Client
|
||||
}
|
||||
|
||||
// Send an SMS.
|
||||
func (t *SmsService) Send(request *SendRequest) (*SendResponse, error) {
|
||||
rsp := &SendResponse{}
|
||||
return rsp, t.client.Call("sms", "Send", request, rsp)
|
||||
}
|
||||
|
||||
type SendRequest struct {
|
||||
// who is the message from? The message will be suffixed with "Sent from <from>"
|
||||
From string `json:"from"`
|
||||
// the main body of the message to send
|
||||
Message string `json:"message"`
|
||||
// the destination phone number including the international dialling code (e.g. +44)
|
||||
To string `json:"to"`
|
||||
}
|
||||
|
||||
type SendResponse struct {
|
||||
// any additional info
|
||||
Info string `json:"info"`
|
||||
// will return "ok" if successful
|
||||
Status string `json:"status"`
|
||||
}
|
||||
132
clients/go/stock/stock.go
Executable file
132
clients/go/stock/stock.go
Executable file
@@ -0,0 +1,132 @@
|
||||
package stock
|
||||
|
||||
import (
|
||||
"github.com/m3o/m3o-go/client"
|
||||
)
|
||||
|
||||
func NewStockService(token string) *StockService {
|
||||
return &StockService{
|
||||
client: client.NewClient(&client.Options{
|
||||
Token: token,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
type StockService struct {
|
||||
client *client.Client
|
||||
}
|
||||
|
||||
// Get the historic open-close for a given day
|
||||
func (t *StockService) History(request *HistoryRequest) (*HistoryResponse, error) {
|
||||
rsp := &HistoryResponse{}
|
||||
return rsp, t.client.Call("stock", "History", request, rsp)
|
||||
}
|
||||
|
||||
// Get the historic order book and each trade by timestamp
|
||||
func (t *StockService) OrderBook(request *OrderBookRequest) (*OrderBookResponse, error) {
|
||||
rsp := &OrderBookResponse{}
|
||||
return rsp, t.client.Call("stock", "OrderBook", request, rsp)
|
||||
}
|
||||
|
||||
// Get the last price for a given stock ticker
|
||||
func (t *StockService) Price(request *PriceRequest) (*PriceResponse, error) {
|
||||
rsp := &PriceResponse{}
|
||||
return rsp, t.client.Call("stock", "Price", request, rsp)
|
||||
}
|
||||
|
||||
// Get the last quote for the stock
|
||||
func (t *StockService) Quote(request *QuoteRequest) (*QuoteResponse, error) {
|
||||
rsp := &QuoteResponse{}
|
||||
return rsp, t.client.Call("stock", "Quote", request, rsp)
|
||||
}
|
||||
|
||||
type HistoryRequest struct {
|
||||
// date to retrieve as YYYY-MM-DD
|
||||
Date string `json:"date"`
|
||||
// the stock symbol e.g AAPL
|
||||
Stock string `json:"stock"`
|
||||
}
|
||||
|
||||
type HistoryResponse struct {
|
||||
// the close price
|
||||
Close float64 `json:"close"`
|
||||
// the date
|
||||
Date string `json:"date"`
|
||||
// the peak price
|
||||
High float64 `json:"high"`
|
||||
// the low price
|
||||
Low float64 `json:"low"`
|
||||
// the open price
|
||||
Open float64 `json:"open"`
|
||||
// the stock symbol
|
||||
Symbol string `json:"symbol"`
|
||||
// the volume
|
||||
Volume int32 `json:"volume"`
|
||||
}
|
||||
|
||||
type Order struct {
|
||||
// the asking price
|
||||
AskPrice float64 `json:"askPrice"`
|
||||
// the ask size
|
||||
AskSize int32 `json:"askSize"`
|
||||
// the bidding price
|
||||
BidPrice float64 `json:"bidPrice"`
|
||||
// the bid size
|
||||
BidSize int32 `json:"bidSize"`
|
||||
// the UTC timestamp of the quote
|
||||
Timestamp string `json:"timestamp"`
|
||||
}
|
||||
|
||||
type OrderBookRequest struct {
|
||||
// the date in format YYYY-MM-dd
|
||||
Date string `json:"date"`
|
||||
// optional RFC3339Nano end time e.g 2006-01-02T15:04:05.999999999Z07:00
|
||||
End string `json:"end"`
|
||||
// limit number of prices
|
||||
Limit int32 `json:"limit"`
|
||||
// optional RFC3339Nano start time e.g 2006-01-02T15:04:05.999999999Z07:00
|
||||
Start string `json:"start"`
|
||||
// stock to retrieve e.g AAPL
|
||||
Stock string `json:"stock"`
|
||||
}
|
||||
|
||||
type OrderBookResponse struct {
|
||||
// date of the request
|
||||
Date string `json:"date"`
|
||||
// list of orders
|
||||
Orders []Order `json:"orders"`
|
||||
// the stock symbol
|
||||
Symbol string `json:"symbol"`
|
||||
}
|
||||
|
||||
type PriceRequest struct {
|
||||
// stock symbol e.g AAPL
|
||||
Symbol string `json:"symbol"`
|
||||
}
|
||||
|
||||
type PriceResponse struct {
|
||||
// the last price
|
||||
Price float64 `json:"price"`
|
||||
// the stock symbol e.g AAPL
|
||||
Symbol string `json:"symbol"`
|
||||
}
|
||||
|
||||
type QuoteRequest struct {
|
||||
// the stock symbol e.g AAPL
|
||||
Symbol string `json:"symbol"`
|
||||
}
|
||||
|
||||
type QuoteResponse struct {
|
||||
// the asking price
|
||||
AskPrice float64 `json:"askPrice"`
|
||||
// the ask size
|
||||
AskSize int32 `json:"askSize"`
|
||||
// the bidding price
|
||||
BidPrice float64 `json:"bidPrice"`
|
||||
// the bid size
|
||||
BidSize int32 `json:"bidSize"`
|
||||
// the stock symbol
|
||||
Symbol string `json:"symbol"`
|
||||
// the UTC timestamp of the quote
|
||||
Timestamp string `json:"timestamp"`
|
||||
}
|
||||
51
clients/go/stream/stream.go
Executable file
51
clients/go/stream/stream.go
Executable file
@@ -0,0 +1,51 @@
|
||||
package stream
|
||||
|
||||
import (
|
||||
"github.com/m3o/m3o-go/client"
|
||||
)
|
||||
|
||||
func NewStreamService(token string) *StreamService {
|
||||
return &StreamService{
|
||||
client: client.NewClient(&client.Options{
|
||||
Token: token,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
type StreamService struct {
|
||||
client *client.Client
|
||||
}
|
||||
|
||||
// Publish a message to the stream. Specify a topic to group messages for a specific topic.
|
||||
func (t *StreamService) Publish(request *PublishRequest) (*PublishResponse, error) {
|
||||
rsp := &PublishResponse{}
|
||||
return rsp, t.client.Call("stream", "Publish", request, rsp)
|
||||
}
|
||||
|
||||
// Subscribe to messages for a given topic.
|
||||
func (t *StreamService) Subscribe(request *SubscribeRequest) (*SubscribeResponse, error) {
|
||||
rsp := &SubscribeResponse{}
|
||||
return rsp, t.client.Call("stream", "Subscribe", request, rsp)
|
||||
}
|
||||
|
||||
type PublishRequest struct {
|
||||
// The json message to publish
|
||||
Message map[string]interface{} `json:"message"`
|
||||
// The topic to publish to
|
||||
Topic string `json:"topic"`
|
||||
}
|
||||
|
||||
type PublishResponse struct {
|
||||
}
|
||||
|
||||
type SubscribeRequest struct {
|
||||
// The topic to subscribe to
|
||||
Topic string `json:"topic"`
|
||||
}
|
||||
|
||||
type SubscribeResponse struct {
|
||||
// The next json message on the topic
|
||||
Message map[string]interface{} `json:"message"`
|
||||
// The topic subscribed to
|
||||
Topic string `json:"topic"`
|
||||
}
|
||||
35
clients/go/thumbnail/thumbnail.go
Executable file
35
clients/go/thumbnail/thumbnail.go
Executable file
@@ -0,0 +1,35 @@
|
||||
package thumbnail
|
||||
|
||||
import (
|
||||
"github.com/m3o/m3o-go/client"
|
||||
)
|
||||
|
||||
func NewThumbnailService(token string) *ThumbnailService {
|
||||
return &ThumbnailService{
|
||||
client: client.NewClient(&client.Options{
|
||||
Token: token,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
type ThumbnailService struct {
|
||||
client *client.Client
|
||||
}
|
||||
|
||||
// Create a thumbnail screenshot by passing in a url, height and width
|
||||
func (t *ThumbnailService) Screenshot(request *ScreenshotRequest) (*ScreenshotResponse, error) {
|
||||
rsp := &ScreenshotResponse{}
|
||||
return rsp, t.client.Call("thumbnail", "Screenshot", request, rsp)
|
||||
}
|
||||
|
||||
type ScreenshotRequest struct {
|
||||
// height of the browser window, optional
|
||||
Height int32 `json:"height"`
|
||||
Url string `json:"url"`
|
||||
// width of the browser window. optional
|
||||
Width int32 `json:"width"`
|
||||
}
|
||||
|
||||
type ScreenshotResponse struct {
|
||||
ImageUrl string `json:"imageUrl"`
|
||||
}
|
||||
73
clients/go/time/time.go
Executable file
73
clients/go/time/time.go
Executable file
@@ -0,0 +1,73 @@
|
||||
package time
|
||||
|
||||
import (
|
||||
"github.com/m3o/m3o-go/client"
|
||||
)
|
||||
|
||||
func NewTimeService(token string) *TimeService {
|
||||
return &TimeService{
|
||||
client: client.NewClient(&client.Options{
|
||||
Token: token,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
type TimeService struct {
|
||||
client *client.Client
|
||||
}
|
||||
|
||||
// Get the current time
|
||||
func (t *TimeService) Now(request *NowRequest) (*NowResponse, error) {
|
||||
rsp := &NowResponse{}
|
||||
return rsp, t.client.Call("time", "Now", request, rsp)
|
||||
}
|
||||
|
||||
// Get the timezone info for a specific location
|
||||
func (t *TimeService) Zone(request *ZoneRequest) (*ZoneResponse, error) {
|
||||
rsp := &ZoneResponse{}
|
||||
return rsp, t.client.Call("time", "Zone", request, rsp)
|
||||
}
|
||||
|
||||
type NowRequest struct {
|
||||
// optional location, otherwise returns UTC
|
||||
Location string `json:"location"`
|
||||
}
|
||||
|
||||
type NowResponse struct {
|
||||
// the current time as HH:MM:SS
|
||||
Localtime string `json:"localtime"`
|
||||
// the location as Europe/London
|
||||
Location string `json:"location"`
|
||||
// timestamp as 2006-01-02T15:04:05.999999999Z07:00
|
||||
Timestamp string `json:"timestamp"`
|
||||
// the timezone as BST
|
||||
Timezone string `json:"timezone"`
|
||||
// the unix timestamp
|
||||
Unix int64 `json:"unix"`
|
||||
}
|
||||
|
||||
type ZoneRequest struct {
|
||||
// location to lookup e.g postcode, city, ip address
|
||||
Location string `json:"location"`
|
||||
}
|
||||
|
||||
type ZoneResponse struct {
|
||||
// the abbreviated code e.g BST
|
||||
Abbreviation string `json:"abbreviation"`
|
||||
// country of the timezone
|
||||
Country string `json:"country"`
|
||||
// is daylight savings
|
||||
Dst bool `json:"dst"`
|
||||
// e.g 51.42
|
||||
Latitude float64 `json:"latitude"`
|
||||
// the local time
|
||||
Localtime string `json:"localtime"`
|
||||
// location requested
|
||||
Location string `json:"location"`
|
||||
// e.g -0.37
|
||||
Longitude float64 `json:"longitude"`
|
||||
// region of timezone
|
||||
Region string `json:"region"`
|
||||
// the timezone e.g Europe/London
|
||||
Timezone string `json:"timezone"`
|
||||
}
|
||||
73
clients/go/url/url.go
Executable file
73
clients/go/url/url.go
Executable file
@@ -0,0 +1,73 @@
|
||||
package url
|
||||
|
||||
import (
|
||||
"github.com/m3o/m3o-go/client"
|
||||
)
|
||||
|
||||
func NewUrlService(token string) *UrlService {
|
||||
return &UrlService{
|
||||
client: client.NewClient(&client.Options{
|
||||
Token: token,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
type UrlService struct {
|
||||
client *client.Client
|
||||
}
|
||||
|
||||
// List information on all the shortened URLs that you have created
|
||||
func (t *UrlService) List(request *ListRequest) (*ListResponse, error) {
|
||||
rsp := &ListResponse{}
|
||||
return rsp, t.client.Call("url", "List", request, rsp)
|
||||
}
|
||||
|
||||
// Proxy returns the destination URL of a short URL.
|
||||
func (t *UrlService) Proxy(request *ProxyRequest) (*ProxyResponse, error) {
|
||||
rsp := &ProxyResponse{}
|
||||
return rsp, t.client.Call("url", "Proxy", request, rsp)
|
||||
}
|
||||
|
||||
// Shortens a destination URL and returns a full short URL.
|
||||
func (t *UrlService) Shorten(request *ShortenRequest) (*ShortenResponse, error) {
|
||||
rsp := &ShortenResponse{}
|
||||
return rsp, t.client.Call("url", "Shorten", request, rsp)
|
||||
}
|
||||
|
||||
type ListRequest struct {
|
||||
// filter by short URL, optional
|
||||
ShortUrl string `json:"shortUrl"`
|
||||
}
|
||||
|
||||
type ListResponse struct {
|
||||
UrlPairs *URLPair `json:"urlPairs"`
|
||||
}
|
||||
|
||||
type ProxyRequest struct {
|
||||
// short url ID, without the domain, eg. if your short URL is
|
||||
// `m3o.one/u/someshorturlid` then pass in `someshorturlid`
|
||||
ShortUrl string `json:"shortUrl"`
|
||||
}
|
||||
|
||||
type ProxyResponse struct {
|
||||
DestinationUrl string `json:"destinationUrl"`
|
||||
}
|
||||
|
||||
type ShortenRequest struct {
|
||||
DestinationUrl string `json:"destinationUrl"`
|
||||
}
|
||||
|
||||
type ShortenResponse struct {
|
||||
ShortUrl string `json:"shortUrl"`
|
||||
}
|
||||
|
||||
type URLPair struct {
|
||||
Created int64 `json:"created"`
|
||||
DestinationUrl string `json:"destinationUrl"`
|
||||
// HitCount keeps track many times the short URL has been resolved.
|
||||
// Hitcount only gets saved to disk (database) after every 10th hit, so
|
||||
// its not intended to be 100% accurate, more like an almost correct estimate.
|
||||
HitCount int64 `json:"hitCount"`
|
||||
Owner string `json:"owner"`
|
||||
ShortUrl string `json:"shortUrl"`
|
||||
}
|
||||
231
clients/go/user/user.go
Executable file
231
clients/go/user/user.go
Executable file
@@ -0,0 +1,231 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"github.com/m3o/m3o-go/client"
|
||||
)
|
||||
|
||||
func NewUserService(token string) *UserService {
|
||||
return &UserService{
|
||||
client: client.NewClient(&client.Options{
|
||||
Token: token,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
type UserService struct {
|
||||
client *client.Client
|
||||
}
|
||||
|
||||
// Create a new user account. The email address and username for the account must be unique.
|
||||
func (t *UserService) Create(request *CreateRequest) (*CreateResponse, error) {
|
||||
rsp := &CreateResponse{}
|
||||
return rsp, t.client.Call("user", "Create", request, rsp)
|
||||
}
|
||||
|
||||
// Delete an account by id
|
||||
func (t *UserService) Delete(request *DeleteRequest) (*DeleteResponse, error) {
|
||||
rsp := &DeleteResponse{}
|
||||
return rsp, t.client.Call("user", "Delete", request, rsp)
|
||||
}
|
||||
|
||||
// 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 (t *UserService) Login(request *LoginRequest) (*LoginResponse, error) {
|
||||
rsp := &LoginResponse{}
|
||||
return rsp, t.client.Call("user", "Login", request, rsp)
|
||||
}
|
||||
|
||||
// Logout a user account
|
||||
func (t *UserService) Logout(request *LogoutRequest) (*LogoutResponse, error) {
|
||||
rsp := &LogoutResponse{}
|
||||
return rsp, t.client.Call("user", "Logout", request, rsp)
|
||||
}
|
||||
|
||||
// Read an account by id, username or email. Only one need to be specified.
|
||||
func (t *UserService) Read(request *ReadRequest) (*ReadResponse, error) {
|
||||
rsp := &ReadResponse{}
|
||||
return rsp, t.client.Call("user", "Read", request, rsp)
|
||||
}
|
||||
|
||||
// Read a session by the session id. In the event it has expired or is not found and error is returned.
|
||||
func (t *UserService) ReadSession(request *ReadSessionRequest) (*ReadSessionResponse, error) {
|
||||
rsp := &ReadSessionResponse{}
|
||||
return rsp, t.client.Call("user", "ReadSession", request, rsp)
|
||||
}
|
||||
|
||||
// Send a verification email
|
||||
// to the user being signed up. Email from will be from 'support@m3o.com',
|
||||
// but you can provide the title and contents.
|
||||
// The verification link will be injected in to the email as a template variable, $micro_verification_link.
|
||||
// Example: 'Hi there, welcome onboard! Use the link below to verify your email: $micro_verification_link'
|
||||
// The variable will be replaced with an actual url that will look similar to this:
|
||||
// 'https://user.m3o.com/user/verify?token=a-verification-token&rediretUrl=your-redir-url'
|
||||
func (t *UserService) SendVerificationEmail(request *SendVerificationEmailRequest) (*SendVerificationEmailResponse, error) {
|
||||
rsp := &SendVerificationEmailResponse{}
|
||||
return rsp, t.client.Call("user", "SendVerificationEmail", request, rsp)
|
||||
}
|
||||
|
||||
// Update the account password
|
||||
func (t *UserService) UpdatePassword(request *UpdatePasswordRequest) (*UpdatePasswordResponse, error) {
|
||||
rsp := &UpdatePasswordResponse{}
|
||||
return rsp, t.client.Call("user", "UpdatePassword", request, rsp)
|
||||
}
|
||||
|
||||
// Update the account username or email
|
||||
func (t *UserService) Update(request *UpdateRequest) (*UpdateResponse, error) {
|
||||
rsp := &UpdateResponse{}
|
||||
return rsp, t.client.Call("user", "Update", request, rsp)
|
||||
}
|
||||
|
||||
// Verify the email address of an account from a token sent in an email to the user.
|
||||
func (t *UserService) VerifyEmail(request *VerifyEmailRequest) (*VerifyEmailResponse, error) {
|
||||
rsp := &VerifyEmailResponse{}
|
||||
return rsp, t.client.Call("user", "VerifyEmail", request, rsp)
|
||||
}
|
||||
|
||||
type Account struct {
|
||||
// unix timestamp
|
||||
Created int64 `json:"created"`
|
||||
// an email address
|
||||
Email string `json:"email"`
|
||||
// unique account id
|
||||
Id string `json:"id"`
|
||||
// Store any custom data you want about your users in this fields.
|
||||
Profile map[string]string `json:"profile"`
|
||||
// unix timestamp
|
||||
Updated int64 `json:"updated"`
|
||||
// alphanumeric username
|
||||
Username string `json:"username"`
|
||||
VerificationDate int64 `json:"verificationDate"`
|
||||
Verified bool `json:"verified"`
|
||||
}
|
||||
|
||||
type CreateRequest struct {
|
||||
// the email address
|
||||
Email string `json:"email"`
|
||||
// optional account id
|
||||
Id string `json:"id"`
|
||||
// the user password
|
||||
Password string `json:"password"`
|
||||
// optional user profile as map<string,string>
|
||||
Profile map[string]string `json:"profile"`
|
||||
// the username
|
||||
Username string `json:"username"`
|
||||
}
|
||||
|
||||
type CreateResponse struct {
|
||||
Account *Account `json:"account"`
|
||||
}
|
||||
|
||||
type DeleteRequest struct {
|
||||
// the account id
|
||||
Id string `json:"id"`
|
||||
}
|
||||
|
||||
type DeleteResponse struct {
|
||||
}
|
||||
|
||||
type LoginRequest struct {
|
||||
// The email address of the user
|
||||
Email string `json:"email"`
|
||||
// The password of the user
|
||||
Password string `json:"password"`
|
||||
// The username of the user
|
||||
Username string `json:"username"`
|
||||
}
|
||||
|
||||
type LoginResponse struct {
|
||||
// The session of the logged in user
|
||||
Session *Session `json:"session"`
|
||||
}
|
||||
|
||||
type LogoutRequest struct {
|
||||
SessionId string `json:"sessionId"`
|
||||
}
|
||||
|
||||
type LogoutResponse struct {
|
||||
}
|
||||
|
||||
type ReadRequest struct {
|
||||
// the account email
|
||||
Email string `json:"email"`
|
||||
// the account id
|
||||
Id string `json:"id"`
|
||||
// the account username
|
||||
Username string `json:"username"`
|
||||
}
|
||||
|
||||
type ReadResponse struct {
|
||||
Account *Account `json:"account"`
|
||||
}
|
||||
|
||||
type ReadSessionRequest struct {
|
||||
// The unique session id
|
||||
SessionId string `json:"sessionId"`
|
||||
}
|
||||
|
||||
type ReadSessionResponse struct {
|
||||
Session *Session `json:"session"`
|
||||
}
|
||||
|
||||
type SendVerificationEmailRequest struct {
|
||||
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"`
|
||||
// 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"`
|
||||
}
|
||||
|
||||
type SendVerificationEmailResponse struct {
|
||||
}
|
||||
|
||||
type Session struct {
|
||||
// unix timestamp
|
||||
Created int64 `json:"created"`
|
||||
// unix timestamp
|
||||
Expires int64 `json:"expires"`
|
||||
// the session id
|
||||
Id string `json:"id"`
|
||||
// the associated user id
|
||||
UserId string `json:"userId"`
|
||||
}
|
||||
|
||||
type UpdatePasswordRequest struct {
|
||||
// confirm new password
|
||||
ConfirmPassword string `json:"confirmPassword"`
|
||||
// the new password
|
||||
NewPassword string `json:"newPassword"`
|
||||
// the old password
|
||||
OldPassword string `json:"oldPassword"`
|
||||
// the account id
|
||||
UserId string `json:"userId"`
|
||||
}
|
||||
|
||||
type UpdatePasswordResponse struct {
|
||||
}
|
||||
|
||||
type UpdateRequest struct {
|
||||
// the new email address
|
||||
Email string `json:"email"`
|
||||
// the account id
|
||||
Id string `json:"id"`
|
||||
// the user profile as map<string,string>
|
||||
Profile map[string]string `json:"profile"`
|
||||
// the new username
|
||||
Username string `json:"username"`
|
||||
}
|
||||
|
||||
type UpdateResponse struct {
|
||||
}
|
||||
|
||||
type VerifyEmailRequest struct {
|
||||
// The token from the verification email
|
||||
Token string `json:"token"`
|
||||
}
|
||||
|
||||
type VerifyEmailResponse struct {
|
||||
}
|
||||
132
clients/go/weather/weather.go
Executable file
132
clients/go/weather/weather.go
Executable file
@@ -0,0 +1,132 @@
|
||||
package weather
|
||||
|
||||
import (
|
||||
"github.com/m3o/m3o-go/client"
|
||||
)
|
||||
|
||||
func NewWeatherService(token string) *WeatherService {
|
||||
return &WeatherService{
|
||||
client: client.NewClient(&client.Options{
|
||||
Token: token,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
type WeatherService struct {
|
||||
client *client.Client
|
||||
}
|
||||
|
||||
// Get the weather forecast for the next 1-10 days
|
||||
func (t *WeatherService) Forecast(request *ForecastRequest) (*ForecastResponse, error) {
|
||||
rsp := &ForecastResponse{}
|
||||
return rsp, t.client.Call("weather", "Forecast", request, rsp)
|
||||
}
|
||||
|
||||
// Get the current weather report for a location by postcode, city, zip code, ip address
|
||||
func (t *WeatherService) Now(request *NowRequest) (*NowResponse, error) {
|
||||
rsp := &NowResponse{}
|
||||
return rsp, t.client.Call("weather", "Now", request, rsp)
|
||||
}
|
||||
|
||||
type Forecast struct {
|
||||
// the average temp in celsius
|
||||
AvgTempC float64 `json:"avgTempC"`
|
||||
// the average temp in fahrenheit
|
||||
AvgTempF float64 `json:"avgTempF"`
|
||||
// chance of rain (percentage)
|
||||
ChanceOfRain int32 `json:"chanceOfRain"`
|
||||
// forecast condition
|
||||
Condition string `json:"condition"`
|
||||
// date of the forecast
|
||||
Date string `json:"date"`
|
||||
// the URL of forecast condition icon. Simply prefix with either http or https to use it
|
||||
IconUrl string `json:"iconUrl"`
|
||||
// max temp in celsius
|
||||
MaxTempC float64 `json:"maxTempC"`
|
||||
// max temp in fahrenheit
|
||||
MaxTempF float64 `json:"maxTempF"`
|
||||
// minimum temp in celsius
|
||||
MinTempC float64 `json:"minTempC"`
|
||||
// minimum temp in fahrenheit
|
||||
MinTempF float64 `json:"minTempF"`
|
||||
// time of sunrise
|
||||
Sunrise string `json:"sunrise"`
|
||||
// time of sunset
|
||||
Sunset string `json:"sunset"`
|
||||
// will it rain
|
||||
WillItRain bool `json:"willItRain"`
|
||||
}
|
||||
|
||||
type ForecastRequest struct {
|
||||
// number of days. default 1, max 10
|
||||
Days int32 `json:"days"`
|
||||
// location of the forecase
|
||||
Location string `json:"location"`
|
||||
}
|
||||
|
||||
type ForecastResponse struct {
|
||||
// country of the request
|
||||
Country string `json:"country"`
|
||||
// forecast for the next number of days
|
||||
Forecast []Forecast `json:"forecast"`
|
||||
// e.g 37.55
|
||||
Latitude float64 `json:"latitude"`
|
||||
// the local time
|
||||
LocalTime string `json:"localTime"`
|
||||
// location of the request
|
||||
Location string `json:"location"`
|
||||
// e.g -77.46
|
||||
Longitude float64 `json:"longitude"`
|
||||
// region related to the location
|
||||
Region string `json:"region"`
|
||||
// timezone of the location
|
||||
Timezone string `json:"timezone"`
|
||||
}
|
||||
|
||||
type NowRequest struct {
|
||||
// location to get weather e.g postcode, city
|
||||
Location string `json:"location"`
|
||||
}
|
||||
|
||||
type NowResponse struct {
|
||||
// cloud cover percentage
|
||||
Cloud int32 `json:"cloud"`
|
||||
// the weather condition
|
||||
Condition string `json:"condition"`
|
||||
// country of the request
|
||||
Country string `json:"country"`
|
||||
// whether its daytime
|
||||
Daytime bool `json:"daytime"`
|
||||
// feels like in celsius
|
||||
FeelsLikeC float64 `json:"feelsLikeC"`
|
||||
// feels like in fahrenheit
|
||||
FeelsLikeF float64 `json:"feelsLikeF"`
|
||||
// the humidity percentage
|
||||
Humidity int32 `json:"humidity"`
|
||||
// the URL of the related icon. Simply prefix with either http or https to use it
|
||||
IconUrl string `json:"iconUrl"`
|
||||
// e.g 37.55
|
||||
Latitude float64 `json:"latitude"`
|
||||
// the local time
|
||||
LocalTime string `json:"localTime"`
|
||||
// location of the request
|
||||
Location string `json:"location"`
|
||||
// e.g -77.46
|
||||
Longitude float64 `json:"longitude"`
|
||||
// region related to the location
|
||||
Region string `json:"region"`
|
||||
// temperature in celsius
|
||||
TempC float64 `json:"tempC"`
|
||||
// temperature in fahrenheit
|
||||
TempF float64 `json:"tempF"`
|
||||
// timezone of the location
|
||||
Timezone string `json:"timezone"`
|
||||
// wind degree
|
||||
WindDegree int32 `json:"windDegree"`
|
||||
// wind direction
|
||||
WindDirection string `json:"windDirection"`
|
||||
// wind in kph
|
||||
WindKph float64 `json:"windKph"`
|
||||
// wind in mph
|
||||
WindMph float64 `json:"windMph"`
|
||||
}
|
||||
1
clients/ts/.gitignore
vendored
Normal file
1
clients/ts/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
dist
|
||||
53
clients/ts/address/index.ts
Executable file
53
clients/ts/address/index.ts
Executable file
@@ -0,0 +1,53 @@
|
||||
import * as m3o from "@m3o/m3o-node";
|
||||
|
||||
export class AddressService {
|
||||
private client: m3o.Client;
|
||||
|
||||
constructor(token: string) {
|
||||
this.client = new m3o.Client({ token: token });
|
||||
}
|
||||
// Lookup a list of UK addresses by postcode
|
||||
lookupPostcode(
|
||||
request: LookupPostcodeRequest
|
||||
): Promise<LookupPostcodeResponse> {
|
||||
return this.client.call(
|
||||
"address",
|
||||
"LookupPostcode",
|
||||
request
|
||||
) as Promise<LookupPostcodeResponse>;
|
||||
}
|
||||
}
|
||||
|
||||
export interface LookupPostcodeRequest {
|
||||
// UK postcode e.g SW1A 2AA
|
||||
postcode?: string;
|
||||
}
|
||||
|
||||
export interface LookupPostcodeResponse {
|
||||
addresses?: Record[];
|
||||
}
|
||||
|
||||
export interface Record {
|
||||
// building name
|
||||
buildingName?: string;
|
||||
// the county
|
||||
county?: string;
|
||||
// line one of address
|
||||
lineOne?: string;
|
||||
// line two of address
|
||||
lineTwo?: string;
|
||||
// dependent locality
|
||||
locality?: string;
|
||||
// organisation if present
|
||||
organisation?: string;
|
||||
// the postcode
|
||||
postcode?: string;
|
||||
// the premise
|
||||
premise?: string;
|
||||
// street name
|
||||
street?: string;
|
||||
// the complete address
|
||||
summary?: string;
|
||||
// post town
|
||||
town?: string;
|
||||
}
|
||||
31
clients/ts/answer/index.ts
Executable file
31
clients/ts/answer/index.ts
Executable file
@@ -0,0 +1,31 @@
|
||||
import * as m3o from "@m3o/m3o-node";
|
||||
|
||||
export class AnswerService {
|
||||
private client: m3o.Client;
|
||||
|
||||
constructor(token: string) {
|
||||
this.client = new m3o.Client({ token: token });
|
||||
}
|
||||
// Ask a question and receive an instant answer
|
||||
question(request: QuestionRequest): Promise<QuestionResponse> {
|
||||
return this.client.call(
|
||||
"answer",
|
||||
"Question",
|
||||
request
|
||||
) as Promise<QuestionResponse>;
|
||||
}
|
||||
}
|
||||
|
||||
export interface QuestionRequest {
|
||||
// the question to answer
|
||||
query?: string;
|
||||
}
|
||||
|
||||
export interface QuestionResponse {
|
||||
// the answer to your question
|
||||
answer?: string;
|
||||
// any related image
|
||||
image?: string;
|
||||
// a related url
|
||||
url?: string;
|
||||
}
|
||||
107
clients/ts/cache/index.ts
vendored
Executable file
107
clients/ts/cache/index.ts
vendored
Executable file
@@ -0,0 +1,107 @@
|
||||
import * as m3o from "@m3o/m3o-node";
|
||||
|
||||
export class CacheService {
|
||||
private client: m3o.Client;
|
||||
|
||||
constructor(token: string) {
|
||||
this.client = new m3o.Client({ token: token });
|
||||
}
|
||||
// Decrement a value (if it's a number)
|
||||
decrement(request: DecrementRequest): Promise<DecrementResponse> {
|
||||
return this.client.call(
|
||||
"cache",
|
||||
"Decrement",
|
||||
request
|
||||
) as Promise<DecrementResponse>;
|
||||
}
|
||||
// Delete a value from the cache
|
||||
delete(request: DeleteRequest): Promise<DeleteResponse> {
|
||||
return this.client.call(
|
||||
"cache",
|
||||
"Delete",
|
||||
request
|
||||
) as Promise<DeleteResponse>;
|
||||
}
|
||||
// Get an item from the cache by key
|
||||
get(request: GetRequest): Promise<GetResponse> {
|
||||
return this.client.call("cache", "Get", request) as Promise<GetResponse>;
|
||||
}
|
||||
// Increment a value (if it's a number)
|
||||
increment(request: IncrementRequest): Promise<IncrementResponse> {
|
||||
return this.client.call(
|
||||
"cache",
|
||||
"Increment",
|
||||
request
|
||||
) as Promise<IncrementResponse>;
|
||||
}
|
||||
// Set an item in the cache. Overwrites any existing value already set.
|
||||
set(request: SetRequest): Promise<SetResponse> {
|
||||
return this.client.call("cache", "Set", request) as Promise<SetResponse>;
|
||||
}
|
||||
}
|
||||
|
||||
export interface DecrementRequest {
|
||||
// The key to decrement
|
||||
key?: string;
|
||||
// The amount to decrement the value by
|
||||
value?: number;
|
||||
}
|
||||
|
||||
export interface DecrementResponse {
|
||||
// The key decremented
|
||||
key?: string;
|
||||
// The new value
|
||||
value?: number;
|
||||
}
|
||||
|
||||
export interface DeleteRequest {
|
||||
// The key to delete
|
||||
key?: string;
|
||||
}
|
||||
|
||||
export interface DeleteResponse {
|
||||
// Returns "ok" if successful
|
||||
status?: string;
|
||||
}
|
||||
|
||||
export interface GetRequest {
|
||||
// The key to retrieve
|
||||
key?: string;
|
||||
}
|
||||
|
||||
export interface GetResponse {
|
||||
// The key
|
||||
key?: string;
|
||||
// Time to live in seconds
|
||||
ttl?: number;
|
||||
// The value
|
||||
value?: string;
|
||||
}
|
||||
|
||||
export interface IncrementRequest {
|
||||
// The key to increment
|
||||
key?: string;
|
||||
// The amount to increment the value by
|
||||
value?: number;
|
||||
}
|
||||
|
||||
export interface IncrementResponse {
|
||||
// The key incremented
|
||||
key?: string;
|
||||
// The new value
|
||||
value?: number;
|
||||
}
|
||||
|
||||
export interface SetRequest {
|
||||
// The key to update
|
||||
key?: string;
|
||||
// Time to live in seconds
|
||||
ttl?: number;
|
||||
// The value to set
|
||||
value?: string;
|
||||
}
|
||||
|
||||
export interface SetResponse {
|
||||
// Returns "ok" if successful
|
||||
status?: string;
|
||||
}
|
||||
116
clients/ts/crypto/index.ts
Executable file
116
clients/ts/crypto/index.ts
Executable file
@@ -0,0 +1,116 @@
|
||||
import * as m3o from "@m3o/m3o-node";
|
||||
|
||||
export class CryptoService {
|
||||
private client: m3o.Client;
|
||||
|
||||
constructor(token: string) {
|
||||
this.client = new m3o.Client({ token: token });
|
||||
}
|
||||
// Returns the history for the previous close
|
||||
history(request: HistoryRequest): Promise<HistoryResponse> {
|
||||
return this.client.call(
|
||||
"crypto",
|
||||
"History",
|
||||
request
|
||||
) as Promise<HistoryResponse>;
|
||||
}
|
||||
// Get news related to a currency
|
||||
news(request: NewsRequest): Promise<NewsResponse> {
|
||||
return this.client.call("crypto", "News", request) as Promise<NewsResponse>;
|
||||
}
|
||||
// Get the last price for a given crypto ticker
|
||||
price(request: PriceRequest): Promise<PriceResponse> {
|
||||
return this.client.call(
|
||||
"crypto",
|
||||
"Price",
|
||||
request
|
||||
) as Promise<PriceResponse>;
|
||||
}
|
||||
// Get the last quote for a given crypto ticker
|
||||
quote(request: QuoteRequest): Promise<QuoteResponse> {
|
||||
return this.client.call(
|
||||
"crypto",
|
||||
"Quote",
|
||||
request
|
||||
) as Promise<QuoteResponse>;
|
||||
}
|
||||
}
|
||||
|
||||
export interface Article {
|
||||
// the date published
|
||||
date?: string;
|
||||
// its description
|
||||
description?: string;
|
||||
// the source
|
||||
source?: string;
|
||||
// title of the article
|
||||
title?: string;
|
||||
// the source url
|
||||
url?: string;
|
||||
}
|
||||
|
||||
export interface HistoryRequest {
|
||||
// the crypto symbol e.g BTCUSD
|
||||
symbol?: string;
|
||||
}
|
||||
|
||||
export interface HistoryResponse {
|
||||
// the close price
|
||||
close?: number;
|
||||
// the date
|
||||
date?: string;
|
||||
// the peak price
|
||||
high?: number;
|
||||
// the low price
|
||||
low?: number;
|
||||
// the open price
|
||||
open?: number;
|
||||
// the crypto symbol
|
||||
symbol?: string;
|
||||
// the volume
|
||||
volume?: number;
|
||||
}
|
||||
|
||||
export interface NewsRequest {
|
||||
// cryptocurrency ticker to request news for e.g BTC
|
||||
symbol?: string;
|
||||
}
|
||||
|
||||
export interface NewsResponse {
|
||||
// list of articles
|
||||
articles?: Article[];
|
||||
// symbol requested for
|
||||
symbol?: string;
|
||||
}
|
||||
|
||||
export interface PriceRequest {
|
||||
// the crypto symbol e.g BTCUSD
|
||||
symbol?: string;
|
||||
}
|
||||
|
||||
export interface PriceResponse {
|
||||
// the last price
|
||||
price?: number;
|
||||
// the crypto symbol e.g BTCUSD
|
||||
symbol?: string;
|
||||
}
|
||||
|
||||
export interface QuoteRequest {
|
||||
// the crypto symbol e.g BTCUSD
|
||||
symbol?: string;
|
||||
}
|
||||
|
||||
export interface QuoteResponse {
|
||||
// the asking price
|
||||
askPrice?: number;
|
||||
// the ask size
|
||||
askSize?: number;
|
||||
// the bidding price
|
||||
bidPrice?: number;
|
||||
// the bid size
|
||||
bidSize?: number;
|
||||
// the crypto symbol
|
||||
symbol?: string;
|
||||
// the UTC timestamp of the quote
|
||||
timestamp?: string;
|
||||
}
|
||||
102
clients/ts/currency/index.ts
Executable file
102
clients/ts/currency/index.ts
Executable file
@@ -0,0 +1,102 @@
|
||||
import * as m3o from "@m3o/m3o-node";
|
||||
|
||||
export class CurrencyService {
|
||||
private client: m3o.Client;
|
||||
|
||||
constructor(token: string) {
|
||||
this.client = new m3o.Client({ token: token });
|
||||
}
|
||||
// Codes returns the supported currency codes for the API
|
||||
codes(request: CodesRequest): Promise<CodesResponse> {
|
||||
return this.client.call(
|
||||
"currency",
|
||||
"Codes",
|
||||
request
|
||||
) as Promise<CodesResponse>;
|
||||
}
|
||||
// Convert returns the currency conversion rate between two pairs e.g USD/GBP
|
||||
convert(request: ConvertRequest): Promise<ConvertResponse> {
|
||||
return this.client.call(
|
||||
"currency",
|
||||
"Convert",
|
||||
request
|
||||
) as Promise<ConvertResponse>;
|
||||
}
|
||||
// Returns the historic rates for a currency on a given date
|
||||
history(request: HistoryRequest): Promise<HistoryResponse> {
|
||||
return this.client.call(
|
||||
"currency",
|
||||
"History",
|
||||
request
|
||||
) as Promise<HistoryResponse>;
|
||||
}
|
||||
// Rates returns the currency rates for a given code e.g USD
|
||||
rates(request: RatesRequest): Promise<RatesResponse> {
|
||||
return this.client.call(
|
||||
"currency",
|
||||
"Rates",
|
||||
request
|
||||
) as Promise<RatesResponse>;
|
||||
}
|
||||
}
|
||||
|
||||
export interface Code {
|
||||
// e.g United States Dollar
|
||||
currency?: string;
|
||||
// e.g USD
|
||||
name?: string;
|
||||
}
|
||||
|
||||
export interface CodesRequest {}
|
||||
|
||||
export interface CodesResponse {
|
||||
codes?: Code[];
|
||||
}
|
||||
|
||||
export interface ConvertRequest {
|
||||
// optional amount to convert e.g 10.0
|
||||
amount?: number;
|
||||
// base code to convert from e.g USD
|
||||
from?: string;
|
||||
// target code to convert to e.g GBP
|
||||
to?: string;
|
||||
}
|
||||
|
||||
export interface ConvertResponse {
|
||||
// converted amount e.g 7.10
|
||||
amount?: number;
|
||||
// the base code e.g USD
|
||||
from?: string;
|
||||
// conversion rate e.g 0.71
|
||||
rate?: number;
|
||||
// the target code e.g GBP
|
||||
to?: string;
|
||||
}
|
||||
|
||||
export interface HistoryRequest {
|
||||
// currency code e.g USD
|
||||
code?: string;
|
||||
// date formatted as YYYY-MM-DD
|
||||
date?: string;
|
||||
}
|
||||
|
||||
export interface HistoryResponse {
|
||||
// The code of the request
|
||||
code?: string;
|
||||
// The date requested
|
||||
date?: string;
|
||||
// The rate for the day as code:rate
|
||||
rates?: { [key: string]: number };
|
||||
}
|
||||
|
||||
export interface RatesRequest {
|
||||
// The currency code to get rates for e.g USD
|
||||
code?: string;
|
||||
}
|
||||
|
||||
export interface RatesResponse {
|
||||
// The code requested e.g USD
|
||||
code?: string;
|
||||
// The rates for the given code as key-value pairs code:rate
|
||||
rates?: { [key: string]: number };
|
||||
}
|
||||
101
clients/ts/db/index.ts
Executable file
101
clients/ts/db/index.ts
Executable file
@@ -0,0 +1,101 @@
|
||||
import * as m3o from "@m3o/m3o-node";
|
||||
|
||||
export class DbService {
|
||||
private client: m3o.Client;
|
||||
|
||||
constructor(token: string) {
|
||||
this.client = new m3o.Client({ token: token });
|
||||
}
|
||||
// Create a record in the database. Optionally include an "id" field otherwise it's set automatically.
|
||||
create(request: CreateRequest): Promise<CreateResponse> {
|
||||
return this.client.call("db", "Create", request) as Promise<CreateResponse>;
|
||||
}
|
||||
// Delete a record in the database by id.
|
||||
delete(request: DeleteRequest): Promise<DeleteResponse> {
|
||||
return this.client.call("db", "Delete", request) as Promise<DeleteResponse>;
|
||||
}
|
||||
// Read data from a table. Lookup can be by ID or via querying any field in the record.
|
||||
read(request: ReadRequest): Promise<ReadResponse> {
|
||||
return this.client.call("db", "Read", request) as Promise<ReadResponse>;
|
||||
}
|
||||
// Truncate the records in a table
|
||||
truncate(request: TruncateRequest): Promise<TruncateResponse> {
|
||||
return this.client.call(
|
||||
"db",
|
||||
"Truncate",
|
||||
request
|
||||
) as Promise<TruncateResponse>;
|
||||
}
|
||||
// Update a record in the database. Include an "id" in the record to update.
|
||||
update(request: UpdateRequest): Promise<UpdateResponse> {
|
||||
return this.client.call("db", "Update", request) as Promise<UpdateResponse>;
|
||||
}
|
||||
}
|
||||
|
||||
export interface CreateRequest {
|
||||
// JSON encoded record or records (can be array or object)
|
||||
record?: { [key: string]: any };
|
||||
// Optional table name. Defaults to 'default'
|
||||
table?: string;
|
||||
}
|
||||
|
||||
export interface CreateResponse {
|
||||
// The id of the record (either specified or automatically created)
|
||||
id?: string;
|
||||
}
|
||||
|
||||
export interface DeleteRequest {
|
||||
// id of the record
|
||||
id?: string;
|
||||
// Optional table name. Defaults to 'default'
|
||||
table?: string;
|
||||
}
|
||||
|
||||
export interface DeleteResponse {}
|
||||
|
||||
export interface ReadRequest {
|
||||
// Read by id. Equivalent to 'id == "your-id"'
|
||||
id?: string;
|
||||
// Maximum number of records to return. Default limit is 25.
|
||||
// Maximum limit is 1000. Anything higher will return an error.
|
||||
limit?: number;
|
||||
offset?: number;
|
||||
// 'asc' (default), 'desc'
|
||||
order?: string;
|
||||
// field name to order by
|
||||
orderBy?: string;
|
||||
// Examples: 'age >= 18', 'age >= 18 and verified == true'
|
||||
// Comparison operators: '==', '!=', '<', '>', '<=', '>='
|
||||
// Logical operator: 'and'
|
||||
// Dot access is supported, eg: 'user.age == 11'
|
||||
// Accessing list elements is not supported yet.
|
||||
query?: string;
|
||||
// Optional table name. Defaults to 'default'
|
||||
table?: string;
|
||||
}
|
||||
|
||||
export interface ReadResponse {
|
||||
// JSON encoded records
|
||||
records?: { [key: string]: any }[];
|
||||
}
|
||||
|
||||
export interface TruncateRequest {
|
||||
// Optional table name. Defaults to 'default'
|
||||
table?: string;
|
||||
}
|
||||
|
||||
export interface TruncateResponse {
|
||||
// The table truncated
|
||||
table?: string;
|
||||
}
|
||||
|
||||
export interface UpdateRequest {
|
||||
// The id of the record. If not specified it is inferred from the 'id' field of the record
|
||||
id?: string;
|
||||
// record, JSON object
|
||||
record?: { [key: string]: any };
|
||||
// Optional table name. Defaults to 'default'
|
||||
table?: string;
|
||||
}
|
||||
|
||||
export interface UpdateResponse {}
|
||||
30
clients/ts/email/index.ts
Executable file
30
clients/ts/email/index.ts
Executable file
@@ -0,0 +1,30 @@
|
||||
import * as m3o from "@m3o/m3o-node";
|
||||
|
||||
export class EmailService {
|
||||
private client: m3o.Client;
|
||||
|
||||
constructor(token: string) {
|
||||
this.client = new m3o.Client({ token: token });
|
||||
}
|
||||
// Send an email by passing in from, to, subject, and a text or html body
|
||||
send(request: SendRequest): Promise<SendResponse> {
|
||||
return this.client.call("email", "Send", request) as Promise<SendResponse>;
|
||||
}
|
||||
}
|
||||
|
||||
export interface SendRequest {
|
||||
// the display name of the sender
|
||||
from?: string;
|
||||
// the html body
|
||||
htmlBody?: string;
|
||||
// an optional reply to email address
|
||||
replyTo?: string;
|
||||
// the email subject
|
||||
subject?: string;
|
||||
// the text body
|
||||
textBody?: string;
|
||||
// the email address of the recipient
|
||||
to?: string;
|
||||
}
|
||||
|
||||
export interface SendResponse {}
|
||||
74
clients/ts/emoji/index.ts
Executable file
74
clients/ts/emoji/index.ts
Executable file
@@ -0,0 +1,74 @@
|
||||
import * as m3o from "@m3o/m3o-node";
|
||||
|
||||
export class EmojiService {
|
||||
private client: m3o.Client;
|
||||
|
||||
constructor(token: string) {
|
||||
this.client = new m3o.Client({ token: token });
|
||||
}
|
||||
// Find an emoji by its alias e.g :beer:
|
||||
find(request: FindRequest): Promise<FindResponse> {
|
||||
return this.client.call("emoji", "Find", request) as Promise<FindResponse>;
|
||||
}
|
||||
// Get the flag for a country. Requires country code e.g GB for great britain
|
||||
flag(request: FlagRequest): Promise<FlagResponse> {
|
||||
return this.client.call("emoji", "Flag", request) as Promise<FlagResponse>;
|
||||
}
|
||||
// Print text and renders the emojis with aliases e.g
|
||||
// let's grab a :beer: becomes let's grab a 🍺
|
||||
print(request: PrintRequest): Promise<PrintResponse> {
|
||||
return this.client.call(
|
||||
"emoji",
|
||||
"Print",
|
||||
request
|
||||
) as Promise<PrintResponse>;
|
||||
}
|
||||
// Send an emoji to anyone via SMS. Messages are sent in the form '<message> Sent from <from>'
|
||||
send(request: SendRequest): Promise<SendResponse> {
|
||||
return this.client.call("emoji", "Send", request) as Promise<SendResponse>;
|
||||
}
|
||||
}
|
||||
|
||||
export interface FindRequest {
|
||||
// the alias code e.g :beer:
|
||||
alias?: string;
|
||||
}
|
||||
|
||||
export interface FindResponse {
|
||||
// the unicode emoji 🍺
|
||||
emoji?: string;
|
||||
}
|
||||
|
||||
export interface FlagRequest {
|
||||
// country code e.g GB
|
||||
code?: string;
|
||||
}
|
||||
|
||||
export interface FlagResponse {
|
||||
// the emoji flag
|
||||
flag?: string;
|
||||
}
|
||||
|
||||
export interface PrintRequest {
|
||||
// text including any alias e.g let's grab a :beer:
|
||||
text?: string;
|
||||
}
|
||||
|
||||
export interface PrintResponse {
|
||||
// text with rendered emojis
|
||||
text?: string;
|
||||
}
|
||||
|
||||
export interface SendRequest {
|
||||
// the name of the sender from e.g Alice
|
||||
from?: string;
|
||||
// message to send including emoji aliases
|
||||
message?: string;
|
||||
// phone number to send to (including international dialing code)
|
||||
to?: string;
|
||||
}
|
||||
|
||||
export interface SendResponse {
|
||||
// whether or not it succeeded
|
||||
success?: boolean;
|
||||
}
|
||||
92
clients/ts/file/index.ts
Executable file
92
clients/ts/file/index.ts
Executable file
@@ -0,0 +1,92 @@
|
||||
import * as m3o from "@m3o/m3o-node";
|
||||
|
||||
export class FileService {
|
||||
private client: m3o.Client;
|
||||
|
||||
constructor(token: string) {
|
||||
this.client = new m3o.Client({ token: token });
|
||||
}
|
||||
// Delete a file by project name/path
|
||||
delete(request: DeleteRequest): Promise<DeleteResponse> {
|
||||
return this.client.call(
|
||||
"file",
|
||||
"Delete",
|
||||
request
|
||||
) as Promise<DeleteResponse>;
|
||||
}
|
||||
// List files by their project and optionally a path.
|
||||
list(request: ListRequest): Promise<ListResponse> {
|
||||
return this.client.call("file", "List", request) as Promise<ListResponse>;
|
||||
}
|
||||
// Read a file by path
|
||||
read(request: ReadRequest): Promise<ReadResponse> {
|
||||
return this.client.call("file", "Read", request) as Promise<ReadResponse>;
|
||||
}
|
||||
// Save a file
|
||||
save(request: SaveRequest): Promise<SaveResponse> {
|
||||
return this.client.call("file", "Save", request) as Promise<SaveResponse>;
|
||||
}
|
||||
}
|
||||
|
||||
export interface BatchSaveRequest {
|
||||
files?: Record[];
|
||||
}
|
||||
|
||||
export interface BatchSaveResponse {}
|
||||
|
||||
export interface DeleteRequest {
|
||||
// Path to the file
|
||||
path?: string;
|
||||
// The project name
|
||||
project?: string;
|
||||
}
|
||||
|
||||
export interface DeleteResponse {}
|
||||
|
||||
export interface ListRequest {
|
||||
// Defaults to '/', ie. lists all files in a project.
|
||||
// Supply path to a folder if you want to list
|
||||
// files inside that folder
|
||||
// eg. '/docs'
|
||||
path?: string;
|
||||
// Project, required for listing.
|
||||
project?: string;
|
||||
}
|
||||
|
||||
export interface ListResponse {
|
||||
files?: Record[];
|
||||
}
|
||||
|
||||
export interface ReadRequest {
|
||||
// Path to the file
|
||||
path?: string;
|
||||
// Project name
|
||||
project?: string;
|
||||
}
|
||||
|
||||
export interface ReadResponse {
|
||||
// Returns the file
|
||||
file?: Record;
|
||||
}
|
||||
|
||||
export interface Record {
|
||||
// File contents
|
||||
content?: string;
|
||||
// Time the file was created e.g 2021-05-20T13:37:21Z
|
||||
created?: string;
|
||||
// Any other associated metadata as a map of key-value pairs
|
||||
metadata?: { [key: string]: string };
|
||||
// Path to file or folder eg. '/documents/text-files/file.txt'.
|
||||
path?: string;
|
||||
// A custom project to group files
|
||||
// eg. file-of-mywebsite.com
|
||||
project?: string;
|
||||
// Time the file was updated e.g 2021-05-20T13:37:21Z
|
||||
updated?: string;
|
||||
}
|
||||
|
||||
export interface SaveRequest {
|
||||
file?: Record;
|
||||
}
|
||||
|
||||
export interface SaveResponse {}
|
||||
83
clients/ts/forex/index.ts
Executable file
83
clients/ts/forex/index.ts
Executable file
@@ -0,0 +1,83 @@
|
||||
import * as m3o from "@m3o/m3o-node";
|
||||
|
||||
export class ForexService {
|
||||
private client: m3o.Client;
|
||||
|
||||
constructor(token: string) {
|
||||
this.client = new m3o.Client({ token: token });
|
||||
}
|
||||
// Returns the data for the previous close
|
||||
history(request: HistoryRequest): Promise<HistoryResponse> {
|
||||
return this.client.call(
|
||||
"forex",
|
||||
"History",
|
||||
request
|
||||
) as Promise<HistoryResponse>;
|
||||
}
|
||||
// Get the latest price for a given forex ticker
|
||||
price(request: PriceRequest): Promise<PriceResponse> {
|
||||
return this.client.call(
|
||||
"forex",
|
||||
"Price",
|
||||
request
|
||||
) as Promise<PriceResponse>;
|
||||
}
|
||||
// Get the latest quote for the forex
|
||||
quote(request: QuoteRequest): Promise<QuoteResponse> {
|
||||
return this.client.call(
|
||||
"forex",
|
||||
"Quote",
|
||||
request
|
||||
) as Promise<QuoteResponse>;
|
||||
}
|
||||
}
|
||||
|
||||
export interface HistoryRequest {
|
||||
// the forex symbol e.g GBPUSD
|
||||
symbol?: string;
|
||||
}
|
||||
|
||||
export interface HistoryResponse {
|
||||
// the close price
|
||||
close?: number;
|
||||
// the date
|
||||
date?: string;
|
||||
// the peak price
|
||||
high?: number;
|
||||
// the low price
|
||||
low?: number;
|
||||
// the open price
|
||||
open?: number;
|
||||
// the forex symbol
|
||||
symbol?: string;
|
||||
// the volume
|
||||
volume?: number;
|
||||
}
|
||||
|
||||
export interface PriceRequest {
|
||||
// forex symbol e.g GBPUSD
|
||||
symbol?: string;
|
||||
}
|
||||
|
||||
export interface PriceResponse {
|
||||
// the last price
|
||||
price?: number;
|
||||
// the forex symbol e.g GBPUSD
|
||||
symbol?: string;
|
||||
}
|
||||
|
||||
export interface QuoteRequest {
|
||||
// the forex symbol e.g GBPUSD
|
||||
symbol?: string;
|
||||
}
|
||||
|
||||
export interface QuoteResponse {
|
||||
// the asking price
|
||||
askPrice?: number;
|
||||
// the bidding price
|
||||
bidPrice?: number;
|
||||
// the forex symbol
|
||||
symbol?: string;
|
||||
// the UTC timestamp of the quote
|
||||
timestamp?: string;
|
||||
}
|
||||
60
clients/ts/geocoding/index.ts
Executable file
60
clients/ts/geocoding/index.ts
Executable file
@@ -0,0 +1,60 @@
|
||||
import * as m3o from "@m3o/m3o-node";
|
||||
|
||||
export class GeocodingService {
|
||||
private client: m3o.Client;
|
||||
|
||||
constructor(token: string) {
|
||||
this.client = new m3o.Client({ token: token });
|
||||
}
|
||||
// Lookup returns a geocoded address including normalized address and gps coordinates. All fields are optional, provide more to get more accurate results
|
||||
lookup(request: LookupRequest): Promise<LookupResponse> {
|
||||
return this.client.call(
|
||||
"geocoding",
|
||||
"Lookup",
|
||||
request
|
||||
) as Promise<LookupResponse>;
|
||||
}
|
||||
// Reverse lookup an address from gps coordinates
|
||||
reverse(request: ReverseRequest): Promise<ReverseResponse> {
|
||||
return this.client.call(
|
||||
"geocoding",
|
||||
"Reverse",
|
||||
request
|
||||
) as Promise<ReverseResponse>;
|
||||
}
|
||||
}
|
||||
|
||||
export interface Address {
|
||||
city?: string;
|
||||
country?: string;
|
||||
lineOne?: string;
|
||||
lineTwo?: string;
|
||||
postcode?: string;
|
||||
}
|
||||
|
||||
export interface Location {
|
||||
latitude?: number;
|
||||
longitude?: number;
|
||||
}
|
||||
|
||||
export interface LookupRequest {
|
||||
address?: string;
|
||||
city?: string;
|
||||
country?: string;
|
||||
postcode?: string;
|
||||
}
|
||||
|
||||
export interface LookupResponse {
|
||||
address?: { [key: string]: any };
|
||||
location?: { [key: string]: any };
|
||||
}
|
||||
|
||||
export interface ReverseRequest {
|
||||
latitude?: number;
|
||||
longitude?: number;
|
||||
}
|
||||
|
||||
export interface ReverseResponse {
|
||||
address?: { [key: string]: any };
|
||||
location?: { [key: string]: any };
|
||||
}
|
||||
43
clients/ts/helloworld/index.ts
Executable file
43
clients/ts/helloworld/index.ts
Executable file
@@ -0,0 +1,43 @@
|
||||
import * as m3o from "@m3o/m3o-node";
|
||||
|
||||
export class HelloworldService {
|
||||
private client: m3o.Client;
|
||||
|
||||
constructor(token: string) {
|
||||
this.client = new m3o.Client({ token: token });
|
||||
}
|
||||
// Call returns a personalised "Hello $name" response
|
||||
call(request: CallRequest): Promise<CallResponse> {
|
||||
return this.client.call(
|
||||
"helloworld",
|
||||
"Call",
|
||||
request
|
||||
) as Promise<CallResponse>;
|
||||
}
|
||||
// Stream returns a stream of "Hello $name" responses
|
||||
stream(request: StreamRequest): Promise<StreamResponse> {
|
||||
return this.client.call(
|
||||
"helloworld",
|
||||
"Stream",
|
||||
request
|
||||
) as Promise<StreamResponse>;
|
||||
}
|
||||
}
|
||||
|
||||
export interface CallRequest {
|
||||
name?: string;
|
||||
}
|
||||
|
||||
export interface CallResponse {
|
||||
message?: string;
|
||||
}
|
||||
|
||||
export interface StreamRequest {
|
||||
// the number of messages to send back
|
||||
messages?: number;
|
||||
name?: string;
|
||||
}
|
||||
|
||||
export interface StreamResponse {
|
||||
message?: string;
|
||||
}
|
||||
39
clients/ts/id/index.ts
Executable file
39
clients/ts/id/index.ts
Executable file
@@ -0,0 +1,39 @@
|
||||
import * as m3o from "@m3o/m3o-node";
|
||||
|
||||
export class IdService {
|
||||
private client: m3o.Client;
|
||||
|
||||
constructor(token: string) {
|
||||
this.client = new m3o.Client({ token: token });
|
||||
}
|
||||
// Generate a unique ID. Defaults to uuid.
|
||||
generate(request: GenerateRequest): Promise<GenerateResponse> {
|
||||
return this.client.call(
|
||||
"id",
|
||||
"Generate",
|
||||
request
|
||||
) as Promise<GenerateResponse>;
|
||||
}
|
||||
// List the types of IDs available. No query params needed.
|
||||
types(request: TypesRequest): Promise<TypesResponse> {
|
||||
return this.client.call("id", "Types", request) as Promise<TypesResponse>;
|
||||
}
|
||||
}
|
||||
|
||||
export interface GenerateRequest {
|
||||
// type of id e.g uuid, shortid, snowflake (64 bit), bigflake (128 bit)
|
||||
type?: string;
|
||||
}
|
||||
|
||||
export interface GenerateResponse {
|
||||
// the unique id generated
|
||||
id?: string;
|
||||
// the type of id generated
|
||||
type?: string;
|
||||
}
|
||||
|
||||
export interface TypesRequest {}
|
||||
|
||||
export interface TypesResponse {
|
||||
types?: string[];
|
||||
}
|
||||
113
clients/ts/image/index.ts
Executable file
113
clients/ts/image/index.ts
Executable file
@@ -0,0 +1,113 @@
|
||||
import * as m3o from "@m3o/m3o-node";
|
||||
|
||||
export class ImageService {
|
||||
private client: m3o.Client;
|
||||
|
||||
constructor(token: string) {
|
||||
this.client = new m3o.Client({ token: token });
|
||||
}
|
||||
// Convert an image from one format (jpeg, png etc.) to an other either on the fly (from base64 to base64),
|
||||
// or by uploading the conversion result.
|
||||
convert(request: ConvertRequest): Promise<ConvertResponse> {
|
||||
return this.client.call(
|
||||
"image",
|
||||
"Convert",
|
||||
request
|
||||
) as Promise<ConvertResponse>;
|
||||
}
|
||||
// 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.
|
||||
resize(request: ResizeRequest): Promise<ResizeResponse> {
|
||||
return this.client.call(
|
||||
"image",
|
||||
"Resize",
|
||||
request
|
||||
) as Promise<ResizeResponse>;
|
||||
}
|
||||
// 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.
|
||||
upload(request: UploadRequest): Promise<UploadResponse> {
|
||||
return this.client.call(
|
||||
"image",
|
||||
"Upload",
|
||||
request
|
||||
) as Promise<UploadResponse>;
|
||||
}
|
||||
}
|
||||
|
||||
export interface ConvertRequest {
|
||||
// base64 encoded image to resize,
|
||||
// ie. "data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="
|
||||
base64?: string;
|
||||
// output name of the image including extension, ie. "cat.png"
|
||||
name?: string;
|
||||
// make output a URL and not a base64 response
|
||||
outputURL?: boolean;
|
||||
// url of the image to resize
|
||||
url?: string;
|
||||
}
|
||||
|
||||
export interface ConvertResponse {
|
||||
base64?: string;
|
||||
url?: string;
|
||||
}
|
||||
|
||||
export interface CropOptions {
|
||||
// Crop anchor point: "top", "top left", "top right",
|
||||
// "left", "center", "right"
|
||||
// "bottom left", "bottom", "bottom right".
|
||||
// Optional. Defaults to center.
|
||||
anchor?: string;
|
||||
// height to crop to
|
||||
height?: number;
|
||||
// width to crop to
|
||||
width?: number;
|
||||
}
|
||||
|
||||
export interface Point {
|
||||
x?: number;
|
||||
y?: number;
|
||||
}
|
||||
|
||||
export interface Rectangle {
|
||||
max?: Point;
|
||||
min?: Point;
|
||||
}
|
||||
|
||||
export interface ResizeRequest {
|
||||
// base64 encoded image to resize,
|
||||
// ie. "data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="
|
||||
base64?: string;
|
||||
// optional crop options
|
||||
// if provided, after resize, the image
|
||||
// will be cropped
|
||||
cropOptions?: CropOptions;
|
||||
height?: number;
|
||||
// output name of the image including extension, ie. "cat.png"
|
||||
name?: string;
|
||||
// make output a URL and not a base64 response
|
||||
outputURL?: boolean;
|
||||
// url of the image to resize
|
||||
url?: string;
|
||||
width?: number;
|
||||
}
|
||||
|
||||
export interface ResizeResponse {
|
||||
base64?: string;
|
||||
url?: string;
|
||||
}
|
||||
|
||||
export interface UploadRequest {
|
||||
// Base64 encoded image to upload,
|
||||
// ie. "data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="
|
||||
base64?: string;
|
||||
// Output name of the image including extension, ie. "cat.png"
|
||||
name?: string;
|
||||
// URL of the image to upload
|
||||
url?: string;
|
||||
}
|
||||
|
||||
export interface UploadResponse {
|
||||
url?: string;
|
||||
}
|
||||
96
clients/ts/index.ts
Executable file
96
clients/ts/index.ts
Executable file
@@ -0,0 +1,96 @@
|
||||
import * as address from "./address";
|
||||
import * as answer from "./answer";
|
||||
import * as cache from "./cache";
|
||||
import * as crypto from "./crypto";
|
||||
import * as currency from "./currency";
|
||||
import * as db from "./db";
|
||||
import * as email from "./email";
|
||||
import * as emoji from "./emoji";
|
||||
import * as file from "./file";
|
||||
import * as forex from "./forex";
|
||||
import * as geocoding from "./geocoding";
|
||||
import * as helloworld from "./helloworld";
|
||||
import * as id from "./id";
|
||||
import * as image from "./image";
|
||||
import * as ip from "./ip";
|
||||
import * as location from "./location";
|
||||
import * as otp from "./otp";
|
||||
import * as postcode from "./postcode";
|
||||
import * as quran from "./quran";
|
||||
import * as routing from "./routing";
|
||||
import * as rss from "./rss";
|
||||
import * as sentiment from "./sentiment";
|
||||
import * as sms from "./sms";
|
||||
import * as stock from "./stock";
|
||||
import * as stream from "./stream";
|
||||
import * as thumbnail from "./thumbnail";
|
||||
import * as time from "./time";
|
||||
import * as url from "./url";
|
||||
import * as user from "./user";
|
||||
import * as weather from "./weather";
|
||||
|
||||
export class Client {
|
||||
constructor(token: string) {
|
||||
this.addressService = new address.AddressService(token);
|
||||
this.answerService = new answer.AnswerService(token);
|
||||
this.cacheService = new cache.CacheService(token);
|
||||
this.cryptoService = new crypto.CryptoService(token);
|
||||
this.currencyService = new currency.CurrencyService(token);
|
||||
this.dbService = new db.DbService(token);
|
||||
this.emailService = new email.EmailService(token);
|
||||
this.emojiService = new emoji.EmojiService(token);
|
||||
this.fileService = new file.FileService(token);
|
||||
this.forexService = new forex.ForexService(token);
|
||||
this.geocodingService = new geocoding.GeocodingService(token);
|
||||
this.helloworldService = new helloworld.HelloworldService(token);
|
||||
this.idService = new id.IdService(token);
|
||||
this.imageService = new image.ImageService(token);
|
||||
this.ipService = new ip.IpService(token);
|
||||
this.locationService = new location.LocationService(token);
|
||||
this.otpService = new otp.OtpService(token);
|
||||
this.postcodeService = new postcode.PostcodeService(token);
|
||||
this.quranService = new quran.QuranService(token);
|
||||
this.routingService = new routing.RoutingService(token);
|
||||
this.rssService = new rss.RssService(token);
|
||||
this.sentimentService = new sentiment.SentimentService(token);
|
||||
this.smsService = new sms.SmsService(token);
|
||||
this.stockService = new stock.StockService(token);
|
||||
this.streamService = new stream.StreamService(token);
|
||||
this.thumbnailService = new thumbnail.ThumbnailService(token);
|
||||
this.timeService = new time.TimeService(token);
|
||||
this.urlService = new url.UrlService(token);
|
||||
this.userService = new user.UserService(token);
|
||||
this.weatherService = new weather.WeatherService(token);
|
||||
}
|
||||
|
||||
addressService: address.AddressService;
|
||||
answerService: answer.AnswerService;
|
||||
cacheService: cache.CacheService;
|
||||
cryptoService: crypto.CryptoService;
|
||||
currencyService: currency.CurrencyService;
|
||||
dbService: db.DbService;
|
||||
emailService: email.EmailService;
|
||||
emojiService: emoji.EmojiService;
|
||||
fileService: file.FileService;
|
||||
forexService: forex.ForexService;
|
||||
geocodingService: geocoding.GeocodingService;
|
||||
helloworldService: helloworld.HelloworldService;
|
||||
idService: id.IdService;
|
||||
imageService: image.ImageService;
|
||||
ipService: ip.IpService;
|
||||
locationService: location.LocationService;
|
||||
otpService: otp.OtpService;
|
||||
postcodeService: postcode.PostcodeService;
|
||||
quranService: quran.QuranService;
|
||||
routingService: routing.RoutingService;
|
||||
rssService: rss.RssService;
|
||||
sentimentService: sentiment.SentimentService;
|
||||
smsService: sms.SmsService;
|
||||
stockService: stock.StockService;
|
||||
streamService: stream.StreamService;
|
||||
thumbnailService: thumbnail.ThumbnailService;
|
||||
timeService: time.TimeService;
|
||||
urlService: url.UrlService;
|
||||
userService: user.UserService;
|
||||
weatherService: weather.WeatherService;
|
||||
}
|
||||
37
clients/ts/ip/index.ts
Executable file
37
clients/ts/ip/index.ts
Executable file
@@ -0,0 +1,37 @@
|
||||
import * as m3o from "@m3o/m3o-node";
|
||||
|
||||
export class IpService {
|
||||
private client: m3o.Client;
|
||||
|
||||
constructor(token: string) {
|
||||
this.client = new m3o.Client({ token: token });
|
||||
}
|
||||
// Lookup the geolocation information for an IP address
|
||||
lookup(request: LookupRequest): Promise<LookupResponse> {
|
||||
return this.client.call("ip", "Lookup", request) as Promise<LookupResponse>;
|
||||
}
|
||||
}
|
||||
|
||||
export interface LookupRequest {
|
||||
// IP to lookup
|
||||
ip?: string;
|
||||
}
|
||||
|
||||
export interface LookupResponse {
|
||||
// Autonomous system number
|
||||
asn?: number;
|
||||
// Name of the city
|
||||
city?: string;
|
||||
// Name of the continent
|
||||
continent?: string;
|
||||
// Name of the country
|
||||
country?: string;
|
||||
// IP of the query
|
||||
ip?: string;
|
||||
// Latitude e.g 52.523219
|
||||
latitude?: number;
|
||||
// Longitude e.g 13.428555
|
||||
longitude?: number;
|
||||
// Timezone e.g Europe/Rome
|
||||
timezone?: string;
|
||||
}
|
||||
75
clients/ts/location/index.ts
Executable file
75
clients/ts/location/index.ts
Executable file
@@ -0,0 +1,75 @@
|
||||
import * as m3o from "@m3o/m3o-node";
|
||||
|
||||
export class LocationService {
|
||||
private client: m3o.Client;
|
||||
|
||||
constructor(token: string) {
|
||||
this.client = new m3o.Client({ token: token });
|
||||
}
|
||||
// Read an entity by its ID
|
||||
read(request: ReadRequest): Promise<ReadResponse> {
|
||||
return this.client.call(
|
||||
"location",
|
||||
"Read",
|
||||
request
|
||||
) as Promise<ReadResponse>;
|
||||
}
|
||||
// Save an entity's current position
|
||||
save(request: SaveRequest): Promise<SaveResponse> {
|
||||
return this.client.call(
|
||||
"location",
|
||||
"Save",
|
||||
request
|
||||
) as Promise<SaveResponse>;
|
||||
}
|
||||
// Search for entities in a given radius
|
||||
search(request: SearchRequest): Promise<SearchResponse> {
|
||||
return this.client.call(
|
||||
"location",
|
||||
"Search",
|
||||
request
|
||||
) as Promise<SearchResponse>;
|
||||
}
|
||||
}
|
||||
|
||||
export interface Entity {
|
||||
id?: string;
|
||||
location?: Point;
|
||||
type?: string;
|
||||
}
|
||||
|
||||
export interface Point {
|
||||
latitude?: number;
|
||||
longitude?: number;
|
||||
timestamp?: number;
|
||||
}
|
||||
|
||||
export interface ReadRequest {
|
||||
// the entity id
|
||||
id?: string;
|
||||
}
|
||||
|
||||
export interface ReadResponse {
|
||||
entity?: { [key: string]: any };
|
||||
}
|
||||
|
||||
export interface SaveRequest {
|
||||
entity?: { [key: string]: any };
|
||||
}
|
||||
|
||||
export interface SaveResponse {}
|
||||
|
||||
export interface SearchRequest {
|
||||
// Central position to search from
|
||||
center?: Point;
|
||||
// Maximum number of entities to return
|
||||
numEntities?: number;
|
||||
// radius in meters
|
||||
radius?: number;
|
||||
// type of entities to filter
|
||||
type?: string;
|
||||
}
|
||||
|
||||
export interface SearchResponse {
|
||||
entities?: Entity[];
|
||||
}
|
||||
51
clients/ts/otp/index.ts
Executable file
51
clients/ts/otp/index.ts
Executable file
@@ -0,0 +1,51 @@
|
||||
import * as m3o from "@m3o/m3o-node";
|
||||
|
||||
export class OtpService {
|
||||
private client: m3o.Client;
|
||||
|
||||
constructor(token: string) {
|
||||
this.client = new m3o.Client({ token: token });
|
||||
}
|
||||
// Generate an OTP (one time pass) code
|
||||
generate(request: GenerateRequest): Promise<GenerateResponse> {
|
||||
return this.client.call(
|
||||
"otp",
|
||||
"Generate",
|
||||
request
|
||||
) as Promise<GenerateResponse>;
|
||||
}
|
||||
// Validate the OTP code
|
||||
validate(request: ValidateRequest): Promise<ValidateResponse> {
|
||||
return this.client.call(
|
||||
"otp",
|
||||
"Validate",
|
||||
request
|
||||
) as Promise<ValidateResponse>;
|
||||
}
|
||||
}
|
||||
|
||||
export interface GenerateRequest {
|
||||
// expiration in seconds (default: 60)
|
||||
expiry?: number;
|
||||
// unique id, email or user to generate an OTP for
|
||||
id?: string;
|
||||
// number of characters (default: 6)
|
||||
size?: number;
|
||||
}
|
||||
|
||||
export interface GenerateResponse {
|
||||
// one time pass code
|
||||
code?: string;
|
||||
}
|
||||
|
||||
export interface ValidateRequest {
|
||||
// one time pass code to validate
|
||||
code?: string;
|
||||
// unique id, email or user for which the code was generated
|
||||
id?: string;
|
||||
}
|
||||
|
||||
export interface ValidateResponse {
|
||||
// returns true if the code is valid for the ID
|
||||
success?: boolean;
|
||||
}
|
||||
566
clients/ts/package-lock.json
generated
Normal file
566
clients/ts/package-lock.json
generated
Normal file
@@ -0,0 +1,566 @@
|
||||
{
|
||||
"name": "@micro/services",
|
||||
"version": "1.0.1",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@micro/services",
|
||||
"version": "1.0.1",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@m3o/m3o-node": "^0.0.24"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^3.5.1"
|
||||
}
|
||||
},
|
||||
"node_modules/@m3o/m3o-node": {
|
||||
"version": "0.0.24",
|
||||
"resolved": "https://registry.npmjs.org/@m3o/m3o-node/-/m3o-node-0.0.24.tgz",
|
||||
"integrity": "sha512-W6VqmZUTFodwBUai5uQ9nO4ylIztUXKYPFfZg2qqTv1lHkOYQ0XiJgFVn+SEOlp4GU/JI9OzCt4k1Ui5XaXGdw==",
|
||||
"dependencies": {
|
||||
"@types/ws": "^7.2.2",
|
||||
"axios": "^0.21.1",
|
||||
"body-parser": "^1.19.0",
|
||||
"dotenv": "^10.0.0",
|
||||
"jsonfile": "^6.1.0",
|
||||
"ws": "^7.2.3"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/node": {
|
||||
"version": "16.7.10",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-16.7.10.tgz",
|
||||
"integrity": "sha512-S63Dlv4zIPb8x6MMTgDq5WWRJQe56iBEY0O3SOFA9JrRienkOVDXSXBjjJw6HTNQYSE2JI6GMCR6LVbIMHJVvA=="
|
||||
},
|
||||
"node_modules/@types/ws": {
|
||||
"version": "7.4.7",
|
||||
"resolved": "https://registry.npmjs.org/@types/ws/-/ws-7.4.7.tgz",
|
||||
"integrity": "sha512-JQbbmxZTZehdc2iszGKs5oC3NFnjeay7mtAWrdt7qNtAVK0g19muApzAy4bm9byz79xa2ZnO/BOBC2R8RC5Lww==",
|
||||
"dependencies": {
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/axios": {
|
||||
"version": "0.21.1",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz",
|
||||
"integrity": "sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==",
|
||||
"dependencies": {
|
||||
"follow-redirects": "^1.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/body-parser": {
|
||||
"version": "1.19.0",
|
||||
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.19.0.tgz",
|
||||
"integrity": "sha512-dhEPs72UPbDnAQJ9ZKMNTP6ptJaionhP5cBb541nXPlW60Jepo9RV/a4fX4XWW9CuFNK22krhrj1+rgzifNCsw==",
|
||||
"dependencies": {
|
||||
"bytes": "3.1.0",
|
||||
"content-type": "~1.0.4",
|
||||
"debug": "2.6.9",
|
||||
"depd": "~1.1.2",
|
||||
"http-errors": "1.7.2",
|
||||
"iconv-lite": "0.4.24",
|
||||
"on-finished": "~2.3.0",
|
||||
"qs": "6.7.0",
|
||||
"raw-body": "2.4.0",
|
||||
"type-is": "~1.6.17"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/bytes": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.0.tgz",
|
||||
"integrity": "sha512-zauLjrfCG+xvoyaqLoV8bLVXXNGC4JqlxFCutSDWA6fJrTo2ZuvLYTqZ7aHBLZSMOopbzwv8f+wZcVzfVTI2Dg==",
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/content-type": {
|
||||
"version": "1.0.4",
|
||||
"resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz",
|
||||
"integrity": "sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/debug": {
|
||||
"version": "2.6.9",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
||||
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
|
||||
"dependencies": {
|
||||
"ms": "2.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/depd": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz",
|
||||
"integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak=",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/dotenv": {
|
||||
"version": "10.0.0",
|
||||
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-10.0.0.tgz",
|
||||
"integrity": "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==",
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
}
|
||||
},
|
||||
"node_modules/ee-first": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
|
||||
"integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0="
|
||||
},
|
||||
"node_modules/follow-redirects": {
|
||||
"version": "1.14.3",
|
||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.3.tgz",
|
||||
"integrity": "sha512-3MkHxknWMUtb23apkgz/83fDoe+y+qr0TdgacGIA7bew+QLBo3vdgEN2xEsuXNivpFy4CyDhBBZnNZOtalmenw==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "individual",
|
||||
"url": "https://github.com/sponsors/RubenVerborgh"
|
||||
}
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=4.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"debug": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/graceful-fs": {
|
||||
"version": "4.2.8",
|
||||
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.8.tgz",
|
||||
"integrity": "sha512-qkIilPUYcNhJpd33n0GBXTB1MMPp14TxEsEs0pTrsSVucApsYzW5V+Q8Qxhik6KU3evy+qkAAowTByymK0avdg==",
|
||||
"optional": true
|
||||
},
|
||||
"node_modules/http-errors": {
|
||||
"version": "1.7.2",
|
||||
"resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.7.2.tgz",
|
||||
"integrity": "sha512-uUQBt3H/cSIVfch6i1EuPNy/YsRSOUBXTVfZ+yR7Zjez3qjBz6i9+i4zjNaoqcoFVI4lQJ5plg63TvGfRSDCRg==",
|
||||
"dependencies": {
|
||||
"depd": "~1.1.2",
|
||||
"inherits": "2.0.3",
|
||||
"setprototypeof": "1.1.1",
|
||||
"statuses": ">= 1.5.0 < 2",
|
||||
"toidentifier": "1.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/iconv-lite": {
|
||||
"version": "0.4.24",
|
||||
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz",
|
||||
"integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==",
|
||||
"dependencies": {
|
||||
"safer-buffer": ">= 2.1.2 < 3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/inherits": {
|
||||
"version": "2.0.3",
|
||||
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
|
||||
"integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4="
|
||||
},
|
||||
"node_modules/jsonfile": {
|
||||
"version": "6.1.0",
|
||||
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz",
|
||||
"integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==",
|
||||
"dependencies": {
|
||||
"universalify": "^2.0.0"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"graceful-fs": "^4.1.6"
|
||||
}
|
||||
},
|
||||
"node_modules/media-typer": {
|
||||
"version": "0.3.0",
|
||||
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
|
||||
"integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/mime-db": {
|
||||
"version": "1.49.0",
|
||||
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.49.0.tgz",
|
||||
"integrity": "sha512-CIc8j9URtOVApSFCQIF+VBkX1RwXp/oMMOrqdyXSBXq5RWNEsRfyj1kiRnQgmNXmHxPoFIxOroKA3zcU9P+nAA==",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/mime-types": {
|
||||
"version": "2.1.32",
|
||||
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.32.tgz",
|
||||
"integrity": "sha512-hJGaVS4G4c9TSMYh2n6SQAGrC4RnfU+daP8G7cSCmaqNjiOoUY0VHCMS42pxnQmVF1GWwFhbHWn3RIxCqTmZ9A==",
|
||||
"dependencies": {
|
||||
"mime-db": "1.49.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/ms": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
||||
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
|
||||
},
|
||||
"node_modules/on-finished": {
|
||||
"version": "2.3.0",
|
||||
"resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz",
|
||||
"integrity": "sha1-IPEzZIGwg811M3mSoWlxqi2QaUc=",
|
||||
"dependencies": {
|
||||
"ee-first": "1.1.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/qs": {
|
||||
"version": "6.7.0",
|
||||
"resolved": "https://registry.npmjs.org/qs/-/qs-6.7.0.tgz",
|
||||
"integrity": "sha512-VCdBRNFTX1fyE7Nb6FYoURo/SPe62QCaAyzJvUjwRaIsc+NePBEniHlvxFmmX56+HZphIGtV0XeCirBtpDrTyQ==",
|
||||
"engines": {
|
||||
"node": ">=0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/raw-body": {
|
||||
"version": "2.4.0",
|
||||
"resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.4.0.tgz",
|
||||
"integrity": "sha512-4Oz8DUIwdvoa5qMJelxipzi/iJIi40O5cGV1wNYp5hvZP8ZN0T+jiNkL0QepXs+EsQ9XJ8ipEDoiH70ySUJP3Q==",
|
||||
"dependencies": {
|
||||
"bytes": "3.1.0",
|
||||
"http-errors": "1.7.2",
|
||||
"iconv-lite": "0.4.24",
|
||||
"unpipe": "1.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/safer-buffer": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
|
||||
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
|
||||
},
|
||||
"node_modules/setprototypeof": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.1.tgz",
|
||||
"integrity": "sha512-JvdAWfbXeIGaZ9cILp38HntZSFSo3mWg6xGcJJsd+d4aRMOqauag1C63dJfDw7OaMYwEbHMOxEZ1lqVRYP2OAw=="
|
||||
},
|
||||
"node_modules/statuses": {
|
||||
"version": "1.5.0",
|
||||
"resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz",
|
||||
"integrity": "sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow=",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/toidentifier": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.0.tgz",
|
||||
"integrity": "sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw==",
|
||||
"engines": {
|
||||
"node": ">=0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/type-is": {
|
||||
"version": "1.6.18",
|
||||
"resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz",
|
||||
"integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==",
|
||||
"dependencies": {
|
||||
"media-typer": "0.3.0",
|
||||
"mime-types": "~2.1.24"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/typescript": {
|
||||
"version": "3.9.10",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.9.10.tgz",
|
||||
"integrity": "sha512-w6fIxVE/H1PkLKcCPsFqKE7Kv7QUwhU8qQY2MueZXWx5cPZdwFupLgKK3vntcK98BtNHZtAF4LA/yl2a7k8R6Q==",
|
||||
"dev": true,
|
||||
"bin": {
|
||||
"tsc": "bin/tsc",
|
||||
"tsserver": "bin/tsserver"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4.2.0"
|
||||
}
|
||||
},
|
||||
"node_modules/universalify": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz",
|
||||
"integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==",
|
||||
"engines": {
|
||||
"node": ">= 10.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/unpipe": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
|
||||
"integrity": "sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw=",
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/ws": {
|
||||
"version": "7.5.4",
|
||||
"resolved": "https://registry.npmjs.org/ws/-/ws-7.5.4.tgz",
|
||||
"integrity": "sha512-zP9z6GXm6zC27YtspwH99T3qTG7bBFv2VIkeHstMLrLlDJuzA7tQ5ls3OJ1hOGGCzTQPniNJoHXIAOS0Jljohg==",
|
||||
"engines": {
|
||||
"node": ">=8.3.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"bufferutil": "^4.0.1",
|
||||
"utf-8-validate": "^5.0.2"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"bufferutil": {
|
||||
"optional": true
|
||||
},
|
||||
"utf-8-validate": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"@m3o/m3o-node": {
|
||||
"version": "0.0.24",
|
||||
"resolved": "https://registry.npmjs.org/@m3o/m3o-node/-/m3o-node-0.0.24.tgz",
|
||||
"integrity": "sha512-W6VqmZUTFodwBUai5uQ9nO4ylIztUXKYPFfZg2qqTv1lHkOYQ0XiJgFVn+SEOlp4GU/JI9OzCt4k1Ui5XaXGdw==",
|
||||
"requires": {
|
||||
"@types/ws": "^7.2.2",
|
||||
"axios": "^0.21.1",
|
||||
"body-parser": "^1.19.0",
|
||||
"dotenv": "^10.0.0",
|
||||
"jsonfile": "^6.1.0",
|
||||
"ws": "^7.2.3"
|
||||
}
|
||||
},
|
||||
"@types/node": {
|
||||
"version": "16.7.10",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-16.7.10.tgz",
|
||||
"integrity": "sha512-S63Dlv4zIPb8x6MMTgDq5WWRJQe56iBEY0O3SOFA9JrRienkOVDXSXBjjJw6HTNQYSE2JI6GMCR6LVbIMHJVvA=="
|
||||
},
|
||||
"@types/ws": {
|
||||
"version": "7.4.7",
|
||||
"resolved": "https://registry.npmjs.org/@types/ws/-/ws-7.4.7.tgz",
|
||||
"integrity": "sha512-JQbbmxZTZehdc2iszGKs5oC3NFnjeay7mtAWrdt7qNtAVK0g19muApzAy4bm9byz79xa2ZnO/BOBC2R8RC5Lww==",
|
||||
"requires": {
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"axios": {
|
||||
"version": "0.21.1",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz",
|
||||
"integrity": "sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==",
|
||||
"requires": {
|
||||
"follow-redirects": "^1.10.0"
|
||||
}
|
||||
},
|
||||
"body-parser": {
|
||||
"version": "1.19.0",
|
||||
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.19.0.tgz",
|
||||
"integrity": "sha512-dhEPs72UPbDnAQJ9ZKMNTP6ptJaionhP5cBb541nXPlW60Jepo9RV/a4fX4XWW9CuFNK22krhrj1+rgzifNCsw==",
|
||||
"requires": {
|
||||
"bytes": "3.1.0",
|
||||
"content-type": "~1.0.4",
|
||||
"debug": "2.6.9",
|
||||
"depd": "~1.1.2",
|
||||
"http-errors": "1.7.2",
|
||||
"iconv-lite": "0.4.24",
|
||||
"on-finished": "~2.3.0",
|
||||
"qs": "6.7.0",
|
||||
"raw-body": "2.4.0",
|
||||
"type-is": "~1.6.17"
|
||||
}
|
||||
},
|
||||
"bytes": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.0.tgz",
|
||||
"integrity": "sha512-zauLjrfCG+xvoyaqLoV8bLVXXNGC4JqlxFCutSDWA6fJrTo2ZuvLYTqZ7aHBLZSMOopbzwv8f+wZcVzfVTI2Dg=="
|
||||
},
|
||||
"content-type": {
|
||||
"version": "1.0.4",
|
||||
"resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz",
|
||||
"integrity": "sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA=="
|
||||
},
|
||||
"debug": {
|
||||
"version": "2.6.9",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
||||
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
|
||||
"requires": {
|
||||
"ms": "2.0.0"
|
||||
}
|
||||
},
|
||||
"depd": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz",
|
||||
"integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak="
|
||||
},
|
||||
"dotenv": {
|
||||
"version": "10.0.0",
|
||||
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-10.0.0.tgz",
|
||||
"integrity": "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q=="
|
||||
},
|
||||
"ee-first": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
|
||||
"integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0="
|
||||
},
|
||||
"follow-redirects": {
|
||||
"version": "1.14.3",
|
||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.3.tgz",
|
||||
"integrity": "sha512-3MkHxknWMUtb23apkgz/83fDoe+y+qr0TdgacGIA7bew+QLBo3vdgEN2xEsuXNivpFy4CyDhBBZnNZOtalmenw=="
|
||||
},
|
||||
"graceful-fs": {
|
||||
"version": "4.2.8",
|
||||
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.8.tgz",
|
||||
"integrity": "sha512-qkIilPUYcNhJpd33n0GBXTB1MMPp14TxEsEs0pTrsSVucApsYzW5V+Q8Qxhik6KU3evy+qkAAowTByymK0avdg==",
|
||||
"optional": true
|
||||
},
|
||||
"http-errors": {
|
||||
"version": "1.7.2",
|
||||
"resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.7.2.tgz",
|
||||
"integrity": "sha512-uUQBt3H/cSIVfch6i1EuPNy/YsRSOUBXTVfZ+yR7Zjez3qjBz6i9+i4zjNaoqcoFVI4lQJ5plg63TvGfRSDCRg==",
|
||||
"requires": {
|
||||
"depd": "~1.1.2",
|
||||
"inherits": "2.0.3",
|
||||
"setprototypeof": "1.1.1",
|
||||
"statuses": ">= 1.5.0 < 2",
|
||||
"toidentifier": "1.0.0"
|
||||
}
|
||||
},
|
||||
"iconv-lite": {
|
||||
"version": "0.4.24",
|
||||
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz",
|
||||
"integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==",
|
||||
"requires": {
|
||||
"safer-buffer": ">= 2.1.2 < 3"
|
||||
}
|
||||
},
|
||||
"inherits": {
|
||||
"version": "2.0.3",
|
||||
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
|
||||
"integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4="
|
||||
},
|
||||
"jsonfile": {
|
||||
"version": "6.1.0",
|
||||
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz",
|
||||
"integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==",
|
||||
"requires": {
|
||||
"graceful-fs": "^4.1.6",
|
||||
"universalify": "^2.0.0"
|
||||
}
|
||||
},
|
||||
"media-typer": {
|
||||
"version": "0.3.0",
|
||||
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
|
||||
"integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g="
|
||||
},
|
||||
"mime-db": {
|
||||
"version": "1.49.0",
|
||||
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.49.0.tgz",
|
||||
"integrity": "sha512-CIc8j9URtOVApSFCQIF+VBkX1RwXp/oMMOrqdyXSBXq5RWNEsRfyj1kiRnQgmNXmHxPoFIxOroKA3zcU9P+nAA=="
|
||||
},
|
||||
"mime-types": {
|
||||
"version": "2.1.32",
|
||||
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.32.tgz",
|
||||
"integrity": "sha512-hJGaVS4G4c9TSMYh2n6SQAGrC4RnfU+daP8G7cSCmaqNjiOoUY0VHCMS42pxnQmVF1GWwFhbHWn3RIxCqTmZ9A==",
|
||||
"requires": {
|
||||
"mime-db": "1.49.0"
|
||||
}
|
||||
},
|
||||
"ms": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
||||
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
|
||||
},
|
||||
"on-finished": {
|
||||
"version": "2.3.0",
|
||||
"resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz",
|
||||
"integrity": "sha1-IPEzZIGwg811M3mSoWlxqi2QaUc=",
|
||||
"requires": {
|
||||
"ee-first": "1.1.1"
|
||||
}
|
||||
},
|
||||
"qs": {
|
||||
"version": "6.7.0",
|
||||
"resolved": "https://registry.npmjs.org/qs/-/qs-6.7.0.tgz",
|
||||
"integrity": "sha512-VCdBRNFTX1fyE7Nb6FYoURo/SPe62QCaAyzJvUjwRaIsc+NePBEniHlvxFmmX56+HZphIGtV0XeCirBtpDrTyQ=="
|
||||
},
|
||||
"raw-body": {
|
||||
"version": "2.4.0",
|
||||
"resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.4.0.tgz",
|
||||
"integrity": "sha512-4Oz8DUIwdvoa5qMJelxipzi/iJIi40O5cGV1wNYp5hvZP8ZN0T+jiNkL0QepXs+EsQ9XJ8ipEDoiH70ySUJP3Q==",
|
||||
"requires": {
|
||||
"bytes": "3.1.0",
|
||||
"http-errors": "1.7.2",
|
||||
"iconv-lite": "0.4.24",
|
||||
"unpipe": "1.0.0"
|
||||
}
|
||||
},
|
||||
"safer-buffer": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
|
||||
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
|
||||
},
|
||||
"setprototypeof": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.1.tgz",
|
||||
"integrity": "sha512-JvdAWfbXeIGaZ9cILp38HntZSFSo3mWg6xGcJJsd+d4aRMOqauag1C63dJfDw7OaMYwEbHMOxEZ1lqVRYP2OAw=="
|
||||
},
|
||||
"statuses": {
|
||||
"version": "1.5.0",
|
||||
"resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz",
|
||||
"integrity": "sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow="
|
||||
},
|
||||
"toidentifier": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.0.tgz",
|
||||
"integrity": "sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw=="
|
||||
},
|
||||
"type-is": {
|
||||
"version": "1.6.18",
|
||||
"resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz",
|
||||
"integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==",
|
||||
"requires": {
|
||||
"media-typer": "0.3.0",
|
||||
"mime-types": "~2.1.24"
|
||||
}
|
||||
},
|
||||
"typescript": {
|
||||
"version": "3.9.10",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.9.10.tgz",
|
||||
"integrity": "sha512-w6fIxVE/H1PkLKcCPsFqKE7Kv7QUwhU8qQY2MueZXWx5cPZdwFupLgKK3vntcK98BtNHZtAF4LA/yl2a7k8R6Q==",
|
||||
"dev": true
|
||||
},
|
||||
"universalify": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz",
|
||||
"integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ=="
|
||||
},
|
||||
"unpipe": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
|
||||
"integrity": "sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw="
|
||||
},
|
||||
"ws": {
|
||||
"version": "7.5.4",
|
||||
"resolved": "https://registry.npmjs.org/ws/-/ws-7.5.4.tgz",
|
||||
"integrity": "sha512-zP9z6GXm6zC27YtspwH99T3qTG7bBFv2VIkeHstMLrLlDJuzA7tQ5ls3OJ1hOGGCzTQPniNJoHXIAOS0Jljohg==",
|
||||
"requires": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
60
clients/ts/package.json
Normal file
60
clients/ts/package.json
Normal file
@@ -0,0 +1,60 @@
|
||||
{
|
||||
"author": "",
|
||||
"dependencies": {
|
||||
"@m3o/m3o-node": "^0.0.24"
|
||||
},
|
||||
"description": "",
|
||||
"devDependencies": {
|
||||
"typescript": "^3.5.1"
|
||||
},
|
||||
"exports": {
|
||||
"./address": "./dist/address/index.js",
|
||||
"./answer": "./dist/answer/index.js",
|
||||
"./cache": "./dist/cache/index.js",
|
||||
"./cmd": "./dist/cmd/index.js",
|
||||
"./crypto": "./dist/crypto/index.js",
|
||||
"./currency": "./dist/currency/index.js",
|
||||
"./db": "./dist/db/index.js",
|
||||
"./email": "./dist/email/index.js",
|
||||
"./emoji": "./dist/emoji/index.js",
|
||||
"./file": "./dist/file/index.js",
|
||||
"./forex": "./dist/forex/index.js",
|
||||
"./geocoding": "./dist/geocoding/index.js",
|
||||
"./helloworld": "./dist/helloworld/index.js",
|
||||
"./id": "./dist/id/index.js",
|
||||
"./image": "./dist/image/index.js",
|
||||
"./ip": "./dist/ip/index.js",
|
||||
"./location": "./dist/location/index.js",
|
||||
"./otp": "./dist/otp/index.js",
|
||||
"./pkg": "./dist/pkg/index.js",
|
||||
"./postcode": "./dist/postcode/index.js",
|
||||
"./quran": "./dist/quran/index.js",
|
||||
"./routing": "./dist/routing/index.js",
|
||||
"./rss": "./dist/rss/index.js",
|
||||
"./sentiment": "./dist/sentiment/index.js",
|
||||
"./sms": "./dist/sms/index.js",
|
||||
"./stock": "./dist/stock/index.js",
|
||||
"./stream": "./dist/stream/index.js",
|
||||
"./test": "./dist/test/index.js",
|
||||
"./thumbnail": "./dist/thumbnail/index.js",
|
||||
"./time": "./dist/time/index.js",
|
||||
"./url": "./dist/url/index.js",
|
||||
"./user": "./dist/user/index.js",
|
||||
"./weather": "./dist/weather/index.js"
|
||||
},
|
||||
"license": "ISC",
|
||||
"main": "dist/index.js",
|
||||
"name": "m3o",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/micro/services"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"prepare": "npm run build",
|
||||
"test": "echo \"Error: no test specified\" \u0026\u0026 exit 1"
|
||||
},
|
||||
"type": "module",
|
||||
"types": "dist/index.d.ts",
|
||||
"version": "1.0.509"
|
||||
}
|
||||
84
clients/ts/postcode/index.ts
Executable file
84
clients/ts/postcode/index.ts
Executable file
@@ -0,0 +1,84 @@
|
||||
import * as m3o from "@m3o/m3o-node";
|
||||
|
||||
export class PostcodeService {
|
||||
private client: m3o.Client;
|
||||
|
||||
constructor(token: string) {
|
||||
this.client = new m3o.Client({ token: token });
|
||||
}
|
||||
// Lookup a postcode to retrieve the related region, county, etc
|
||||
lookup(request: LookupRequest): Promise<LookupResponse> {
|
||||
return this.client.call(
|
||||
"postcode",
|
||||
"Lookup",
|
||||
request
|
||||
) as Promise<LookupResponse>;
|
||||
}
|
||||
// Return a random postcode and its related info
|
||||
random(request: RandomRequest): Promise<RandomResponse> {
|
||||
return this.client.call(
|
||||
"postcode",
|
||||
"Random",
|
||||
request
|
||||
) as Promise<RandomResponse>;
|
||||
}
|
||||
// Validate a postcode.
|
||||
validate(request: ValidateRequest): Promise<ValidateResponse> {
|
||||
return this.client.call(
|
||||
"postcode",
|
||||
"Validate",
|
||||
request
|
||||
) as Promise<ValidateResponse>;
|
||||
}
|
||||
}
|
||||
|
||||
export interface LookupRequest {
|
||||
// UK postcode e.g SW1A 2AA
|
||||
postcode?: string;
|
||||
}
|
||||
|
||||
export interface LookupResponse {
|
||||
// country e.g United Kingdom
|
||||
country?: string;
|
||||
// e.g Westminster
|
||||
district?: string;
|
||||
// e.g 51.50354
|
||||
latitude?: number;
|
||||
// e.g -0.127695
|
||||
longitude?: number;
|
||||
// UK postcode e.g SW1A 2AA
|
||||
postcode?: string;
|
||||
// related region e.g London
|
||||
region?: string;
|
||||
// e.g St James's
|
||||
ward?: string;
|
||||
}
|
||||
|
||||
export interface RandomRequest {}
|
||||
|
||||
export interface RandomResponse {
|
||||
// country e.g United Kingdom
|
||||
country?: string;
|
||||
// e.g Westminster
|
||||
district?: string;
|
||||
// e.g 51.50354
|
||||
latitude?: number;
|
||||
// e.g -0.127695
|
||||
longitude?: number;
|
||||
// UK postcode e.g SW1A 2AA
|
||||
postcode?: string;
|
||||
// related region e.g London
|
||||
region?: string;
|
||||
// e.g St James's
|
||||
ward?: string;
|
||||
}
|
||||
|
||||
export interface ValidateRequest {
|
||||
// UK postcode e.g SW1A 2AA
|
||||
postcode?: string;
|
||||
}
|
||||
|
||||
export interface ValidateResponse {
|
||||
// Is the postcode valid (true) or not (false)
|
||||
valid?: boolean;
|
||||
}
|
||||
216
clients/ts/quran/index.ts
Executable file
216
clients/ts/quran/index.ts
Executable file
@@ -0,0 +1,216 @@
|
||||
import * as m3o from "@m3o/m3o-node";
|
||||
|
||||
export class QuranService {
|
||||
private client: m3o.Client;
|
||||
|
||||
constructor(token: string) {
|
||||
this.client = new m3o.Client({ token: token });
|
||||
}
|
||||
// List the Chapters (surahs) of the Quran
|
||||
chapters(request: ChaptersRequest): Promise<ChaptersResponse> {
|
||||
return this.client.call(
|
||||
"quran",
|
||||
"Chapters",
|
||||
request
|
||||
) as Promise<ChaptersResponse>;
|
||||
}
|
||||
// Search the Quran for any form of query or questions
|
||||
search(request: SearchRequest): Promise<SearchResponse> {
|
||||
return this.client.call(
|
||||
"quran",
|
||||
"Search",
|
||||
request
|
||||
) as Promise<SearchResponse>;
|
||||
}
|
||||
// Get a summary for a given chapter (surah)
|
||||
summary(request: SummaryRequest): Promise<SummaryResponse> {
|
||||
return this.client.call(
|
||||
"quran",
|
||||
"Summary",
|
||||
request
|
||||
) as Promise<SummaryResponse>;
|
||||
}
|
||||
// Lookup the verses (ayahs) for a chapter
|
||||
verses(request: VersesRequest): Promise<VersesResponse> {
|
||||
return this.client.call(
|
||||
"quran",
|
||||
"Verses",
|
||||
request
|
||||
) as Promise<VersesResponse>;
|
||||
}
|
||||
}
|
||||
|
||||
export interface Chapter {
|
||||
// The arabic name of the chapter
|
||||
arabicName?: string;
|
||||
// The complex name of the chapter
|
||||
complexName?: string;
|
||||
// The id of the chapter as a number e.g 1
|
||||
id?: number;
|
||||
// The simple name of the chapter
|
||||
name?: string;
|
||||
// The pages from and to e.g 1, 1
|
||||
pages?: number[];
|
||||
// Should the chapter start with bismillah
|
||||
prefixBismillah?: boolean;
|
||||
// The order in which it was revealed
|
||||
revelationOrder?: number;
|
||||
// The place of revelation
|
||||
revelationPlace?: string;
|
||||
// The translated name
|
||||
translatedName?: string;
|
||||
// The number of verses in the chapter
|
||||
verses?: number;
|
||||
}
|
||||
|
||||
export interface ChaptersRequest {
|
||||
// Specify the language e.g en
|
||||
language?: string;
|
||||
}
|
||||
|
||||
export interface ChaptersResponse {
|
||||
chapters?: Chapter[];
|
||||
}
|
||||
|
||||
export interface Interpretation {
|
||||
// The unique id of the interpretation
|
||||
id?: number;
|
||||
// The source of the interpretation
|
||||
source?: string;
|
||||
// The translated text
|
||||
text?: string;
|
||||
}
|
||||
|
||||
export interface Result {
|
||||
// The associated arabic text
|
||||
text?: string;
|
||||
// The related translations to the text
|
||||
translations?: Interpretation[];
|
||||
// The unique verse id across the Quran
|
||||
verseId?: number;
|
||||
// The verse key e.g 1:1
|
||||
verseKey?: string;
|
||||
}
|
||||
|
||||
export interface SearchRequest {
|
||||
// The language for translation
|
||||
language?: string;
|
||||
// The number of results to return
|
||||
limit?: number;
|
||||
// The pagination number
|
||||
page?: number;
|
||||
// The query to ask
|
||||
query?: string;
|
||||
}
|
||||
|
||||
export interface SearchResponse {
|
||||
// The current page
|
||||
page?: number;
|
||||
// The question asked
|
||||
query?: string;
|
||||
// The results for the query
|
||||
results?: Result[];
|
||||
// The total pages
|
||||
totalPages?: number;
|
||||
// The total results returned
|
||||
totalResults?: number;
|
||||
}
|
||||
|
||||
export interface SummaryRequest {
|
||||
// The chapter id e.g 1
|
||||
chapter?: number;
|
||||
// Specify the language e.g en
|
||||
language?: string;
|
||||
}
|
||||
|
||||
export interface SummaryResponse {
|
||||
// The chapter id
|
||||
chapter?: number;
|
||||
// The source of the summary
|
||||
source?: string;
|
||||
// The short summary for the chapter
|
||||
summary?: string;
|
||||
// The full description for the chapter
|
||||
text?: string;
|
||||
}
|
||||
|
||||
export interface Translation {
|
||||
// The unique id of the translation
|
||||
id?: number;
|
||||
// The source of the translation
|
||||
source?: string;
|
||||
// The translated text
|
||||
text?: string;
|
||||
}
|
||||
|
||||
export interface Verse {
|
||||
// The unique id of the verse in the whole book
|
||||
id?: number;
|
||||
// The interpretations of the verse
|
||||
interpretations?: Translation[];
|
||||
// The key of this verse (chapter:verse) e.g 1:1
|
||||
key?: string;
|
||||
// The verse number in this chapter
|
||||
number?: number;
|
||||
// The page of the Quran this verse is on
|
||||
page?: number;
|
||||
// The arabic text for this verse
|
||||
text?: string;
|
||||
// The basic translation of the verse
|
||||
translatedText?: string;
|
||||
// The alternative translations for the verse
|
||||
translations?: Translation[];
|
||||
// The phonetic transliteration from arabic
|
||||
transliteration?: string;
|
||||
// The individual words within the verse (Ayah)
|
||||
words?: Word[];
|
||||
}
|
||||
|
||||
export interface VersesRequest {
|
||||
// The chapter id to retrieve
|
||||
chapter?: number;
|
||||
// Return the interpretation (tafsir)
|
||||
interpret?: boolean;
|
||||
// The language of translation
|
||||
language?: string;
|
||||
// The verses per page
|
||||
limit?: number;
|
||||
// The page number to request
|
||||
page?: number;
|
||||
// Return alternate translations
|
||||
translate?: boolean;
|
||||
// Return the individual words with the verses
|
||||
words?: boolean;
|
||||
}
|
||||
|
||||
export interface VersesResponse {
|
||||
// The chapter requested
|
||||
chapter?: number;
|
||||
// The page requested
|
||||
page?: number;
|
||||
// The total pages
|
||||
totalPages?: number;
|
||||
// The verses on the page
|
||||
verses?: Verse[];
|
||||
}
|
||||
|
||||
export interface Word {
|
||||
// The character type e.g word, end
|
||||
charType?: string;
|
||||
// The QCF v2 font code
|
||||
code?: string;
|
||||
// The id of the word within the verse
|
||||
id?: number;
|
||||
// The line number
|
||||
line?: number;
|
||||
// The page number
|
||||
page?: number;
|
||||
// The position of the word
|
||||
position?: number;
|
||||
// The arabic text for this word
|
||||
text?: string;
|
||||
// The translated text
|
||||
translation?: string;
|
||||
// The transliteration text
|
||||
transliteration?: string;
|
||||
}
|
||||
123
clients/ts/routing/index.ts
Executable file
123
clients/ts/routing/index.ts
Executable file
@@ -0,0 +1,123 @@
|
||||
import * as m3o from "@m3o/m3o-node";
|
||||
|
||||
export class RoutingService {
|
||||
private client: m3o.Client;
|
||||
|
||||
constructor(token: string) {
|
||||
this.client = new m3o.Client({ token: token });
|
||||
}
|
||||
// Turn by turn directions from a start point to an end point including maneuvers and bearings
|
||||
directions(request: DirectionsRequest): Promise<DirectionsResponse> {
|
||||
return this.client.call(
|
||||
"routing",
|
||||
"Directions",
|
||||
request
|
||||
) as Promise<DirectionsResponse>;
|
||||
}
|
||||
// Get the eta for a route from origin to destination. The eta is an estimated time based on car routes
|
||||
eta(request: EtaRequest): Promise<EtaResponse> {
|
||||
return this.client.call("routing", "Eta", request) as Promise<EtaResponse>;
|
||||
}
|
||||
// Retrieve a route as a simple list of gps points along with total distance and estimated duration
|
||||
route(request: RouteRequest): Promise<RouteResponse> {
|
||||
return this.client.call(
|
||||
"routing",
|
||||
"Route",
|
||||
request
|
||||
) as Promise<RouteResponse>;
|
||||
}
|
||||
}
|
||||
|
||||
export interface Direction {
|
||||
// distance to travel in meters
|
||||
distance?: number;
|
||||
// duration to travel in seconds
|
||||
duration?: number;
|
||||
// human readable instruction
|
||||
instruction?: string;
|
||||
// intersections on route
|
||||
intersections?: Intersection[];
|
||||
// maneuver to take
|
||||
maneuver?: { [key: string]: any };
|
||||
// street name or location
|
||||
name?: string;
|
||||
// alternative reference
|
||||
reference?: string;
|
||||
}
|
||||
|
||||
export interface DirectionsRequest {
|
||||
// The destination of the journey
|
||||
destination?: Point;
|
||||
// The staring point for the journey
|
||||
origin?: Point;
|
||||
}
|
||||
|
||||
export interface DirectionsResponse {
|
||||
// Turn by turn directions
|
||||
directions?: Direction[];
|
||||
// Estimated distance of the route in meters
|
||||
distance?: number;
|
||||
// Estimated duration of the route in seconds
|
||||
duration?: number;
|
||||
// The waypoints on the route
|
||||
waypoints?: Waypoint[];
|
||||
}
|
||||
|
||||
export interface EtaRequest {
|
||||
// The end point for the eta calculation
|
||||
destination?: Point;
|
||||
// The starting point for the eta calculation
|
||||
origin?: Point;
|
||||
// speed in kilometers
|
||||
speed?: number;
|
||||
// type of transport. Only "car" is supported currently.
|
||||
type?: string;
|
||||
}
|
||||
|
||||
export interface EtaResponse {
|
||||
// eta in seconds
|
||||
duration?: number;
|
||||
}
|
||||
|
||||
export interface Intersection {
|
||||
bearings?: number[];
|
||||
location?: Point;
|
||||
}
|
||||
|
||||
export interface Maneuver {
|
||||
action?: string;
|
||||
bearingAfter?: number;
|
||||
bearingBefore?: number;
|
||||
direction?: string;
|
||||
location?: Point;
|
||||
}
|
||||
|
||||
export interface Point {
|
||||
// Lat e.g 52.523219
|
||||
latitude?: number;
|
||||
// Long e.g 13.428555
|
||||
longitude?: number;
|
||||
}
|
||||
|
||||
export interface RouteRequest {
|
||||
// Point of destination for the trip
|
||||
destination?: Point;
|
||||
// Point of origin for the trip
|
||||
origin?: Point;
|
||||
}
|
||||
|
||||
export interface RouteResponse {
|
||||
// estimated distance in meters
|
||||
distance?: number;
|
||||
// estimated duration in seconds
|
||||
duration?: number;
|
||||
// waypoints on the route
|
||||
waypoints?: Waypoint[];
|
||||
}
|
||||
|
||||
export interface Waypoint {
|
||||
// gps point coordinates
|
||||
location?: Point;
|
||||
// street name or related reference
|
||||
name?: string;
|
||||
}
|
||||
99
clients/ts/rss/index.ts
Executable file
99
clients/ts/rss/index.ts
Executable file
@@ -0,0 +1,99 @@
|
||||
import * as m3o from "@m3o/m3o-node";
|
||||
|
||||
export class RssService {
|
||||
private client: m3o.Client;
|
||||
|
||||
constructor(token: string) {
|
||||
this.client = new m3o.Client({ token: token });
|
||||
}
|
||||
// Add a new RSS feed with a name, url, and category
|
||||
add(request: AddRequest): Promise<AddResponse> {
|
||||
return this.client.call("rss", "Add", request) as Promise<AddResponse>;
|
||||
}
|
||||
// Get an RSS feed by name. If no name is given, all feeds are returned. Default limit is 25 entries.
|
||||
feed(request: FeedRequest): Promise<FeedResponse> {
|
||||
return this.client.call("rss", "Feed", request) as Promise<FeedResponse>;
|
||||
}
|
||||
// List the saved RSS fields
|
||||
list(request: ListRequest): Promise<ListResponse> {
|
||||
return this.client.call("rss", "List", request) as Promise<ListResponse>;
|
||||
}
|
||||
// Remove an RSS feed by name
|
||||
remove(request: RemoveRequest): Promise<RemoveResponse> {
|
||||
return this.client.call(
|
||||
"rss",
|
||||
"Remove",
|
||||
request
|
||||
) as Promise<RemoveResponse>;
|
||||
}
|
||||
}
|
||||
|
||||
export interface AddRequest {
|
||||
// category to add e.g news
|
||||
category?: string;
|
||||
// rss feed name
|
||||
// eg. a16z
|
||||
name?: string;
|
||||
// rss feed url
|
||||
// eg. http://a16z.com/feed/
|
||||
url?: string;
|
||||
}
|
||||
|
||||
export interface AddResponse {}
|
||||
|
||||
export interface Entry {
|
||||
// article content
|
||||
content?: string;
|
||||
// data of the entry
|
||||
date?: string;
|
||||
// the rss feed where it came from
|
||||
feed?: string;
|
||||
// unique id of the entry
|
||||
id?: string;
|
||||
// rss feed url of the entry
|
||||
link?: string;
|
||||
// article summary
|
||||
summary?: string;
|
||||
// title of the entry
|
||||
title?: string;
|
||||
}
|
||||
|
||||
export interface Feed {
|
||||
// category of the feed e.g news
|
||||
category?: string;
|
||||
// unique id
|
||||
id?: string;
|
||||
// rss feed name
|
||||
// eg. a16z
|
||||
name?: string;
|
||||
// rss feed url
|
||||
// eg. http://a16z.com/feed/
|
||||
url?: string;
|
||||
}
|
||||
|
||||
export interface FeedRequest {
|
||||
// limit entries returned
|
||||
limit?: number;
|
||||
// rss feed name
|
||||
name?: string;
|
||||
// offset entries
|
||||
offset?: number;
|
||||
}
|
||||
|
||||
export interface FeedResponse {
|
||||
entries?: Entry[];
|
||||
}
|
||||
|
||||
export interface ListRequest {}
|
||||
|
||||
export interface ListResponse {
|
||||
feeds?: Feed[];
|
||||
}
|
||||
|
||||
export interface RemoveRequest {
|
||||
// rss feed name
|
||||
// eg. a16z
|
||||
name?: string;
|
||||
}
|
||||
|
||||
export interface RemoveResponse {}
|
||||
29
clients/ts/sentiment/index.ts
Executable file
29
clients/ts/sentiment/index.ts
Executable file
@@ -0,0 +1,29 @@
|
||||
import * as m3o from "@m3o/m3o-node";
|
||||
|
||||
export class SentimentService {
|
||||
private client: m3o.Client;
|
||||
|
||||
constructor(token: string) {
|
||||
this.client = new m3o.Client({ token: token });
|
||||
}
|
||||
// Analyze and score a piece of text
|
||||
analyze(request: AnalyzeRequest): Promise<AnalyzeResponse> {
|
||||
return this.client.call(
|
||||
"sentiment",
|
||||
"Analyze",
|
||||
request
|
||||
) as Promise<AnalyzeResponse>;
|
||||
}
|
||||
}
|
||||
|
||||
export interface AnalyzeRequest {
|
||||
// The language. Defaults to english.
|
||||
lang?: string;
|
||||
// The text to analyze
|
||||
text?: string;
|
||||
}
|
||||
|
||||
export interface AnalyzeResponse {
|
||||
// The score of the text {positive is 1, negative is 0}
|
||||
score?: number;
|
||||
}
|
||||
29
clients/ts/sms/index.ts
Executable file
29
clients/ts/sms/index.ts
Executable file
@@ -0,0 +1,29 @@
|
||||
import * as m3o from "@m3o/m3o-node";
|
||||
|
||||
export class SmsService {
|
||||
private client: m3o.Client;
|
||||
|
||||
constructor(token: string) {
|
||||
this.client = new m3o.Client({ token: token });
|
||||
}
|
||||
// Send an SMS.
|
||||
send(request: SendRequest): Promise<SendResponse> {
|
||||
return this.client.call("sms", "Send", request) as Promise<SendResponse>;
|
||||
}
|
||||
}
|
||||
|
||||
export interface SendRequest {
|
||||
// who is the message from? The message will be suffixed with "Sent from <from>"
|
||||
from?: string;
|
||||
// the main body of the message to send
|
||||
message?: string;
|
||||
// the destination phone number including the international dialling code (e.g. +44)
|
||||
to?: string;
|
||||
}
|
||||
|
||||
export interface SendResponse {
|
||||
// any additional info
|
||||
info?: string;
|
||||
// will return "ok" if successful
|
||||
status?: string;
|
||||
}
|
||||
132
clients/ts/stock/index.ts
Executable file
132
clients/ts/stock/index.ts
Executable file
@@ -0,0 +1,132 @@
|
||||
import * as m3o from "@m3o/m3o-node";
|
||||
|
||||
export class StockService {
|
||||
private client: m3o.Client;
|
||||
|
||||
constructor(token: string) {
|
||||
this.client = new m3o.Client({ token: token });
|
||||
}
|
||||
// Get the historic open-close for a given day
|
||||
history(request: HistoryRequest): Promise<HistoryResponse> {
|
||||
return this.client.call(
|
||||
"stock",
|
||||
"History",
|
||||
request
|
||||
) as Promise<HistoryResponse>;
|
||||
}
|
||||
// Get the historic order book and each trade by timestamp
|
||||
orderBook(request: OrderBookRequest): Promise<OrderBookResponse> {
|
||||
return this.client.call(
|
||||
"stock",
|
||||
"OrderBook",
|
||||
request
|
||||
) as Promise<OrderBookResponse>;
|
||||
}
|
||||
// Get the last price for a given stock ticker
|
||||
price(request: PriceRequest): Promise<PriceResponse> {
|
||||
return this.client.call(
|
||||
"stock",
|
||||
"Price",
|
||||
request
|
||||
) as Promise<PriceResponse>;
|
||||
}
|
||||
// Get the last quote for the stock
|
||||
quote(request: QuoteRequest): Promise<QuoteResponse> {
|
||||
return this.client.call(
|
||||
"stock",
|
||||
"Quote",
|
||||
request
|
||||
) as Promise<QuoteResponse>;
|
||||
}
|
||||
}
|
||||
|
||||
export interface HistoryRequest {
|
||||
// date to retrieve as YYYY-MM-DD
|
||||
date?: string;
|
||||
// the stock symbol e.g AAPL
|
||||
stock?: string;
|
||||
}
|
||||
|
||||
export interface HistoryResponse {
|
||||
// the close price
|
||||
close?: number;
|
||||
// the date
|
||||
date?: string;
|
||||
// the peak price
|
||||
high?: number;
|
||||
// the low price
|
||||
low?: number;
|
||||
// the open price
|
||||
open?: number;
|
||||
// the stock symbol
|
||||
symbol?: string;
|
||||
// the volume
|
||||
volume?: number;
|
||||
}
|
||||
|
||||
export interface Order {
|
||||
// the asking price
|
||||
askPrice?: number;
|
||||
// the ask size
|
||||
askSize?: number;
|
||||
// the bidding price
|
||||
bidPrice?: number;
|
||||
// the bid size
|
||||
bidSize?: number;
|
||||
// the UTC timestamp of the quote
|
||||
timestamp?: string;
|
||||
}
|
||||
|
||||
export interface OrderBookRequest {
|
||||
// the date in format YYYY-MM-dd
|
||||
date?: string;
|
||||
// optional RFC3339Nano end time e.g 2006-01-02T15:04:05.999999999Z07:00
|
||||
end?: string;
|
||||
// limit number of prices
|
||||
limit?: number;
|
||||
// optional RFC3339Nano start time e.g 2006-01-02T15:04:05.999999999Z07:00
|
||||
start?: string;
|
||||
// stock to retrieve e.g AAPL
|
||||
stock?: string;
|
||||
}
|
||||
|
||||
export interface OrderBookResponse {
|
||||
// date of the request
|
||||
date?: string;
|
||||
// list of orders
|
||||
orders?: Order[];
|
||||
// the stock symbol
|
||||
symbol?: string;
|
||||
}
|
||||
|
||||
export interface PriceRequest {
|
||||
// stock symbol e.g AAPL
|
||||
symbol?: string;
|
||||
}
|
||||
|
||||
export interface PriceResponse {
|
||||
// the last price
|
||||
price?: number;
|
||||
// the stock symbol e.g AAPL
|
||||
symbol?: string;
|
||||
}
|
||||
|
||||
export interface QuoteRequest {
|
||||
// the stock symbol e.g AAPL
|
||||
symbol?: string;
|
||||
}
|
||||
|
||||
export interface QuoteResponse {
|
||||
// the asking price
|
||||
askPrice?: number;
|
||||
// the ask size
|
||||
askSize?: number;
|
||||
// the bidding price
|
||||
bidPrice?: number;
|
||||
// the bid size
|
||||
bidSize?: number;
|
||||
// the stock symbol
|
||||
symbol?: string;
|
||||
// the UTC timestamp of the quote
|
||||
timestamp?: string;
|
||||
}
|
||||
46
clients/ts/stream/index.ts
Executable file
46
clients/ts/stream/index.ts
Executable file
@@ -0,0 +1,46 @@
|
||||
import * as m3o from "@m3o/m3o-node";
|
||||
|
||||
export class StreamService {
|
||||
private client: m3o.Client;
|
||||
|
||||
constructor(token: string) {
|
||||
this.client = new m3o.Client({ token: token });
|
||||
}
|
||||
// Publish a message to the stream. Specify a topic to group messages for a specific topic.
|
||||
publish(request: PublishRequest): Promise<PublishResponse> {
|
||||
return this.client.call(
|
||||
"stream",
|
||||
"Publish",
|
||||
request
|
||||
) as Promise<PublishResponse>;
|
||||
}
|
||||
// Subscribe to messages for a given topic.
|
||||
subscribe(request: SubscribeRequest): Promise<SubscribeResponse> {
|
||||
return this.client.call(
|
||||
"stream",
|
||||
"Subscribe",
|
||||
request
|
||||
) as Promise<SubscribeResponse>;
|
||||
}
|
||||
}
|
||||
|
||||
export interface PublishRequest {
|
||||
// The json message to publish
|
||||
message?: { [key: string]: any };
|
||||
// The topic to publish to
|
||||
topic?: string;
|
||||
}
|
||||
|
||||
export interface PublishResponse {}
|
||||
|
||||
export interface SubscribeRequest {
|
||||
// The topic to subscribe to
|
||||
topic?: string;
|
||||
}
|
||||
|
||||
export interface SubscribeResponse {
|
||||
// The next json message on the topic
|
||||
message?: { [key: string]: any };
|
||||
// The topic subscribed to
|
||||
topic?: string;
|
||||
}
|
||||
29
clients/ts/thumbnail/index.ts
Executable file
29
clients/ts/thumbnail/index.ts
Executable file
@@ -0,0 +1,29 @@
|
||||
import * as m3o from "@m3o/m3o-node";
|
||||
|
||||
export class ThumbnailService {
|
||||
private client: m3o.Client;
|
||||
|
||||
constructor(token: string) {
|
||||
this.client = new m3o.Client({ token: token });
|
||||
}
|
||||
// Create a thumbnail screenshot by passing in a url, height and width
|
||||
screenshot(request: ScreenshotRequest): Promise<ScreenshotResponse> {
|
||||
return this.client.call(
|
||||
"thumbnail",
|
||||
"Screenshot",
|
||||
request
|
||||
) as Promise<ScreenshotResponse>;
|
||||
}
|
||||
}
|
||||
|
||||
export interface ScreenshotRequest {
|
||||
// height of the browser window, optional
|
||||
height?: number;
|
||||
url?: string;
|
||||
// width of the browser window. optional
|
||||
width?: number;
|
||||
}
|
||||
|
||||
export interface ScreenshotResponse {
|
||||
imageURL?: string;
|
||||
}
|
||||
61
clients/ts/time/index.ts
Executable file
61
clients/ts/time/index.ts
Executable file
@@ -0,0 +1,61 @@
|
||||
import * as m3o from "@m3o/m3o-node";
|
||||
|
||||
export class TimeService {
|
||||
private client: m3o.Client;
|
||||
|
||||
constructor(token: string) {
|
||||
this.client = new m3o.Client({ token: token });
|
||||
}
|
||||
// Get the current time
|
||||
now(request: NowRequest): Promise<NowResponse> {
|
||||
return this.client.call("time", "Now", request) as Promise<NowResponse>;
|
||||
}
|
||||
// Get the timezone info for a specific location
|
||||
zone(request: ZoneRequest): Promise<ZoneResponse> {
|
||||
return this.client.call("time", "Zone", request) as Promise<ZoneResponse>;
|
||||
}
|
||||
}
|
||||
|
||||
export interface NowRequest {
|
||||
// optional location, otherwise returns UTC
|
||||
location?: string;
|
||||
}
|
||||
|
||||
export interface NowResponse {
|
||||
// the current time as HH:MM:SS
|
||||
localtime?: string;
|
||||
// the location as Europe/London
|
||||
location?: string;
|
||||
// timestamp as 2006-01-02T15:04:05.999999999Z07:00
|
||||
timestamp?: string;
|
||||
// the timezone as BST
|
||||
timezone?: string;
|
||||
// the unix timestamp
|
||||
unix?: number;
|
||||
}
|
||||
|
||||
export interface ZoneRequest {
|
||||
// location to lookup e.g postcode, city, ip address
|
||||
location?: string;
|
||||
}
|
||||
|
||||
export interface ZoneResponse {
|
||||
// the abbreviated code e.g BST
|
||||
abbreviation?: string;
|
||||
// country of the timezone
|
||||
country?: string;
|
||||
// is daylight savings
|
||||
dst?: boolean;
|
||||
// e.g 51.42
|
||||
latitude?: number;
|
||||
// the local time
|
||||
localtime?: string;
|
||||
// location requested
|
||||
location?: string;
|
||||
// e.g -0.37
|
||||
longitude?: number;
|
||||
// region of timezone
|
||||
region?: string;
|
||||
// the timezone e.g Europe/London
|
||||
timezone?: string;
|
||||
}
|
||||
16
clients/ts/tsconfig.json
Normal file
16
clients/ts/tsconfig.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "es6",
|
||||
"target": "es5",
|
||||
"declaration": true,
|
||||
"lib": ["es2015", "dom"],
|
||||
"experimentalDecorators": true,
|
||||
"emitDecoratorMetadata": true,
|
||||
"outDir": "./dist",
|
||||
"strict": true,
|
||||
"moduleResolution": "node",
|
||||
"esModuleInterop": true
|
||||
},
|
||||
"include": ["index.ts", "./*"],
|
||||
"exclude": ["src/**/*.spec.*", "./dist", "./node_modules"]
|
||||
}
|
||||
63
clients/ts/url/index.ts
Executable file
63
clients/ts/url/index.ts
Executable file
@@ -0,0 +1,63 @@
|
||||
import * as m3o from "@m3o/m3o-node";
|
||||
|
||||
export class UrlService {
|
||||
private client: m3o.Client;
|
||||
|
||||
constructor(token: string) {
|
||||
this.client = new m3o.Client({ token: token });
|
||||
}
|
||||
// List information on all the shortened URLs that you have created
|
||||
list(request: ListRequest): Promise<ListResponse> {
|
||||
return this.client.call("url", "List", request) as Promise<ListResponse>;
|
||||
}
|
||||
// Proxy returns the destination URL of a short URL.
|
||||
proxy(request: ProxyRequest): Promise<ProxyResponse> {
|
||||
return this.client.call("url", "Proxy", request) as Promise<ProxyResponse>;
|
||||
}
|
||||
// Shortens a destination URL and returns a full short URL.
|
||||
shorten(request: ShortenRequest): Promise<ShortenResponse> {
|
||||
return this.client.call(
|
||||
"url",
|
||||
"Shorten",
|
||||
request
|
||||
) as Promise<ShortenResponse>;
|
||||
}
|
||||
}
|
||||
|
||||
export interface ListRequest {
|
||||
// filter by short URL, optional
|
||||
shortURL?: string;
|
||||
}
|
||||
|
||||
export interface ListResponse {
|
||||
urlPairs?: URLPair;
|
||||
}
|
||||
|
||||
export interface ProxyRequest {
|
||||
// short url ID, without the domain, eg. if your short URL is
|
||||
// `m3o.one/u/someshorturlid` then pass in `someshorturlid`
|
||||
shortURL?: string;
|
||||
}
|
||||
|
||||
export interface ProxyResponse {
|
||||
destinationURL?: string;
|
||||
}
|
||||
|
||||
export interface ShortenRequest {
|
||||
destinationURL?: string;
|
||||
}
|
||||
|
||||
export interface ShortenResponse {
|
||||
shortURL?: string;
|
||||
}
|
||||
|
||||
export interface URLPair {
|
||||
created?: number;
|
||||
destinationURL?: string;
|
||||
// HitCount keeps track many times the short URL has been resolved.
|
||||
// Hitcount only gets saved to disk (database) after every 10th hit, so
|
||||
// its not intended to be 100% accurate, more like an almost correct estimate.
|
||||
hitCount?: number;
|
||||
owner?: string;
|
||||
shortURL?: string;
|
||||
}
|
||||
233
clients/ts/user/index.ts
Executable file
233
clients/ts/user/index.ts
Executable file
@@ -0,0 +1,233 @@
|
||||
import * as m3o from "@m3o/m3o-node";
|
||||
|
||||
export class UserService {
|
||||
private client: m3o.Client;
|
||||
|
||||
constructor(token: string) {
|
||||
this.client = new m3o.Client({ token: token });
|
||||
}
|
||||
// Create a new user account. The email address and username for the account must be unique.
|
||||
create(request: CreateRequest): Promise<CreateResponse> {
|
||||
return this.client.call(
|
||||
"user",
|
||||
"Create",
|
||||
request
|
||||
) as Promise<CreateResponse>;
|
||||
}
|
||||
// Delete an account by id
|
||||
delete(request: DeleteRequest): Promise<DeleteResponse> {
|
||||
return this.client.call(
|
||||
"user",
|
||||
"Delete",
|
||||
request
|
||||
) as Promise<DeleteResponse>;
|
||||
}
|
||||
// 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
|
||||
login(request: LoginRequest): Promise<LoginResponse> {
|
||||
return this.client.call("user", "Login", request) as Promise<LoginResponse>;
|
||||
}
|
||||
// Logout a user account
|
||||
logout(request: LogoutRequest): Promise<LogoutResponse> {
|
||||
return this.client.call(
|
||||
"user",
|
||||
"Logout",
|
||||
request
|
||||
) as Promise<LogoutResponse>;
|
||||
}
|
||||
// Read an account by id, username or email. Only one need to be specified.
|
||||
read(request: ReadRequest): Promise<ReadResponse> {
|
||||
return this.client.call("user", "Read", request) as Promise<ReadResponse>;
|
||||
}
|
||||
// Read a session by the session id. In the event it has expired or is not found and error is returned.
|
||||
readSession(request: ReadSessionRequest): Promise<ReadSessionResponse> {
|
||||
return this.client.call(
|
||||
"user",
|
||||
"ReadSession",
|
||||
request
|
||||
) as Promise<ReadSessionResponse>;
|
||||
}
|
||||
// Send a verification email
|
||||
// to the user being signed up. Email from will be from 'support@m3o.com',
|
||||
// but you can provide the title and contents.
|
||||
// The verification link will be injected in to the email as a template variable, $micro_verification_link.
|
||||
// Example: 'Hi there, welcome onboard! Use the link below to verify your email: $micro_verification_link'
|
||||
// The variable will be replaced with an actual url that will look similar to this:
|
||||
// 'https://user.m3o.com/user/verify?token=a-verification-token&rediretUrl=your-redir-url'
|
||||
sendVerificationEmail(
|
||||
request: SendVerificationEmailRequest
|
||||
): Promise<SendVerificationEmailResponse> {
|
||||
return this.client.call(
|
||||
"user",
|
||||
"SendVerificationEmail",
|
||||
request
|
||||
) as Promise<SendVerificationEmailResponse>;
|
||||
}
|
||||
// Update the account password
|
||||
updatePassword(
|
||||
request: UpdatePasswordRequest
|
||||
): Promise<UpdatePasswordResponse> {
|
||||
return this.client.call(
|
||||
"user",
|
||||
"UpdatePassword",
|
||||
request
|
||||
) as Promise<UpdatePasswordResponse>;
|
||||
}
|
||||
// Update the account username or email
|
||||
update(request: UpdateRequest): Promise<UpdateResponse> {
|
||||
return this.client.call(
|
||||
"user",
|
||||
"Update",
|
||||
request
|
||||
) as Promise<UpdateResponse>;
|
||||
}
|
||||
// Verify the email address of an account from a token sent in an email to the user.
|
||||
verifyEmail(request: VerifyEmailRequest): Promise<VerifyEmailResponse> {
|
||||
return this.client.call(
|
||||
"user",
|
||||
"VerifyEmail",
|
||||
request
|
||||
) as Promise<VerifyEmailResponse>;
|
||||
}
|
||||
}
|
||||
|
||||
export interface Account {
|
||||
// unix timestamp
|
||||
created?: number;
|
||||
// an email address
|
||||
email?: string;
|
||||
// unique account id
|
||||
id?: string;
|
||||
// Store any custom data you want about your users in this fields.
|
||||
profile?: { [key: string]: string };
|
||||
// unix timestamp
|
||||
updated?: number;
|
||||
// alphanumeric username
|
||||
username?: string;
|
||||
verificationDate?: number;
|
||||
verified?: boolean;
|
||||
}
|
||||
|
||||
export interface CreateRequest {
|
||||
// the email address
|
||||
email?: string;
|
||||
// optional account id
|
||||
id?: string;
|
||||
// the user password
|
||||
password?: string;
|
||||
// optional user profile as map<string,string>
|
||||
profile?: { [key: string]: string };
|
||||
// the username
|
||||
username?: string;
|
||||
}
|
||||
|
||||
export interface CreateResponse {
|
||||
account?: { [key: string]: any };
|
||||
}
|
||||
|
||||
export interface DeleteRequest {
|
||||
// the account id
|
||||
id?: string;
|
||||
}
|
||||
|
||||
export interface DeleteResponse {}
|
||||
|
||||
export interface LoginRequest {
|
||||
// The email address of the user
|
||||
email?: string;
|
||||
// The password of the user
|
||||
password?: string;
|
||||
// The username of the user
|
||||
username?: string;
|
||||
}
|
||||
|
||||
export interface LoginResponse {
|
||||
// The session of the logged in user
|
||||
session?: { [key: string]: any };
|
||||
}
|
||||
|
||||
export interface LogoutRequest {
|
||||
sessionId?: string;
|
||||
}
|
||||
|
||||
export interface LogoutResponse {}
|
||||
|
||||
export interface ReadRequest {
|
||||
// the account email
|
||||
email?: string;
|
||||
// the account id
|
||||
id?: string;
|
||||
// the account username
|
||||
username?: string;
|
||||
}
|
||||
|
||||
export interface ReadResponse {
|
||||
account?: { [key: string]: any };
|
||||
}
|
||||
|
||||
export interface ReadSessionRequest {
|
||||
// The unique session id
|
||||
sessionId?: string;
|
||||
}
|
||||
|
||||
export interface ReadSessionResponse {
|
||||
session?: { [key: string]: any };
|
||||
}
|
||||
|
||||
export interface SendVerificationEmailRequest {
|
||||
email?: string;
|
||||
failureRedirectUrl?: string;
|
||||
// Display name of the sender for the email. Note: the email address will still be 'support@m3o.com'
|
||||
fromName?: string;
|
||||
redirectUrl?: string;
|
||||
subject?: string;
|
||||
// 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;
|
||||
}
|
||||
|
||||
export interface SendVerificationEmailResponse {}
|
||||
|
||||
export interface Session {
|
||||
// unix timestamp
|
||||
created?: number;
|
||||
// unix timestamp
|
||||
expires?: number;
|
||||
// the session id
|
||||
id?: string;
|
||||
// the associated user id
|
||||
userId?: string;
|
||||
}
|
||||
|
||||
export interface UpdatePasswordRequest {
|
||||
// confirm new password
|
||||
confirmPassword?: string;
|
||||
// the new password
|
||||
newPassword?: string;
|
||||
// the old password
|
||||
oldPassword?: string;
|
||||
// the account id
|
||||
userId?: string;
|
||||
}
|
||||
|
||||
export interface UpdatePasswordResponse {}
|
||||
|
||||
export interface UpdateRequest {
|
||||
// the new email address
|
||||
email?: string;
|
||||
// the account id
|
||||
id?: string;
|
||||
// the user profile as map<string,string>
|
||||
profile?: { [key: string]: string };
|
||||
// the new username
|
||||
username?: string;
|
||||
}
|
||||
|
||||
export interface UpdateResponse {}
|
||||
|
||||
export interface VerifyEmailRequest {
|
||||
// The token from the verification email
|
||||
token?: string;
|
||||
}
|
||||
|
||||
export interface VerifyEmailResponse {}
|
||||
124
clients/ts/weather/index.ts
Executable file
124
clients/ts/weather/index.ts
Executable file
@@ -0,0 +1,124 @@
|
||||
import * as m3o from "@m3o/m3o-node";
|
||||
|
||||
export class WeatherService {
|
||||
private client: m3o.Client;
|
||||
|
||||
constructor(token: string) {
|
||||
this.client = new m3o.Client({ token: token });
|
||||
}
|
||||
// Get the weather forecast for the next 1-10 days
|
||||
forecast(request: ForecastRequest): Promise<ForecastResponse> {
|
||||
return this.client.call(
|
||||
"weather",
|
||||
"Forecast",
|
||||
request
|
||||
) as Promise<ForecastResponse>;
|
||||
}
|
||||
// Get the current weather report for a location by postcode, city, zip code, ip address
|
||||
now(request: NowRequest): Promise<NowResponse> {
|
||||
return this.client.call("weather", "Now", request) as Promise<NowResponse>;
|
||||
}
|
||||
}
|
||||
|
||||
export interface Forecast {
|
||||
// the average temp in celsius
|
||||
avgTempC?: number;
|
||||
// the average temp in fahrenheit
|
||||
avgTempF?: number;
|
||||
// chance of rain (percentage)
|
||||
chanceOfRain?: number;
|
||||
// forecast condition
|
||||
condition?: string;
|
||||
// date of the forecast
|
||||
date?: string;
|
||||
// the URL of forecast condition icon. Simply prefix with either http or https to use it
|
||||
iconUrl?: string;
|
||||
// max temp in celsius
|
||||
maxTempC?: number;
|
||||
// max temp in fahrenheit
|
||||
maxTempF?: number;
|
||||
// minimum temp in celsius
|
||||
minTempC?: number;
|
||||
// minimum temp in fahrenheit
|
||||
minTempF?: number;
|
||||
// time of sunrise
|
||||
sunrise?: string;
|
||||
// time of sunset
|
||||
sunset?: string;
|
||||
// will it rain
|
||||
willItRain?: boolean;
|
||||
}
|
||||
|
||||
export interface ForecastRequest {
|
||||
// number of days. default 1, max 10
|
||||
days?: number;
|
||||
// location of the forecase
|
||||
location?: string;
|
||||
}
|
||||
|
||||
export interface ForecastResponse {
|
||||
// country of the request
|
||||
country?: string;
|
||||
// forecast for the next number of days
|
||||
forecast?: { [key: string]: any }[];
|
||||
// e.g 37.55
|
||||
latitude?: number;
|
||||
// the local time
|
||||
localTime?: string;
|
||||
// location of the request
|
||||
location?: string;
|
||||
// e.g -77.46
|
||||
longitude?: number;
|
||||
// region related to the location
|
||||
region?: string;
|
||||
// timezone of the location
|
||||
timezone?: string;
|
||||
}
|
||||
|
||||
export interface NowRequest {
|
||||
// location to get weather e.g postcode, city
|
||||
location?: string;
|
||||
}
|
||||
|
||||
export interface NowResponse {
|
||||
// cloud cover percentage
|
||||
cloud?: number;
|
||||
// the weather condition
|
||||
condition?: string;
|
||||
// country of the request
|
||||
country?: string;
|
||||
// whether its daytime
|
||||
daytime?: boolean;
|
||||
// feels like in celsius
|
||||
feelsLikeC?: number;
|
||||
// feels like in fahrenheit
|
||||
feelsLikeF?: number;
|
||||
// the humidity percentage
|
||||
humidity?: number;
|
||||
// the URL of the related icon. Simply prefix with either http or https to use it
|
||||
iconUrl?: string;
|
||||
// e.g 37.55
|
||||
latitude?: number;
|
||||
// the local time
|
||||
localTime?: string;
|
||||
// location of the request
|
||||
location?: string;
|
||||
// e.g -77.46
|
||||
longitude?: number;
|
||||
// region related to the location
|
||||
region?: string;
|
||||
// temperature in celsius
|
||||
tempC?: number;
|
||||
// temperature in fahrenheit
|
||||
tempF?: number;
|
||||
// timezone of the location
|
||||
timezone?: string;
|
||||
// wind degree
|
||||
windDegree?: number;
|
||||
// wind direction
|
||||
windDirection?: string;
|
||||
// wind in kph
|
||||
windKph?: number;
|
||||
// wind in mph
|
||||
windMph?: number;
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
package main
|
||||
|
||||
const goIndexTemplate = `package micro
|
||||
const goIndexTemplate = `package m3o
|
||||
|
||||
import(
|
||||
{{ range $service := .services }}"github.com/micro/micro-go/{{ $service.Name}}"
|
||||
{{ range $service := .services }}"github.com/micro/services/clients/go/{{ $service.Name}}"
|
||||
{{ end }}
|
||||
)
|
||||
|
||||
@@ -59,7 +59,7 @@ const goExampleTemplate = `{{ $service := .service }}package example
|
||||
import(
|
||||
"fmt"
|
||||
"os"
|
||||
"github.com/micro/micro-go/{{ $service.Name }}"
|
||||
"github.com/micro/services/clients/go/{{ $service.Name}}"
|
||||
)
|
||||
|
||||
{{ if endpointComment .endpoint $service.Spec.Components.Schemas }}{{ endpointComment .endpoint $service.Spec.Components.Schemas }}{{ end }}func {{ .funcName }}() {
|
||||
|
||||
@@ -52,6 +52,13 @@ func main() {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
examplesPath := filepath.Join(workDir, "examples")
|
||||
err = os.MkdirAll(goPath, 0777)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
funcs := map[string]interface{}{
|
||||
"recursiveTypeDefinition": func(language, serviceName, typeName string, schemas map[string]*openapi3.SchemaRef) string {
|
||||
return schemaToType(language, serviceName, typeName, schemas)
|
||||
@@ -103,6 +110,9 @@ func main() {
|
||||
services := []service{}
|
||||
tsExportsMap := map[string]string{}
|
||||
for _, f := range files {
|
||||
if strings.Contains(f.Name(), "clients") || strings.Contains(f.Name(), "examples") {
|
||||
continue
|
||||
}
|
||||
if f.IsDir() && !strings.HasPrefix(f.Name(), ".") {
|
||||
serviceName := f.Name()
|
||||
// see https://stackoverflow.com/questions/44345257/import-from-subfolder-of-npm-package
|
||||
@@ -277,12 +287,12 @@ func main() {
|
||||
}
|
||||
|
||||
// create go examples directory
|
||||
err = os.MkdirAll(filepath.Join(goPath, serviceName, "examples", endpoint), 0777)
|
||||
err = os.MkdirAll(filepath.Join(examplesPath, serviceName, endpoint, "go"), 0777)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
goExampleFile := filepath.Join(goPath, serviceName, "examples", endpoint, title+".go")
|
||||
goExampleFile := filepath.Join(examplesPath, serviceName, endpoint, "go", title+".go")
|
||||
f, err = os.OpenFile(goExampleFile, os.O_TRUNC|os.O_WRONLY|os.O_CREATE, 0744)
|
||||
if err != nil {
|
||||
fmt.Println("Failed to open schema file", err)
|
||||
@@ -297,7 +307,7 @@ func main() {
|
||||
}
|
||||
|
||||
cmd := exec.Command("gofmt", "-w", title+".go")
|
||||
cmd.Dir = filepath.Join(goPath, serviceName, "examples", endpoint)
|
||||
cmd.Dir = filepath.Join(examplesPath, serviceName, endpoint, "go")
|
||||
outp, err = cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
fmt.Println(fmt.Sprintf("Problem with '%v' example '%v': %v", serviceName, endpoint, string(outp)))
|
||||
@@ -319,12 +329,12 @@ func main() {
|
||||
"funcName": strcase.UpperCamelCase(title),
|
||||
})
|
||||
|
||||
err = os.MkdirAll(filepath.Join(tsPath, serviceName, "examples", endpoint), 0777)
|
||||
err = os.MkdirAll(filepath.Join(examplesPath, serviceName, endpoint, "node"), 0777)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
tsExampleFile := filepath.Join(tsPath, serviceName, "examples", endpoint, title+".js")
|
||||
tsExampleFile := filepath.Join(examplesPath, serviceName, endpoint, "node", title+".js")
|
||||
f, err = os.OpenFile(tsExampleFile, os.O_TRUNC|os.O_WRONLY|os.O_CREATE, 0744)
|
||||
if err != nil {
|
||||
fmt.Println("Failed to open schema file", err)
|
||||
@@ -339,7 +349,7 @@ func main() {
|
||||
}
|
||||
|
||||
cmd = exec.Command("prettier", "-w", title+".js")
|
||||
cmd.Dir = filepath.Join(tsPath, serviceName, "examples", endpoint)
|
||||
cmd.Dir = filepath.Join(examplesPath, serviceName, endpoint, "node")
|
||||
outp, err = cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
fmt.Println(fmt.Sprintf("Problem with '%v' example '%v': %v", serviceName, endpoint, string(outp)))
|
||||
@@ -361,7 +371,13 @@ func main() {
|
||||
"funcName": strcase.UpperCamelCase(title),
|
||||
})
|
||||
|
||||
curlExampleFile := filepath.Join(goPath, serviceName, "examples", endpoint, title+".sh")
|
||||
err = os.MkdirAll(filepath.Join(examplesPath, serviceName, endpoint, "curl"), 0777)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
curlExampleFile := filepath.Join(examplesPath, serviceName, endpoint, "curl", title+".sh")
|
||||
f, err = os.OpenFile(curlExampleFile, os.O_TRUNC|os.O_WRONLY|os.O_CREATE, 0744)
|
||||
if err != nil {
|
||||
fmt.Println("Failed to open schema file", err)
|
||||
@@ -378,7 +394,7 @@ func main() {
|
||||
// only build after each example is generated as old files from
|
||||
// previous generation might not compile
|
||||
cmd = exec.Command("go", "build", "-o", "/tmp/bin/outputfile")
|
||||
cmd.Dir = filepath.Join(goPath, serviceName, "examples", endpoint)
|
||||
cmd.Dir = filepath.Join(examplesPath, serviceName, endpoint, "go")
|
||||
outp, err = cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
fmt.Println(fmt.Sprintf("Problem with '%v' example '%v': %v", serviceName, endpoint, string(outp)))
|
||||
@@ -425,7 +441,7 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
tsFiles := filepath.Join(workDir, "cmd", "clients", "ts")
|
||||
cmd = exec.Command("cp", filepath.Join(tsFiles, "package.json"), filepath.Join(tsFiles, ".npmrc"), filepath.Join(tsFiles, ".gitignore"), filepath.Join(tsFiles, "package-lock.json"), filepath.Join(tsFiles, "tsconfig.json"), filepath.Join(workDir, "clients", "ts"))
|
||||
cmd = exec.Command("cp", filepath.Join(tsFiles, "package.json"), filepath.Join(tsFiles, ".gitignore"), filepath.Join(tsFiles, "package-lock.json"), filepath.Join(tsFiles, "tsconfig.json"), filepath.Join(workDir, "clients", "ts"))
|
||||
cmd.Dir = filepath.Join(tsPath)
|
||||
outp, err = cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
@@ -474,7 +490,7 @@ func main() {
|
||||
}
|
||||
|
||||
// login to NPM
|
||||
f, err = os.OpenFile(filepath.Join(tsPath, ".npmrc"), os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600)
|
||||
f, err = os.OpenFile(filepath.Join(tsPath, ".npmrc"), os.O_TRUNC|os.O_WRONLY|os.O_CREATE, 0600)
|
||||
if err != nil {
|
||||
fmt.Println("Failed to open npmrc", err)
|
||||
os.Exit(1)
|
||||
@@ -485,13 +501,13 @@ func main() {
|
||||
fmt.Println("No NPM_TOKEN env found")
|
||||
os.Exit(1)
|
||||
}
|
||||
if _, err = f.WriteString("\n//npm.pkg.github.com/:_authToken=" + os.Getenv("NPM_TOKEN")); err != nil {
|
||||
if _, err = f.WriteString("//registry.npmjs.org/:_authToken=" + os.Getenv("NPM_TOKEN")); err != nil {
|
||||
fmt.Println("Failed to open npmrc", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// get latest version from github
|
||||
getVersions := exec.Command("npm", "show", "@micro/services", "--time", "--json")
|
||||
getVersions := exec.Command("npm", "show", "m3o", "--time", "--json")
|
||||
getVersions.Dir = tsPath
|
||||
|
||||
outp, err = getVersions.CombinedOutput()
|
||||
@@ -553,7 +569,7 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
m["exports"] = tsExportsMap
|
||||
pakJS, err := json.Marshal(m)
|
||||
pakJS, err := json.MarshalIndent(m, "", " ")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
registry=https://npm.pkg.github.com/micro
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "@micro/services",
|
||||
"name": "m3o",
|
||||
"version": "1.0.1",
|
||||
"description": "",
|
||||
"main": "dist/index.js",
|
||||
|
||||
@@ -35,7 +35,7 @@ export interface {{ title $typeName }}{{ "{" }}
|
||||
{{end}}
|
||||
`
|
||||
|
||||
const tsExampleTemplate = `{{ $service := .service }}import * as {{ $service.Name }} from '@m3o/services/{{ $service.Name }}';
|
||||
const tsExampleTemplate = `{{ $service := .service }}import * as {{ $service.Name }} from 'm3o/{{ $service.Name }}';
|
||||
|
||||
{{ if endpointComment .endpoint $service.Spec.Components.Schemas }}{{ endpointComment .endpoint $service.Spec.Components.Schemas }}{{ end }}async function {{ .funcName }}() {
|
||||
let {{ $service.Name }}Service = new {{ $service.Name }}.{{ title $service.Name }}Service(process.env.MICRO_API_TOKEN)
|
||||
|
||||
@@ -68,6 +68,9 @@ func main() {
|
||||
workDir, _ := os.Getwd()
|
||||
|
||||
for _, f := range files {
|
||||
if strings.Contains(f.Name(), "clients") || strings.Contains(f.Name(), "examples") {
|
||||
continue
|
||||
}
|
||||
if f.IsDir() && !strings.HasPrefix(f.Name(), ".") {
|
||||
serviceDir := filepath.Join(workDir, f.Name())
|
||||
serviceFiles, err := ioutil.ReadDir(serviceDir)
|
||||
|
||||
6
examples/address/lookupPostcode/curl/lookupPostcode.sh
Executable file
6
examples/address/lookupPostcode/curl/lookupPostcode.sh
Executable file
@@ -0,0 +1,6 @@
|
||||
curl "https://api.m3o.com/v1/address/LookupPostcode" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $MICRO_API_TOKEN" \
|
||||
-d '{
|
||||
"postcode": "SW1A 2AA"
|
||||
}'
|
||||
16
examples/address/lookupPostcode/go/lookupPostcode.go
Executable file
16
examples/address/lookupPostcode/go/lookupPostcode.go
Executable file
@@ -0,0 +1,16 @@
|
||||
package example
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/micro/services/clients/go/address"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Lookup a list of UK addresses by postcode
|
||||
func LookupPostcode() {
|
||||
addressService := address.NewAddressService(os.Getenv("MICRO_API_TOKEN"))
|
||||
rsp, err := addressService.LookupPostcode(&address.LookupPostcodeRequest{
|
||||
Postcode: "SW1A 2AA",
|
||||
})
|
||||
fmt.Println(rsp, err)
|
||||
}
|
||||
12
examples/address/lookupPostcode/node/lookupPostcode.js
Executable file
12
examples/address/lookupPostcode/node/lookupPostcode.js
Executable file
@@ -0,0 +1,12 @@
|
||||
import * as address from "m3o/address";
|
||||
|
||||
// Lookup a list of UK addresses by postcode
|
||||
async function LookupPostcode() {
|
||||
let addressService = new address.AddressService(process.env.MICRO_API_TOKEN);
|
||||
let rsp = await addressService.lookupPostcode({
|
||||
postcode: "SW1A 2AA",
|
||||
});
|
||||
console.log(rsp);
|
||||
}
|
||||
|
||||
await LookupPostcode();
|
||||
6
examples/answer/question/curl/askAQuestion.sh
Executable file
6
examples/answer/question/curl/askAQuestion.sh
Executable file
@@ -0,0 +1,6 @@
|
||||
curl "https://api.m3o.com/v1/answer/Question" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $MICRO_API_TOKEN" \
|
||||
-d '{
|
||||
"query": "google"
|
||||
}'
|
||||
16
examples/answer/question/go/askAQuestion.go
Executable file
16
examples/answer/question/go/askAQuestion.go
Executable file
@@ -0,0 +1,16 @@
|
||||
package example
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/micro/services/clients/go/answer"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Ask a question and receive an instant answer
|
||||
func AskAquestion() {
|
||||
answerService := answer.NewAnswerService(os.Getenv("MICRO_API_TOKEN"))
|
||||
rsp, err := answerService.Question(&answer.QuestionRequest{
|
||||
Query: "google",
|
||||
})
|
||||
fmt.Println(rsp, err)
|
||||
}
|
||||
12
examples/answer/question/node/askAQuestion.js
Executable file
12
examples/answer/question/node/askAQuestion.js
Executable file
@@ -0,0 +1,12 @@
|
||||
import * as answer from "m3o/answer";
|
||||
|
||||
// Ask a question and receive an instant answer
|
||||
async function AskAquestion() {
|
||||
let answerService = new answer.AnswerService(process.env.MICRO_API_TOKEN);
|
||||
let rsp = await answerService.question({
|
||||
query: "google",
|
||||
});
|
||||
console.log(rsp);
|
||||
}
|
||||
|
||||
await AskAquestion();
|
||||
7
examples/cache/decrement/curl/decrementAValue.sh
vendored
Executable file
7
examples/cache/decrement/curl/decrementAValue.sh
vendored
Executable file
@@ -0,0 +1,7 @@
|
||||
curl "https://api.m3o.com/v1/cache/Decrement" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $MICRO_API_TOKEN" \
|
||||
-d '{
|
||||
"key": "counter",
|
||||
"value": 2
|
||||
}'
|
||||
17
examples/cache/decrement/go/decrementAValue.go
vendored
Executable file
17
examples/cache/decrement/go/decrementAValue.go
vendored
Executable file
@@ -0,0 +1,17 @@
|
||||
package example
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/micro/services/clients/go/cache"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Decrement a value (if it's a number)
|
||||
func DecrementAvalue() {
|
||||
cacheService := cache.NewCacheService(os.Getenv("MICRO_API_TOKEN"))
|
||||
rsp, err := cacheService.Decrement(&cache.DecrementRequest{
|
||||
Key: "counter",
|
||||
Value: 2,
|
||||
})
|
||||
fmt.Println(rsp, err)
|
||||
}
|
||||
13
examples/cache/decrement/node/decrementAValue.js
vendored
Executable file
13
examples/cache/decrement/node/decrementAValue.js
vendored
Executable file
@@ -0,0 +1,13 @@
|
||||
import * as cache from "m3o/cache";
|
||||
|
||||
// Decrement a value (if it's a number)
|
||||
async function DecrementAvalue() {
|
||||
let cacheService = new cache.CacheService(process.env.MICRO_API_TOKEN);
|
||||
let rsp = await cacheService.decrement({
|
||||
key: "counter",
|
||||
value: 2,
|
||||
});
|
||||
console.log(rsp);
|
||||
}
|
||||
|
||||
await DecrementAvalue();
|
||||
6
examples/cache/delete/curl/deleteAValue.sh
vendored
Executable file
6
examples/cache/delete/curl/deleteAValue.sh
vendored
Executable file
@@ -0,0 +1,6 @@
|
||||
curl "https://api.m3o.com/v1/cache/Delete" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $MICRO_API_TOKEN" \
|
||||
-d '{
|
||||
"key": "foo"
|
||||
}'
|
||||
16
examples/cache/delete/go/deleteAValue.go
vendored
Executable file
16
examples/cache/delete/go/deleteAValue.go
vendored
Executable file
@@ -0,0 +1,16 @@
|
||||
package example
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/micro/services/clients/go/cache"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Delete a value from the cache
|
||||
func DeleteAvalue() {
|
||||
cacheService := cache.NewCacheService(os.Getenv("MICRO_API_TOKEN"))
|
||||
rsp, err := cacheService.Delete(&cache.DeleteRequest{
|
||||
Key: "foo",
|
||||
})
|
||||
fmt.Println(rsp, err)
|
||||
}
|
||||
12
examples/cache/delete/node/deleteAValue.js
vendored
Executable file
12
examples/cache/delete/node/deleteAValue.js
vendored
Executable file
@@ -0,0 +1,12 @@
|
||||
import * as cache from "m3o/cache";
|
||||
|
||||
// Delete a value from the cache
|
||||
async function DeleteAvalue() {
|
||||
let cacheService = new cache.CacheService(process.env.MICRO_API_TOKEN);
|
||||
let rsp = await cacheService.delete({
|
||||
key: "foo",
|
||||
});
|
||||
console.log(rsp);
|
||||
}
|
||||
|
||||
await DeleteAvalue();
|
||||
6
examples/cache/get/curl/getAValue.sh
vendored
Executable file
6
examples/cache/get/curl/getAValue.sh
vendored
Executable file
@@ -0,0 +1,6 @@
|
||||
curl "https://api.m3o.com/v1/cache/Get" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $MICRO_API_TOKEN" \
|
||||
-d '{
|
||||
"key": "foo"
|
||||
}'
|
||||
16
examples/cache/get/go/getAValue.go
vendored
Executable file
16
examples/cache/get/go/getAValue.go
vendored
Executable file
@@ -0,0 +1,16 @@
|
||||
package example
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/micro/services/clients/go/cache"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Get an item from the cache by key
|
||||
func GetAvalue() {
|
||||
cacheService := cache.NewCacheService(os.Getenv("MICRO_API_TOKEN"))
|
||||
rsp, err := cacheService.Get(&cache.GetRequest{
|
||||
Key: "foo",
|
||||
})
|
||||
fmt.Println(rsp, err)
|
||||
}
|
||||
12
examples/cache/get/node/getAValue.js
vendored
Executable file
12
examples/cache/get/node/getAValue.js
vendored
Executable file
@@ -0,0 +1,12 @@
|
||||
import * as cache from "m3o/cache";
|
||||
|
||||
// Get an item from the cache by key
|
||||
async function GetAvalue() {
|
||||
let cacheService = new cache.CacheService(process.env.MICRO_API_TOKEN);
|
||||
let rsp = await cacheService.get({
|
||||
key: "foo",
|
||||
});
|
||||
console.log(rsp);
|
||||
}
|
||||
|
||||
await GetAvalue();
|
||||
7
examples/cache/increment/curl/incrementAValue.sh
vendored
Executable file
7
examples/cache/increment/curl/incrementAValue.sh
vendored
Executable file
@@ -0,0 +1,7 @@
|
||||
curl "https://api.m3o.com/v1/cache/Increment" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $MICRO_API_TOKEN" \
|
||||
-d '{
|
||||
"key": "counter",
|
||||
"value": 2
|
||||
}'
|
||||
17
examples/cache/increment/go/incrementAValue.go
vendored
Executable file
17
examples/cache/increment/go/incrementAValue.go
vendored
Executable file
@@ -0,0 +1,17 @@
|
||||
package example
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/micro/services/clients/go/cache"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Increment a value (if it's a number)
|
||||
func IncrementAvalue() {
|
||||
cacheService := cache.NewCacheService(os.Getenv("MICRO_API_TOKEN"))
|
||||
rsp, err := cacheService.Increment(&cache.IncrementRequest{
|
||||
Key: "counter",
|
||||
Value: 2,
|
||||
})
|
||||
fmt.Println(rsp, err)
|
||||
}
|
||||
13
examples/cache/increment/node/incrementAValue.js
vendored
Executable file
13
examples/cache/increment/node/incrementAValue.js
vendored
Executable file
@@ -0,0 +1,13 @@
|
||||
import * as cache from "m3o/cache";
|
||||
|
||||
// Increment a value (if it's a number)
|
||||
async function IncrementAvalue() {
|
||||
let cacheService = new cache.CacheService(process.env.MICRO_API_TOKEN);
|
||||
let rsp = await cacheService.increment({
|
||||
key: "counter",
|
||||
value: 2,
|
||||
});
|
||||
console.log(rsp);
|
||||
}
|
||||
|
||||
await IncrementAvalue();
|
||||
7
examples/cache/set/curl/setAValue.sh
vendored
Executable file
7
examples/cache/set/curl/setAValue.sh
vendored
Executable file
@@ -0,0 +1,7 @@
|
||||
curl "https://api.m3o.com/v1/cache/Set" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $MICRO_API_TOKEN" \
|
||||
-d '{
|
||||
"key": "foo",
|
||||
"value": "bar"
|
||||
}'
|
||||
17
examples/cache/set/go/setAValue.go
vendored
Executable file
17
examples/cache/set/go/setAValue.go
vendored
Executable file
@@ -0,0 +1,17 @@
|
||||
package example
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/micro/services/clients/go/cache"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Set an item in the cache. Overwrites any existing value already set.
|
||||
func SetAvalue() {
|
||||
cacheService := cache.NewCacheService(os.Getenv("MICRO_API_TOKEN"))
|
||||
rsp, err := cacheService.Set(&cache.SetRequest{
|
||||
Key: "foo",
|
||||
Value: "bar",
|
||||
})
|
||||
fmt.Println(rsp, err)
|
||||
}
|
||||
13
examples/cache/set/node/setAValue.js
vendored
Executable file
13
examples/cache/set/node/setAValue.js
vendored
Executable file
@@ -0,0 +1,13 @@
|
||||
import * as cache from "m3o/cache";
|
||||
|
||||
// Set an item in the cache. Overwrites any existing value already set.
|
||||
async function SetAvalue() {
|
||||
let cacheService = new cache.CacheService(process.env.MICRO_API_TOKEN);
|
||||
let rsp = await cacheService.set({
|
||||
key: "foo",
|
||||
value: "bar",
|
||||
});
|
||||
console.log(rsp);
|
||||
}
|
||||
|
||||
await SetAvalue();
|
||||
6
examples/crypto/history/curl/getPreviousClose.sh
Executable file
6
examples/crypto/history/curl/getPreviousClose.sh
Executable file
@@ -0,0 +1,6 @@
|
||||
curl "https://api.m3o.com/v1/crypto/History" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $MICRO_API_TOKEN" \
|
||||
-d '{
|
||||
"symbol": "BTCUSD"
|
||||
}'
|
||||
16
examples/crypto/history/go/getPreviousClose.go
Executable file
16
examples/crypto/history/go/getPreviousClose.go
Executable file
@@ -0,0 +1,16 @@
|
||||
package example
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/micro/services/clients/go/crypto"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Returns the history for the previous close
|
||||
func GetPreviousClose() {
|
||||
cryptoService := crypto.NewCryptoService(os.Getenv("MICRO_API_TOKEN"))
|
||||
rsp, err := cryptoService.History(&crypto.HistoryRequest{
|
||||
Symbol: "BTCUSD",
|
||||
})
|
||||
fmt.Println(rsp, err)
|
||||
}
|
||||
12
examples/crypto/history/node/getPreviousClose.js
Executable file
12
examples/crypto/history/node/getPreviousClose.js
Executable file
@@ -0,0 +1,12 @@
|
||||
import * as crypto from "m3o/crypto";
|
||||
|
||||
// Returns the history for the previous close
|
||||
async function GetPreviousClose() {
|
||||
let cryptoService = new crypto.CryptoService(process.env.MICRO_API_TOKEN);
|
||||
let rsp = await cryptoService.history({
|
||||
symbol: "BTCUSD",
|
||||
});
|
||||
console.log(rsp);
|
||||
}
|
||||
|
||||
await GetPreviousClose();
|
||||
6
examples/crypto/price/curl/getCryptocurrencyPrice.sh
Executable file
6
examples/crypto/price/curl/getCryptocurrencyPrice.sh
Executable file
@@ -0,0 +1,6 @@
|
||||
curl "https://api.m3o.com/v1/crypto/Price" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $MICRO_API_TOKEN" \
|
||||
-d '{
|
||||
"symbol": "BTCUSD"
|
||||
}'
|
||||
16
examples/crypto/price/go/getCryptocurrencyPrice.go
Executable file
16
examples/crypto/price/go/getCryptocurrencyPrice.go
Executable file
@@ -0,0 +1,16 @@
|
||||
package example
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/micro/services/clients/go/crypto"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Get the last price for a given crypto ticker
|
||||
func GetCryptocurrencyPrice() {
|
||||
cryptoService := crypto.NewCryptoService(os.Getenv("MICRO_API_TOKEN"))
|
||||
rsp, err := cryptoService.Price(&crypto.PriceRequest{
|
||||
Symbol: "BTCUSD",
|
||||
})
|
||||
fmt.Println(rsp, err)
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user