Class: Fog::Account::Softlayer::Mock
- Inherits:
-
Object
- Object
- Fog::Account::Softlayer::Mock
- Includes:
- Softlayer::Compute::Shared
- Defined in:
- lib/fog/softlayer/account.rb,
lib/fog/softlayer/requests/account/get_brand.rb,
lib/fog/softlayer/requests/account/create_brand.rb,
lib/fog/softlayer/requests/account/get_account_owned_brands.rb,
lib/fog/softlayer/requests/account/get_account_owned_brands.rb,
lib/fog/softlayer/requests/account/get_brand_owned_accounts.rb,
lib/fog/softlayer/requests/account/get_brand_owned_accounts.rb more...
Overview
The Mock Service allows you to run a fake instance of the Service which makes no real connections.
Instance Method Summary collapse
-
#create_brand(attributes) ⇒ Excon::Response
Create a Brand.
- #credentials ⇒ Object
-
#get_account_owned_brands(identifier) ⇒ Excon::Response
Get all brands who are owned by account.
-
#get_brand(identifier) ⇒ Excon::Response
Get a Brand.
-
#get_brand_owned_accounts(identifier) ⇒ Excon::Response
Get all accounts who are owned by brand.
-
#initialize(options = {}) ⇒ Mock
constructor
A new instance of Mock.
- #mocked_accounts ⇒ Object
- #mocked_brands ⇒ Object
Methods included from Softlayer::Compute::Shared
Constructor Details
permalink #initialize(options = {}) ⇒ Mock
Returns a new instance of Mock.
33 34 35 36 37 |
# File 'lib/fog/softlayer/account.rb', line 33 def initialize(={}) @brands = [] @accounts = [{'id' => 1}] super() end |
Instance Method Details
permalink #create_brand(attributes) ⇒ Excon::Response
Create a Brand
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/fog/softlayer/requests/account/create_brand.rb', line 15 def create_brand(attributes) raise ArgumentError, "Fog::Account::Softlayer#create_brand expects argument of type Hash" unless attributes.kind_of?(Hash) response = Excon::Response.new required = %w{keyName longName name account} if Fog::Softlayer.valid_request?(required, attributes) response.status = 201 response.body = { :id => Fog::Softlayer.mock_vm_id.to_i, :catalogId => 14 }.merge(attributes) @brands << response.body else response.status = 500 response.body = { "code" => "SoftLayer_Exception_MissingCreationProperty", "error" => "Properties #{required.join(', ')} ALL must be set to create an instance of 'SoftLayer_Brand'." } end response end |
permalink #credentials ⇒ Object
[View source]
39 40 41 42 43 44 |
# File 'lib/fog/softlayer/account.rb', line 39 def credentials { :provider => 'softlayer', :softlayer_username => @softlayer_username, :softlayer_api_key => @softlayer_api_key } end |
permalink #get_account_owned_brands(identifier) ⇒ Excon::Response
Get all brands who are owned by account.
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/fog/softlayer/requests/account/get_account_owned_brands.rb', line 15 def get_account_owned_brands(identifier) response = Excon::Response.new response.status = 200 response.body = mocked_brands if @accounts.select {|account| account['id'] == identifier.to_i }.empty? response.status = 404 response.body = { "error" => "Unable to find object with id of '#{identifier}'.", "code"=>"SoftLayer_Exception_ObjectNotFound" } end response end |
permalink #get_brand(identifier) ⇒ Excon::Response
Get a Brand
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/fog/softlayer/requests/account/get_brand.rb', line 15 def get_brand(identifier) response = Excon::Response.new response.body = @brands.select {|brand| brand[:id] == identifier.to_i }.first || {} response.status = response.body.empty? ? 404 : 200 if response.status == 404 response.body = { "error" => "Unable to find object with id of '#{identifier}'.", "code"=>"SoftLayer_Exception_ObjectNotFound" } end response end |
permalink #get_brand_owned_accounts(identifier) ⇒ Excon::Response
Get all accounts who are owned by brand.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/fog/softlayer/requests/account/get_brand_owned_accounts.rb', line 15 def get_brand_owned_accounts(identifier) response = Excon::Response.new if @brands.select {|brand| brand[:id] == identifier.to_i }.empty? response.status = 404 response.body = { "error" => "Unable to find object with id of '#{identifier}'.", "code"=>"SoftLayer_Exception_ObjectNotFound" } else response.status = 200 response.body = mocked_accounts end response end |
permalink #mocked_accounts ⇒ Object
[View source]
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/fog/softlayer/requests/account/get_brand_owned_accounts.rb', line 45 def mocked_accounts [ { "accountManagedResourcesFlag"=>false, "accountStatusId"=>1001, "address1"=>"R 1", "allowedPptpVpnQuantity"=>1, "brandId"=>23456, "city"=>"Itajuba", "claimedTaxExemptTxFlag"=>false, "companyName"=>"teste", "country"=>"BR", "createDate"=>"2015-06-10T17:06:27-03:00", "email"=>"a@gmail.com", "firstName"=>"Matheus2", "id"=>23456, "isReseller"=>0, "lastName"=>"Mina2", "lateFeeProtectionFlag"=>nil, "modifyDate"=>"2015-06-10T17:06:31-03:00", "postalCode"=>"37500-050", "state"=>"OT", "statusDate"=>nil, "brand"=> { "catalogId"=>14, "id"=>12345, "keyName"=>"ALS", "longName"=>"als", "name"=>"als", "ownedAccounts"=> [ { "accountManagedResourcesFlag"=>false, "accountStatusId"=>1001, "address1"=>"Av, 1303 Sl 10", "address2"=>"Sl 11", "allowedPptpVpnQuantity"=>2, "brandId"=>44443, "city"=>"Itajuba", "claimedTaxExemptTxFlag"=>false, "companyName"=>"Tecnologias LTDA", "country"=>"BR", "createDate"=>"2010-10-06T11:32:30-03:00", "email"=>"sysadmin@example.com.br", "firstName"=>"Xe", "id"=>12345, "isReseller"=>1, "lastName"=>"Silva", "lateFeeProtectionFlag"=>true, "modifyDate"=>"2011-02-14T17:40:23-02:00", "officePhone"=>"+55 35 3629-1616", "postalCode"=>"37500-903", "state"=>"OT", "statusDate"=>nil, "brand"=>nil }, nil ] } } ] end |
permalink #mocked_brands ⇒ Object
[View source]
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/fog/softlayer/requests/account/get_account_owned_brands.rb', line 44 def mocked_brands [ { "catalogId"=>14, "id"=>11111, "keyName"=>"NAME", "longName"=>"Name Name", "name"=>"Name" } ] end |