Class: WireIO::Client

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

Constant Summary collapse

API_VERSION =
'v1'

Instance Method Summary collapse

Constructor Details

#initialize(public_key, private_key) ⇒ Client

Returns a new instance of Client.



10
11
12
13
14
15
# File 'lib/wireio.rb', line 10

def initialize(public_key, private_key)
  @public_key, @private_key = public_key.downcase, private_key.downcase
  @base_uri     = 'https://app.getwire.io'
  @api_endpoint = "api/#{API_VERSION}/events"
  @action       = "fire.json"
end

Instance Method Details

#on(event_name, payload) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/wireio.rb', line 17

def on(event_name, payload)
  RestClient.post(construct_endpoint_for(event_name), 
    JSON.dump({
      :payload => payload, 
      :auth_hash =>  generate_auth_hash_for(@api_endpoint, payload)
    }), 
    :content_type => :json) { |response, _request, _result|
      case response.code
      when 200
        true
      else
        false
      end
    }
end