Class: Wiq::Commands::Prospects

Inherits:
Base
  • Object
show all
Defined in:
lib/wiq/commands/prospects.rb

Constant Summary collapse

STAGES =
%w[inquiry trial_scheduled trialing trial_complete converted didnt_join archived].freeze
ATTENTION_MODES =
%w[needs_attention handled].freeze

Instance Method Summary collapse

Methods inherited from Base

exit_on_failure?

Instance Method Details

#listObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/wiq/commands/prospects.rb', line 52

def list
  params = { "per_page" => 50 }
  if options[:query]
    params["query"] = options[:query]
  else
    params["attention_mode"] = options[:attention] if options[:attention]
    params["stage"] = options[:stage] if options[:stage]
    if options[:assigned_to_me]
      params["assigned_to"] = "me"
    elsif options[:assigned_coach]
      params["assigned_coach_id"] = options[:assigned_coach]
    end
  end

  records, total = fetch_index("/api/v1/prospects", params, key: "prospects")
  render_index(records, total: total,
                        summary: "Listed #{records.size} prospects.",
                        breadcrumbs: breadcrumbs)
end

#show(id) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
# File 'lib/wiq/commands/prospects.rb', line 83

def show(id)
  prospect = client.get("/api/v1/prospects/#{id}")
  render(prospect,
         summary: "Prospect #{prospect["id"]}#{prospect["child_first_name"]} #{prospect["child_last_name"]} (stage=#{prospect["stage"]}).",
         breadcrumbs: [
           { "cmd" => "wiq prospect_families show #{prospect["prospect_family_id"]}",
             "description" => "Family this prospect belongs to" },
           { "cmd" => "wiq prospect_families notes #{prospect["prospect_family_id"]}",
             "description" => "Contact log for the family" }
         ])
end

#summaryObject



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/wiq/commands/prospects.rb', line 119

def summary
  params = {}
  if options[:start_date] && options[:end_date]
    params["start_date"] = options[:start_date]
    params["end_date"] = options[:end_date]
  elsif options[:start_date] || options[:end_date]
    raise Wiq::Error.new("--start-date and --end-date must be passed together.",
                         code: "missing_cohort_dates")
  end
  params["conversion_days"] = options[:conversion_days] if options[:conversion_days]

  data = client.get("/api/v1/prospects/summary", params)
  render(data,
         summary: "Prospect pipeline: #{data["needs_action_count"]} need action, " \
                  "#{data["active_trials_count"]} active trials, " \
                  "conversion=#{data["conversion_rate"]}%.",
         breadcrumbs: [
           { "cmd" => "wiq prospects list --attention needs_attention",
             "description" => "Drill into leads needing action" },
           { "cmd" => "wiq prospect_families list --sort oldest_followup",
             "description" => "Queue of families ordered by stalest follow-up" }
         ])
end