Module: Rugalytics

Defined in:
lib/rugalytics.rb,
lib/rugalytics/item.rb,
lib/rugalytics/graph.rb,
lib/rugalytics/report.rb,
lib/rugalytics/server.rb,
lib/rugalytics/account.rb,
lib/rugalytics/profile.rb,
lib/rugalytics/connection.rb

Overview

See README for usage documentation.

Defined Under Namespace

Modules: MorphLessMethodMissing Classes: Account, Connection, Graph, InvalidCredentials, Item, Profile, Report, Server

Constant Summary collapse

VERSION =
"0.1.7"
FORMAT_PDF =
'0'
FORMAT_XML =
'1'
FORMAT_CSV =
'2'
FORMAT_TAB =
'3'
VALID_REPORTS =
%w[ Dashboard ]

Class Method Summary collapse

Class Method Details

.configObject



68
69
70
# File 'lib/rugalytics.rb', line 68

def config
  @config
end

.config_setup(root) ⇒ Object



72
73
74
75
76
# File 'lib/rugalytics.rb', line 72

def config_setup root
  config_file = "#{root}/config/rugalytics.yml"
  config_file = "#{root}/rugalytics.yml" unless File.exist? config_file
  @config = load_config(config_file) if File.exist? config_file
end

.default_profileObject



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/rugalytics.rb', line 54

def default_profile
  config_setup '.' unless config
  if config && config.
    begin
      find_profile config., config.profile
    rescue Exception => e
      if e.to_s.include? 'No connection'
         config.username, config.password if config.username && config.password
        find_profile config., config.profile
      end
    end
  end
end

.find_profile(account_id_or_name, profile_id_or_name = nil) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/rugalytics.rb', line 39

def find_profile , profile_id_or_name=nil
  begin
    Profile.find , profile_id_or_name
  rescue NameError => e
    raise 'No connection - call Rugalytics.login(<username>,<password>)'
  end
end

.i18n_date_parse(text) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/rugalytics.rb', line 83

def i18n_date_parse text
  if text.include? ''
    text = text.sub('','-')
    text = text.sub('','-')
    text = text.sub('','')
  end
  begin
    Date.parse(text)
  rescue Exception => e
    raise "#{e}: #{text}"
  end
end

.load_config(filename) ⇒ Object



78
79
80
81
# File 'lib/rugalytics.rb', line 78

def load_config filename
  hash = YAML.load_file(filename)
  OpenStruct.new(hash)
end

.login(username, password) ⇒ Object



35
36
37
# File 'lib/rugalytics.rb', line 35

def  username, password
  Google::Base.establish_connection(username, password)
end

.reportsObject



47
48
49
50
51
52
# File 'lib/rugalytics.rb', line 47

def reports
  profile = Rugalytics.default_profile
  names = profile.report_names
  puts names
  names.collect {|n| puts ''; puts n; profile.send(n.to_sym)}
end