Class: GetConnector
- Inherits:
-
Object
- Object
- GetConnector
- Defined in:
- lib/afasgem/getconnector.rb
Overview
Implements communication with getconnectors
Instance Method Summary collapse
-
#add_filter(field, operator, value = nil) ⇒ Object
Adds a filter to the current filter list Provides a fluent interface.
-
#add_or ⇒ Object
Adds an OR to the current filter list Provides a fluent interface.
-
#clear_filters ⇒ Object
Clears the filters in place Provides a fluent interface.
-
#execute ⇒ Object
execute the request Provides a fluent interface.
-
#get_all_results ⇒ Object
Fetches all results Data is not cached.
-
#get_data ⇒ Object
Returns the actual data as a hash.
-
#get_data_xml ⇒ Object
Returns the raw xml.
-
#get_result ⇒ Object
Returns the result as a hash This includes the type definition.
-
#initialize(name) ⇒ GetConnector
constructor
Constructor, takes the name of the connector.
-
#next ⇒ Object
Fetch the next page Provides a fluent interface.
-
#page(number) ⇒ Object
Set the page we want to fetch 1 indexed (i.e. page 1 will fetch result 0 to x) Provides a fluent interface.
-
#previous ⇒ Object
Fetch the previous page Provides a fluent interface.
-
#skip(count) ⇒ Object
Set the number of results we want to skip Provides a fluent interface.
-
#take(count) ⇒ Object
Set the number of results we want to have Provides a fluent interface.
Constructor Details
#initialize(name) ⇒ GetConnector
Constructor, takes the name of the connector
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/afasgem/getconnector.rb', line 5 def initialize(name) @connectorname = name @filters = [] if Afasgem::debug # Build a debug client if the debug flag is set @client = Savon.client( wsdl: Afasgem::getconnector_url, log: true, log_level: :debug, pretty_print_xml: true ) else # Build a normal client otherwise @client = Savon.client(wsdl: Afasgem::getconnector_url) end end |
Instance Method Details
#add_filter(field, operator, value = nil) ⇒ Object
Adds a filter to the current filter list Provides a fluent interface
94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/afasgem/getconnector.rb', line 94 def add_filter(field, operator, value = nil) if @filters.size == 0 @filters.push([]) end # Only the EMPTY and NOT_EMPTY filters should accept a nil value if !value unless operator == FilterOperators::EMPTY || operator == FilterOperators::NOT_EMPTY raise ArgumentError.new('Value can only be empty when using FilterOperator::EMPTY or FilterOperator::NOT_EMPTY') end end @filters.last.push({field: field, operator: operator, value: value}) return self end |
#add_or ⇒ Object
Adds an OR to the current filter list Provides a fluent interface
111 112 113 114 |
# File 'lib/afasgem/getconnector.rb', line 111 def add_or @filters.push([]) if @filters.last && @filters.last.size > 0 return self end |
#clear_filters ⇒ Object
Clears the filters in place Provides a fluent interface
118 119 120 121 |
# File 'lib/afasgem/getconnector.rb', line 118 def clear_filters @filters = [] return self end |
#execute ⇒ Object
execute the request Provides a fluent interface
69 70 71 72 73 74 75 |
# File 'lib/afasgem/getconnector.rb', line 69 def execute result = execute_request(get_resultcount, @skip) @data_xml = result[0] @result = result[1] return self end |
#get_all_results ⇒ Object
Fetches all results Data is not cached
79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/afasgem/getconnector.rb', line 79 def get_all_results result_array = [] skip = 0 take = 1000 loop do current_result = get_data_from_result(execute_request(take, skip)[1]) result_array.concat(current_result) skip = skip + take break if current_result.size != take end return result_array end |
#get_data ⇒ Object
Returns the actual data as a hash
131 132 133 134 |
# File 'lib/afasgem/getconnector.rb', line 131 def get_data execute unless @result return get_data_from_result(@result) end |
#get_data_xml ⇒ Object
Returns the raw xml
137 138 139 140 |
# File 'lib/afasgem/getconnector.rb', line 137 def get_data_xml execute unless @data_xml return @data_xml end |
#get_result ⇒ Object
Returns the result as a hash This includes the type definition
125 126 127 128 |
# File 'lib/afasgem/getconnector.rb', line 125 def get_result execute unless @result return @result end |
#next ⇒ Object
Fetch the next page Provides a fluent interface
52 53 54 55 56 |
# File 'lib/afasgem/getconnector.rb', line 52 def next @skip = (@skip || 0) + get_resultcount @result = nil return self end |
#page(number) ⇒ Object
Set the page we want to fetch 1 indexed (i.e. page 1 will fetch result 0 to x) Provides a fluent interface
43 44 45 46 47 48 |
# File 'lib/afasgem/getconnector.rb', line 43 def page(number) fail ArgumentError.new("Page number cannot be lower than 1, #{number} given") unless number > 0 @result = nil @skip = (number - 1) * get_resultcount return self end |
#previous ⇒ Object
Fetch the previous page Provides a fluent interface
60 61 62 63 64 65 |
# File 'lib/afasgem/getconnector.rb', line 60 def previous @result = nil @skip = (@skip || 0) - get_resultcount @skip = [0, @skip].max return self end |
#skip(count) ⇒ Object
Set the number of results we want to skip Provides a fluent interface
33 34 35 36 37 38 |
# File 'lib/afasgem/getconnector.rb', line 33 def skip(count) fail ArgumentError.new("Count cannot be lower than 1, #{count} given") unless count > 0 @result = nil @skip = count return self end |
#take(count) ⇒ Object
Set the number of results we want to have Provides a fluent interface
24 25 26 27 28 29 |
# File 'lib/afasgem/getconnector.rb', line 24 def take(count) fail ArgumentError.new("Count cannot be lower than 1, #{count} given") unless count > 0 @result = nil @resultcount = count return self end |