Class: Adsense::Info

Inherits:
Object
  • Object
show all
Defined in:
lib/adsense-info.rb,
lib/adsense-info/version.rb

Constant Summary collapse

VERSION =
"1.0.4"

Instance Method Summary collapse

Constructor Details

#initialize(username, password) ⇒ Info

Returns a new instance of Info.



7
8
9
10
11
# File 'lib/adsense-info.rb', line 7

def initialize( username, password )
  @username = username
  @password = password
  @agent = Mechanize::Mechanize.new
end

Instance Method Details

#last_monthObject



48
49
50
51
# File 'lib/adsense-info.rb', line 48

def last_month
  update_values! unless @last_month
  @last_month
end

#login!Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/adsense-info.rb', line 13

def login!
  page = @agent.get 'http://www.gmail.com'
  form = page.forms.first
  if form
    form.Email = @username
    form.Passwd = @password
    @agent.submit form
  end
  nil
end

#this_month_so_farObject



43
44
45
46
# File 'lib/adsense-info.rb', line 43

def this_month_so_far
  update_values! unless @this_month_so_far
  @this_month_so_far
end

#today_so_farObject



33
34
35
36
# File 'lib/adsense-info.rb', line 33

def today_so_far
  update_values! unless @today_so_far
  @today_so_far
end

#update_values!Object



24
25
26
27
28
29
30
31
# File 'lib/adsense-info.rb', line 24

def update_values!
  login!
  values = ( get('https://www.google.com/adsense/v3/m/home') / 'span[@class~=value]' )
  @today_so_far = values[0].inner_html
  @yesterday = values[1].inner_html
  @this_month_so_far = values[2].inner_html
  @last_month = values[3].inner_html
end

#yesterdayObject



38
39
40
41
# File 'lib/adsense-info.rb', line 38

def yesterday
  update_values! unless @yesterday
  @yesterday
end