class Emojidex::Service::Search

Search functionality for the emojidex service

Public Class Methods

advanced(code_cont, categories = [], tags = [], opts = {}) click to toggle source

An expanded version of term with categories and tags as arguments. Options are: detailed: set to true to enable detailed results (defaults to false) limit: sets the number of items per page (default Emojidex::Defaults.limit) Returns a service Collection.

# File lib/emojidex/service/search.rb, line 56
def self.advanced(code_cont, categories = [], tags = [], opts = {})
  opts[:code_cont] = Emojidex.escape_code(code_cont)
  tags = [] << tags unless tags.class == Array
  opts[:tags] = tags
  categories = [] << categories unless categories.class == Array
  opts[:categories] = categories
  _do_search(opts)
end
ending(code_ew, opts = {}) click to toggle source

Searches for a code ending with the given term. Available options are the same as term. Returns a service Collection.

# File lib/emojidex/service/search.rb, line 37
def self.ending(code_ew, opts = {})
  opts[:code_ew] = Emojidex.escape_code(code_ew)
  _do_search(opts)
end
find(code, opts = {}) click to toggle source

Looks directly for an emoji with the exact code provided, returning only the emoji object if found, and nil if not. The find method is unique in the Search module as it is the only method that doesn't actually search, it just looks up the code directly. The only options you can specify are :username and :auth_token for if you are not initializing a User within the client but still want to return R-18 emoji for users that have them enabled.

# File lib/emojidex/service/search.rb, line 72
def self.find(code, opts = {})
  res = Emojidex::Service::Transactor.get("emoji/#{Emojidex.escape_code(code)}",
                           _check_auth(opts));
  return nil if res.include? :error
  Emojidex::Data::Emoji.new(res)
end
starting(code_sw, opts = {}) click to toggle source

Searches for a code starting with the given term. Available options are the same as term. Returns a service Collection.

# File lib/emojidex/service/search.rb, line 29
def self.starting(code_sw, opts = {})
  opts[:code_sw] = Emojidex.escape_code(code_sw)
  _do_search(opts)
end
tags(tags, opts = {}) click to toggle source

Searches an array of tags for emoji associated with all those tags. Available options are the same as term. Returns a service Collection.

# File lib/emojidex/service/search.rb, line 45
def self.tags(tags, opts = {})
  tags = [] << tags unless tags.class == Array
  opts[:tags] = tags
  _do_search(opts)
end
term(code_cont, opts = {}) click to toggle source

Searches by term with the options given. Options are: tags: an array of tags to restrict the search to categories: an arry of categories to restrict the serach to detailed: set to true to enable detailed results (defaults to false) limit: sets the number of items per page (default Emojidex::Defaults.limit) Returns a service Collection.

# File lib/emojidex/service/search.rb, line 17
def self.term(code_cont, opts = {})
  opts[:code_cont] = Emojidex.escape_code(code_cont)
  _do_search(opts)
end

Private Class Methods

_check_auth(opts) click to toggle source
# File lib/emojidex/service/search.rb, line 99
def self._check_auth(opts)
  if !(opts.include? :auth_token) && Emojidex::Client.USER.authorized?
    opts[:username] = Emojidex::Client.USER.username
    opts[:auth_token] = Emojidex::Client.USER.auth_token
  end

  opts
end
_sanitize_opts(opts) click to toggle source
# File lib/emojidex/service/search.rb, line 81
def self._sanitize_opts(opts)
  opts[:tags].map!(&:to_s) if opts.include? :tags
  opts[:categories].map!(&:to_s) if opts.include? :categories
  opts
end