Class: Connectwise::BaseAPI
- Inherits:
-
Object
- Object
- Connectwise::BaseAPI
- Defined in:
- lib/connectwise/connectwise.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
Instance Method Summary collapse
- #create_company(company, &err_handler) ⇒ Object
-
#create_contact(contact, company_id = nil, &err_handler) ⇒ Object
Contact.
-
#create_opportunity(opportunity, company_id, contact_id, &err_handler) ⇒ Object
Opportunity.
- #create_ticket(ticket, company, &err_handler) ⇒ Object
- #delete_company(company, &err_handler) ⇒ Object
- #delete_contact(contact, &err_handler) ⇒ Object
- #delete_opportunity(opportunity, &err_handler) ⇒ Object
-
#find_company(company, &err_handler) ⇒ Object
Companies.
-
#find_member(user, &err_handler) ⇒ Object
Members.
-
#find_ticket(ticket, company) ⇒ Object
Ticket TODO - these find methods are too limited, need to allow proper query.
-
#initialize(connection) ⇒ BaseAPI
constructor
A new instance of BaseAPI.
Constructor Details
#initialize(connection) ⇒ BaseAPI
Returns a new instance of BaseAPI.
105 106 107 |
# File 'lib/connectwise/connectwise.rb', line 105 def initialize(connection) @connection = connection end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
104 105 106 |
# File 'lib/connectwise/connectwise.rb', line 104 def connection @connection end |
Instance Method Details
#create_company(company, &err_handler) ⇒ Object
137 138 139 140 141 142 143 144 145 146 |
# File 'lib/connectwise/connectwise.rb', line 137 def create_company(company, &err_handler) = { Id: 0, CompanyName: company.name, CompanyID: company.id.to_s, WebSite: company.url, Status: 'Active', } connection.call 'CompanyApi', :add_company, {company: }, &err_handler end |
#create_contact(contact, company_id = nil, &err_handler) ⇒ Object
Contact
116 117 118 119 120 121 122 123 124 125 |
# File 'lib/connectwise/connectwise.rb', line 116 def create_contact(contact, company_id=nil, &err_handler) = { FirstName: contact.first_name, LastName: contact.last_name, Email: contact.email, Phone: contact.phone, } = .merge(CompanyId: company_id) if company_id connection.call 'ContactApi', :add_or_update_contact, {contact: }, &err_handler end |
#create_opportunity(opportunity, company_id, contact_id, &err_handler) ⇒ Object
Opportunity
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/connectwise/connectwise.rb', line 153 def create_opportunity(opportunity, company_id, contact_id, &err_handler) = { Id: 0, OpportunityName: "Opportunity from Easyofficephone - #{opportunity.company.name}", Company: {CompanyID: company_id}, Contact: {Id: contact_id}, Source: 'Easy Office Phone opportunity', PrimarySalesRep: opportunity.user.full_name, Notes: { Note: { note_text: opportunity.note, } }, } connection.call 'OpportunityApi', :add_opportunity, {opportunity: }, &err_handler end |
#create_ticket(ticket, company, &err_handler) ⇒ Object
182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/connectwise/connectwise.rb', line 182 def create_ticket(ticket, company, &err_handler) resp = connection.call 'ServiceTicketApi', :add_service_ticket_via_company_id, { serviceTicket: { Id: 0, CompanyId: company.id, Summary: ticket.subject, Status: 'N', ProblemDescription: ticket.description, } }, &err_handler end |
#delete_company(company, &err_handler) ⇒ Object
148 149 150 |
# File 'lib/connectwise/connectwise.rb', line 148 def delete_company(company, &err_handler) connection.call 'CompanyApi', :delete_company, {id: company.id}, &err_handler end |
#delete_contact(contact, &err_handler) ⇒ Object
127 128 129 |
# File 'lib/connectwise/connectwise.rb', line 127 def delete_contact(contact, &err_handler) connection.call 'ContactApi', :delete_contact, {id: contact.id}, &err_handler end |
#delete_opportunity(opportunity, &err_handler) ⇒ Object
171 172 173 |
# File 'lib/connectwise/connectwise.rb', line 171 def delete_opportunity(opportunity, &err_handler) connection.call 'OpportunityApi', :delete_opportunity, {id: opportunity.id}, &err_handler end |
#find_company(company, &err_handler) ⇒ Object
Companies
132 133 134 135 |
# File 'lib/connectwise/connectwise.rb', line 132 def find_company(company, &err_handler) resp = connection.call 'CompanyApi', :find_companies, { conditions: "CompanyName like '%#{company.name}%' or CompanyID = '#{company.id}'" }, &err_handler (result = resp[:company_find_result]) ? Array(result) : resp end |
#find_member(user, &err_handler) ⇒ Object
Members
110 111 112 113 |
# File 'lib/connectwise/connectwise.rb', line 110 def find_member(user, &err_handler) resp = connection.call 'MemberApi', :find_members, {conditions: "EmailAddress like '#{user.email}'"}, &err_handler (result = resp[:member_find_result]) ? Array(result) : resp end |
#find_ticket(ticket, company) ⇒ Object
Ticket TODO - these find methods are too limited, need to allow proper query
177 178 179 180 |
# File 'lib/connectwise/connectwise.rb', line 177 def find_ticket(ticket, company) resp = connection.call 'ServiceTicketApi', :find_service_tickets, {conditions: "CompanyName like '%#{company.name}%' or SRServiceRecID = '#{ticket.id}'"} (result = resp[:tickets]) ? Array(result) : resp end |