Class: Persistiq::Client
- Inherits:
-
Object
- Object
- Persistiq::Client
- Defined in:
- lib/persistiq/client.rb,
lib/persistiq/resources/lead.rb,
lib/persistiq/resources/user.rb,
lib/persistiq/resources/campaign.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
- #delete(path, options = {}) ⇒ Object
- #get(path, options = {}) ⇒ Object
-
#initialize(api_key, logger = true) ⇒ Client
constructor
A new instance of Client.
- #paginate(path) ⇒ Object
- #post(path, req_body) ⇒ Object
- #put(path, options = {}) ⇒ Object
Methods included from Campaign
#add_leads_to_campaign, #list_campaigns
Methods included from Lead
#create_lead, #get_lead, #list_leads
Methods included from User
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_key ⇒ Object (readonly)
Returns the value of attribute api_key.
12 13 14 |
# File 'lib/persistiq/client.rb', line 12 def api_key @api_key end |
#logger ⇒ Object (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, = {}) connection.delete(path, ).body end |
#get(path, options = {}) ⇒ Object
19 20 21 |
# File 'lib/persistiq/client.rb', line 19 def get(path, ={}) connection.get(path, ).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, ={}) connection.put(path, ).body end |