Sha256: b5185e51c9e7ea3f3d7b6162f259f62733c42b69c597783dc7adba85e191c401
Contents?: true
Size: 1.27 KB
Versions: 1
Compression:
Stored size: 1.27 KB
Contents
require 'uri' require 'json' module Yahoo class AdsEstimates attr_reader :keyword attr_reader :budgets attr_reader :max_cpcs, :impressions, :clicks 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 private def request_uri(_budget) # From: http://sem.smallbusiness.yahoo.com/searchenginemarketing/marketingcost.php _keyword_escaped = URI.escape(@keyword) "http://sem.smallbusiness.yahoo.com/inc/getKeywordForecast.php?format=json&budget=#{_budget}&keyword=#{_keyword_escaped}&target=none" end def query(_budget) open(request_uri(_budget)) { |f| return f.string } nil end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
yahoo_ads_estimates-0.1.3 | lib/yahoo/ads_estimates.rb |