Class: Persistiq::Client

Inherits:
Object
  • Object
show all
Includes:
Campaign, Lead, User
Defined in:
lib/persistiq/client.rb,
lib/persistiq/resources/lead.rb,
lib/persistiq/resources/user.rb,
lib/persistiq/resources/campaign.rb

Defined Under Namespace

Modules: Campaign, Lead, User

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Campaign

#add_leads_to_campaign, #list_campaigns

Methods included from Lead

#create_lead, #get_lead, #list_leads

Methods included from User

#list_users

Constructor Details

#initialize(api_key, logger = true) ⇒ Client

Returns a new instance of Client.



14
15
16
17
# File 'lib/persistiq/client.rb', line 14

def initialize(api_key, logger = true)
  @api_key = api_key
  @logger  = logger
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



12
13
14
# File 'lib/persistiq/client.rb', line 12

def api_key
  @api_key
end

#loggerObject (readonly)

Returns the value of attribute logger.



12
13
14
# File 'lib/persistiq/client.rb', line 12

def logger
  @logger
end

Instance Method Details

#delete(path, options = {}) ⇒ Object



34
35
36
# File 'lib/persistiq/client.rb', line 34

def delete(path, options = {})
  connection.delete(path, options).body
end

#get(path, options = {}) ⇒ Object



19
20
21
# File 'lib/persistiq/client.rb', line 19

def get(path, options={})
  connection.get(path, options).body
end

#paginate(path) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/persistiq/client.rb', line 38

def paginate(path)
  results = []

  begin
    res = get(path)
    unless res.data.empty?
      results.push res.data
      page = res.next_page
      page.slice!('https://api.persistiq.com/v1/')
      path = page
    end
  end while res.has_more
  json = {has_more: false, data: results.flatten}
  Hashie::Mash.new json
end

#post(path, req_body) ⇒ Object



23
24
25
26
27
28
# File 'lib/persistiq/client.rb', line 23

def post(path, req_body)
  connection.post do |req|
    req.url(path)
    req.body = req_body
  end.body
end

#put(path, options = {}) ⇒ Object



30
31
32
# File 'lib/persistiq/client.rb', line 30

def put(path, options={})
  connection.put(path, options).body
end