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

[brightbox] Moved JSON parsing to request method to DRY up models, make requests easier to use

This commit is contained in:
Paul Thornthwaite 2010-11-09 17:40:04 +00:00 committed by geemus
parent 0ec77fc5a5
commit 07bbc05951
11 changed files with 25 additions and 27 deletions

View file

@ -89,11 +89,13 @@ module Fog
get_oauth_token
response = authenticated_request(params)
end
response
unless response.body.empty?
response = JSON.parse(response.body)
end
end
def account
Fog::Brightbox::Compute::Account.new(JSON.parse(get_account.body))
Fog::Brightbox::Compute::Account.new(get_account)
end
private

View file

@ -41,8 +41,7 @@ module Fog
def reset_ftp_password
requires :identity
response = connection.reset_ftp_password_account(identity)
JSON.parse(response.body)["library_ftp_password"]
connection.reset_ftp_password_account(identity)["library_ftp_password"]
end
end

View file

@ -10,20 +10,20 @@ module Fog
model Fog::Brightbox::Compute::CloudIp
def all
data = JSON.parse(connection.list_cloud_ips.body)
data = connection.list_cloud_ips
load(data)
end
def get(identifier)
return nil if identifier.nil? || identifier == ""
data = JSON.parse(connection.get_cloud_ip(identifier).body)
data = connection.get_cloud_ip(identifier)
new(data)
rescue Excon::Errors::NotFound
nil
end
def allocate
data = JSON.parse(connection.create_cloud_ip.body)
data = connection.create_cloud_ip
new(data)
end

View file

@ -10,13 +10,13 @@ module Fog
model Fog::Brightbox::Compute::Flavor
def all
data = connection.list_server_types.body
load(JSON.parse(data))
data = connection.list_server_types
load(data)
end
def get(identifier)
response = connection.get_server_type(identifier)
new(JSON.parse(response.body))
data = connection.get_server_type(identifier)
new(data)
rescue Excon::Errors::NotFound
nil
end

View file

@ -34,8 +34,7 @@ module Fog
:name => @name,
:description => @description
}.delete_if {|k,v| v.nil? || v == "" }
response = connection.create_image(options)
data = JSON.parse(response.body)
data = connection.create_image(options)
merge_attributes(data)
true
end

View file

@ -10,13 +10,13 @@ module Fog
model Fog::Brightbox::Compute::Image
def all
data = connection.list_images.body
load(JSON.parse(data))
data = connection.list_images
load(data)
end
def get(identifier)
response = connection.get_image(identifier)
new(JSON.parse(response.body))
data = connection.get_image(identifier)
new(data)
rescue Excon::Errors::NotFound
nil
end

View file

@ -87,8 +87,7 @@ module Fog
:zone => @zone_id,
:user_data => @user_data
}.delete_if {|k,v| v.nil? || v == "" }
response = connection.create_server(options)
data = JSON.parse(response.body)
data = connection.create_server(options)
merge_attributes(data)
true
end

View file

@ -10,13 +10,13 @@ module Fog
model Fog::Brightbox::Compute::Server
def all
data = JSON.parse(connection.list_servers.body)
data = connection.list_servers
load(data)
end
def get(identifier)
return nil if identifier.nil? || identifier == ""
data = JSON.parse(connection.get_server(identifier).body)
data = connection.get_server(identifier)
new(data)
rescue Excon::Errors::NotFound
nil

View file

@ -27,8 +27,7 @@ module Fog
:name => @name
}
response = connection.update_user(identity, options)
data = JSON.parse(response.body)
data = connection.update_user(identity, options)
merge_attributes(data)
true
end

View file

@ -10,13 +10,13 @@ module Fog
model Fog::Brightbox::Compute::User
def all
data = JSON.parse(connection.list_users.body)
data = connection.list_users
load(data)
end
def get(identifier)
return nil if identifier.nil? || identifier == ""
data = JSON.parse(connection.get_user(identifier).body)
data = connection.get_user(identifier)
new(data)
rescue Excon::Errors::NotFound
nil

View file

@ -10,13 +10,13 @@ module Fog
model Fog::Brightbox::Compute::Zone
def all
data = JSON.parse(connection.list_zones.body)
data = connection.list_zones
load(data)
end
def get(identifier)
return nil if identifier.nil? || identifier == ""
data = JSON.parse(connection.get_zone(identifier).body)
data = connection.get_zone(identifier)
new(data)
rescue Excon::Errors::NotFound
nil