Class: Pigeon::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/pigeon-ruby/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Client

Returns a new instance of Client.



10
11
12
13
14
15
16
17
18
# File 'lib/pigeon-ruby/client.rb', line 10

def initialize(config)
  @config = config

  self.class.base_uri(config.base_uri || 'https://api.pigeonapp.io/v1')
  self.class.headers({
    'X-Public-Key' => config.public_key,
    'X-Private-Key' => config.private_key
  })
end

Instance Method Details

#add_contact(customer_id, attrs = {}) ⇒ Object



40
41
42
43
44
# File 'lib/pigeon-ruby/client.rb', line 40

def add_contact(customer_id, attrs = {})
  send_request(:post, '/contacts', {
    body: process_contact_attributes(customer_id, attrs)
  })
end

#deliver(message_identifier, attrs) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/pigeon-ruby/client.rb', line 20

def deliver(message_identifier, attrs)
  send_request(:post, '/deliveries', {
    body: process_delivery_attributes(attrs).merge({
      message_identifier: message_identifier
    })
  })
end

#generate_token(customer_id) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/pigeon-ruby/client.rb', line 46

def generate_token(customer_id)
  cipher = OpenSSL::Cipher::AES256.new :CBC
  cipher.encrypt
  cipher.key = OpenSSL::Digest::SHA256.digest @config.private_key
  encrypted = cipher.update(customer_id.to_s) + cipher.final
  Base64.urlsafe_encode64(encrypted)
end

#identify(attrs = {}) ⇒ Object



34
35
36
37
38
# File 'lib/pigeon-ruby/client.rb', line 34

def identify(attrs = {})
  send_request(:post, '/customers', {
    body: process_identify_attributes(attrs)
  })
end

#track(attrs = {}) ⇒ Object



28
29
30
31
32
# File 'lib/pigeon-ruby/client.rb', line 28

def track(attrs = {})
  send_request(:post, '/event_logs', {
    body: process_track_attributes(attrs)
  })
end