Class: Yahoo::AdsEstimates

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_keyword, _budgets = [1.0, 50.0]) ⇒ AdsEstimates

Returns a new instance of AdsEstimates.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/yahoo/ads_estimates.rb', line 12

def initialize(_keyword, _budgets=[1.0, 50.0])
  @keyword = _keyword
  @budgets = _budgets

  @max_cpcs = []
  @impressions = []
  @clicks = []

  @budgets.each do |budget|
    begin
      json = query(budget)
      result = JSON.parse(json)
      @impressions << result['impressions'].to_f
      @clicks << result['clicks'].to_f
      @max_cpcs << result['maxBid'].to_f
    rescue
      if defined?(RAILS_DEFAULT_LOGGER)
        RAILS_DEFAULT_LOGGER.info "Problem querying and parsing Yahoo, json: #{json}"
      else
        puts "Problem querying and parsing Yahoo, json: #{json}"
      end
    end
  end
end

Instance Attribute Details

#budgetsObject (readonly)

Returns the value of attribute budgets.



9
10
11
# File 'lib/yahoo/ads_estimates.rb', line 9

def budgets
  @budgets
end

#clicksObject (readonly)

Returns the value of attribute clicks.



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

def clicks
  @clicks
end

#impressionsObject (readonly)

Returns the value of attribute impressions.



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

def impressions
  @impressions
end

#keywordObject (readonly)

Returns the value of attribute keyword.



8
9
10
# File 'lib/yahoo/ads_estimates.rb', line 8

def keyword
  @keyword
end

#max_cpcsObject (readonly)

Returns the value of attribute max_cpcs.



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

def max_cpcs
  @max_cpcs
end