Permalink
Browse files

Merge pull request #1243 from brightbox/deprecate_overloaded_requests

[Brightbox] Deprecates overloaded requests
  • Loading branch information...
2 parents 7dd131e + 1272fc1 commit 5366815418fe508e6da8d65ed2e18736e8ad9150 @tokengeek tokengeek committed Nov 2, 2012
@@ -75,12 +75,14 @@ class Brightbox < Fog::Service
request :get_account
request :get_api_client
request :get_application
+ request :get_authenticated_user
request :get_cloud_ip
request :get_firewall_policy
request :get_firewall_rule
request :get_image
request :get_interface
request :get_load_balancer
+ request :get_scoped_account
request :get_server
request :get_server_group
request :get_server_type
@@ -118,6 +120,7 @@ class Brightbox < Fog::Service
request :update_firewall_rule
request :update_image
request :update_load_balancer
+ request :update_scoped_account
request :update_server
request :update_server_group
request :update_user
@@ -184,8 +187,19 @@ def request(method, url, expected_responses, options = {})
make_request(request_options)
end
+ # Returns the scoped account being used for requests
+ #
+ # API Clients:: This is the owning account
+ # User Apps:: This is the account specified by either +account_id+
+ # option on a connection or the +brightbox_account+
+ # setting in your configuration
+ #
+ # === Returns:
+ #
+ # <tt>Fog::Compute::Brightbox::Account</tt>
+ #
def account
- Fog::Compute::Brightbox::Account.new(get_account)
+ Fog::Compute::Brightbox::Account.new(get_scoped_account)
end
private
@@ -2,10 +2,30 @@ module Fog
module Compute
class Brightbox
class Real
-
+ # Requests details about an account from the API
+ #
+ # === Parameters:
+ #
+ # <tt>identifier <String></tt>:: The identifier to request (Default is +nil+)
+ #
+ # === Returns:
+ #
+ # <tt>Hash</tt>:: The JSON response parsed to a Hash
+ #
+ # === Notes:
+ #
+ # This also supports a deprecated form where if an identifier is not
+ # passed then the scoping account is returned instead. This should not
+ # be used in new code. Use #get_scoped_account instead.
+ #
+ # === Reference:
+ #
+ # https://api.gb1.brightbox.com/1.0/#account_get_account
+ #
def get_account(identifier = nil)
if identifier.nil? || identifier.empty?
- request("get", "/1.0/account", [200])
+ Fog::Logger.deprecation("get_account() without a parameter is deprecated, use get_scoped_account instead [light_black](#{caller.first})[/]")
+ get_scoped_account
else
request("get", "/1.0/accounts/#{identifier}", [200])
end
@@ -0,0 +1,19 @@
+module Fog
+ module Compute
+ class Brightbox
+ class Real
+ # Requests details about authenticated user from the API
+ #
+ # === Returns:
+ #
+ # <tt>Hash</tt>:: The JSON response parsed to a Hash
+ #
+ def get_authenticated_user
+ request("get", "/1.0/user", [200])
+ end
+
+ end
+ end
+ end
+end
+
@@ -0,0 +1,19 @@
+module Fog
+ module Compute
+ class Brightbox
+ class Real
+
+ # Requests details about currently scoped account
+ #
+ # === Returns:
+ #
+ # <tt>Hash</tt>:: The JSON response parsed to a Hash
+ #
+ def get_scoped_account
+ request("get", "/1.0/account", [200])
+ end
+
+ end
+ end
+ end
+end
@@ -2,10 +2,30 @@ module Fog
module Compute
class Brightbox
class Real
-
+ # Requests details about a user from the API
+ #
+ # === Parameters:
+ #
+ # <tt>identifier <String></tt>:: The identifier to request (Default is +nil+)
+ #
+ # === Returns:
+ #
+ # <tt>Hash</tt>:: The JSON response parsed to a Hash
+ #
+ # === Notes:
+ #
+ # This also supports a deprecated form where if an identifier is not
+ # passed then the requesting user is returned instead. This should not
+ # be used in new code. Use #get_authenticated_user instead.
+ #
+ # === Reference:
+ #
+ # https://api.gb1.brightbox.com/1.0/#user_get_user
+ #
def get_user(identifier = nil)
- if identifier.nil? || identifier.empty?
- request("get", "/1.0/user", [200])
+ if identifier.nil? || identifier == ""
+ Fog::Logger.deprecation("get_user() without a parameter is deprecated, use get_authenticated_user instead [light_black](#{caller.first})[/]")
+ get_authenticated_user
else
request("get", "/1.0/users/#{identifier}", [200])
end
@@ -3,12 +3,60 @@ module Compute
class Brightbox
class Real
- def update_account(options)
+ # Requests an update to the currently scoped account
+ #
+ # === Parameters:
+ #
+ # <tt>identifier <String></tt>:: The identifier to request (Default is +nil+)
+ # <tt>options <Hash></tt>:: Hash of options for update
+ #
+ # === Options:
+ #
+ # <tt>name</tt>:: Account name
+ # <tt>address_1</tt>:: First line of address
+ # <tt>address_2</tt>:: Second line of address
+ # <tt>city</tt>:: City part of address
+ # <tt>county</tt>:: County part of address
+ # <tt>postcode</tt>:: Postal code
+ # <tt>country_code</tt>:: ISO 3166-1 two letter code (example: +GB+)
+ # <tt>vat_registration_number</tt>:: Valid EU VAT Number or +nil+
+ # <tt>telephone_number</tt>:: Valid International telephone number in E.164 format prefixed with ’+’
+ #
+ # === Returns:
+ #
+ # <tt>Hash</tt>:: The JSON response parsed to a Hash
+ # <tt>nil</tt>:: If no options were passed to update
+ #
+ # === Notes:
+ #
+ # This also supports a deprecated form where if an identifier is not
+ # passed then the scoping account is updated instead. This should not
+ # be used in new code. Use #update_scoped_account instead.
+ #
+ # === Reference:
+ #
+ # https://api.gb1.brightbox.com/1.0/#account_update_account
+ #
+ def update_account(*args)
+ if args.size == 2
+ identifier = args[0]
+ options = args[1]
+ elsif args.size == 1
+ options = args[0]
+ else
+ raise ArgumentError, "wrong number of arguments (0 for 2)"
+ end
+
return nil if options.empty? || options.nil?
- request("put", "/1.0/account", [200], options)
+ if identifier.nil? || identifier.empty?
+ Fog::Logger.deprecation("update_account() without a parameter is deprecated, use update_scoped_account instead [light_black](#{caller.first})[/]")
+ update_scoped_account(options)
+ else
+ request("put", "/1.0/account", [200], options)
+ end
end
end
end
end
-end
+end
@@ -3,8 +3,10 @@ module Compute
class Brightbox
class Real
- def update_firewall_rule(id, options)
- request("put", "/1.0/firewall_rules/#{id}", [202], options)
+ def update_firewall_rule(identifier, options)
+ return nil if identifier.nil? || identifier == ""
+ return nil if options.empty? || options.nil?
+ request("put", "/1.0/firewall_rules/#{identifier}", [202], options)
end
end
@@ -0,0 +1,37 @@
+module Fog
+ module Compute
+ class Brightbox
+ class Real
+
+ # Requests an update to the currently scoped account
+ #
+ # === Parameters:
+ #
+ # <tt>options</tt>:: Hash of options for update
+ #
+ # === Options:
+ #
+ # <tt>name</tt>:: Account name
+ # <tt>address_1</tt>:: First line of address
+ # <tt>address_2</tt>:: Second line of address
+ # <tt>city</tt>:: City part of address
+ # <tt>county</tt>:: County part of address
+ # <tt>postcode</tt>:: Postal code
+ # <tt>country_code</tt>:: ISO 3166-1 two letter code (example: +GB+)
+ # <tt>vat_registration_number</tt>:: Valid EU VAT Number or +nil+
+ # <tt>telephone_number</tt>:: Valid International telephone number in E.164 format prefixed with ’+’
+ #
+ # === Returns:
+ #
+ # <tt>Hash</tt>:: The JSON response parsed to a Hash
+ # <tt>nil</tt>:: If no options were passed to update
+ #
+ def update_scoped_account(options)
+ return nil if options.empty? || options.nil?
+ request("put", "/1.0/account", [200], options)
+ end
+
+ end
+ end
+ end
+end
@@ -8,17 +8,31 @@
formats(Brightbox::Compute::Formats::Collection::ACCOUNTS, false) { result }
end
- tests("#get_account") do
+ tests("#get_scoped_account") do
pending if Fog.mocking?
- result = Fog::Compute[:brightbox].get_account
+ result = Fog::Compute[:brightbox].get_scoped_account
+ @scoped_account_identifier = result["id"]
+ formats(Brightbox::Compute::Formats::Full::ACCOUNT, false) { result }
+ test("ftp password is blanked") { result["library_ftp_password"].nil? }
+ end
+
+ tests("#get_account(#{@scoped_account_identifier}") do
+ pending if Fog.mocking?
+ result = Fog::Compute[:brightbox].get_account(@scoped_account_identifier)
formats(Brightbox::Compute::Formats::Full::ACCOUNT, false) { result }
test("ftp password is blanked") { result["library_ftp_password"].nil? }
end
update_options = {:name => "Fog@#{Time.now.iso8601}"}
- tests("#update_account(#{update_options.inspect})") do
+ tests("#update_scoped_account(#{update_options.inspect})") do
+ pending if Fog.mocking?
+ result = Fog::Compute[:brightbox].update_scoped_account(update_options)
+ formats(Brightbox::Compute::Formats::Full::ACCOUNT, false) { result }
+ end
+
+ tests("#update_account(#{@scoped_account_identifier}, #{update_options.inspect})") do
pending if Fog.mocking?
- result = Fog::Compute[:brightbox].update_account(update_options)
+ result = Fog::Compute[:brightbox].update_account(@scoped_account_identifier, update_options)
formats(Brightbox::Compute::Formats::Full::ACCOUNT, false) { result }
end

0 comments on commit 5366815

Please sign in to comment.