Class: Closeio::Client

Inherits:
Object
  • Object
show all
Includes:
Activity, BulkAction, Contact, CustomField, EmailTemplate, IntegrationLink, 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/integration_link.rb,
lib/closeio/resources/opportunity_status.rb

Defined Under Namespace

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from User

#fetch_api_key, #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

#activity_report, #lead_status_report, #sent_emails_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 IntegrationLink

#create_integration_link, #delete_integration_link, #find_integration_link, #list_integration_links, #update_integration_link

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, #find_email, #list_activities, #list_calls, #list_emails, #list_notes, #update_email, #update_note

Constructor Details

#initialize(api_key, logger = true, ca_file = nil, errors = false) ⇒ Client

Returns a new instance of Client.



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

def initialize(api_key, logger = true, ca_file = nil, errors = false)
  @api_key = api_key
  @logger  = logger
  @ca_file = ca_file
  @errors  = errors
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



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

def api_key
  @api_key
end

#ca_fileObject (readonly)

Returns the value of attribute ca_file.



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

def ca_file
  @ca_file
end

#errorsObject (readonly)

Returns the value of attribute errors.



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

def errors
  @errors
end

#loggerObject (readonly)

Returns the value of attribute logger.



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

def logger
  @logger
end

Instance Method Details

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



49
50
51
# File 'lib/closeio/client.rb', line 49

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

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



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

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

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



53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/closeio/client.rb', line 53

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

  begin
    res   = get(path, options.merge!(_skip: skip))
    unless res.data.nil? || 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



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

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

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



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

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