Class: SoftLayer::APIParameterFilter
- Inherits:
-
Object
- Object
- SoftLayer::APIParameterFilter
- Defined in:
- lib/softlayer/APIParameterFilter.rb
Overview
class to be created with the service as its target.
Instance Attribute Summary collapse
-
#parameters ⇒ Object
readonly
Returns the value of attribute parameters.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Instance Method Summary collapse
-
#initialize(target, starting_parameters = nil) ⇒ APIParameterFilter
constructor
A new instance of APIParameterFilter.
-
#method_missing(method_name, *args, &block) ⇒ Object
This allows the filters to be used at the end of a long chain of calls that ends at a service.
-
#object_filter(filter) ⇒ Object
Adds an object_filter to the result.
-
#object_mask(*args) ⇒ Object
Use this as part of a method call chain to add an object mask to the request.
-
#object_with_id(value) ⇒ Object
Adds an API filter that narrows the scope of a call to an object with a particular ID.
-
#result_limit(offset, limit) ⇒ Object
Adds a result limit which helps you page through a long list of entities.
- #server_object_filter ⇒ Object
-
#server_object_id ⇒ Object
A utility method that returns the server object ID (if any) stored in this parameter set.
-
#server_object_mask ⇒ Object
a utility method that returns the object mask (if any) stored in this parameter set.
-
#server_result_limit ⇒ Object
a utility method that returns the starting index of the result limit (if any) stored in this parameter set.
-
#server_result_offset ⇒ Object
a utility method that returns the starting index of the result limit offset (if any) stored in this parameter set.
Constructor Details
#initialize(target, starting_parameters = nil) ⇒ APIParameterFilter
Returns a new instance of APIParameterFilter.
25 26 27 28 |
# File 'lib/softlayer/APIParameterFilter.rb', line 25 def initialize(target, starting_parameters = nil) @target = target @parameters = starting_parameters || {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
This allows the filters to be used at the end of a long chain of calls that ends at a service.
118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/softlayer/APIParameterFilter.rb', line 118 def method_missing(method_name, *args, &block) puts "SoftLayer::APIParameterFilter#method_missing called #{method_name}, #{args.inspect}" if $DEBUG if(!block && method_name.to_s.match(/[[:alnum:]]+/)) result = @target.call_softlayer_api_with_params(method_name, self, args) else result = super end result end |
Instance Attribute Details
#parameters ⇒ Object (readonly)
Returns the value of attribute parameters.
23 24 25 |
# File 'lib/softlayer/APIParameterFilter.rb', line 23 def parameters @parameters end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
22 23 24 |
# File 'lib/softlayer/APIParameterFilter.rb', line 22 def target @target end |
Instance Method Details
#object_filter(filter) ⇒ Object
Adds an object_filter to the result. An Object Filter allows you to specify criteria which are used to filter the results returned by the server.
80 81 82 83 84 85 86 |
# File 'lib/softlayer/APIParameterFilter.rb', line 80 def object_filter(filter) raise ArgumentError, "Object mask expects mask properties" if filter.nil? # we create a new object in case the user wants to store off the # filter chain and reuse it later APIParameterFilter.new(self.target, @parameters.merge({:object_filter => filter})); end |
#object_mask(*args) ⇒ Object
Use this as part of a method call chain to add an object mask to the request. The arguments to object mask should be well formed Extended Object Mask strings:
ticket_service.object_mask(
"mask[createDate, modifyDate]",
"mask(SoftLayer_Some_Type).aProperty").getObject
The object_mask becomes part of the request sent to the server
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/softlayer/APIParameterFilter.rb', line 51 def object_mask(*args) raise ArgumentError, "object_mask expects well-formatted root object mask strings" if args.empty? || (1 == args.count && !args[0]) raise ArgumentError, "object_mask expects well-formatted root object mask strings" if args.find { |arg| !(arg.kind_of?(String)) } object_mask = (@parameters[:object_mask] || []) + args # we create a new object in case the user wants to store off the # filter chain and reuse it later APIParameterFilter.new(self.target, @parameters.merge({ :object_mask => object_mask })); end |
#object_with_id(value) ⇒ Object
Adds an API filter that narrows the scope of a call to an object with a particular ID. For example, if you want to get the ticket with an ID of 12345 from the ticket service you might use
ticket_service.object_with_id(12345).getObject
35 36 37 38 39 |
# File 'lib/softlayer/APIParameterFilter.rb', line 35 def object_with_id(value) # we create a new object in case the user wants to store off the # filter chain and reuse it later APIParameterFilter.new(self.target, @parameters.merge({ :server_object_id => value })) end |
#result_limit(offset, limit) ⇒ Object
Adds a result limit which helps you page through a long list of entities
The offset is the index of the first item you wish to have returned The limit describes how many items you wish the call to return.
For example, if you wanted to get five open tickets from the account starting with the tenth item in the open tickets list you might call
account_service.result_limit(10, 5).getOpenTickets
71 72 73 74 75 |
# File 'lib/softlayer/APIParameterFilter.rb', line 71 def result_limit(offset, limit) # we create a new object in case the user wants to store off the # filter chain and reuse it later APIParameterFilter.new(self.target, @parameters.merge({ :result_offset => offset, :result_limit => limit })) end |
#server_object_filter ⇒ Object
112 113 114 |
# File 'lib/softlayer/APIParameterFilter.rb', line 112 def server_object_filter self.parameters[:object_filter] end |
#server_object_id ⇒ Object
A utility method that returns the server object ID (if any) stored in this parameter set.
90 91 92 |
# File 'lib/softlayer/APIParameterFilter.rb', line 90 def server_object_id self.parameters[:server_object_id] end |
#server_object_mask ⇒ Object
a utility method that returns the object mask (if any) stored in this parameter set.
96 97 98 |
# File 'lib/softlayer/APIParameterFilter.rb', line 96 def server_object_mask self.parameters[:object_mask] end |
#server_result_limit ⇒ Object
a utility method that returns the starting index of the result limit (if any) stored in this parameter set.
102 103 104 |
# File 'lib/softlayer/APIParameterFilter.rb', line 102 def server_result_limit self.parameters[:result_limit] end |
#server_result_offset ⇒ Object
a utility method that returns the starting index of the result limit offset (if any) stored in this parameter set.
108 109 110 |
# File 'lib/softlayer/APIParameterFilter.rb', line 108 def server_result_offset self.parameters[:result_offset] end |