1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[ibm] Don't need json_body, so we can simplify requests; remove unused params

This commit is contained in:
Decklin Foster 2012-01-17 16:34:47 -05:00
parent 63ac66362c
commit 010e86081d
9 changed files with 65 additions and 86 deletions

View file

@ -27,8 +27,11 @@ module Fog
options[:headers]['Authorization'] = auth_header
options[:headers]['Accept'] = 'application/json'
options[:headers]['Accept-Encoding'] = 'gzip'
unless options[:body].nil?
options[:headers]['Content-Type'] = 'application/x-www-form-urlencoded'
options[:body] = form_encode(options[:body])
end
response = super(options)
unless response.body.empty?
response.body = MultiJson.decode(response.body)
end
@ -39,20 +42,9 @@ module Fog
@auth_header ||= 'Basic ' + Base64.encode64("#{@user}:#{@password}").gsub("\n",'')
end
end
def self.form_body(params)
{
:headers => { 'Content-Type' => 'application/x-www-form-urlencoded' },
:body => params.map {|pair| pair.map {|x| URI.escape(x) }.join('=') }.join('&')
}
end
def self.json_body(params)
{
:headers => { 'Content-Type' => 'application/json' },
:body => MultiJson.encode(params)
}
def form_encode(params)
params.reject {|k, v| v.nil? }.map {|pair| pair.map {|x| URI.escape(x) }.join('=') }.join('&')
end
end
end

View file

@ -9,18 +9,16 @@ module Fog
# * response<~Excon::Response>:
# * body<~Hash>
# TODO: docs
def clone_image(image_id, name, description, extra_params={})
options = {
def clone_image(image_id, name, description)
request(
:method => 'POST',
:expects => 200,
:path => "/offerings/image/#{image_id}"
}
params = {
'name' => name,
'description' => description
}
options.merge!(Fog::IBM.form_body(params.merge(extra_params)))
request(options)
:path => "/offerings/image/#{image_id}",
:body => {
'name' => name,
'description' => description
}
)
end
end

View file

@ -9,19 +9,17 @@ module Fog
# * response<~Excon::Response>:
# * body<~Hash>
# TODO: docs
def create_address(offering_id, location, vlan_id)
options = {
def create_address(location, offering_id, vlan_id=nil)
request(
:method => 'POST',
:expects => 200,
:path => '/addresses',
}
params = {
'offeringID' => offering_id,
'location' => location,
'vlanID' => vlan_id
}
options.merge!(Fog::IBM.form_body(params.merge(extra_params)))
request(options)
:body => {
'offeringID' => offering_id,
'location' => location,
'vlanID' => vlan_id
}
)
end
end

View file

@ -9,18 +9,16 @@ module Fog
# * response<~Excon::Response>:
# * body<~Hash>
# TODO: docs
def create_image(instance_id, name, description, extra_params={})
options = {
def create_image(instance_id, name, description)
request(
:method => 'POST',
:expects => 200,
:path => "/instances/#{instance_id}",
}
params = {
'name' => name,
'description' => description
}
options.merge!(Fog::IBM.form_body(params.merge(extra_params)))
request(options)
:body => {
'name' => name,
'description' => description
}
)
end
end

View file

@ -9,20 +9,19 @@ module Fog
# * response<~Excon::Response>:
# * body<~Hash>
# TODO: docs
def create_instance(name, image_id, instance_type, location, extra_params={})
options = {
def create_instance(name, image_id, instance_type, location, public_key=nil, options={})
request(
:method => 'POST',
:expects => 200,
:path => '/instances'
}
params = {
'name' => name,
'imageID' => image_id,
'instanceType' => instance_type,
'location' => location
}
options.merge!(Fog::IBM.form_body(params.merge(extra_params)))
request(options)
:path => '/instances',
:body => {
'name' => name,
'imageID' => image_id,
'instanceType' => instance_type,
'location' => location,
'publicKey' => public_key
}.merge(options)
)
end
end

View file

@ -9,18 +9,16 @@ module Fog
# * response<~Excon::Response>:
# * body<~Hash>
# TODO: docs
def create_key(name, public_key, extra_params={})
options = {
def create_key(name, public_key=nil)
request(
:method => 'POST',
:expects => 200,
:path => '/keys',
}
params = {
'name' => name,
'publicKey' => public_key
}
options.merge!(Fog::IBM.form_body(params.merge(extra_params)))
request(options)
:body => {
'name' => name,
'publicKey' => public_key
}
)
end
end

View file

@ -9,14 +9,13 @@ module Fog
# * response<~Excon::Response>:
# * body<~Hash>
# TODO: docs
def modify_instance(instance_id, params={})
options = {
def modify_instance(instance_id, options={})
request(
:method => 'PUT',
:expects => 200,
:path => "/instances/#{instance_id}",
}
options.merge!(Fog::IBM.form_body(params))
request(options)
:body => options
)
end
end

View file

@ -10,13 +10,12 @@ module Fog
# * body<~Hash>
# TODO: docs
def modify_key(key_name, params={})
options = {
request(
:method => 'PUT',
:expects => 200,
:path => "/keys/#{key_name}",
}
options.merge!(Fog::IBM.form_body(params))
request(options)
:body => params
)
end
end

View file

@ -9,21 +9,19 @@ module Fog
# * response<~Excon::Response>:
# * body<~Hash>
# TODO: docs
def create_volume(name, offering_id, format, location, size, extra_params={})
options = {
def create_volume(name, offering_id, format, location_id, size)
request(
:method => 'POST',
:expects => 200,
:path => '/storage',
}
params = {
'name' => name,
'offeringID' => offering_id,
'format' => format,
'location' => location,
'size' => size
}
options.merge!(form_body(params.merge(extra_params)))
request(options)
:body => {
'name' => name,
'offeringID' => offering_id,
'format' => format,
'location' => location_id,
'size' => size
}
)
end
end