Class: AdmobSiteStats

Inherits:
Object
  • Object
show all
Defined in:
lib/admob_site_stats.rb,
lib/admob_site_stats/version.rb

Constant Summary collapse

VERSION =
"0.0.1"

Instance Attribute Summary collapse

Instance Method Summary collapse

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.parse("https://api.admob.com/v2/auth/login")

  http = Net::HTTP.new( .host, .port )
  http.use_ssl = true if .port == 443
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE if .port == 443

   = Net::HTTP::Post.new(.request_uri)
  .set_form_data({"client_key" => client_key, "email" => email, "password" => password })

  begin
    res, data = http.request()
    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()
     #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

#clicksObject (readonly)

Returns the value of attribute clicks.



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

def clicks
  @clicks
end

#cpc_impressionsObject (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_revenueObject (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_impressionsObject (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_revenueObject (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

#ctrObject (readonly)

Returns the value of attribute ctr.



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

def ctr
  @ctr
end

#dateObject (readonly)

Returns the value of attribute date.



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

def date
  @date
end

#ecpmObject (readonly)

Returns the value of attribute ecpm.



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

def ecpm
  @ecpm
end

#exchange_downloadsObject (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_impressionsObject (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_rateObject (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_clicksObject (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_ctrObject (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_rateObject (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_impressionsObject (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_requestsObject (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

#impressionsObject (readonly)

Returns the value of attribute impressions.



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

def impressions
  @impressions
end

#interstitial_impressionsObject (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_requestsObject (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_rateObject (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_requestsObject (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

#requestsObject (readonly)

Returns the value of attribute requests.



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

def requests
  @requests
end

#revenueObject (readonly)

Returns the value of attribute revenue.



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

def revenue
  @revenue
end