Module: Neighborparrot

Included in:
ESParrot
Defined in:
lib/neighborparrot.rb,
lib/neighborparrot/send.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.configurationObject

Return settings



16
17
18
# File 'lib/neighborparrot.rb', line 16

def self.configuration
  @@config
end

.configure(params = {}) ⇒ Object

Setup the configuration options

  • :api_id => Your api ID in neighborparrot.com

  • :api_key => Your api key

  • :server => Server to connect (Only for development)



11
12
13
# File 'lib/neighborparrot.rb', line 11

def self.configure(params={})
  @@config.merge! params
end

.send(params = {}) ⇒ Boolean

Post a message to a channel Raise exception if channel is not setted If empty data, refuse to send nothing

  • :api_id => Your api ID in neighborparrot.com

  • :api_key => Your api key

  • :server => Server to connect (Only for development)

  • :channel => The channel name

  • :data => Your payload

Parameters:

  • params (Hash) (defaults to: {})

Returns:

  • (Boolean)

    true if sended



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/neighborparrot/send.rb', line 13

def self.send(params={})
  params = self.configuration.merge params
  self.check_params params
  return false if params[:data].nil? || params[:data].length == 0

  uri = URI(params[:server])
  Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
    request = Net::HTTP::Post.new('/send')
    request.set_form_data(params)
    response = http.request(request)
    return true if response.body == "Ok"
  end
end

Instance Method Details

#post(channel, data, params = {}) ⇒ Object



27
28
29
# File 'lib/neighborparrot/send.rb', line 27

def post(channel, data, params={})
  Neighborparrot.post(channel, data, params)
end