Class: Zootool::ZooQuery

Inherits:
Object
  • Object
show all
Defined in:
lib/zootool/zoo_query.rb

Overview

The base class for other Zootool API query classes. Simply provides common functionality to simplify the API querying process.

Direct Known Subclasses

ItemsQuery, UsersQuery

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api) ⇒ ZooQuery

Initializes the ZooQuery.



12
13
14
# File 'lib/zootool/zoo_query.rb', line 12

def initialize api
  @api = api
end

Instance Attribute Details

#apiObject

The ZootoolApi to use for making requests.



9
10
11
# File 'lib/zootool/zoo_query.rb', line 9

def api
  @api
end

Instance Method Details

#args_to_hash(args) ⇒ Object

Returns a hash containing the first element of the specified args array or a new hash if the args array is nil or empty. This is simply a convenience to simplify the API queries that allow optional arguments.



29
30
31
32
33
34
35
# File 'lib/zootool/zoo_query.rb', line 29

def args_to_hash args
  if args.nil? || args.length < 1
    return {}
  else
    return args[0]
  end
end

#build_query_string(hash = nil) ⇒ Object

Builds a query string from a hash for use in the query URL in the form: key1=value1&key2=value2



19
20
21
22
# File 'lib/zootool/zoo_query.rb', line 19

def build_query_string hash=nil
  return '' if hash.nil?
  return (hash.to_a.map {|q| "#{q[0]}=#{q[1]}"}).join("&")
end