Class: Ruboty::Niftycloud::Actions::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/ruboty/niftycloud/actions/base.rb

Constant Summary collapse

NAMESPACE =
"niftycloud"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message) ⇒ Base

Returns a new instance of Base.



12
13
14
# File 'lib/ruboty/niftycloud/actions/base.rb', line 12

def initialize(message)
  @message = message
end

Instance Attribute Details

#messageObject (readonly)

Returns the value of attribute message.



10
11
12
# File 'lib/ruboty/niftycloud/actions/base.rb', line 10

def message
  @message
end

Instance Method Details

#accountsObject



16
17
18
19
20
21
22
23
24
25
# File 'lib/ruboty/niftycloud/actions/base.rb', line 16

def accounts
  ENV["NIFTYCLOUD_ACCOUNTS"].split(",").map do ||
    {
      name: ,
      description: ENV["NIFTYCLOUD_ACCOUNT_#{}_DESCRIPTION"],
      access_key_id: ENV["NIFTYCLOUD_ACCOUNT_#{}_ACCESS_KEY_ID"],
      secret_access_key: ENV["NIFTYCLOUD_ACCOUNT_#{}_SECRET_ACCESS_KEY"],
    }
  end
end

#computingObject



46
47
48
49
50
# File 'lib/ruboty/niftycloud/actions/base.rb', line 46

def computing
  AceClient::Niftycloud::Computing.build_client(
    .merge(endpoint: "#{current_region}.cp.cloud.nifty.com", path: '/api')
  )
end

#current_account(account = nil) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/ruboty/niftycloud/actions/base.rb', line 27

def (=nil)
  message.robot.brain.data[NAMESPACE] ||= {}
  if 
    message.robot.brain.data[NAMESPACE]["current_account"] = 
  else
    name = message.robot.brain.data[NAMESPACE]["current_account"] || ENV["NIFTYCLOUD_DEFAULT_ACCOUNT"]
    accounts.find {|| [:name] == name }
  end
end

#current_region(region = nil) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/ruboty/niftycloud/actions/base.rb', line 37

def current_region(region=nil)
  message.robot.brain.data[NAMESPACE] ||= {}
  if region
    message.robot.brain.data[NAMESPACE]["current_region"] = region
  else
    message.robot.brain.data[NAMESPACE]["current_region"] || 'east-1'
  end 
end

#rdbObject



52
53
54
55
56
# File 'lib/ruboty/niftycloud/actions/base.rb', line 52

def rdb
  AceClient::Niftycloud::Rdb.build_client(
    .merge(endpoint: "rdb.jp-#{current_region}.api.cloud.nifty.com")
  )
end