Sha256: 623de2fc32300ce1099efcba691ba68db0dbd6ecbf1f9995639aee8ef226536b

Contents?: true

Size: 1.07 KB

Versions: 24

Compression:

Stored size: 1.07 KB

Contents

class Cloudinary::Search
  def initialize
    @query_hash = {
      :sort_by    => [],
      :aggregate  => [],
      :with_field   => []
    }
  end

  ## implicitly generate an instance delegate the method
  def self.method_missing(method_name, *arguments)
    instance = new
    instance.send(method_name, *arguments)
  end

  def expression(value)
    @query_hash[:expression] = value
    self
  end

  def max_results(value)
    @query_hash[:max_results] = value
    self
  end

  def next_cursor(value)
    @query_hash[:next_cursor] = value
    self
  end

  def sort_by(field_name, dir = 'desc')
    @query_hash[:sort_by].push(field_name => dir)
    self
  end

  def aggregate(value)
    @query_hash[:aggregate].push(value)
    self
  end

  def with_field(value)
    @query_hash[:with_field].push(value)
    self
  end

  def to_h
    @query_hash.select { |_, value| !value.nil? && !(value.is_a?(Array) && value.empty?) }
  end

  def execute(options = {})
    options[:content_type] = :json
    uri = 'resources/search'
    Cloudinary::Api.call_api(:post, uri, to_h, options)
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
cloudinary-1.20.0 lib/cloudinary/search.rb
cloudinary-1.19.0 lib/cloudinary/search.rb
cloudinary-1.18.1 lib/cloudinary/search.rb
cloudinary-1.18.0 lib/cloudinary/search.rb
cloudinary-1.17.1 lib/cloudinary/search.rb
cloudinary-1.17.0 lib/cloudinary/search.rb
cloudinary-1.16.1 lib/cloudinary/search.rb
cloudinary-1.16.0 lib/cloudinary/search.rb
cloudinary-1.15.0 lib/cloudinary/search.rb
cloudinary-1.14.0 lib/cloudinary/search.rb
cloudinary-1.13.2 lib/cloudinary/search.rb
cloudinary-1.13.1 lib/cloudinary/search.rb
cloudinary-1.13.0 lib/cloudinary/search.rb
cloudinary-1.12.0 lib/cloudinary/search.rb
cloudinary-1.11.1 lib/cloudinary/search.rb
cloudinary-1.11.0 lib/cloudinary/search.rb
cloudinary-1.10.1.pre.rc lib/cloudinary/search.rb
cloudinary-1.10.0 lib/cloudinary/search.rb
cloudinary-1.9.1 lib/cloudinary/search.rb
cloudinary-1.9.0 lib/cloudinary/search.rb