Sha256: f88477757bd0e720f0f75be14cfcc9a45a97f0e4ceea14af5fc3fa08e855178f

Contents?: true

Size: 811 Bytes

Versions: 4

Compression:

Stored size: 811 Bytes

Contents

require 'sms_manager/error/sending_error'
require 'httpclient'

module SmsManager
  class << self
    attr_writer :username, :hashed_password

    def configure
      yield self
    end

    # options should be { number: String, message: String }
    def send(options = {})
      options = {
        username: SmsManager.instance_variable_get(:@username),
        password: SmsManager.instance_variable_get(:@hashed_password),
        number: options[:number],
        message: options[:message]
      }
      begin
        body = HTTPClient.get('http://http-api.smsmanager.cz/Send', options).body
      rescue StandardError => e
        raise Error.new(e.message)
      end
      raise SendingError.new(body) unless body =~ /^OK/
    end

    def send_message(options = {})
      send options
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
sms_manager-0.3.3 lib/sms_manager.rb
sms_manager-0.3.2 lib/sms_manager.rb
sms_manager-0.3.1 lib/sms_manager.rb
sms_manager-0.3.0 lib/sms_manager.rb