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

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(options = {}) ⇒ Real

Returns a new instance of Real.



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/fog/sakuracloud/script.rb', line 20

def initialize(options = {})
  @auth_encord = 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'

  @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_encord}"
    },
    :expects  => 201,
    :method => 'POST',
    :path => "#{Fog::SakuraCloud::SAKURACLOUD_API_ENDPOINT}/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_encord}"
    },
    :expects  => [200],
    :method => 'DELETE',
    :path => "#{Fog::SakuraCloud::SAKURACLOUD_API_ENDPOINT}/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_encord}"
    },
    :method => 'GET',
    :path => "#{Fog::SakuraCloud::SAKURACLOUD_API_ENDPOINT}/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_encord}"
    },
    :expects  => [200],
    :method => 'PUT',
    :path => "#{Fog::SakuraCloud::SAKURACLOUD_API_ENDPOINT}/note/#{options[:id]}",
    :body => Fog::JSON.encode(body)
  )
end

#request(params) ⇒ Object



33
34
35
36
# File 'lib/fog/sakuracloud/script.rb', line 33

def request(params)
  response = parse @connection.request(params)
  response
end