From ac7779427e3e7f76eeac1ba26135258c44cb2d3e Mon Sep 17 00:00:00 2001 From: Taylor Brooks Date: Wed, 15 Aug 2018 12:16:28 -0500 Subject: [PATCH] Rubocop changes --- Rakefile | 4 +-- closeio.gemspec | 27 ++++++++-------- lib/closeio/client.rb | 36 ++++++++++++--------- lib/closeio/error.rb | 2 +- lib/closeio/resources/activity.rb | 28 ++++++++-------- lib/closeio/resources/bulk_action.rb | 10 +++--- lib/closeio/resources/contact.rb | 8 ++--- lib/closeio/resources/custom_field.rb | 8 ++--- lib/closeio/resources/email_account.rb | 4 +-- lib/closeio/resources/email_template.rb | 7 ++-- lib/closeio/resources/event.rb | 4 +-- lib/closeio/resources/integration_link.rb | 8 ++--- lib/closeio/resources/lead.rb | 8 ++--- lib/closeio/resources/lead_status.rb | 10 +++--- lib/closeio/resources/opportunity.rb | 12 +++---- lib/closeio/resources/opportunity_status.rb | 10 +++--- lib/closeio/resources/organization.rb | 2 -- lib/closeio/resources/report.rb | 2 -- lib/closeio/resources/smart_view.rb | 10 +++--- lib/closeio/resources/task.rb | 12 +++---- lib/closeio/resources/user.rb | 5 ++- 21 files changed, 94 insertions(+), 123 deletions(-) diff --git a/Rakefile b/Rakefile index aa10917..5717f0c 100644 --- a/Rakefile +++ b/Rakefile @@ -1,8 +1,8 @@ -require "bundler/gem_tasks" +require 'bundler/gem_tasks' require 'rdoc/task' Rake::RDocTask.new do |rdoc| - version = File.exist?('VERSION') ? File.read('VERSION') : "" + version = File.exist?('VERSION') ? File.read('VERSION') : '' rdoc.rdoc_dir = 'rdoc' rdoc.title = "closeio #{version}" diff --git a/closeio.gemspec b/closeio.gemspec index d2f165f..6fa1b37 100644 --- a/closeio.gemspec +++ b/closeio.gemspec @@ -1,31 +1,30 @@ -# -*- encoding: utf-8 -*- -$:.push File.expand_path("../lib", __FILE__) -require "closeio/version" -require "base64" +$:.push File.expand_path('../lib', __FILE__) +require 'closeio/version' +require 'base64' Gem::Specification.new do |s| - s.name = "closeio" + s.name = 'closeio' s.version = Closeio::VERSION - s.authors = ["Taylor Brooks"] - s.email = ["dGJyb29rc0BnbWFpbC5jb20="].map{ |e| Base64.decode64(e) } - s.homepage = "https://github.com/taylorbrooks/closeio" - s.summary = %q{A Ruby wrapper for the CloseIO API} - s.description = %q{A Ruby wrapper for the CloseIO API -- a sales CRM built by salespeople, for salespeople.} - s.license = "MIT" + s.authors = ['Taylor Brooks'] + s.email = ['dGJyb29rc0BnbWFpbC5jb20='].map { |e| Base64.decode64(e) } + s.homepage = 'https://github.com/taylorbrooks/closeio' + s.summary = 'A Ruby wrapper for the CloseIO API' + s.description = 'A Ruby wrapper for the CloseIO API -- a sales CRM built by salespeople, for salespeople.' + s.license = 'MIT' s.files = `git ls-files`.split($/) - s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) } + s.executables = s.files.grep(%r{^bin/}).map { |f| File.basename(f) } s.test_files = s.files.grep(%r{^(test)/}) - s.require_paths = ["lib"] + s.require_paths = ['lib'] s.add_runtime_dependency 'faraday' s.add_runtime_dependency 'faraday_middleware' s.add_runtime_dependency 'json' s.add_development_dependency 'bundler' - s.add_development_dependency 'rake' s.add_development_dependency 'minitest' + s.add_development_dependency 'rake' s.add_development_dependency 'vcr' s.add_development_dependency 'webmock' end diff --git a/lib/closeio/client.rb b/lib/closeio/client.rb index aadfe93..b6d737c 100644 --- a/lib/closeio/client.rb +++ b/lib/closeio/client.rb @@ -1,9 +1,9 @@ require 'faraday' require 'faraday_middleware' -require_relative "error" -require_relative "version" +require_relative 'error' +require_relative 'version' -Dir[File.expand_path('../resources/*.rb', __FILE__)].each{|f| require f} +Dir[File.expand_path('../resources/*.rb', __FILE__)].each { |f| require f } module Closeio class Client @@ -35,7 +35,7 @@ def initialize(api_key, logger = true, ca_file = nil, errors = false, utc_offset @utc_offset = utc_offset end - def get(path, options={}) + def get(path, options = {}) connection.get(path, options).body end @@ -46,7 +46,7 @@ def post(path, req_body) end.body end - def put(path, options={}) + def put(path, options = {}) connection.put(path, options).body end @@ -54,7 +54,7 @@ def delete(path, options = {}) connection.delete(path, options).body end - def paginate(path, options={}) + def paginate(path, options = {}) results = [] skip = 0 @@ -65,27 +65,31 @@ def paginate(path, options={}) skip += res['data'].count end end while res['has_more'] - {has_more: false, total_results: res['total_results'], data: results.flatten} + { has_more: false, total_results: res['total_results'], data: results.flatten } end private def assemble_list_query(query, options) options[:query] = if query.respond_to? :map - query.map { |k,v| "#{k}:'#{v}'" }.join(' ') - else - query - end + query.map { |k, v| "#{k}:'#{v}'" }.join(' ') + else + query + end options end def connection - Faraday.new(url: "https://app.close.io/api/v1", headers: { - accept: 'application/json', - 'User-Agent' => "closeio-ruby-gem/v#{Closeio::VERSION}", - 'X-TZ-Offset' => utc_offset.to_s - }, ssl: { ca_file: ca_file}) do |conn| + Faraday.new( + url: 'https://app.close.io/api/v1', + headers: { + accept: 'application/json', + 'User-Agent' => "closeio-ruby-gem/v#{Closeio::VERSION}", + 'X-TZ-Offset' => utc_offset.to_s + }, + ssl: { ca_file: ca_file } + ) do |conn| conn.basic_auth api_key, '' conn.request :json conn.response :logger if logger diff --git a/lib/closeio/error.rb b/lib/closeio/error.rb index 90784f9..6057a07 100644 --- a/lib/closeio/error.rb +++ b/lib/closeio/error.rb @@ -5,7 +5,7 @@ class NotFound < Error; end class GatewayTimeout < Error; end end -require "faraday" +require 'faraday' module FaradayMiddleware class CloseioErrorHandler < Faraday::Response::Middleware ERROR_STATUSES = 400..600 diff --git a/lib/closeio/resources/activity.rb b/lib/closeio/resources/activity.rb index 3c144b1..3f15b3f 100644 --- a/lib/closeio/resources/activity.rb +++ b/lib/closeio/resources/activity.rb @@ -1,8 +1,7 @@ module Closeio class Client module Activity - - def list_activities(options={}) + def list_activities(options = {}) get(activity_path, options) end @@ -10,7 +9,7 @@ def list_activities(options={}) # Note Activities # - def list_notes(options={}) + def list_notes(options = {}) get(note_path, options) end @@ -22,7 +21,7 @@ def create_note(options) post(note_path, options) end - def update_note(id, options={}) + def update_note(id, options = {}) put("#{note_path}#{id}/", options) end @@ -34,7 +33,7 @@ def delete_note(id) # Email Activities # - def list_emails(options={}) + def list_emails(options = {}) get(email_path, options) end @@ -46,7 +45,7 @@ def create_email(body) post(email_path, body) end - def update_email(id, options={}) + def update_email(id, options = {}) put("#{email_path}#{id}/", options) end @@ -58,7 +57,7 @@ def delete_email(id) # EmailThread Activities # - def list_emailthreads(options={}) + def list_emailthreads(options = {}) get(emailthread_path, options) end @@ -74,11 +73,11 @@ def delete_emailthread(id) # Call Activities # - def list_calls(options={}) + def list_calls(options = {}) get(call_path, options) end - def create_call(options={}) + def create_call(options = {}) post(call_path, options) end @@ -89,25 +88,24 @@ def delete_call(id) private def activity_path - "activity/" + 'activity/' end def note_path - "activity/note/" + 'activity/note/' end def email_path - "activity/email/" + 'activity/email/' end def emailthread_path - "activity/emailthread/" + 'activity/emailthread/' end def call_path - "activity/call/" + 'activity/call/' end - end end end diff --git a/lib/closeio/resources/bulk_action.rb b/lib/closeio/resources/bulk_action.rb index d24afa7..16b0680 100644 --- a/lib/closeio/resources/bulk_action.rb +++ b/lib/closeio/resources/bulk_action.rb @@ -1,20 +1,19 @@ module Closeio class Client module BulkAction - def list_bulk_emails get(bulk_action_path) end - def send_bulk_email(options={}) + def send_bulk_email(options = {}) post("#{bulk_action_path}email/", options) end - def bulk_delete(options={}) + def bulk_delete(options = {}) post("#{bulk_action_path}delete/", options) end - def bulk_edit(options={}) + def bulk_edit(options = {}) # query: search query for the edit # type: # set_lead_status: lead_status_id @@ -26,9 +25,8 @@ def bulk_edit(options={}) private def bulk_action_path - "bulk_action/" + 'bulk_action/' end - end end end diff --git a/lib/closeio/resources/contact.rb b/lib/closeio/resources/contact.rb index 598da72..6058246 100644 --- a/lib/closeio/resources/contact.rb +++ b/lib/closeio/resources/contact.rb @@ -1,8 +1,7 @@ module Closeio class Client module Contact - - def list_contacts(params=nil) + def list_contacts(_params = nil) get(contact_path) end @@ -24,10 +23,9 @@ def delete_contact(id) private - def contact_path(id=nil) - id ? "contact/#{id}/" : "contact/" + def contact_path(id = nil) + id ? "contact/#{id}/" : 'contact/' end - end end end diff --git a/lib/closeio/resources/custom_field.rb b/lib/closeio/resources/custom_field.rb index 91188e8..85fb3aa 100644 --- a/lib/closeio/resources/custom_field.rb +++ b/lib/closeio/resources/custom_field.rb @@ -1,7 +1,6 @@ module Closeio class Client module CustomField - def list_custom_fields get(custom_field_path) end @@ -10,11 +9,11 @@ def find_custom_field(id) get("#{custom_field_path}#{id}/") end - def create_custom_field(options={}) + def create_custom_field(options = {}) post(custom_field_path, options) end - def update_custom_field(id, options={}) + def update_custom_field(id, options = {}) put("#{custom_field_path}#{id}/", options) end @@ -25,9 +24,8 @@ def delete_custom_field(id) private def custom_field_path - "custom_fields/lead/" + 'custom_fields/lead/' end - end end end diff --git a/lib/closeio/resources/email_account.rb b/lib/closeio/resources/email_account.rb index fbb003d..5c2348a 100644 --- a/lib/closeio/resources/email_account.rb +++ b/lib/closeio/resources/email_account.rb @@ -1,11 +1,9 @@ module Closeio class Client module EmailAccount - def list_email_accounts - get("email_account/") + get('email_account/') end - end end end diff --git a/lib/closeio/resources/email_template.rb b/lib/closeio/resources/email_template.rb index ed6ff37..068d6e1 100644 --- a/lib/closeio/resources/email_template.rb +++ b/lib/closeio/resources/email_template.rb @@ -1,7 +1,6 @@ module Closeio class Client module EmailTemplate - def list_email_templates(params = {}, paginate = false) if paginate paginate(email_template_path, params) @@ -22,11 +21,11 @@ def render_email_templates(id, params = {}, paginate = false) end end - def create_email_template(id, options={}) + def create_email_template(_id, options = {}) post(email_template_path, options) end - def update_email_template(id, options={}) + def update_email_template(id, options = {}) put("#{email_template_path}#{id}/", options) end @@ -37,7 +36,7 @@ def delete_email_template(id) private def email_template_path - "email_template/" + 'email_template/' end end end diff --git a/lib/closeio/resources/event.rb b/lib/closeio/resources/event.rb index 75f112d..fb95567 100644 --- a/lib/closeio/resources/event.rb +++ b/lib/closeio/resources/event.rb @@ -1,11 +1,9 @@ module Closeio class Client module Event - def list_events(options = {}) - get("event/", options) + get('event/', options) end - end end end diff --git a/lib/closeio/resources/integration_link.rb b/lib/closeio/resources/integration_link.rb index 2af7664..8d0564e 100644 --- a/lib/closeio/resources/integration_link.rb +++ b/lib/closeio/resources/integration_link.rb @@ -1,7 +1,6 @@ module Closeio class Client module IntegrationLink - def list_integration_links get(integration_link_path) end @@ -10,11 +9,11 @@ def find_integration_link(id) get("#{integration_link_path}#{id}/") end - def create_integration_link(options={}) + def create_integration_link(options = {}) post(integration_link_path, options) end - def update_integration_link(id, options={}) + def update_integration_link(id, options = {}) put("#{integration_link_path}#{id}/", options) end @@ -25,9 +24,8 @@ def delete_integration_link(id) private def integration_link_path - "integration_link/" + 'integration_link/' end - end end end diff --git a/lib/closeio/resources/lead.rb b/lib/closeio/resources/lead.rb index b8b3471..80622f0 100644 --- a/lib/closeio/resources/lead.rb +++ b/lib/closeio/resources/lead.rb @@ -1,7 +1,6 @@ module Closeio class Client module Lead - def list_leads(query = {}, paginate = false, fields = nil, options = {}) options[:_fields] = fields if fields params = assemble_list_query query, options @@ -30,15 +29,14 @@ def delete_lead(id) end def merge_leads(id_source, id_destination) - post('lead/merge/', { source: id_source, destination: id_destination }) + post('lead/merge/', source: id_source, destination: id_destination) end private - def lead_path(id=nil) - id ? "lead/#{id}/" : "lead/" + def lead_path(id = nil) + id ? "lead/#{id}/" : 'lead/' end - end end end diff --git a/lib/closeio/resources/lead_status.rb b/lib/closeio/resources/lead_status.rb index 1a21743..9339172 100644 --- a/lib/closeio/resources/lead_status.rb +++ b/lib/closeio/resources/lead_status.rb @@ -1,16 +1,15 @@ module Closeio class Client module LeadStatus - def list_lead_statuses get(lead_status_path) end - def create_lead_status(options={}) + def create_lead_status(options = {}) post(lead_status_path, options) end - def update_lead_status(id, options={}) + def update_lead_status(id, options = {}) put(lead_status_path(id), options) end @@ -20,10 +19,9 @@ def delete_lead_status(id) private - def lead_status_path(id=nil) - id ? "status/lead/#{id}/" : "status/lead/" + def lead_status_path(id = nil) + id ? "status/lead/#{id}/" : 'status/lead/' end - end end end diff --git a/lib/closeio/resources/opportunity.rb b/lib/closeio/resources/opportunity.rb index c840e92..feff729 100644 --- a/lib/closeio/resources/opportunity.rb +++ b/lib/closeio/resources/opportunity.rb @@ -1,8 +1,7 @@ module Closeio class Client module Opportunity - - def list_opportunities(options={}, paginate = false) + def list_opportunities(options = {}, paginate = false) if paginate paginate(opportunity_path, options) else @@ -14,11 +13,11 @@ def find_opportunity(id) get(opportunity_path(id)) end - def create_opportunity(options={}) + def create_opportunity(options = {}) post(opportunity_path, options) end - def update_opportunity(id, options={}) + def update_opportunity(id, options = {}) put(opportunity_path(id), options) end @@ -28,10 +27,9 @@ def delete_opportunity(id) private - def opportunity_path(id=nil) - id ? "opportunity/#{id}/" : "opportunity/" + def opportunity_path(id = nil) + id ? "opportunity/#{id}/" : 'opportunity/' end - end end end diff --git a/lib/closeio/resources/opportunity_status.rb b/lib/closeio/resources/opportunity_status.rb index 63d28e4..9ea5dd1 100644 --- a/lib/closeio/resources/opportunity_status.rb +++ b/lib/closeio/resources/opportunity_status.rb @@ -1,16 +1,15 @@ module Closeio class Client module OpportunityStatus - def list_opportunity_statuses get(opportunity_status_path) end - def create_opportunity_status(options={}) + def create_opportunity_status(options = {}) post(opportunity_status_path, options) end - def update_opportunity_status(id, options={}) + def update_opportunity_status(id, options = {}) put(opportunity_status_path(id), options) end @@ -20,10 +19,9 @@ def delete_opportunity_status(id) private - def opportunity_status_path(id=nil) - id ? "status/opportunity/#{id}/" : "status/opportunity/" + def opportunity_status_path(id = nil) + id ? "status/opportunity/#{id}/" : 'status/opportunity/' end - end end end diff --git a/lib/closeio/resources/organization.rb b/lib/closeio/resources/organization.rb index 2a76150..9c12383 100644 --- a/lib/closeio/resources/organization.rb +++ b/lib/closeio/resources/organization.rb @@ -1,7 +1,6 @@ module Closeio class Client module Organization - def find_organization(id) get("organization/#{id}/") end @@ -9,7 +8,6 @@ def find_organization(id) def update_organization(id, options = {}) put("organization/#{id}/", options) end - end end end diff --git a/lib/closeio/resources/report.rb b/lib/closeio/resources/report.rb index 6cd34b6..12d31c6 100644 --- a/lib/closeio/resources/report.rb +++ b/lib/closeio/resources/report.rb @@ -1,7 +1,6 @@ module Closeio class Client module Report - # OPTIONS [date_start, date_end, user_id] def activity_report(organization_id, options = {}) get("report/activity/#{organization_id}/?", options) @@ -16,7 +15,6 @@ def lead_status_report(organization_id, options = {}) def sent_emails_report(organization_id, options = {}) get("report/sent_emails/#{organization_id}/", options) end - end end end diff --git a/lib/closeio/resources/smart_view.rb b/lib/closeio/resources/smart_view.rb index d44da53..4a0e083 100644 --- a/lib/closeio/resources/smart_view.rb +++ b/lib/closeio/resources/smart_view.rb @@ -1,7 +1,6 @@ module Closeio class Client module SmartView - def list_smart_views get(smart_view_path) end @@ -10,11 +9,11 @@ def find_smart_view(id) get(smart_view_path(id)) end - def create_smart_view(options={}) + def create_smart_view(options = {}) post(smart_view_path, options) end - def update_smart_view(id, options={}) + def update_smart_view(id, options = {}) put(smart_view_path(id), options) end @@ -24,10 +23,9 @@ def delete_smart_view(id) private - def smart_view_path(id=nil) - id ? "saved_search/#{id}/" : "saved_search/" + def smart_view_path(id = nil) + id ? "saved_search/#{id}/" : 'saved_search/' end - end end end diff --git a/lib/closeio/resources/task.rb b/lib/closeio/resources/task.rb index 1c08bf2..cffc0a9 100644 --- a/lib/closeio/resources/task.rb +++ b/lib/closeio/resources/task.rb @@ -1,8 +1,7 @@ module Closeio class Client module Task - - def list_tasks(options={}) + def list_tasks(options = {}) get(task_path, options) end @@ -10,11 +9,11 @@ def find_task(id) get(task_path(id)) end - def create_task(options={}) + def create_task(options = {}) post(task_path, options) end - def update_task(id, options={}) + def update_task(id, options = {}) put(task_path(id), options) end @@ -24,10 +23,9 @@ def delete_task(id) private - def task_path(id=nil) - id ? "task/#{id}/" : "task/" + def task_path(id = nil) + id ? "task/#{id}/" : 'task/' end - end end end diff --git a/lib/closeio/resources/user.rb b/lib/closeio/resources/user.rb index 887a08a..1c05f0c 100644 --- a/lib/closeio/resources/user.rb +++ b/lib/closeio/resources/user.rb @@ -1,9 +1,8 @@ module Closeio class Client module User - def list_users - get("user/") + get('user/') end def find_user(id) @@ -11,7 +10,7 @@ def find_user(id) end def me - get("me/") + get('me/') end def fetch_api_key