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:
parent
0ec77fc5a5
commit
07bbc05951
11 changed files with 25 additions and 27 deletions
|
@ -89,11 +89,13 @@ module Fog
|
||||||
get_oauth_token
|
get_oauth_token
|
||||||
response = authenticated_request(params)
|
response = authenticated_request(params)
|
||||||
end
|
end
|
||||||
response
|
unless response.body.empty?
|
||||||
|
response = JSON.parse(response.body)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def account
|
def account
|
||||||
Fog::Brightbox::Compute::Account.new(JSON.parse(get_account.body))
|
Fog::Brightbox::Compute::Account.new(get_account)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -41,8 +41,7 @@ module Fog
|
||||||
|
|
||||||
def reset_ftp_password
|
def reset_ftp_password
|
||||||
requires :identity
|
requires :identity
|
||||||
response = connection.reset_ftp_password_account(identity)
|
connection.reset_ftp_password_account(identity)["library_ftp_password"]
|
||||||
JSON.parse(response.body)["library_ftp_password"]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,20 +10,20 @@ module Fog
|
||||||
model Fog::Brightbox::Compute::CloudIp
|
model Fog::Brightbox::Compute::CloudIp
|
||||||
|
|
||||||
def all
|
def all
|
||||||
data = JSON.parse(connection.list_cloud_ips.body)
|
data = connection.list_cloud_ips
|
||||||
load(data)
|
load(data)
|
||||||
end
|
end
|
||||||
|
|
||||||
def get(identifier)
|
def get(identifier)
|
||||||
return nil if identifier.nil? || identifier == ""
|
return nil if identifier.nil? || identifier == ""
|
||||||
data = JSON.parse(connection.get_cloud_ip(identifier).body)
|
data = connection.get_cloud_ip(identifier)
|
||||||
new(data)
|
new(data)
|
||||||
rescue Excon::Errors::NotFound
|
rescue Excon::Errors::NotFound
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def allocate
|
def allocate
|
||||||
data = JSON.parse(connection.create_cloud_ip.body)
|
data = connection.create_cloud_ip
|
||||||
new(data)
|
new(data)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -10,13 +10,13 @@ module Fog
|
||||||
model Fog::Brightbox::Compute::Flavor
|
model Fog::Brightbox::Compute::Flavor
|
||||||
|
|
||||||
def all
|
def all
|
||||||
data = connection.list_server_types.body
|
data = connection.list_server_types
|
||||||
load(JSON.parse(data))
|
load(data)
|
||||||
end
|
end
|
||||||
|
|
||||||
def get(identifier)
|
def get(identifier)
|
||||||
response = connection.get_server_type(identifier)
|
data = connection.get_server_type(identifier)
|
||||||
new(JSON.parse(response.body))
|
new(data)
|
||||||
rescue Excon::Errors::NotFound
|
rescue Excon::Errors::NotFound
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
|
@ -34,8 +34,7 @@ module Fog
|
||||||
:name => @name,
|
:name => @name,
|
||||||
:description => @description
|
:description => @description
|
||||||
}.delete_if {|k,v| v.nil? || v == "" }
|
}.delete_if {|k,v| v.nil? || v == "" }
|
||||||
response = connection.create_image(options)
|
data = connection.create_image(options)
|
||||||
data = JSON.parse(response.body)
|
|
||||||
merge_attributes(data)
|
merge_attributes(data)
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,13 +10,13 @@ module Fog
|
||||||
model Fog::Brightbox::Compute::Image
|
model Fog::Brightbox::Compute::Image
|
||||||
|
|
||||||
def all
|
def all
|
||||||
data = connection.list_images.body
|
data = connection.list_images
|
||||||
load(JSON.parse(data))
|
load(data)
|
||||||
end
|
end
|
||||||
|
|
||||||
def get(identifier)
|
def get(identifier)
|
||||||
response = connection.get_image(identifier)
|
data = connection.get_image(identifier)
|
||||||
new(JSON.parse(response.body))
|
new(data)
|
||||||
rescue Excon::Errors::NotFound
|
rescue Excon::Errors::NotFound
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
|
@ -87,8 +87,7 @@ module Fog
|
||||||
:zone => @zone_id,
|
:zone => @zone_id,
|
||||||
:user_data => @user_data
|
:user_data => @user_data
|
||||||
}.delete_if {|k,v| v.nil? || v == "" }
|
}.delete_if {|k,v| v.nil? || v == "" }
|
||||||
response = connection.create_server(options)
|
data = connection.create_server(options)
|
||||||
data = JSON.parse(response.body)
|
|
||||||
merge_attributes(data)
|
merge_attributes(data)
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,13 +10,13 @@ module Fog
|
||||||
model Fog::Brightbox::Compute::Server
|
model Fog::Brightbox::Compute::Server
|
||||||
|
|
||||||
def all
|
def all
|
||||||
data = JSON.parse(connection.list_servers.body)
|
data = connection.list_servers
|
||||||
load(data)
|
load(data)
|
||||||
end
|
end
|
||||||
|
|
||||||
def get(identifier)
|
def get(identifier)
|
||||||
return nil if identifier.nil? || identifier == ""
|
return nil if identifier.nil? || identifier == ""
|
||||||
data = JSON.parse(connection.get_server(identifier).body)
|
data = connection.get_server(identifier)
|
||||||
new(data)
|
new(data)
|
||||||
rescue Excon::Errors::NotFound
|
rescue Excon::Errors::NotFound
|
||||||
nil
|
nil
|
||||||
|
|
|
@ -27,8 +27,7 @@ module Fog
|
||||||
:name => @name
|
:name => @name
|
||||||
}
|
}
|
||||||
|
|
||||||
response = connection.update_user(identity, options)
|
data = connection.update_user(identity, options)
|
||||||
data = JSON.parse(response.body)
|
|
||||||
merge_attributes(data)
|
merge_attributes(data)
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,13 +10,13 @@ module Fog
|
||||||
model Fog::Brightbox::Compute::User
|
model Fog::Brightbox::Compute::User
|
||||||
|
|
||||||
def all
|
def all
|
||||||
data = JSON.parse(connection.list_users.body)
|
data = connection.list_users
|
||||||
load(data)
|
load(data)
|
||||||
end
|
end
|
||||||
|
|
||||||
def get(identifier)
|
def get(identifier)
|
||||||
return nil if identifier.nil? || identifier == ""
|
return nil if identifier.nil? || identifier == ""
|
||||||
data = JSON.parse(connection.get_user(identifier).body)
|
data = connection.get_user(identifier)
|
||||||
new(data)
|
new(data)
|
||||||
rescue Excon::Errors::NotFound
|
rescue Excon::Errors::NotFound
|
||||||
nil
|
nil
|
||||||
|
|
|
@ -10,13 +10,13 @@ module Fog
|
||||||
model Fog::Brightbox::Compute::Zone
|
model Fog::Brightbox::Compute::Zone
|
||||||
|
|
||||||
def all
|
def all
|
||||||
data = JSON.parse(connection.list_zones.body)
|
data = connection.list_zones
|
||||||
load(data)
|
load(data)
|
||||||
end
|
end
|
||||||
|
|
||||||
def get(identifier)
|
def get(identifier)
|
||||||
return nil if identifier.nil? || identifier == ""
|
return nil if identifier.nil? || identifier == ""
|
||||||
data = JSON.parse(connection.get_zone(identifier).body)
|
data = connection.get_zone(identifier)
|
||||||
new(data)
|
new(data)
|
||||||
rescue Excon::Errors::NotFound
|
rescue Excon::Errors::NotFound
|
||||||
nil
|
nil
|
||||||
|
|
Loading…
Add table
Reference in a new issue