Sha256: 122d0d40a05028fa413646ab4cd89e2ea366e40a381c806d17ee30e2f337b1e9

Contents?: true

Size: 824 Bytes

Versions: 19

Compression:

Stored size: 824 Bytes

Contents

class Zendesk2::Client::Search < Zendesk2::Client::Request
  request_method :get
  request_body { |r| { query: r.query } }
  request_path { |_| "/search.json" }

  page_params!

  attr_reader :query

  def _mock(query, params={})
    @query = query
    setup(params)
    mock
  end

  def _real(query, params={})
    @query = query
    setup(params)
    real
  end

  def mock
    terms = Hash[query.split(" ").map { |t| t.split(":") }]
    type  = terms.delete("type")

    collection = if type.nil?
                   service.data.values
                 else
                   service.data[pluralize(type).to_sym]
                 end

    results = collection.values.select { |v| terms.all?{ |term, condition| v[term].to_s == condition.to_s } }

    page(results, params: {"query" => query}, root: "results")
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
zendesk2-1.7.5 lib/zendesk2/client/requests/search.rb
zendesk2-1.7.4 lib/zendesk2/client/requests/search.rb
zendesk2-1.7.2 lib/zendesk2/client/requests/search.rb
zendesk2-1.7.1 lib/zendesk2/client/requests/search.rb
zendesk2-1.7.0 lib/zendesk2/client/requests/search.rb
zendesk2-1.6.1 lib/zendesk2/client/requests/search.rb
zendesk2-1.5.17 lib/zendesk2/client/requests/search.rb
zendesk2-1.5.16 lib/zendesk2/client/requests/search.rb
zendesk2-1.5.15 lib/zendesk2/client/requests/search.rb
zendesk2-1.5.14 lib/zendesk2/client/requests/search.rb
zendesk2-1.5.13 lib/zendesk2/client/requests/search.rb
zendesk2-1.5.12 lib/zendesk2/client/requests/search.rb
zendesk2-1.5.11 lib/zendesk2/client/requests/search.rb
zendesk2-1.5.10 lib/zendesk2/client/requests/search.rb
zendesk2-1.5.9 lib/zendesk2/client/requests/search.rb
zendesk2-1.5.8 lib/zendesk2/client/requests/search.rb
zendesk2-1.5.7 lib/zendesk2/client/requests/search.rb
zendesk2-1.5.6 lib/zendesk2/client/requests/search.rb
zendesk2-1.5.5 lib/zendesk2/client/requests/search.rb