class Saasu::Search
Constants
- VALID_SCOPES
Attributes
keywords[RW]
scope[RW]
Public Class Methods
new(keywords, params = {})
click to toggle source
allowed params: :scope - All, Transactions, Contacts, InventoryItems :transaction_type - Sale, Purchase, Journal, Payroll
# File lib/saasu/search.rb, line 9 def initialize(keywords, params = {}) if params.is_a?(Hash) @scope = params[:scope].presence || 'All' @transaction_type = "Transactions.#{params[:transaction_type]}" if params[:transaction_type].present? else @scope = params end @keywords = keywords validate_scope! end
Public Instance Methods
contacts()
click to toggle source
# File lib/saasu/search.rb, line 27 def contacts search_results["Contacts"].map do |contact| Saasu::Contact.new(contact) end end
invoices()
click to toggle source
# File lib/saasu/search.rb, line 33 def invoices search_results["Transactions"].map do |contact| Saasu::Invoice.new(contact) end end
items()
click to toggle source
# File lib/saasu/search.rb, line 39 def items search_results["InventoryItems"].map do |contact| Saasu::Item.new(contact) end end
perform()
click to toggle source
# File lib/saasu/search.rb, line 22 def perform perform_search! { contacts: search_results['TotalContactsFound'], invoices: search_results['TotalTransactionsFound'], items: search_results['TotalInventoryItemsFound'] } end
Private Instance Methods
perform_search!()
click to toggle source
# File lib/saasu/search.rb, line 52 def perform_search! @search_results = Saasu::Client.request(:get, 'search', search_params) end
search_params()
click to toggle source
# File lib/saasu/search.rb, line 46 def search_params _params = { Scope: @scope, Keywords: @keywords, IncludeSearchTermHighlights: false } _params[:TransactionType] = @transaction_type if @transaction_type.present? _params end
search_results()
click to toggle source
# File lib/saasu/search.rb, line 56 def search_results @search_results ||= perform_search! end
validate_scope!()
click to toggle source
# File lib/saasu/search.rb, line 60 def validate_scope! unless @scope.in? VALID_SCOPES raise "Invalid scope argument. Valid values are: #{VALID_SCOPES.join(', ')}" end end