Class: AdmobSiteStats
- Inherits:
-
Object
- Object
- AdmobSiteStats
- Defined in:
- lib/admob_site_stats.rb,
lib/admob_site_stats/version.rb
Constant Summary collapse
- VERSION =
"0.0.1"
Instance Attribute Summary collapse
-
#clicks ⇒ Object
readonly
Returns the value of attribute clicks.
-
#cpc_impressions ⇒ Object
readonly
Returns the value of attribute cpc_impressions.
-
#cpc_revenue ⇒ Object
readonly
Returns the value of attribute cpc_revenue.
-
#cpm_impressions ⇒ Object
readonly
Returns the value of attribute cpm_impressions.
-
#cpm_revenue ⇒ Object
readonly
Returns the value of attribute cpm_revenue.
-
#ctr ⇒ Object
readonly
Returns the value of attribute ctr.
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#ecpm ⇒ Object
readonly
Returns the value of attribute ecpm.
-
#exchange_downloads ⇒ Object
readonly
Returns the value of attribute exchange_downloads.
-
#exchange_impressions ⇒ Object
readonly
Returns the value of attribute exchange_impressions.
-
#fill_rate ⇒ Object
readonly
Returns the value of attribute fill_rate.
-
#housead_clicks ⇒ Object
readonly
Returns the value of attribute housead_clicks.
-
#housead_ctr ⇒ Object
readonly
Returns the value of attribute housead_ctr.
-
#housead_fill_rate ⇒ Object
readonly
Returns the value of attribute housead_fill_rate.
-
#housead_impressions ⇒ Object
readonly
Returns the value of attribute housead_impressions.
-
#housead_requests ⇒ Object
readonly
Returns the value of attribute housead_requests.
-
#impressions ⇒ Object
readonly
Returns the value of attribute impressions.
-
#interstitial_impressions ⇒ Object
readonly
Returns the value of attribute interstitial_impressions.
-
#interstitial_requests ⇒ Object
readonly
Returns the value of attribute interstitial_requests.
-
#overall_fill_rate ⇒ Object
readonly
Returns the value of attribute overall_fill_rate.
-
#overall_requests ⇒ Object
readonly
Returns the value of attribute overall_requests.
-
#requests ⇒ Object
readonly
Returns the value of attribute requests.
-
#revenue ⇒ Object
readonly
Returns the value of attribute revenue.
Instance Method Summary collapse
-
#initialize(client_key, email, password, site_id_array, start_date, end_date) ⇒ AdmobSiteStats
constructor
A new instance of AdmobSiteStats.
Constructor Details
#initialize(client_key, email, password, site_id_array, start_date, end_date) ⇒ AdmobSiteStats
Returns a new instance of AdmobSiteStats.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/admob_site_stats.rb', line 32 def initialize (client_key, email, password, site_id_array, start_date, end_date) #login and get token uri_login = URI.parse("https://api.admob.com/v2/auth/login") http = Net::HTTP.new( uri_login.host, uri_login.port ) http.use_ssl = true if uri_login.port == 443 http.verify_mode = OpenSSL::SSL::VERIFY_NONE if uri_login.port == 443 request_login = Net::HTTP::Post.new(uri_login.request_uri) request_login.set_form_data({"client_key" => client_key, "email" => email, "password" => password }) begin res, data = http.request(request_login) hash = JSON.parse res.body token = hash['data']['token'] #TODO catch 500 response codes --- if res.code rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e puts e.to_s end # end of begin #login and get token uri_stats = URI.parse("https://api.admob.com/v2/site/stats") uri_stats.query = "client_key="+client_key+"&token="+token+"&start_date="+start_date+"&end_date="+end_date site_id_array.each do |site| uri_stats.query = uri_stats.query+"&site_id[]="+site end request_stats = Net::HTTP::Get.new(uri_stats.request_uri) begin res_stats, data_stats = http.request(request_stats) hash_stats = JSON.parse res_stats.body @overall_fill_rate = hash_stats["data"][0]["overall_fill_rate"] @exchange_impressions = hash_stats["data"][0]["exchange_impressions"] @interstitial_requests = hash_stats["data"][0]["interstitial_requests"] @requests = hash_stats["data"][0]["requests"] @fill_rate = hash_stats["data"][0]["fill_rate"] @ctr = hash_stats["data"][0]["ctr"] @housead_requests = hash_stats["data"][0]["housead_requests"] @housead_clicks = hash_stats["data"][0]["housead_clicks"] @impressions = hash_stats["data"][0]["impressions"] @cpm_revenue = hash_stats["data"][0]["cpm_revenue"] @overall_requests = hash_stats["data"][0]["overall_requests"] @requests = hash_stats["data"][0]["requests"] @revenue = hash_stats["data"][0]["revenue"] @housead_ctr = hash_stats["data"][0]["housead_ctr"] @exchange_downloads = hash_stats["data"][0]["exchange_downloads"] @housead_fill_rate = hash_stats["data"][0]["housead_fill_rate"] @date = hash_stats["data"][0]["date"] @cpc_revenue = hash_stats["data"][0]["cpc_revenue"] @clicks = hash_stats["data"][0]["clicks"] @housead_impressions = hash_stats["data"][0]["housead_impressions"] @cpm_impressions = hash_stats["data"][0]["cpm_impressions"] @interstitial_impressions = hash_stats["data"][0]["interstitial_impressions"] @cpc_impressions = hash_stats["data"][0]["cpc_impressions"] @ecpm = hash_stats["data"][0]["ecpm"] #TODO catch 500 response codes --- if res.code rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e puts e.to_s end # end of begin #login and get token uri_logout = URI.parse("https://api.admob.com/v2/auth/logout") request_logout = Net::HTTP::Post.new(uri_logout.request_uri) request_logout.set_form_data({"client_key" => client_key, "token" => token }) begin res, data = http.request(request_login) #TODO catch 500 response codes --- if res.code rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e puts e.to_s end # end of begin end |
Instance Attribute Details
#clicks ⇒ Object (readonly)
Returns the value of attribute clicks.
8 9 10 |
# File 'lib/admob_site_stats.rb', line 8 def clicks @clicks end |
#cpc_impressions ⇒ Object (readonly)
Returns the value of attribute cpc_impressions.
8 9 10 |
# File 'lib/admob_site_stats.rb', line 8 def cpc_impressions @cpc_impressions end |
#cpc_revenue ⇒ Object (readonly)
Returns the value of attribute cpc_revenue.
8 9 10 |
# File 'lib/admob_site_stats.rb', line 8 def cpc_revenue @cpc_revenue end |
#cpm_impressions ⇒ Object (readonly)
Returns the value of attribute cpm_impressions.
8 9 10 |
# File 'lib/admob_site_stats.rb', line 8 def cpm_impressions @cpm_impressions end |
#cpm_revenue ⇒ Object (readonly)
Returns the value of attribute cpm_revenue.
8 9 10 |
# File 'lib/admob_site_stats.rb', line 8 def cpm_revenue @cpm_revenue end |
#ctr ⇒ Object (readonly)
Returns the value of attribute ctr.
8 9 10 |
# File 'lib/admob_site_stats.rb', line 8 def ctr @ctr end |
#date ⇒ Object (readonly)
Returns the value of attribute date.
8 9 10 |
# File 'lib/admob_site_stats.rb', line 8 def date @date end |
#ecpm ⇒ Object (readonly)
Returns the value of attribute ecpm.
8 9 10 |
# File 'lib/admob_site_stats.rb', line 8 def ecpm @ecpm end |
#exchange_downloads ⇒ Object (readonly)
Returns the value of attribute exchange_downloads.
8 9 10 |
# File 'lib/admob_site_stats.rb', line 8 def exchange_downloads @exchange_downloads end |
#exchange_impressions ⇒ Object (readonly)
Returns the value of attribute exchange_impressions.
8 9 10 |
# File 'lib/admob_site_stats.rb', line 8 def exchange_impressions @exchange_impressions end |
#fill_rate ⇒ Object (readonly)
Returns the value of attribute fill_rate.
8 9 10 |
# File 'lib/admob_site_stats.rb', line 8 def fill_rate @fill_rate end |
#housead_clicks ⇒ Object (readonly)
Returns the value of attribute housead_clicks.
8 9 10 |
# File 'lib/admob_site_stats.rb', line 8 def housead_clicks @housead_clicks end |
#housead_ctr ⇒ Object (readonly)
Returns the value of attribute housead_ctr.
8 9 10 |
# File 'lib/admob_site_stats.rb', line 8 def housead_ctr @housead_ctr end |
#housead_fill_rate ⇒ Object (readonly)
Returns the value of attribute housead_fill_rate.
8 9 10 |
# File 'lib/admob_site_stats.rb', line 8 def housead_fill_rate @housead_fill_rate end |
#housead_impressions ⇒ Object (readonly)
Returns the value of attribute housead_impressions.
8 9 10 |
# File 'lib/admob_site_stats.rb', line 8 def housead_impressions @housead_impressions end |
#housead_requests ⇒ Object (readonly)
Returns the value of attribute housead_requests.
8 9 10 |
# File 'lib/admob_site_stats.rb', line 8 def housead_requests @housead_requests end |
#impressions ⇒ Object (readonly)
Returns the value of attribute impressions.
8 9 10 |
# File 'lib/admob_site_stats.rb', line 8 def impressions @impressions end |
#interstitial_impressions ⇒ Object (readonly)
Returns the value of attribute interstitial_impressions.
8 9 10 |
# File 'lib/admob_site_stats.rb', line 8 def interstitial_impressions @interstitial_impressions end |
#interstitial_requests ⇒ Object (readonly)
Returns the value of attribute interstitial_requests.
8 9 10 |
# File 'lib/admob_site_stats.rb', line 8 def interstitial_requests @interstitial_requests end |
#overall_fill_rate ⇒ Object (readonly)
Returns the value of attribute overall_fill_rate.
8 9 10 |
# File 'lib/admob_site_stats.rb', line 8 def overall_fill_rate @overall_fill_rate end |
#overall_requests ⇒ Object (readonly)
Returns the value of attribute overall_requests.
8 9 10 |
# File 'lib/admob_site_stats.rb', line 8 def overall_requests @overall_requests end |
#requests ⇒ Object (readonly)
Returns the value of attribute requests.
8 9 10 |
# File 'lib/admob_site_stats.rb', line 8 def requests @requests end |
#revenue ⇒ Object (readonly)
Returns the value of attribute revenue.
8 9 10 |
# File 'lib/admob_site_stats.rb', line 8 def revenue @revenue end |