diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..95c0eb7 --- /dev/null +++ b/go.sum @@ -0,0 +1,12 @@ +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/sms77io/go-client v0.0.0-20211026080708-90d592e387a5 h1:UPsStTjrEgvfDzD3ENu9mltCnJBULPSEQqH6JCS6Ans= +github.com/sms77io/go-client v0.0.0-20211026080708-90d592e387a5/go.mod h1:Z4Gf/PUrT5wam9ugP7VI/p2CgNVkwHJtj1wEV6Aeo1c= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/vendor/github.com/sms77io/go-client/LICENSE b/vendor/github.com/sms77io/go-client/LICENSE new file mode 100644 index 0000000..a0d305d --- /dev/null +++ b/vendor/github.com/sms77io/go-client/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020-present sms77 e.K. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/vendor/github.com/sms77io/go-client/sms77api/analytics.go b/vendor/github.com/sms77io/go-client/sms77api/analytics.go new file mode 100644 index 0000000..8697fd2 --- /dev/null +++ b/vendor/github.com/sms77io/go-client/sms77api/analytics.go @@ -0,0 +1,59 @@ +package sms77api + +import ( + "context" + "encoding/json" +) + +type AnalyticsParams struct { + End string `json:"end,omitempty"` + GroupBy AnalyticsGroupBy `json:"group_by,omitempty"` + Label string `json:"label,omitempty"` + Start string `json:"start,omitempty"` + Subaccounts string `json:"subaccounts,omitempty"` +} + +type Analytics struct { + Account *string `json:"account"` + Country *string `json:"country"` + Date *string `json:"date"` + Label *string `json:"label"` + + Direct int `json:"direct"` + Economy int `json:"economy"` + Hlr int `json:"hlr"` + Inbound int `json:"inbound"` + Mnp int `json:"mnp"` + Voice int `json:"voice"` + UsageEur float64 `json:"usage_eur"` +} + +type AnalyticsResource resource + +type AnalyticsGroupBy string + +const ( + AnalyticsGroupByCountry AnalyticsGroupBy = "country" + AnalyticsGroupByDate AnalyticsGroupBy = "date" + AnalyticsGroupByLabel AnalyticsGroupBy = "label" + AnalyticsGroupBySubaccount AnalyticsGroupBy = "subaccount" +) + +func (api *AnalyticsResource) Get(p *AnalyticsParams) (o []Analytics, err error) { + return api.GetContext(context.Background(), p) +} + +func (api *AnalyticsResource) GetContext(ctx context.Context, p *AnalyticsParams) (o []Analytics, err error) { + res, err := api.client.request(ctx, "analytics", "GET", p) + if err != nil { + return nil, err + } + + err = json.Unmarshal([]byte(res), &o) + + if nil != err { + return nil, err + } + + return o, nil +} diff --git a/vendor/github.com/sms77io/go-client/sms77api/balance.go b/vendor/github.com/sms77io/go-client/sms77api/balance.go new file mode 100644 index 0000000..0611ebc --- /dev/null +++ b/vendor/github.com/sms77io/go-client/sms77api/balance.go @@ -0,0 +1,27 @@ +package sms77api + +import ( + "context" + "strconv" +) + +type BalanceResource resource + +func (api *BalanceResource) Get() (*float64, error) { + return api.GetContext(context.Background()) +} + +func (api *BalanceResource) GetContext(ctx context.Context) (*float64, error) { + res, err := api.client.request(ctx, "balance", "GET", nil) + + if err != nil { + return nil, err + } + + float, err := strconv.ParseFloat(res, 64) + if err != nil { + return nil, err + } + + return &float, nil +} diff --git a/vendor/github.com/sms77io/go-client/sms77api/contacts.go b/vendor/github.com/sms77io/go-client/sms77api/contacts.go new file mode 100644 index 0000000..0ef68fa --- /dev/null +++ b/vendor/github.com/sms77io/go-client/sms77api/contacts.go @@ -0,0 +1,206 @@ +package sms77api + +import ( + "context" + "encoding/json" +) + +type ContactsResource resource + +type ContactsWriteCode string + +const ( + ContactsWriteCodeUnchanged ContactsWriteCode = "151" + ContactsWriteCodeChanged ContactsWriteCode = "152" +) + +type ContactsAction string + +const ( + ContactsActionDelete ContactsAction = "del" + ContactsActionRead ContactsAction = "read" + ContactsActionWrite ContactsAction = "write" +) + +type Contact struct { + Id string `json:"ID"` + Nick string `json:"Name"` + Phone string `json:"Number"` +} + +type ContactEditParams struct { + Id string `json:"id"` + Nick string `json:"nick,omitempty"` + Phone string `json:"empfaenger,omitempty"` +} + +type ContactsCreateJsonResponse struct { + contactsPropReturn + Id uint64 `json:"id"` +} + +type ContactsDeleteParams = contactsParamId + +type ContactsDeleteJsonResponse = contactsPropReturn + +type ContactsEditJsonResponse = contactsPropReturn + +type ContactsReadParams = contactsParamId + +type contactsParamAction struct { + Action ContactsAction `json:"action"` +} + +type contactsParamId struct { + Id uint64 `json:"id,omitempty"` +} + +type contactsParamJson struct { + Json bool `json:"json,omitempty"` +} + +type contactsPropReturn struct { + Return ContactsWriteCode `json:"return"` +} + +type contactsReadApiParams struct { + contactsParamAction + ContactsReadParams + contactsParamJson +} + +func newReadApiParams(readParams ContactsReadParams, json bool) contactsReadApiParams { + return contactsReadApiParams{ + contactsParamAction: contactsParamAction{ContactsActionRead}, + contactsParamJson: contactsParamJson{json}, + ContactsReadParams: readParams, + } +} + +type contactsCreateApiParams struct { + contactsParamAction + contactsParamJson +} + +func newContactsCreateApiParams(json bool) contactsCreateApiParams { + return contactsCreateApiParams{ + contactsParamAction: contactsParamAction{ContactsActionWrite}, + contactsParamJson: contactsParamJson{json}, + } +} + +type contactsDeleteApiParams struct { + ContactsDeleteParams + contactsParamAction + contactsParamJson +} + +func newContactsDeleteApiParams(p ContactsDeleteParams, json bool) contactsDeleteApiParams { + return contactsDeleteApiParams{ + ContactsDeleteParams: p, + contactsParamAction: contactsParamAction{ContactsActionDelete}, + contactsParamJson: contactsParamJson{json}, + } +} + +type contactsEditJsonApiParams struct { + ContactEditParams + contactsParamAction + contactsParamJson +} + +func newContactsEditJsonApiParams(p ContactEditParams, json bool) contactsEditJsonApiParams { + return contactsEditJsonApiParams{ + ContactEditParams: p, + contactsParamAction: contactsParamAction{ContactsActionWrite}, + contactsParamJson: contactsParamJson{json}, + } +} + +func (api *ContactsResource) request(ctx context.Context, method HttpMethod, params interface{}) (string, error) { + return api.client.request(ctx, "contacts", string(method), params) +} + +func (api *ContactsResource) ReadCsv(p ContactsReadParams) (string, error) { + return api.ReadCsvContext(context.Background(), p) +} + +func (api *ContactsResource) ReadCsvContext(ctx context.Context, p ContactsReadParams) (string, error) { + return api.request(ctx, HttpMethodGet, newReadApiParams(p, false)) +} + +func (api *ContactsResource) ReadJson(p ContactsReadParams) (a []Contact, e error) { + return api.ReadJsonContext(context.Background(), p) +} + +func (api *ContactsResource) ReadJsonContext(ctx context.Context, p ContactsReadParams) (a []Contact, e error) { + s, e := api.request(ctx, HttpMethodGet, newReadApiParams(p, true)) + + if nil != e { + return + } + + json.Unmarshal([]byte(s), &a) + + return +} + +func (api *ContactsResource) CreateCsv() (string, error) { + return api.CreateCsvContext(context.Background()) +} + +func (api *ContactsResource) CreateCsvContext(ctx context.Context) (string, error) { + return api.request(ctx, HttpMethodPost, newContactsCreateApiParams(false)) +} + +func (api *ContactsResource) CreateJson() (o ContactsCreateJsonResponse, e error) { + return api.CreateJsonContext(context.Background()) +} + +func (api *ContactsResource) CreateJsonContext(ctx context.Context) (o ContactsCreateJsonResponse, e error) { + s, e := api.request(ctx, HttpMethodGet, newContactsCreateApiParams(true)) + + e = json.Unmarshal([]byte(s), &o) + + return +} + +func (api *ContactsResource) DeleteCsv(p ContactsDeleteParams) (string, error) { + return api.DeleteCsvContext(context.Background(), p) +} + +func (api *ContactsResource) DeleteCsvContext(ctx context.Context, p ContactsDeleteParams) (string, error) { + return api.request(ctx, HttpMethodPost, newContactsDeleteApiParams(p, false)) +} + +func (api *ContactsResource) DeleteJson(p ContactsDeleteParams) (o ContactsDeleteJsonResponse, e error) { + return api.DeleteJsonContext(context.Background(), p) +} + +func (api *ContactsResource) DeleteJsonContext(ctx context.Context, p ContactsDeleteParams) (o ContactsDeleteJsonResponse, e error) { + s, e := api.request(ctx, HttpMethodGet, newContactsDeleteApiParams(p, true)) + + e = json.Unmarshal([]byte(s), &o) + + return +} + +func (api *ContactsResource) EditCsv(p ContactEditParams) (string, error) { + return api.EditCsvContext(context.Background(), p) +} + +func (api *ContactsResource) EditCsvContext(ctx context.Context, p ContactEditParams) (string, error) { + return api.request(ctx, HttpMethodGet, newContactsEditJsonApiParams(p, false)) +} + +func (api *ContactsResource) EditJson(p ContactEditParams) (o ContactsEditJsonResponse, e error) { + return api.EditJsonContext(context.Background(), p) +} + +func (api *ContactsResource) EditJsonContext(ctx context.Context, p ContactEditParams) (o ContactsEditJsonResponse, e error) { + s, e := api.request(ctx, HttpMethodGet, newContactsEditJsonApiParams(p, true)) + + e = json.Unmarshal([]byte(s), &o) + + return +} diff --git a/vendor/github.com/sms77io/go-client/sms77api/hooks.go b/vendor/github.com/sms77io/go-client/sms77api/hooks.go new file mode 100644 index 0000000..09f1777 --- /dev/null +++ b/vendor/github.com/sms77io/go-client/sms77api/hooks.go @@ -0,0 +1,96 @@ +package sms77api + +import ( + "context" + "encoding/json" +) + +type HookEventType string + +const ( + HookEventTypeSmsStatus HookEventType = "dlr" + HookEventTypeVoiceStatus HookEventType = "voice_status" + HookEventTypeInboundSms HookEventType = "sms_mo" +) + +type HookRequestMethod string + +const ( + HookRequestMethodGet HookRequestMethod = "GET" + HookRequestMethodJson HookRequestMethod = "JSON" + HookRequestMethodPost HookRequestMethod = "POST" +) + +type HooksAction string + +const ( + HooksActionRead HooksAction = "read" + HooksActionSubscribe HooksAction = "subscribe" + HooksActionUnsubscribe HooksAction = "unsubscribe" +) + +type Hook struct { + Created string `json:"created"` + EventType HookEventType `json:"event_type"` + Id string `json:"id"` + RequestMethod HookRequestMethod `json:"request_method"` + TargetUrl string `json:"target_url"` +} + +type HooksParams struct { + Action HooksAction `json:"action"` + EventType HookEventType `json:"event_type,omitempty"` + Id int `json:"id,omitempty"` + RequestMethod HookRequestMethod `json:"request_method,omitempty"` + TargetUrl string `json:"target_url,omitempty"` +} + +type HooksReadResponse struct { + Success bool `json:"success"` + Hooks []Hook `json:"hooks"` +} + +type HooksUnsubscribeResponse struct { + Success bool `json:"success"` +} + +type HooksSubscribeResponse struct { + Id int `json:"id"` + Success bool `json:"success"` +} + +type HooksResource resource + +func (api *HooksResource) Request(p HooksParams) (interface{}, error) { + return api.RequestContext(context.Background(), p) +} + +func (api *HooksResource) RequestContext(ctx context.Context, p HooksParams) (interface{}, error) { + method := "POST" + if p.Action == HooksActionRead { + method = "GET" + } + + res, err := api.client.request(ctx, "hooks", method, p) + + if err != nil { + return nil, err + } + + var js interface{} + + switch p.Action { + case HooksActionRead: + js = &HooksReadResponse{} + case HooksActionSubscribe: + js = &HooksSubscribeResponse{} + case HooksActionUnsubscribe: + js = &HooksUnsubscribeResponse{} + } + + if err := json.Unmarshal([]byte(res), js); err != nil { + return nil, err + } + + return js, nil +} diff --git a/vendor/github.com/sms77io/go-client/sms77api/journal.go b/vendor/github.com/sms77io/go-client/sms77api/journal.go new file mode 100644 index 0000000..e9bfff8 --- /dev/null +++ b/vendor/github.com/sms77io/go-client/sms77api/journal.go @@ -0,0 +1,149 @@ +package sms77api + +import ( + "context" + "encoding/json" +) + +type JournalResource resource + +type JournalType string + +const ( + JournalTypeInbound JournalType = "inbound" + JournalTypeOutbound JournalType = "outbound" + JournalTypeReplies JournalType = "replies" + JournalTypeVoice JournalType = "voice" +) + +type JournalBase struct { + From string `json:"from"` + Id string `json:"id"` + Price string `json:"price"` + Text string `json:"text"` + Timestamp string `json:"timestamp"` + To string `json:"to"` +} + +type JournalOutbound struct { + JournalBase + Connection string `json:"connection"` + Dlr string `json:"dlr"` + DlrTimestamp string `json:"dlr_timestamp"` + ForeignId string `json:"foreign_id"` + Label string `json:"label"` + Latency string `json:"latency"` + MccMnc string `json:"mccmnc"` + Type string `json:"type"` +} + +type JournalInbound struct { + JournalBase +} + +type JournalReplies struct { + JournalBase +} + +type JournalVoice struct { + JournalBase + Duration string `json:"duration"` + Error string `json:"error"` + Status string `json:"status"` + Xml bool `json:"xml"` +} + +type JournalParams struct { + DateFrom string `json:"date_from,omitempty"` + DateTo string `json:"date_to,omitempty"` + Id int `json:"id,omitempty"` + State string `json:"state,omitempty"` + To string `json:"to,omitempty"` + Type JournalType `json:"type"` +} + +func BuildJournalParams(journalType JournalType, p *JournalParams) *JournalParams { + p.Type = journalType + + return p +} + +func (api *JournalResource) Inbound(p *JournalParams) ([]JournalInbound, error) { + return api.InboundContext(context.Background(), p) +} + +func (api *JournalResource) InboundContext(ctx context.Context, p *JournalParams) ([]JournalInbound, error) { + res, err := api.client.request(ctx, "journal", "GET", BuildJournalParams(JournalTypeInbound, p)) + + if err != nil { + return nil, err + } + + var js []JournalInbound + + if err := json.Unmarshal([]byte(res), &js); err != nil { + return nil, err + } + + return js, nil +} + +func (api *JournalResource) Outbound(p *JournalParams) ([]JournalOutbound, error) { + return api.OutboundContext(context.Background(), p) +} + +func (api *JournalResource) OutboundContext(ctx context.Context, p *JournalParams) ([]JournalOutbound, error) { + res, err := api.client.request(ctx, "journal", "GET", BuildJournalParams(JournalTypeOutbound, p)) + + if err != nil { + return nil, err + } + + var js []JournalOutbound + + if err := json.Unmarshal([]byte(res), &js); err != nil { + return nil, err + } + + return js, nil +} + +func (api *JournalResource) Replies(p *JournalParams) ([]JournalReplies, error) { + return api.RepliesContext(context.Background(), p) +} + +func (api *JournalResource) RepliesContext(ctx context.Context, p *JournalParams) ([]JournalReplies, error) { + res, err := api.client.request(ctx, "journal", "GET", BuildJournalParams(JournalTypeReplies, p)) + + if err != nil { + return nil, err + } + + var js []JournalReplies + + if err := json.Unmarshal([]byte(res), &js); err != nil { + return nil, err + } + + return js, nil +} + +func (api *JournalResource) Voice(p *JournalParams) ([]JournalVoice, error) { + return api.VoiceContext(context.Background(), p) +} + +func (api *JournalResource) VoiceContext(ctx context.Context, p *JournalParams) ([]JournalVoice, error) { + res, err := api.client.request(ctx, "journal", "GET", BuildJournalParams(JournalTypeVoice, p)) + + if err != nil { + return nil, err + } + + var js []JournalVoice + + if err := json.Unmarshal([]byte(res), &js); err != nil { + return nil, err + } + + return js, nil +} diff --git a/vendor/github.com/sms77io/go-client/sms77api/lookup.go b/vendor/github.com/sms77io/go-client/sms77api/lookup.go new file mode 100644 index 0000000..c654939 --- /dev/null +++ b/vendor/github.com/sms77io/go-client/sms77api/lookup.go @@ -0,0 +1,114 @@ +package sms77api + +import ( + "context" + "encoding/json" +) + +type Carrier struct { + Country string `json:"country"` + Name string `json:"name"` + NetworkCode string `json:"network_code"` + NetworkType string `json:"network_type"` +} + +type LookupParams struct { + Type string `json:"type"` + Number string `json:"number,omitempty"` + Json bool `json:"json,omitempty"` +} + +type LookupCnamResponse struct { + Code string `json:"code"` + Name string `json:"name"` + Number string `json:"number"` + Success string `json:"success"` +} + +type LookupFormatResponse struct { + National string `json:"national"` + Carrier string `json:"carrier"` + CountryCode string `json:"country_code"` + CountryIso string `json:"country_iso"` + CountryName string `json:"country_name"` + International string `json:"international"` + InternationalFormatted string `json:"international_formatted"` + NetworkType string `json:"network_type"` + Success bool `json:"success"` +} + +type LookupHlrResponse struct { + CountryCode string `json:"country_code"` + CountryCodeIso3 *string `json:"country_code_iso3,omitempty"` + CountryName string `json:"country_name"` + CountryPrefix string `json:"country_prefix"` + CurrentCarrier Carrier `json:"current_carrier"` + GsmCode string `json:"gsm_code"` + GsmMessage string `json:"gsm_message"` + InternationalFormatNumber string `json:"international_format_number"` + InternationalFormatted string `json:"international_formatted"` + LookupOutcome bool `json:"lookup_outcome"` + LookupOutcomeMessage string `json:"lookup_outcome_message"` + NationalFormatNumber string `json:"national_format_number"` + OriginalCarrier Carrier `json:"original_carrier"` + Ported string `json:"ported"` + Reachable string `json:"reachable"` + Roaming string `json:"roaming"` + Status bool `json:"status"` + StatusMessage string `json:"status_message"` + ValidNumber string `json:"valid_number"` +} + +type LookupMnpResponse struct { + Code int64 `json:"code"` + Mnp Mnp `json:"mnp"` + Price float64 `json:"price"` + Success bool `json:"success"` +} + +type Mnp struct { + Country string `json:"country"` + InternationalFormatted string `json:"international_formatted"` + IsPorted bool `json:"isPorted"` + Mccmnc string `json:"mccmnc"` + NationalFormat string `json:"national_format"` + Network string `json:"network"` + Number string `json:"number"` +} + +type LookupResource resource + +func (api *LookupResource) Post(p LookupParams) (interface{}, error) { + return api.PostContext(context.Background(), p) +} + +func (api *LookupResource) PostContext(ctx context.Context, p LookupParams) (interface{}, error) { + res, err := api.client.request(ctx, "lookup", "GET", p) + + if err != nil { + return nil, err + } + + var js interface{} + + switch p.Type { + case "mnp": + if !p.Json { + return res, nil + } + + js = &LookupMnpResponse{} + case "cnam": + js = &LookupCnamResponse{} + case "format": + js = &LookupFormatResponse{} + case "hlr": + js = &LookupHlrResponse{} + } + + if err := json.Unmarshal([]byte(res), js); err != nil { + return nil, err + } + + return js, nil +} diff --git a/vendor/github.com/sms77io/go-client/sms77api/pricing.go b/vendor/github.com/sms77io/go-client/sms77api/pricing.go new file mode 100644 index 0000000..12d8cdc --- /dev/null +++ b/vendor/github.com/sms77io/go-client/sms77api/pricing.go @@ -0,0 +1,124 @@ +package sms77api + +import ( + "context" + "encoding/json" +) + +type PricingResource resource + +type CountryNetwork struct { + Comment string `json:"comment,omitempty"` + Features []string `json:"features,omitempty"` + Mcc string `json:"mcc,omitempty"` + Mncs []string `json:"mncs,omitempty"` + NetworkName string `json:"networkName,omitempty"` + Price float64 `json:"price,omitempty"` +} + +type CountryPricing struct { + CountryCode string `json:"countryCode,omitempty"` + CountryName string `json:"countryName,omitempty"` + CountryPrefix string `json:"countryPrefix,omitempty"` + Networks []CountryNetwork `json:"networks,omitempty"` +} + +type PricingFormat string + +const ( + PricingFormatCsv PricingFormat = "csv" + PricingFormatJson PricingFormat = "json" +) + +type PricingParams struct { + Country string `json:"country,omitempty"` +} + +type PricingResponse struct { + CountCountries int64 `json:"countCountries"` + CountNetworks int64 `json:"countNetworks"` + Countries []CountryPricing `json:"countries"` +} + +type PricingApiParams struct { + PricingParams + Format PricingFormat `json:"format,omitempty"` +} + +type PricingCsvHeader int + +const ( + PricingHeaderCountryCode PricingCsvHeader = iota + PricingHeaderCountryName + PricingHeaderCountryPrefix + PricingHeaderMcc + PricingHeaderMncs + PricingHeaderNetworkName + PricingHeaderPrice + PricingHeaderFeatures + PricingHeaderComment +) + +var PricingCsvHeaders = map[PricingCsvHeader]string{ + PricingHeaderCountryCode: "countryCode", + PricingHeaderCountryName: "countryName", + PricingHeaderCountryPrefix: "countryPrefix", + PricingHeaderMcc: "mcc", + PricingHeaderMncs: "mnc", + PricingHeaderNetworkName: "networkName", + PricingHeaderPrice: "price", + PricingHeaderFeatures: "features", + PricingHeaderComment: "comment", +} + +type PricingCsvColumn int + +const ( + PricingColumnCountryCode PricingCsvColumn = iota + PricingColumnCountryName + PricingColumnCountryPrefix + PricingColumnMcc + PricingColumnNetworkName + PricingColumnPrice + PricingColumnFeatures + PricingColumnComment + PricingColumnMncs +) + +const EndpointPricing = "pricing" + +func (api *PricingResource) Csv(p PricingParams) (string, error) { + return api.CsvContext(context.Background(), p) +} + +func (api *PricingResource) CsvContext(ctx context.Context, p PricingParams) (string, error) { + res, err := api.client.request(ctx, EndpointPricing, "GET", PricingApiParams{ + PricingParams: p, + Format: PricingFormatCsv, + }) + + if err != nil { + return "", err + } + + return res, nil +} + +func (api *PricingResource) Json(p PricingParams) (*PricingResponse, error) { + return api.JsonContext(context.Background(), p) +} +func (api *PricingResource) JsonContext(ctx context.Context, p PricingParams) (*PricingResponse, error) { + res, err := api.client.request(ctx, EndpointPricing, "GET", PricingApiParams{PricingParams: p}) + + if err != nil { + return nil, err + } + + var js = &PricingResponse{} + + if err := json.Unmarshal([]byte(res), &js); err != nil { + return nil, err + } + + return js, nil +} diff --git a/vendor/github.com/sms77io/go-client/sms77api/sms.go b/vendor/github.com/sms77io/go-client/sms77api/sms.go new file mode 100644 index 0000000..74e2b8e --- /dev/null +++ b/vendor/github.com/sms77io/go-client/sms77api/sms.go @@ -0,0 +1,104 @@ +package sms77api + +import ( + "context" + "encoding/json" +) + +type SmsFile struct { + Contents string `json:"contents"` + Name string `json:"name"` + Validity *uint8 `json:"validity,omitempty"` + Password *string `json:"password,omitempty"` +} + +type SmsBaseParams struct { + Debug bool `json:"debug,omitempty"` + Delay string `json:"delay,omitempty"` + Files []SmsFile `json:"files,omitempty"` + Flash bool `json:"flash,omitempty"` + ForeignId string `json:"foreign_id,omitempty"` + From string `json:"from,omitempty"` + Label string `json:"label,omitempty"` + NoReload bool `json:"no_reload,omitempty"` + PerformanceTracking bool `json:"performance_tracking,omitempty"` + Text string `json:"text"` + To string `json:"to"` + Ttl int64 `json:"ttl,omitempty"` + Udh string `json:"udh,omitempty"` + Unicode bool `json:"unicode,omitempty"` + Utf8 bool `json:"utf8,omitempty"` +} + +type SmsTextParams struct { + SmsBaseParams + Details bool `json:"details,omitempty"` + ReturnMessageId bool `json:"return_msg_id,omitempty"` +} + +type SmsResource resource + +type SmsResponse struct { + Debug string `json:"debug"` + Balance float64 `json:"balance"` + Messages []SmsResponseMessage `json:"messages"` + SmsType string `json:"sms_type"` + Success StatusCode `json:"success"` + TotalPrice float64 `json:"total_price"` +} + +type SmsResponseMessage struct { + Encoding string `json:"encoding"` + Error *string `json:"error"` + ErrorText *string `json:"error_text"` + Id *string `json:"id"` + Label *string `json:"label"` + Messages *[]string `json:"messages,omitempty"` + Parts int64 `json:"parts"` + Price float64 `json:"price"` + Recipient string `json:"recipient"` + Sender string `json:"sender"` + Success bool `json:"success"` + Text string `json:"text"` +} + +func (api *SmsResource) request(ctx context.Context, p interface{}) (*string, error) { + res, err := api.client.request(ctx, "sms", "POST", p) + + if err != nil { + return nil, err + } + + return &res, nil +} + +func (api *SmsResource) Text(p SmsTextParams) (res *string, err error) { + return api.TextContext(context.Background(), p) +} + +func (api *SmsResource) TextContext(ctx context.Context, p SmsTextParams) (res *string, err error) { + return api.request(ctx, p) +} + +func (api *SmsResource) Json(p SmsBaseParams) (o *SmsResponse, err error) { + return api.JsonContext(context.Background(), p) +} +func (api *SmsResource) JsonContext(ctx context.Context, p SmsBaseParams) (o *SmsResponse, err error) { + type SmsJsonParams struct { + SmsBaseParams + Json bool `json:"json,omitempty"` + } + + res, err := api.request(ctx, SmsJsonParams{ + SmsBaseParams: p, + Json: true, + }) + + if nil != err { + return nil, err + } + + err = json.Unmarshal([]byte(*res), &o) + + return +} diff --git a/vendor/github.com/sms77io/go-client/sms77api/sms77api.go b/vendor/github.com/sms77io/go-client/sms77api/sms77api.go new file mode 100644 index 0000000..9a2048a --- /dev/null +++ b/vendor/github.com/sms77io/go-client/sms77api/sms77api.go @@ -0,0 +1,242 @@ +package sms77api + +import ( + "context" + "encoding/json" + "errors" + "fmt" + "io/ioutil" + "log" + "net/http" + "net/url" + "strconv" + "strings" +) + +type HttpMethod string +type Options struct { + ApiKey string + Debug bool + SentWith string +} +type resource struct { + client *Sms77API +} +type StatusCode string +type Sms77API struct { + Options + client *http.Client + base resource // Instead of allocating a struct for each service we reuse a one + + Analytics *AnalyticsResource + Balance *BalanceResource + Contacts *ContactsResource + Hooks *HooksResource + Journal *JournalResource + Lookup *LookupResource + Pricing *PricingResource + Sms *SmsResource + Status *StatusResource + ValidateForVoice *ValidateForVoiceResource + Voice *VoiceResource +} + +const ( + defaultOptionSentWith = "go-client" + + sentWithKey = "sentWith" + + HttpMethodGet HttpMethod = "GET" + HttpMethodPost HttpMethod = "POST" + + StatusCodeErrorCarrierNotAvailable StatusCode = "11" + StatusCodeSuccess StatusCode = "100" + StatusCodeSuccessPartial StatusCode = "101" + StatusCodeInvalidSender StatusCode = "201" + StatusCodeInvalidRecipient StatusCode = "202" + StatusCodeMissingParamTo StatusCode = "301" + StatusCodeMissingParamText StatusCode = "305" + StatusCodeParamTextExceedsLengthLimit StatusCode = "401" + StatusCodePreventedByReloadLock StatusCode = "402" + StatusCodeReachedDailyLimitForNumber StatusCode = "403" + StatusCodeInsufficientCredits StatusCode = "500" + StatusCodeErrorCarrierDelivery StatusCode = "600" + StatusCodeErrorUnknown StatusCode = "700" + StatusCodeErrorAuthentication StatusCode = "900" + StatusCodeErrorApiDisabledForKey StatusCode = "902" + StatusCodeErrorServerIp StatusCode = "903" +) + +var StatusCodes = map[StatusCode]string{ + StatusCodeErrorCarrierNotAvailable: "ErrorCarrierNotAvailable", + StatusCodeSuccess: "Success", + StatusCodeSuccessPartial: "SuccessPartial", + StatusCodeInvalidSender: "InvalidSender", + StatusCodeInvalidRecipient: "InvalidRecipient", + StatusCodeMissingParamTo: "MissingParamTo", + StatusCodeMissingParamText: "MissingParamText", + StatusCodeParamTextExceedsLengthLimit: "ParamTextExceedsLengthLimit", + StatusCodePreventedByReloadLock: "PreventedByReloadLock", + StatusCodeReachedDailyLimitForNumber: "ReachedDailyLimitForNumber", + StatusCodeInsufficientCredits: "InsufficientCredits", + StatusCodeErrorCarrierDelivery: "ErrorCarrierDelivery", + StatusCodeErrorUnknown: "ErrorUnknown", + StatusCodeErrorAuthentication: "ErrorAuthentication", + StatusCodeErrorApiDisabledForKey: "ErrorApiDisabledForKey", + StatusCodeErrorServerIp: "ErrorServerIp", +} + +func New(options Options) *Sms77API { + if "" == options.SentWith { + options.SentWith = defaultOptionSentWith + } + + c := &Sms77API{client: http.DefaultClient} + c.Options = options + c.base.client = c + + c.Analytics = (*AnalyticsResource)(&c.base) + c.Balance = (*BalanceResource)(&c.base) + c.Contacts = (*ContactsResource)(&c.base) + c.Hooks = (*HooksResource)(&c.base) + c.Journal = (*JournalResource)(&c.base) + c.Lookup = (*LookupResource)(&c.base) + c.Pricing = (*PricingResource)(&c.base) + c.Sms = (*SmsResource)(&c.base) + c.Status = (*StatusResource)(&c.base) + c.ValidateForVoice = (*ValidateForVoiceResource)(&c.base) + c.Voice = (*VoiceResource)(&c.base) + + return c +} + +func (api *Sms77API) get(ctx context.Context, endpoint string, data map[string]interface{}) (string, error) { + return api.request(ctx, endpoint, http.MethodGet, data) +} + +func (api *Sms77API) post(ctx context.Context, endpoint string, data map[string]interface{}) (string, error) { + return api.request(ctx, endpoint, http.MethodPost, data) +} + +func (api *Sms77API) request(ctx context.Context, endpoint string, method string, data interface{}) (string, error) { + createRequestPayload := func() string { + params := url.Values{} + + for k, v := range data.(map[string]interface{}) { + if api.Debug { + log.Printf("%s: %v", k, v) + } + + switch v.(type) { + case nil: + continue + case bool: + if true == v { + v = "1" + } else { + v = "0" + } + case int64: + v = strconv.FormatInt(v.(int64), 10) + case []interface{}: + for fileIndex, files := range v.([]interface{}) { + for fileKey, fileValue := range files.(map[string]interface{}) { + params.Add( + fmt.Sprintf("%s[%d][%s]", k, fileIndex, fileKey), fmt.Sprintf("%v", fileValue)) + } + } + + continue + } + + params.Add(k, fmt.Sprintf("%v", v)) + } + + return params.Encode() + } + + initClient := func() (req *http.Request, err error) { + var uri = fmt.Sprintf("https://gateway.sms77.io/api/%s", endpoint) + var qs = createRequestPayload() + var headers = map[string]string{ + "Authorization": fmt.Sprintf("Basic %s", api.ApiKey), + sentWithKey: api.SentWith, + } + var body = "" + + if http.MethodGet == method { + if "" != qs { + uri = fmt.Sprintf("%s?%s", uri, qs) + } + } else { + body = qs + + headers["Content-Type"] = "application/x-www-form-urlencoded" + } + + if api.Debug { + log.Printf("%s %s", method, uri) + } + + req, err = http.NewRequestWithContext(ctx, method, uri, strings.NewReader(body)) + + if nil != err { + log.Println(err.Error()) + panic(err) + } + + for k, v := range headers { + req.Header.Add(k, v) + } + + return + } + + if http.MethodGet != method && http.MethodPost != method { + return "", errors.New(fmt.Sprintf("unsupported http method %s", method)) + } + + if "" == api.Options.ApiKey { + return "", errors.New("missing required option ApiKey") + } + + if nil == data { + data = map[string]interface{}{} + } + data, _ = json.Marshal(&data) + json.Unmarshal(data.([]byte), &data) + + req, err := initClient() + if err != nil { + return "", fmt.Errorf("could not execute request! #1 (%s)", err.Error()) + } + + res, err := api.client.Do(req) + if err != nil { + return "", fmt.Errorf("could not execute request! #2 (%s)", err.Error()) + } + + defer res.Body.Close() + + body, err := ioutil.ReadAll(res.Body) + if err != nil { + return "", fmt.Errorf("could not execute request! #3 (%s)", err.Error()) + } + + str := strings.TrimSpace(string(body)) + + if api.Debug { + log.Println(str) + } + + length := len(str) + + if 2 == length || 3 == length { + code, msg := pickMapByKey(str, StatusCodes) + if nil != code { + return "", errors.New(fmt.Sprintf("%s: %s", code, msg)) + } + } + + return str, nil +} diff --git a/vendor/github.com/sms77io/go-client/sms77api/status.go b/vendor/github.com/sms77io/go-client/sms77api/status.go new file mode 100644 index 0000000..f61fe1d --- /dev/null +++ b/vendor/github.com/sms77io/go-client/sms77api/status.go @@ -0,0 +1,64 @@ +package sms77api + +import ( + "context" + "errors" + "strings" +) + +type StatusResource resource + +type StatusParams struct { + MessageId uint64 `json:"msg_id"` +} + +type Status struct { + Code string + DateTime string +} + +func makeStatus(res *string) (s *Status, e error) { + if nil == res { + return nil, errors.New("cannot make status from nil") + } + + if StatusApiCodeInvalidMessageId == *res { + return nil, errors.New(StatusApiCodeInvalidMessageId + ": Invalid message ID") + } + + lines := strings.Split(*res, "\n") + + if 2 != len(lines) { + return nil, errors.New("need exactly 2 lines to make a status") + } + + return &Status{ + Code: lines[0], + DateTime: lines[1], + }, nil +} + +const StatusApiCodeInvalidMessageId = "901" + +func (api *StatusResource) Text(p StatusParams) (*string, error) { + return api.TextContext(context.Background(), p) +} +func (api *StatusResource) TextContext(ctx context.Context, p StatusParams) (*string, error) { + res, err := api.client.request(ctx, "status", "POST", p) + + if err != nil { + return nil, err + } + + return &res, nil +} + +func (api *StatusResource) Json(p StatusParams) (o *Status, e error) { + r, e := api.Text(p) + + if nil != e { + return + } + + return makeStatus(r) +} diff --git a/vendor/github.com/sms77io/go-client/sms77api/util.go b/vendor/github.com/sms77io/go-client/sms77api/util.go new file mode 100644 index 0000000..2c579d6 --- /dev/null +++ b/vendor/github.com/sms77io/go-client/sms77api/util.go @@ -0,0 +1,41 @@ +package sms77api + +import ( + "reflect" + "strconv" +) + +func pickMapByKey(needle interface{}, haystack interface{}) (interface{}, interface{}) { + mapIter := reflect.ValueOf(haystack).MapRange() + + for mapIter.Next() { + if needle == mapIter.Key() { + return needle, mapIter.Value() + } + } + + return nil, nil +} + +func inArray(needle interface{}, haystack interface{}) bool { + slice := reflect.ValueOf(haystack) + c := slice.Len() + + for i := 0; i < c; i++ { + if needle == slice.Index(i).Interface() { + return true + } + } + + return false +} + +func toUint(id string, bitSize int) uint64 { + n, err := strconv.ParseUint(id, 10, bitSize) + + if nil == err { + return n + } + + return 0 +} diff --git a/vendor/github.com/sms77io/go-client/sms77api/validate_for_voice.go b/vendor/github.com/sms77io/go-client/sms77api/validate_for_voice.go new file mode 100644 index 0000000..99bb08e --- /dev/null +++ b/vendor/github.com/sms77io/go-client/sms77api/validate_for_voice.go @@ -0,0 +1,39 @@ +package sms77api + +import ( + "context" + "encoding/json" +) + +type ValidateForVoiceParams struct { + Callback string `json:"callback"` + Number string `json:"number"` +} + +type ValidateForVoiceResponse struct { + Code string `json:"code"` + Error *string `json:"error"` + FormattedOutput *string `json:"formatted_output"` + Id *int64 `json:"id"` + Sender string `json:"sender"` + Success bool `json:"success"` + Voice bool `json:"voice"` +} + +type ValidateForVoiceResource resource + +func (api *ValidateForVoiceResource) Get(p ValidateForVoiceParams) (o *ValidateForVoiceResponse, e error) { + return api.GetContext(context.Background(), p) +} + +func (api *ValidateForVoiceResource) GetContext(ctx context.Context, p ValidateForVoiceParams) (o *ValidateForVoiceResponse, e error) { + r, e := api.client.request(ctx, "validate_for_voice", "GET", p) + + if nil != e { + return + } + + e = json.Unmarshal([]byte(r), o) + + return +} diff --git a/vendor/github.com/sms77io/go-client/sms77api/voice.go b/vendor/github.com/sms77io/go-client/sms77api/voice.go new file mode 100644 index 0000000..31c1e39 --- /dev/null +++ b/vendor/github.com/sms77io/go-client/sms77api/voice.go @@ -0,0 +1,61 @@ +package sms77api + +import ( + "context" + "strconv" + "strings" +) + +type Voice struct { + Code int + Cost float64 + Id int +} + +type VoiceParams struct { + Debug bool `json:"debug,omitempty"` + To string `json:"to"` + Text string `json:"text"` + Xml bool `json:"xml,omitempty"` + From string `json:"from,omitempty"` +} + +type VoiceResource resource + +func makeVoice(res string) Voice { + lines := strings.Split(res, "\n") + + code, _ := strconv.Atoi(lines[0]) + id, _ := strconv.Atoi(lines[1]) + cost, _ := strconv.ParseFloat(lines[2], 64) + + return Voice{ + Code: code, + Cost: cost, + Id: id, + } +} + +func (api *VoiceResource) Text(p VoiceParams) (*string, error) { + return api.TextContext(context.Background(), p) +} + +func (api *VoiceResource) TextContext(ctx context.Context, p VoiceParams) (*string, error) { + res, err := api.client.request(ctx, "voice", "POST", p) + + if err != nil { + return nil, err + } + + return &res, nil +} + +func (api *VoiceResource) Json(p VoiceParams) (o Voice, e error) { + r, e := api.Text(p) + + if nil != e { + return + } + + return makeVoice(*r), nil +} diff --git a/vendor/modules.txt b/vendor/modules.txt new file mode 100644 index 0000000..fcc9498 --- /dev/null +++ b/vendor/modules.txt @@ -0,0 +1,3 @@ +# github.com/sms77io/go-client v0.0.0-20211026080708-90d592e387a5 +## explicit; go 1.15 +github.com/sms77io/go-client/sms77api