Class: LearnWeb::Client::SshKeys::Add

Inherits:
Object
  • Object
show all
Includes:
AttributePopulatable
Defined in:
lib/learn_web/client/ssh_keys/add.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AttributePopulatable

included

Constructor Details

#initialize(response) ⇒ Add

Returns a new instance of Add.



10
11
12
# File 'lib/learn_web/client/ssh_keys/add.rb', line 10

def initialize(response)
  @response = response
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



6
7
8
# File 'lib/learn_web/client/ssh_keys/add.rb', line 6

def data
  @data
end

#responseObject (readonly)

Returns the value of attribute response.



5
6
7
# File 'lib/learn_web/client/ssh_keys/add.rb', line 5

def response
  @response
end

Instance Method Details

#parse!Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/learn_web/client/ssh_keys/add.rb', line 14

def parse!
  if response.status == 200
    self.data = Oj.load(response.body, symbol_keys: true)

    populate_attributes!
    self
  else
    case response.status
    when 304
      puts "This key is already in use."
    when 422
      puts "Something went wrong. Please try again."
    else
      puts "Something went wrong. Please try again."
    end
    :error
  end
end