Class: Moonshado::Sender

Inherits:
Object
  • Object
show all
Defined in:
lib/moonshado/sender.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Sender

Returns a new instance of Sender.



5
6
7
8
9
# File 'lib/moonshado/sender.rb', line 5

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

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



3
4
5
# File 'lib/moonshado/sender.rb', line 3

def api_key
  @api_key
end

#hostObject (readonly)

Returns the value of attribute host.



3
4
5
# File 'lib/moonshado/sender.rb', line 3

def host
  @host
end

#http_open_timeoutObject (readonly)

Returns the value of attribute http_open_timeout.



3
4
5
# File 'lib/moonshado/sender.rb', line 3

def http_open_timeout
  @http_open_timeout
end

#http_read_timeoutObject (readonly)

Returns the value of attribute http_read_timeout.



3
4
5
# File 'lib/moonshado/sender.rb', line 3

def http_read_timeout
  @http_read_timeout
end

#portObject (readonly)

Returns the value of attribute port.



3
4
5
# File 'lib/moonshado/sender.rb', line 3

def port
  @port
end

#protocolObject (readonly)

Returns the value of attribute protocol.



3
4
5
# File 'lib/moonshado/sender.rb', line 3

def protocol
  @protocol
end

#secureObject (readonly)

Returns the value of attribute secure.



3
4
5
# File 'lib/moonshado/sender.rb', line 3

def secure
  @secure
end

Instance Method Details

#get(uri) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/moonshado/sender.rb', line 22

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

#send_to_moonshado(data, uri) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/moonshado/sender.rb', line 11

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