Class: Closeio::Client

Inherits:
Object
  • Object
show all
Includes:
Activity, BulkAction, Contact, CustomField, EmailTemplate, Lead, LeadStatus, Opportunity, OpportunityStatus, Organization, Report, SmartView, Task, User
Defined in:
lib/closeio/client.rb,
lib/closeio/resources/lead.rb,
lib/closeio/resources/task.rb,
lib/closeio/resources/user.rb,
lib/closeio/resources/report.rb,
lib/closeio/resources/contact.rb,
lib/closeio/resources/activity.rb,
lib/closeio/resources/smart_view.rb,
lib/closeio/resources/bulk_action.rb,
lib/closeio/resources/lead_status.rb,
lib/closeio/resources/opportunity.rb,
lib/closeio/resources/custom_field.rb,
lib/closeio/resources/organization.rb,
lib/closeio/resources/email_template.rb,
lib/closeio/resources/opportunity_status.rb

Defined Under Namespace

Modules: Activity, BulkAction, Contact, CustomField, EmailTemplate, Lead, LeadStatus, Opportunity, OpportunityStatus, Organization, Report, SmartView, Task, User

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from User

#find_user, #me

Methods included from Task

#create_task, #delete_task, #find_task, #list_tasks, #update_task

Methods included from SmartView

#create_smart_view, #delete_smart_view, #find_smart_view, #list_smart_views, #update_smart_view

Methods included from Report

#lead_status_report

Methods included from Organization

#find_organization, #update_organization

Methods included from OpportunityStatus

#create_opportunity_status, #delete_opportunity_status, #list_opportunity_statuses, #update_opportunity_status

Methods included from Opportunity

#create_opportunity, #delete_opportunity, #find_opportunity, #list_opportunities, #update_opportunity

Methods included from LeadStatus

#create_lead_status, #delete_lead_status, #list_lead_statuses, #update_lead_status

Methods included from Lead

#create_lead, #delete_lead, #find_lead, #list_leads, #merge_leads, #update_lead

Methods included from EmailTemplate

#create_email_template, #delete_email_template, #find_email_template, #list_email_templates, #render_email_templates, #update_email_template

Methods included from CustomField

#create_custom_field, #delete_custom_field, #find_custom_field, #list_custom_fields, #update_custom_field

Methods included from Contact

#create_contact, #delete_contact, #find_contact, #list_contacts, #update_contact

Methods included from BulkAction

#bulk_delete, #bulk_edit, #list_bulk_emails, #send_bulk_email

Methods included from Activity

#create_call, #create_email, #create_note, #delete_call, #delete_email, #delete_note, #list_activities, #list_emails, #list_notes, #update_email, #update_note

Constructor Details

#initialize(api_key, logger = true) ⇒ Client

Returns a new instance of Client.



25
26
27
28
# File 'lib/closeio/client.rb', line 25

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.



23
24
25
# File 'lib/closeio/client.rb', line 23

def api_key
  @api_key
end

#loggerObject (readonly)

Returns the value of attribute logger.



23
24
25
# File 'lib/closeio/client.rb', line 23

def logger
  @logger
end

Instance Method Details

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



45
46
47
# File 'lib/closeio/client.rb', line 45

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

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



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

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

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



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/closeio/client.rb', line 49

def paginate(path, options={})
  results = []
  skip    = 0

  begin
    res   = get(path, options.merge!(_skip: skip))
    unless res.data.empty?
      results.push res.data
      skip += res.data.count
    end
  end while res.has_more
  json = {has_more: false, total_results: res.total_results, data: results.flatten}
  Hashie::Mash.new json
end

#post(path, req_body) ⇒ Object



34
35
36
37
38
39
# File 'lib/closeio/client.rb', line 34

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

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



41
42
43
# File 'lib/closeio/client.rb', line 41

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