class Knowtify::Client

Attributes

handler[RW]

Public Class Methods

new() click to toggle source

TODO: Refactor to separate classes for each method

# File lib/knowtify/client.rb, line 6
def initialize
  @handler = config.handler.new
end

Public Instance Methods

config() click to toggle source
# File lib/knowtify/client.rb, line 112
def config
  Knowtify.config
end
contacts_create_or_update(contacts=[],request_options={},api_key=nil) click to toggle source

POST /contacts/upsert Sends a request to create or update contacts with the supplied data. Example contacts: [

{
  "name":"John",
  "email":"john@test.com",
  "data":{
    "category":"sports",
    "followers":300
  }
},
{
  "name":"Samuel",
  "email":"sam@test.com",
  "data":{
    "category":"sports",
    "followers":32,
    "comments":54,
    "role":"Editor"
  }
}

]

# File lib/knowtify/client.rb, line 34
def contacts_create_or_update(contacts=[],request_options={},api_key=nil)
  options = {
    :path => "#{config.base_path}/contacts/upsert",
    :params => {:contacts => contacts},
    :request_options => request_options,
    :api_key => api_key
  }
  request = Knowtify::Request.new(options)
  handler.post(request)
end
Also aliased as: contacts_upsert
contacts_delete(contacts=[],http_request_options={},api_key=nil) click to toggle source

POST /contacts/delete Sends a request to delete contacts whose emails match those provided. Example contacts: [

"john@test.com",
"sam@test.com",
"sarah@test.com",
"mike@test.com",
"jill@test.com",
"ashley@test.com",
"frank@test.com",
"bill@test.com"

]

# File lib/knowtify/client.rb, line 60
def contacts_delete(contacts=[],http_request_options={},api_key=nil)
  options = {
    :path => "#{config.base_path}/contacts/delete",
    :params => {:contacts => contacts},
    :http_request_options => http_request_options,
    :api_key => api_key
  }
  request = Knowtify::Request.new(options)
  handler.post(request)
end
contacts_upsert(contacts=[],request_options={},api_key=nil)
global_edit(data={},http_request_options={},api_key=nil) click to toggle source

POST /data/edit Updates global data based on the data provided Example data: {

"users":890,
"comments":994,
"top_story_url":"test.com/story",
"top_story_title":"Article!"

}

# File lib/knowtify/client.rb, line 80
def global_edit(data={},http_request_options={},api_key=nil)
  options = {
    :path => "#{config.base_path}/data/edit",
    :params => {:data => data},
    :http_request_options => http_request_options,
    :api_key => api_key
  }
  request = Knowtify::Request.new(options)
  handler.post(request)
end
transactional_email(event, contacts=[],http_request_options={},api_key=nil) click to toggle source

POST contacts/upsert Sends a transaction email with the event and contacts provided {

"event":"purchase",
"contacts": [
  {
    "email":"dane@knowtify.io"
  }
]

}

# File lib/knowtify/client.rb, line 101
def transactional_email(event, contacts=[],http_request_options={},api_key=nil)
  options = {
    :path => "#{config.base_path}/data/edit",
    :params => {:data => contacts},
    :http_request_options => http_request_options,
    :api_key => api_key
  }
  request = Knowtify::Request.new(options)
  handler.post(request)
end