Skip to content

Commit

Permalink
[brightbox] Moved JSON parsing to request method to DRY up models, ma…
Browse files Browse the repository at this point in the history
…ke requests easier to use
  • Loading branch information
tokengeek authored and geemus committed Nov 16, 2010
1 parent 0ec77fc commit 07bbc05
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 27 deletions.
6 changes: 4 additions & 2 deletions lib/fog/brightbox/compute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,13 @@ def request(params)
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
Expand Down
3 changes: 1 addition & 2 deletions lib/fog/brightbox/models/compute/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ class Account < Fog::Model

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
Expand Down
6 changes: 3 additions & 3 deletions lib/fog/brightbox/models/compute/cloud_ips.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ class CloudIps < Fog::Collection
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

Expand Down
8 changes: 4 additions & 4 deletions lib/fog/brightbox/models/compute/flavors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ class Flavors < Fog::Collection
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
Expand Down
3 changes: 1 addition & 2 deletions lib/fog/brightbox/models/compute/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ def save
: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
Expand Down
8 changes: 4 additions & 4 deletions lib/fog/brightbox/models/compute/images.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ class Images < Fog::Collection
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
Expand Down
3 changes: 1 addition & 2 deletions lib/fog/brightbox/models/compute/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ def save
: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
Expand Down
4 changes: 2 additions & 2 deletions lib/fog/brightbox/models/compute/servers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ class Servers < Fog::Collection
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
Expand Down
3 changes: 1 addition & 2 deletions lib/fog/brightbox/models/compute/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ def save
:name => @name
}

response = connection.update_user(identity, options)
data = JSON.parse(response.body)
data = connection.update_user(identity, options)
merge_attributes(data)
true
end
Expand Down
4 changes: 2 additions & 2 deletions lib/fog/brightbox/models/compute/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ class Users < Fog::Collection
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
Expand Down
4 changes: 2 additions & 2 deletions lib/fog/brightbox/models/compute/zones.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ class Zones < Fog::Collection
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
Expand Down

0 comments on commit 07bbc05

Please sign in to comment.