<commit_before>package sms

import (
	"bytes"
	"encoding/json"
	"errors"
	"io/ioutil"
	"net/http"
	"strconv"
	"time"

	log "github.com/Sirupsen/logrus"
	"github.com/cosminrentea/go-uuid"
	"github.com/cosminrentea/gobbler/protocol"
	"github.com/cosminrentea/gobbler/server/kafka"
	"github.com/jpillora/backoff"
)

type ResponseCode int

const (
	ResponseSuccess ResponseCode = iota
	ResponseThrottled
	ResponseMissingParams
	ResponseInvalidParams
	ResponseInvalidCredentials
	ResponseInternalError
	ResponseInvalidMessage
	ResponseNumberBarred
	ResponsePartnerAcctBarred
	ResponsePartnerQuotaExceeded
	ResponseUnused //Defined in Nexmo Api
	ResponseRESTNotEnabled
	ResponseMessageTooLong
	ResponseCommunicationFailed
	ResponseInvalidSignature
	ResponseInvalidSenderAddress
	ResponseInvalidTTL
	ResponseFacilityNotAllowed
	ResponseInvalidMessageClass
)

var (
	URL                = "https://rest.nexmo.com/sms/json?"
	MaxIdleConnections = 100
	RequestTimeout     = 500 * time.Millisecond

	ErrHTTPClientError             = errors.New("Http client sending to Nexmo Failed.No sms was sent")
	ErrNexmoResponseStatusNotOk    = errors.New("Nexmo response status not ResponseSuccess")
	ErrSMSResponseDecodingFailed   = errors.New("Nexmo response decoding failed")
	ErrInvalidSender               = errors.New("Sms destination phoneNumber is invalid")
	ErrMultipleSmsSent             = errors.New("Multiple  or no sms we're sent.SMS message may be too long")
	ErrRetryFailed                 = errors.New("Failed retrying to send message")
	ErrEncodeFailed                = errors.New("Encoding of message to be sent to Nexmo  failed")
	ErrLastIDCouldNotBeSet         = errors.New("Setting last id failed")
	errKafkaReportingConfiguration = errors.New("Kafka Reporting for Nexmo is not correctly configured")
	ErrSmsTooLong                  = errors.New("Sms maximum length exceeded.")
)

var nexmoResponseCodeMap = map[ResponseCode]string{
	ResponseSuccess:              "Success",
	ResponseThrottled:            "Throttled",
	ResponseMissingParams:        "Missing params",
	ResponseInvalidParams:        "Invalid params",
	ResponseInvalidCredentials:   "Invalid credentials",
	ResponseInternalError:        "Internal error",
	ResponseInvalidMessage:       "Invalid message",<commit_msg>fixing some error-strings<commit_after>package sms

import (
	"bytes"
	"encoding/json"
	"errors"
	"io/ioutil"
	"net/http"
	"strconv"
	"time"

	log "github.com/Sirupsen/logrus"
	"github.com/cosminrentea/go-uuid"
	"github.com/cosminrentea/gobbler/protocol"
	"github.com/cosminrentea/gobbler/server/kafka"
	"github.com/jpillora/backoff"
)

type ResponseCode int

const (
	ResponseSuccess ResponseCode = iota
	ResponseThrottled
	ResponseMissingParams
	ResponseInvalidParams
	ResponseInvalidCredentials
	ResponseInternalError
	ResponseInvalidMessage
	ResponseNumberBarred
	ResponsePartnerAcctBarred
	ResponsePartnerQuotaExceeded
	ResponseUnused //Defined in Nexmo Api
	ResponseRESTNotEnabled
	ResponseMessageTooLong
	ResponseCommunicationFailed
	ResponseInvalidSignature
	ResponseInvalidSenderAddress
	ResponseInvalidTTL
	ResponseFacilityNotAllowed
	ResponseInvalidMessageClass
)

var (
	URL                = "https://rest.nexmo.com/sms/json?"
	MaxIdleConnections = 100
	RequestTimeout     = 500 * time.Millisecond

	ErrHTTPClientError             = errors.New("Http client sending to Nexmo Failed. No sms was sent")
	ErrNexmoResponseStatusNotOk    = errors.New("Nexmo response status not ResponseSuccess")
	ErrSMSResponseDecodingFailed   = errors.New("Nexmo response decoding failed")
	ErrInvalidSender               = errors.New("Sms destination phoneNumber is invalid")
	ErrMultipleSmsSent             = errors.New("Multiple or no sms were sent. SMS message may be too long")
	ErrRetryFailed                 = errors.New("Failed retrying to send message")
	ErrEncodeFailed                = errors.New("Encoding of message to be sent to Nexmo failed")
	ErrLastIDCouldNotBeSet         = errors.New("Setting last id failed")
	errKafkaReportingConfiguration = errors.New("Kafka Reporting for Nexmo is not correctly configured")
	ErrSmsTooLong                  = errors.New("Sms maximum length exceeded")
)

var nexmoResponseCodeMap = map[ResponseCode]string{
	ResponseSuccess:              "Success",
	ResponseThrottled:            "Throttled",
	ResponseMissingParams:        "Missing params",
	ResponseInvalidParams:        "Invalid params",
	ResponseInvalidCredentials:   "Invalid credentials",
	ResponseInternalError:        "Internal error",
	ResponseInvalidMessage:       "Invalid message",
{'fraction_non_alphanumeric': 0.07377408056042031, 'fraction_numerical': 0.002626970227670753, 'mean_word_length': 4.116461366181411, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6863204', 'n_tokens_mistral': 1348, 'n_tokens_neox': 1313, 'n_words': 301}