Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unqualified_reason_id to leads service #66

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/basecrm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
require 'basecrm/models/associated_contact'
require 'basecrm/models/call'
require 'basecrm/models/call_outcome'
require 'basecrm/models/choice'
require 'basecrm/models/contact'
require 'basecrm/models/deal'
require 'basecrm/models/deal_source'
require 'basecrm/models/deal_unqualified_reason'
require 'basecrm/models/lead'
require 'basecrm/models/lead_custom_field'
require 'basecrm/models/lead_source'
require 'basecrm/models/lead_unqualified_reason'
require 'basecrm/models/line_item'
Expand Down Expand Up @@ -52,6 +54,7 @@
require 'basecrm/services/deal_sources_service'
require 'basecrm/services/deal_unqualified_reasons_service'
require 'basecrm/services/leads_service'
require 'basecrm/services/lead_custom_fields_service'
require 'basecrm/services/lead_sources_service'
require 'basecrm/services/lead_unqualified_reasons_service'
require 'basecrm/services/line_items_service'
Expand Down Expand Up @@ -181,6 +184,15 @@ def leads
@leads ||= LeadsService.new(@http_client)
end

# Access all LeadCustomField related actions.
# @see LeadCustomFieldsService
# @see LeadCustomField
#
# @return [LeadCustomFieldsService] Service object for resources.
def lead_custom_fields
@lead_custom_fields ||= LeadCustomFieldsService.new(@http_client)
end

# Access all LeadSources related actions.
# @see LeadSourcesService
# @see LeadSource
Expand Down
5 changes: 5 additions & 0 deletions lib/basecrm/models/choice.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module BaseCRM
class Choice < Model
end
end

4 changes: 4 additions & 0 deletions lib/basecrm/models/lead_custom_field.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module BaseCRM
class LeadCustomField < Model
end
end
26 changes: 26 additions & 0 deletions lib/basecrm/services/lead_custom_fields_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module BaseCRM
class LeadCustomFieldsService
def initialize(client)
@client = client
end

# Retrieve all lead custom fields
#
# get '/lead/custom_fields'
#
# If you want to use filtering or sorting (see #where).
# @return [Enumerable] Paginated resource you can use to iterate over all the resources.
def all
_, _, root = @client.get("/lead/custom_fields")
root[:items].map do |item|
LeadCustomField.new(item[:data]).tap do |custom_field|
if item[:data][:choices]
custom_field.choices = item[:data][:choices].map do |choice|
Choice.new(choice)
end
end
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/basecrm/services/leads_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module BaseCRM
class LeadsService
OPTS_KEYS_TO_PERSIST = Set[:address, :custom_fields, :description, :email, :facebook, :fax, :first_name, :industry, :last_name, :linkedin, :mobile, :organization_name, :owner_id, :phone, :skype, :source_id, :status, :tags, :title, :twitter, :website]
OPTS_KEYS_TO_PERSIST = Set[:address, :custom_fields, :description, :email, :facebook, :fax, :first_name, :industry, :last_name, :linkedin, :mobile, :organization_name, :owner_id, :phone, :skype, :source_id, :status, :tags, :title, :twitter, :website, :unqualified_reason_id]

def initialize(client)
@client = client
Expand Down
16 changes: 16 additions & 0 deletions spec/services/lead_custom_fields_service_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require 'spec_helper'

describe BaseCRM::LeadCustomFieldsService do
describe 'Responds to' do
subject { client.lead_custom_fields }

it { should respond_to :all }
end

describe :all do
it "returns an array" do
expect(client.lead_custom_fields.all).to be_an Array
end
end
end