Class: Whoa::Feed

Inherits:
Object
  • Object
show all
Includes:
HappyMapper
Defined in:
lib/whoa/feed.rb

Constant Summary collapse

ListExperimentsUrl =
"https://www.google.com/analytics/feeds/websiteoptimizer/experiments"

Class Method Summary collapse

Class Method Details

.allObject



12
13
14
15
16
# File 'lib/whoa/feed.rb', line 12

def self.all
  Whoa::Request.get(ListExperimentsUrl) do |response|
    parse(response.body)
  end
end

.all_pages(exp_id) ⇒ Object

TODO: can probably be handled more eloquently combined with mm (extract_options!), or remove the mm altogether.



20
21
22
23
24
# File 'lib/whoa/feed.rb', line 20

def self.all_pages(exp_id)
  Whoa::Request.get(experiment_pages_url(exp_id)) do |response|
    parse(response.body).pages
  end
end

.experiment_pages_url(exp_id) ⇒ Object



26
27
28
# File 'lib/whoa/feed.rb', line 26

def self.experiment_pages_url(exp_id)
  "#{ListExperimentsUrl}/#{exp_id}/abpagevariations"
end

.method_missing(id, *args, &blk) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/whoa/feed.rb', line 30

def self.method_missing(id, *args, &blk) 
  if id.to_s =~ /^all_/
    assoc = id.to_s.gsub("all_","")
    return all.send(assoc) if args.first.blank?
    
    selection_statements = returning Array.new do |stmts|
      args.first.each_pair do |key, value|
        stmts << "self.#{key}.to_s == '#{value.to_s}'"
      end
    end
    
    all.send(assoc).select do |assoc|
      assoc.instance_eval selection_statements.join(" && ")
    end
  else
    super
  end
end