Skip to content

Commit 3f0a4bd

Browse files
committed
Moved the open_tickets to the Account rather than the Ticket class
1 parent c521644 commit 3f0a4bd

5 files changed

Lines changed: 30 additions & 43 deletions

File tree

CHANGELOG.textile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Substantially rewrote the ObjectFilter class. ObjectFilters used to be hashes which made it easy to manipulate their content incorrectly. The new implementation has a strict interface that makes it harder to manipulate filters incorrectly.
44
* Added a model for Virtual Server Image Templates (SoftLayer::ImageTemplate) - VirtualServerOrder now requires an instance of this class rather than allowing you to provide just the global_id of an image
55
* Added a model for data centers (SoftLayer::Datacenter). Bare Metal, Bare Metal Package, and Virtual server orders now use an instance of Datacenter to identify where their servers will be provisioned. The routines in those classes which used to provide lists of valid data center names now return data center objects.
6+
* The routine to retreive the open tickets on an account has been moved from the Ticket class to a dynamic property of an account
67

78
*2.1.1*
89
* Virtual server upgrades no longer raise exceptions

lib/softlayer/Account.rb

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
# For licensing information see the LICENSE.md file in the project root.
55
#++
66

7-
8-
97
module SoftLayer
108
class Account < SoftLayer::ModelBase
119
include ::SoftLayer::DynamicAttribute
@@ -111,6 +109,19 @@ class Account < SoftLayer::ModelBase
111109
end
112110
end
113111

112+
sl_dynamic_attr :open_tickets do |open_tickets|
113+
open_tickets.should_update? do
114+
@last_open_tickets_update ||= Time.at(0)
115+
(Time.now - @last_open_tickets_update) > 5 * 60 # update every 5 minutes
116+
end
117+
118+
open_tickets.to_update do
119+
@last_open_tickets_update ||= Time.now
120+
open_tickets_data = self.service.object_mask(SoftLayer::Ticket.default_object_mask).getOpenTickets
121+
open_tickets_data.collect { |ticket_data| SoftLayer::Ticket.new(self.softlayer_client, ticket_data) }
122+
end
123+
end
124+
114125
def service
115126
softlayer_client["Account"].object_with_id(self.id)
116127
end

lib/softlayer/Ticket.rb

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
# For licensing information see the LICENSE.md file in the project root.
55
#++
66

7-
8-
97
module SoftLayer
108
class Ticket < SoftLayer::ModelBase
119

@@ -85,7 +83,7 @@ def self.default_object_mask
8583
'awaitingUserResponseFlag', # This comes in from the server as a Boolean value
8684
'serverAdministrationFlag', # This comes in from the server as an integer :-(
8785
]
88-
}
86+
}.to_sl_object_mask
8987
end
9088

9189
##
@@ -104,29 +102,6 @@ def self.ticket_subjects(client = nil)
104102
@ticket_subjects
105103
end
106104

107-
##
108-
# Returns the set of currently open tickets
109-
#
110-
# Options should contain:
111-
#
112-
# <b>+:client+</b> - the client in which to search for the ticket
113-
#
114-
# If a client is not provided then the routine will search Client::default_client
115-
# If Client::default_client is also nil the routine will raise an error.
116-
def self.open_tickets(options = {})
117-
softlayer_client = options[:client] || Client.default_client
118-
raise "#{__method__} requires a client but none was given and Client::default_client is not set" if !softlayer_client
119-
120-
if options.has_key?(:object_mask)
121-
object_mask = options[:object_mask]
122-
else
123-
object_mask = default_object_mask.to_sl_object_mask
124-
end
125-
126-
open_tickets_data = softlayer_client["Account"].object_mask(object_mask).getOpenTickets
127-
open_tickets_data.collect { |ticket_data| new(softlayer_client, ticket_data) }
128-
end
129-
130105
##
131106
# Find the ticket with the given ID and return it
132107
#

spec/Account_spec.rb

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
# For licensing information see the LICENSE.md file in the project root.
55
#++
66

7-
8-
97
$LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), "../lib"))
108

119
require 'rubygems'
@@ -81,6 +79,21 @@
8179
expect(test_account.officePhone).to eq "555.123.4567"
8280
end
8381
end
82+
83+
it "fetches a list of open tickets" do
84+
mock_client = SoftLayer::Client.new(:username => "fakeuser", :api_key => "fake_api_key")
85+
account_service = mock_client["Account"]
86+
87+
expect(account_service).to receive(:call_softlayer_api_with_params).with(:getOpenTickets, instance_of(SoftLayer::APIParameterFilter),[]) do
88+
fixture_from_json("test_tickets")
89+
end
90+
91+
test_account = SoftLayer::Account.new(mock_client, fixture_from_json("test_account"))
92+
open_tickets = nil
93+
expect { open_tickets = test_account.open_tickets }.to_not raise_error
94+
ticket_ids = open_tickets.collect { |ticket| ticket.id }
95+
expect(ticket_ids.sort).to eq [12345, 12346, 12347, 12348, 12349].sort
96+
end
8497

8598
describe "relationship to servers" do
8699
it "should respond to a request for servers" do

spec/Ticket_spec.rb

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
# For licensing information see the LICENSE.md file in the project root.
55
#++
66

7-
8-
97
$LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), "../lib"))
108

119
require 'rubygems'
@@ -19,17 +17,6 @@
1917
SoftLayer::Ticket.instance_eval { @ticket_subjects = nil }
2018
end
2119

22-
it "fetches a list of open tickets" do
23-
mock_client = SoftLayer::Client.new(:username => "fakeuser", :api_key => "fake_api_key")
24-
account_service = mock_client["Account"]
25-
26-
expect(account_service).to receive(:call_softlayer_api_with_params).with(:getOpenTickets, instance_of(SoftLayer::APIParameterFilter),[]) do
27-
fixture_from_json("test_tickets")
28-
end
29-
30-
SoftLayer::Ticket.open_tickets(:client => mock_client)
31-
end
32-
3320
it "retrieves ticket subjects from API once" do
3421
fakeTicketSubjects = fixture_from_json("ticket_subjects")
3522

0 commit comments

Comments
 (0)