Class: Loquor::ApiCall::Index

Inherits:
Loquor::ApiCall show all
Defined in:
lib/loquor/api_calls/index.rb

Instance Attribute Summary collapse

Attributes inherited from Loquor::ApiCall

#klass

Instance Method Summary collapse

Constructor Details

#initialize(klass) ⇒ Index

Returns a new instance of Index.



6
7
8
9
10
# File 'lib/loquor/api_calls/index.rb', line 6

def initialize(klass)
  super(klass)
  @criteria = {}
  @clauses = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object

Proxy everything to the results so that this this class transparently acts as an Array.



48
49
50
# File 'lib/loquor/api_calls/index.rb', line 48

def method_missing(name, *args, &block)
  results.send(name, *args, &block)
end

Instance Attribute Details

#clausesObject (readonly)

Returns the value of attribute clauses.



4
5
6
# File 'lib/loquor/api_calls/index.rb', line 4

def clauses
  @clauses
end

#criteriaObject (readonly)

Returns the value of attribute criteria.



4
5
6
# File 'lib/loquor/api_calls/index.rb', line 4

def criteria
  @criteria
end

Instance Method Details

#find_eachObject



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/loquor/api_calls/index.rb', line 52

def find_each
  page = 1
  per = 200
  results = []
  begin
    results = Loquor.get("#{generate_url}&page=#{page}&per=#{per}")
    results.each do |result|
      yield klass.new(result)
    end
    page += 1
  end while(results.size == per)
end

#order(value) ⇒ Object



30
31
32
33
# File 'lib/loquor/api_calls/index.rb', line 30

def order(value)
  @order = value
  self
end

#page(value) ⇒ Object



41
42
43
44
# File 'lib/loquor/api_calls/index.rb', line 41

def page(value)
  @page = value
  self
end

#per(value) ⇒ Object Also known as: limit



35
36
37
38
# File 'lib/loquor/api_calls/index.rb', line 35

def per(value)
  @per = value
  self
end

#select(value) ⇒ Object



24
25
26
27
28
# File 'lib/loquor/api_calls/index.rb', line 24

def select(value)
  @criteria[:fields] ||= []
  @criteria[:fields] += value
  self
end

#where(data) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/loquor/api_calls/index.rb', line 12

def where(data)
  case data
  when String
    @clauses << data
  else
    data.each do |key, value|
      @criteria[key] = value
    end
  end
  self
end