Class: GoogleSpreadSheet

Inherits:
Object
  • Object
show all
Defined in:
lib/roo/google.rb

Constant Summary collapse

GOOGLE_LOGIN_URL =
URI.parse('https://www.google.com/accounts/ClientLogin')

Instance Method Summary collapse

Constructor Details

#initialize(spreadsheet_key) ⇒ GoogleSpreadSheet

Returns a new instance of GoogleSpreadSheet.



23
24
25
26
27
# File 'lib/roo/google.rb', line 23

def initialize(spreadsheet_key)
  @spreadsheet_key = spreadsheet_key
  @headers = nil
  @default_sheet = nil
end

Instance Method Details

#add_to_cell(formula) ⇒ Object

puts entry(formula)



67
68
69
# File 'lib/roo/google.rb', line 67

def add_to_cell(formula)    #puts entry(formula)
  set_entry(entry(formula))
end

#authenticate(email, password) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/roo/google.rb', line 33

def authenticate(email, password)
  $VERBOSE = nil
  response = Net::HTTPS.post_form(GOOGLE_LOGIN_URL,
    {'Email'   => email,
     'Passwd'  => password,
     'source'  => "formula",
     'service' => 'wise' })
  @headers = {     'Authorization' => "GoogleLogin auth=#{response.body.split(/=/).last}",
   'Content-Type'  => 'application/atom+xml'
  }
end

#default_sheet=(numberofsheet) ⇒ Object



29
30
31
# File 'lib/roo/google.rb', line 29

def default_sheet=(numberofsheet)
  @default_sheet = numberofsheet
end

#entry(formula, row = 1, col = 1) ⇒ Object



58
59
60
61
62
63
64
65
# File 'lib/roo/google.rb', line 58

def entry(formula, row=1, col=1)
  <<XML
<?xml version='1.0' ?>
<entry xmlns='http://www.w3.org/2005/Atom' xmlns:gs='http://schemas.google.com/spreadsheets/2006'>
<gs:cell row='#{row}' col='#{col}' inputValue='=#{formula}' />
</entry>
XML
end

#evaluate_cell(cell) ⇒ Object



45
46
47
48
49
50
# File 'lib/roo/google.rb', line 45

def evaluate_cell(cell)
  path = "/feeds/cells/#{@spreadsheet_key}/#{@default_sheet}/#{@headers ? "private" : "public"}/basic/#{cell}"

  doc = Hpricot(request(path))
  result = (doc/"content[@type='text']").inner_html
end

#set_entry(entry) ⇒ Object



52
53
54
55
56
# File 'lib/roo/google.rb', line 52

def set_entry(entry)
  path = "/feeds/cells/#{@spreadsheet_key}/#{@default_sheet}/#{@headers ? 'private' : 'public'}/full"

  post(path, entry)
end