Class: Pike13::CLI::Commands::Desk::Person

Inherits:
Base
  • Object
show all
Defined in:
lib/pike13/cli/commands/desk/person.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

format_options, handle_argument_error, printable_commands

Methods included from ThorNestedSubcommand

included

Class Method Details

.base_usageObject

Override the command name display to use “people” instead of “person”



9
10
11
# File 'lib/pike13/cli/commands/desk/person.rb', line 9

def self.base_usage
  "desk people"
end

Instance Method Details

#createObject



66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/pike13/cli/commands/desk/person.rb', line 66

def create
  handle_error do
    attributes = {
      first_name: options[:first_name],
      last_name: options[:last_name],
      email: options[:email]
    }
    attributes[:phone] = options[:phone] if options[:phone]

    result = Pike13::Desk::Person.create(attributes)
    output(result)
  end
end

#delete(id) ⇒ Object



100
101
102
103
104
105
# File 'lib/pike13/cli/commands/desk/person.rb', line 100

def delete(id)
  handle_error do
    Pike13::Desk::Person.destroy(id)
    success_message "Person #{id} deleted successfully"
  end
end

#get(id) ⇒ Object



34
35
36
37
38
39
# File 'lib/pike13/cli/commands/desk/person.rb', line 34

def get(id)
  handle_error do
    result = Pike13::Desk::Person.find(id)
    output(result)
  end
end

#listObject



22
23
24
25
26
27
28
29
30
# File 'lib/pike13/cli/commands/desk/person.rb', line 22

def list
  handle_error do
    params = build_person_params
    result = with_progress("Fetching people") do
      Pike13::Desk::Person.all(**params)
    end
    output(result)
  end
end

#meObject



53
54
55
56
57
58
# File 'lib/pike13/cli/commands/desk/person.rb', line 53

def me
  handle_error do
    result = Pike13::Desk::Person.me
    output(result)
  end
end

#search(query) ⇒ Object



44
45
46
47
48
49
# File 'lib/pike13/cli/commands/desk/person.rb', line 44

def search(query)
  handle_error do
    result = Pike13::Desk::Person.search(query, fields: options[:fields])
    output(result)
  end
end

#update(id) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/pike13/cli/commands/desk/person.rb', line 86

def update(id)
  handle_error do
    attributes = {}
    attributes[:first_name] = options[:first_name] if options[:first_name]
    attributes[:last_name] = options[:last_name] if options[:last_name]
    attributes[:email] = options[:email] if options[:email]
    attributes[:phone] = options[:phone] if options[:phone]

    result = Pike13::Desk::Person.update(id, attributes)
    output(result)
  end
end