Class: Klimt::Commands::Partner

Inherits:
Thor
  • Object
show all
Includes:
Rendering
Defined in:
lib/klimt/commands/partner.rb

Constant Summary collapse

CHECK =
"\u2705".freeze
CROSS =
"\u274C".freeze
RADIUS =
'75km'.freeze

Instance Method Summary collapse

Methods included from Rendering

#jq_installed?, #render, #render_pretty, #render_with_jq

Instance Method Details

#check_locations(partner_id) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/klimt/commands/partner.rb', line 37

def check_locations(partner_id)
  coords = options.values_at :y, :x
  if coords.any? && !coords.all?
    $stderr.puts 'Must provide both X and Y'
    exit 1
  end
  point = coords.all? ? coords.join(',') : nil
  client = GravityClient.new(env: options[:env])
  response = client.find(type: 'partner', id: partner_id)
  partner = JSON.parse(response)

  # subscriber or institution ?
  if institution?(partner)
    puts "#{CHECK}  Institution"
  elsif gallery?(partner) && current_subscriber?(partner)
    puts "#{CHECK}  Gallery with current subscription"
  else
    puts "#{CROSS}  Neither Institution nor current subscriber Gallery"
    exit 1
  end

  # pubished locations?
  public_count = published_locations_count(partner)
  if public_count.zero?
    puts "#{CROSS}  No publicly viewable locations"
    exit 1
  else
    puts "#{CHECK}  #{public_count} publicly viewable locations"
  end

  return if point.nil?
  # close enough to desired coords?
  near_count = published_locations_count(partner, point: point)
  if near_count.zero?
    puts "#{CROSS}  No publicly viewable locations within #{RADIUS} of #{point}"
    report_distances(partner, point: point)
    exit 1
  else
    puts "#{CHECK}  #{near_count} publicly viewable locations within #{RADIUS} of #{point}"
  end
end

#locations(partner_id, *params) ⇒ Object



14
15
16
17
18
19
# File 'lib/klimt/commands/partner.rb', line 14

def locations(partner_id, *params)
  params << 'private=true' if options[:private]
  client = GravityClient.new(env: options[:env])
  response = client.partner_locations(id: partner_id, params: params)
  render response
end

#near(*params) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/klimt/commands/partner.rb', line 26

def near(*params)
  params << "near=#{options[:y]},#{options[:x]}"
  params << 'eligible_for_listing=true' if options[:eligible]
  client = GravityClient.new(env: options[:env])
  response = client.partner_near(params: params)
  render response
end