class Fog::SakuraCloud::Script::Real

Public Class Methods

new(options = {}) click to toggle source
# 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

Public Instance Methods

create_note(options) click to toggle source
# File lib/fog/sakuracloud/requests/script/create_note.rb, line 6
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 ) click to toggle source
# File lib/fog/sakuracloud/requests/script/delete_note.rb, line 6
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 = {}) click to toggle source
# File lib/fog/sakuracloud/requests/script/list_notes.rb, line 6
def list_notes(options = {})
  request(
    :headers => {
      'Authorization' => "Basic #{@auth_encode}"
    },
    :method => 'GET',
    :path => "#{Fog::SakuraCloud.build_endpoint(@api_zone)}/note"
  )
end
modify_note( options ) click to toggle source
# File lib/fog/sakuracloud/requests/script/modify_note.rb, line 6
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