Class: Wakoopa::Base

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

Direct Known Subclasses

Comment, PlacedComment, Relation, Review, Software, Team

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(item) ⇒ Base

Returns a new instance of Base.



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

def initialize(item)
  @data = item
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_id, *args) ⇒ Object



16
17
18
# File 'lib/wakoopa.rb', line 16

def method_missing(method_id, *args)
  @data[method_id.to_s]
end

Class Attribute Details

.sectionObject

Returns the value of attribute section.



21
22
23
# File 'lib/wakoopa.rb', line 21

def section
  @section
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



10
11
12
# File 'lib/wakoopa.rb', line 10

def data
  @data
end

Class Method Details

.all(*args) ⇒ Object



40
41
42
# File 'lib/wakoopa.rb', line 40

def all(*args)
  find(:all, *args)
end

.find(*args) ⇒ Object



23
24
25
26
27
# File 'lib/wakoopa.rb', line 23

def find(*args)
  options = args.last.is_a?(Hash) ? args.pop : {}
  warn "The Wakoopa API doesn\'t support finding single rows. \n Please use \".all()\" or \"s.find(:all)\" instead of \".find()\"." unless args.first == :all
  find_every(options)
end

.find_every(options = {}) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/wakoopa.rb', line 29

def find_every(options = {})
  query = {:limit => 100}.merge(options)
      
  feedkey = Wakoopa.feedkey
  if feedkey
    query.merge!(:key => feedkey)
  end
          
  Wakoopa::Request.get(@section, :query => query)
end

.method_missing(method_id, *args) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/wakoopa.rb', line 44

def method_missing(method_id, *args)
  options = args.last.is_a?(Hash) ? args.pop : {}
  
  method_id.to_s.match(/^find_all_by_([_a-zA-Z]\w*)$/)
  attributes = {}

  $1.split('_and_').each do |key|
    attributes.merge!({key.intern => args.shift})
  end
 
  find(:all, attributes.merge(options))
end