Sha256: ec0d250f61d723eb95eaa9ea64062616b5dcd8fcc8c50f0b622969c33504f986

Contents?: true

Size: 970 Bytes

Versions: 1

Compression:

Stored size: 970 Bytes

Contents

require "sms_manager/error/sending_error"
require "httpclient"

module SmsManager

  class Client
    # options should be { number: String, message: String }
    def send_message(options = {})
      validate_send_message_options! options
      options = {
        username: SmsManager.instance_variable_get(:@username),
        password: SmsManager.instance_variable_get(:@hashed_password),
        number: options[:number],
        message: options[:message]
      }
      body = HTTPClient.get('http://http-api.smsmanager.cz/Send', options).body
      unless body =~ /^OK/
        raise SendingError, "Sending text '#{options[:message]}' to phone '#{options[:number]}' failed"
      end
      nil
    end

    private

    def validate_send_message_options!(options)
      options.each do |option, value|
        unless value.is_a?(String)
          raise ArgumentError, "Invalid #{option} specified: #{value} must be a string."
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sms_manager-0.1.2 lib/sms_manager/client.rb