Ejemplo n.º 1
0
        /// <summary>
        /// Send a messsage to a cell recipient.
        /// </summary>
        /// <param name="user">The user identity (api key) to authenticate with the provider.</param>
        /// <param name="password">The user password (secondary key) to authenticate with the provider.</param>
        /// <param name="to">The cell phone number to send the message to.</param>
        /// <param name="from">The long or short code to send the message from.</param>
        /// <param name="message">The SMS message content.</param>
        /// <param name="reference">An optional reference to associate and keep with the message.</param>
        /// <param name="note">An optional note to associate and keep with the message.</param>
        /// <returns>Indicates the success or failure of the send.</returns>
        public bool Send(string user, string password, string to, string from, string message, string reference, string note)
        {
            if (String.IsNullOrEmpty(user))
            {
                this.ApplyResponse(HttpStatusCode.InternalServerError, "Api user name is missing or empty.");
                return(false);
            }

            if (String.IsNullOrEmpty(password))
            {
                this.ApplyResponse(HttpStatusCode.InternalServerError, "Api user passsword is missing or empty.");
                return(false);
            }

            this.auth = Convert.ToBase64String(Encoding.UTF8.GetBytes(String.Format("{0}:{1}", user, password)));
            this.sent = false;

            SendRequest request = new SendRequest();

            request.payload.destination.address = to;
            request.payload.source.address      = from;
            request.payload.source.type         = 1; // 1 = long code, 3 = short code
            request.payload.message.content     = message;
            request.payload.message.type        = "text";

            if ((!String.IsNullOrEmpty(reference)) || (!String.IsNullOrEmpty(note)))
            {
                request.payload.options       = new SendOptions();
                request.payload.options.note1 = reference;
                request.payload.options.note2 = note;
            }

            HttpTransceiver adapter = new HttpTransceiver();

            adapter.OnRequestInitialized += this.RequestInitialized;
            adapter.OnRequestComplete    += this.SendRequestComplete;
            adapter.OnRequestError       += this.SendRequestError;

            string url = String.Format("{0}{1}", om.Default.api_base_url, om.Default.send_method_name);

            adapter.Post(url, typeof(SendRequest), request, typeof(SendResponse));

            return(this.sent);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="user"></param>
        /// <param name="password"></param>
        /// <param name="to"></param>
        /// <param name="from"></param>
        /// <param name="filePath"></param>
        /// <param name="b64Filedata"></param>
        /// <param name="description"></param>
        /// <returns></returns>
        public bool Media(string user, string password, string to, string from, string filePath, string b64Filedata, string description)
        {
            if (String.IsNullOrEmpty(user))
            {
                this.ApplyResponse(HttpStatusCode.InternalServerError, "Api user name is missing or empty.");
                return(false);
            }

            if (String.IsNullOrEmpty(password))
            {
                this.ApplyResponse(HttpStatusCode.InternalServerError, "Api user passsword is missing or empty.");
                return(false);
            }

            this.auth = Convert.ToBase64String(Encoding.UTF8.GetBytes(String.Format("{0}:{1}", user, password)));
            this.sent = false;

            MediaRequest request = new MediaRequest(to, from, filePath, b64Filedata, description);

            request.OnHttpResponse += this.ApplyResponse;
            request.OnPostEntry    += this.PostEntry;

            if (request.IsNotValid())
            {
                return(false);
            }

            HttpTransceiver adapter = new HttpTransceiver();

            adapter.OnRequestInitialized += this.RequestInitialized;
            adapter.OnRequestComplete    += this.SendRequestComplete;
            adapter.OnRequestError       += this.SendRequestError;

            string url = String.Format("{0}{1}", om.Default.api_base_url, om.Default.mms_method_name);

            adapter.Post(url, typeof(string), request.Serialize(), typeof(MediaResponse));

            return(this.sent);
        }