Class: Ralph::CLI::Commands::Post

Inherits:
Base
  • Object
show all
Defined in:
lib/ralph/cli/commands/post.rb

Class Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#gen_client

Class Attribute Details

.pathObject

Returns the value of attribute path.



4
5
6
# File 'lib/ralph/cli/commands/post.rb', line 4

def path
  @path
end

.required_parametersObject

Returns the value of attribute required_parameters.



5
6
7
# File 'lib/ralph/cli/commands/post.rb', line 5

def required_parameters
  @required_parameters
end

Instance Method Details

#call(**options) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/ralph/cli/commands/post.rb', line 22

def call(**options)
  client = gen_client

  if file = options[:file]
    json = File.open(file) {|io| JSON.load(io.read) }
    [json].flatten.each do |item|
      puts JSON.dump(client.post(path, item).body)
    end
  else
    required_parameters&.each do |p|
      if options[p].nil?
        puts "Error: #{p} is required."
        exit 1
      end
    end
    puts JSON.dump(client.post(path, options).body)
  end
end

#pathObject



7
8
9
# File 'lib/ralph/cli/commands/post.rb', line 7

def path
  self.class.path
end

#path=(v) ⇒ Object



10
11
12
# File 'lib/ralph/cli/commands/post.rb', line 10

def path=(v)
  self.class.path = v
end

#required_parametersObject



14
15
16
# File 'lib/ralph/cli/commands/post.rb', line 14

def required_parameters
  self.class.required_parameters
end

#required_parameters=(v) ⇒ Object



18
19
20
# File 'lib/ralph/cli/commands/post.rb', line 18

def required_parameters=(v)
  self.class.required_parameters = v
end