Class: Fog::SakuraCloud::Script::Real

Inherits:
Object
  • Object
show all
Includes:
Utils::Request
Defined in:
lib/fog/sakuracloud/script.rb,
lib/fog/sakuracloud/requests/script/list_notes.rb,
lib/fog/sakuracloud/requests/script/create_note.rb,
lib/fog/sakuracloud/requests/script/delete_note.rb,
lib/fog/sakuracloud/requests/script/modify_note.rb

Instance Method Summary collapse

Methods included from Utils::Request

#request

Constructor Details

#initialize(options = {}) ⇒ Real

Returns a new instance of Real.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/fog/sakuracloud/script.rb', line 22

def initialize(options = {})
  @auth_encode = Base64.strict_encode64([
    options[:sakuracloud_api_token],
    options[:sakuracloud_api_token_secret]
  ].join(':'))
  Fog.credentials[:sakuracloud_api_token]        = options[:sakuracloud_api_token]
  Fog.credentials[:sakuracloud_api_token_secret] = options[:sakuracloud_api_token_secret]

  @sakuracloud_api_url = options[:sakuracloud_api_url] || 'https://secure.sakura.ad.jp'
  @api_zone            = options[:api_zone] || Fog.credentials[:sakuracloud_api_zone] || 'is1b'
  Fog::SakuraCloud.validate_api_zone!(@api_zone)

  @connection = Fog::Core::Connection.new(@sakuracloud_api_url)
end

Instance Method Details

#create_note(options) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/fog/sakuracloud/requests/script/create_note.rb', line 7

def create_note(options)
  body = {
    "Note" => {
      "Name" => options[:name],
      "Content" => options[:content]
    }
  }

  request(
    :headers => {
      'Authorization' => "Basic #{@auth_encode}"
    },
    :expects  => 201,
    :method => 'POST',
    :path => "#{Fog::SakuraCloud.build_endpoint(@api_zone)}/note",
    :body => Fog::JSON.encode(body)
  )
end

#delete_note(id) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/fog/sakuracloud/requests/script/delete_note.rb', line 7

def delete_note( id )
  request(
    :headers => {
      'Authorization' => "Basic #{@auth_encode}"
    },
    :expects  => [200],
    :method => 'DELETE',
    :path => "#{Fog::SakuraCloud.build_endpoint(@api_zone)}/note/#{id}"
  )
end

#list_notes(options = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/fog/sakuracloud/requests/script/list_notes.rb', line 7

def list_notes(options = {})
  request(
    :headers => {
      'Authorization' => "Basic #{@auth_encode}"
    },
    :method => 'GET',
    :path => "#{Fog::SakuraCloud.build_endpoint(@api_zone)}/note"
  )
end

#modify_note(options) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/fog/sakuracloud/requests/script/modify_note.rb', line 7

def modify_note( options )
  body = {
    "Note" => {
      "Name" => options[:name],
      "Content" => options[:content]
    }
  }

  request(
    :headers => {
      'Authorization' => "Basic #{@auth_encode}"
    },
    :expects  => [200],
    :method => 'PUT',
    :path => "#{Fog::SakuraCloud.build_endpoint(@api_zone)}/note/#{options[:id]}",
    :body => Fog::JSON.encode(body)
  )
end