Class: GData::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/gdata/base.rb

Direct Known Subclasses

Spreadsheet

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(service, source, url) ⇒ Base

Returns a new instance of Base.



26
27
28
29
30
# File 'lib/gdata/base.rb', line 26

def initialize(service, source, url)
  @service = service
  @source = source
  @url = url
end

Instance Attribute Details

#serviceObject (readonly)

Returns the value of attribute service.



24
25
26
# File 'lib/gdata/base.rb', line 24

def service
  @service
end

#sourceObject (readonly)

Returns the value of attribute source.



24
25
26
# File 'lib/gdata/base.rb', line 24

def source
  @source
end

#urlObject (readonly)

Returns the value of attribute url.



24
25
26
# File 'lib/gdata/base.rb', line 24

def url
  @url
end

Instance Method Details

#authenticate(email, password) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/gdata/base.rb', line 32

def authenticate(email, password)
  $VERBOSE = nil
  response = Net::HTTPS.post_form(GOOGLE_LOGIN_URL,
    {'Email'   => email,
     'Passwd'  => password,
     'source'  => source,
     'service' => service })

  response.error! unless response.kind_of? Net::HTTPSuccess

  @headers = {
   'Authorization' => "GoogleLogin auth=#{response.body.split(/=/).last}",
   'Content-Type'  => 'application/atom+xml'
  }
end

#get(path) ⇒ Object



53
54
55
# File 'lib/gdata/base.rb', line 53

def get(path)
  response, data = http.get(path, @headers)
end

#httpObject



68
69
70
71
72
# File 'lib/gdata/base.rb', line 68

def http
  conn = Net::HTTP.new(url, 80)
  #conn.set_debug_output $stderr
  conn
end

#post(path, entry) ⇒ Object



57
58
59
# File 'lib/gdata/base.rb', line 57

def post(path, entry)
  http.post(path, entry, @headers)
end

#put(path, entry) ⇒ Object



61
62
63
64
65
66
# File 'lib/gdata/base.rb', line 61

def put(path, entry)
  h = @headers
  h['X-HTTP-Method-Override'] = 'PUT' # just to be nice, add the method override
  
  http.put(path, entry, h)
end

#request(path) ⇒ Object



48
49
50
51
# File 'lib/gdata/base.rb', line 48

def request(path)
  response, data = get(path)
  data
end