Class: FentonShell::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/fenton_shell/client.rb

Overview

Interfaces with the client api on fenton server

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#messageString

Returns success or failure message and why.

Returns:

  • (String)

    success or failure message and why



6
7
8
# File 'lib/fenton_shell/client.rb', line 6

def message
  @message
end

Instance Method Details

#create(global_options, options) ⇒ String

Creates a new client on fenton server by sending a post request with json from the command line to create the client

Parameters:

  • global_options (Hash)

    global command line options

  • options (Hash)

    json fields to send to fenton server

Returns:

  • (String)

    success or failure message



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/fenton_shell/client.rb', line 15

def create(global_options, options)
  status, body = client_create(global_options, options)

  if status == 201
    save_message('Client': ['created!'])
    true
  else
    save_message(body)
    false
  end
end

#create_with_organization(global_options, options) ⇒ String

Calls create new client then creates an organization for that client via a post request with json from the command line

Parameters:

  • global_options (Hash)

    global command line options

  • options (Hash)

    json fields to send to fenton server

Returns:

  • (String)

    success or failure message



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/fenton_shell/client.rb', line 34

def create_with_organization(global_options, options)
  create(global_options, options)

  if Organization.new.create(global_options, name: options[:username],
                                             key: options[:username])
    save_message('Organization': ['created!'])
    true
  else
    save_message('Organization': ['not created!'])
    false
  end
end