Sha256: 829b8b5e54af1f874328e45026611b1f50e81f566ff5b898a5fc290798f562c6

Contents?: true

Size: 1.17 KB

Versions: 10

Compression:

Stored size: 1.17 KB

Contents

module Moonshado
  class Sender
    attr_reader :host, :port, :secure, :http_open_timeout, :http_read_timeout, :protocol, :api_key

    def initialize(options = {})
      [:protocol, :host, :port, :secure, :http_open_timeout, :http_read_timeout, :api_key].each do |option|
        instance_variable_set("@#{option}", options[option])
      end
    end

    def send_to_moonshado(data, uri)
      http  = RestClient::Resource.new(
                url(uri),
                :user => api_key,
                :timeout => http_read_timeout,
                :open_timeout => http_open_timeout
              )

      response = http.post(data)
    end

    def get(uri)
      http  = RestClient::Resource.new(
                url(uri),
                :user => api_key,
                :timeout => http_read_timeout,
                :open_timeout => http_open_timeout
              )

      response = http.get
    end

    private
      def url(uri = "")
        URI.parse("#{protocol}://#{host}:#{port}").merge(uri).to_s
      end

      def configuration
        Moonshado::Sms.configuration
      end

      def production_environment?
        configuration.production_environment
      end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
moonshado-sms-1.1.1 lib/moonshado/sender.rb
moonshado-sms-1.1.1.rc2 lib/moonshado/sender.rb
moonshado-sms-1.1.1.rc1 lib/moonshado/sender.rb
moonshado-sms-1.1.0 lib/moonshado/sender.rb
moonshado-sms-1.1.0.rc1 lib/moonshado/sender.rb
moonshado-sms-1.0.1 lib/moonshado/sender.rb
moonshado-sms-1.0.0 lib/moonshado/sender.rb
moonshado-sms-0.5.0 lib/moonshado/sender.rb
moonshado-sms-0.4.1 lib/moonshado/sender.rb
moonshado-sms-0.4.0 lib/moonshado/sender.rb