Class: GoogleSpreadsheets::Base

Inherits:
ActiveResource::Base
  • Object
show all
Defined in:
lib/google_spreadsheets/base.rb

Direct Known Subclasses

List, Spreadsheet, Worksheet

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.access_token(&block) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/google_spreadsheets/base.rb', line 29

def access_token(&block)
  if block_given?
    self.password = block
  else
    password
  end
end

.access_token=(access_token) ⇒ Object



25
26
27
# File 'lib/google_spreadsheets/base.rb', line 25

def access_token=(access_token)
  self.password = access_token
end

.auth_typeObject

Inherit from superclass



17
18
19
20
21
22
23
# File 'lib/google_spreadsheets/base.rb', line 17

def auth_type
  if defined?(@auth_type)
    @auth_type
  elsif superclass != Object && superclass.auth_type
    superclass.auth_type
  end
end

.collection_path(prefix_options = {}, query_options = nil) ⇒ Object



59
60
61
62
# File 'lib/google_spreadsheets/base.rb', line 59

def collection_path(prefix_options = {}, query_options = nil)
  prefix_options, query_options = split_options(prefix_options) if query_options.nil?
  "/feeds/#{collection_name}#{prefix(prefix_options)}#{query_string(query_options)}"
end

.connection(refresh = false) ⇒ Object

Use GoogleSpreadsheets::Connection instead of ActiveResource::Connection



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/google_spreadsheets/base.rb', line 38

def connection(refresh = false)
  if _connection_defined? || self == GoogleSpreadsheets::Base
    self._connection = GoogleSpreadsheets::Connection.new(site, format) if refresh || _connection.nil?
    _connection.proxy = proxy if proxy
    _connection.user = user if user
    _connection.password = password if password
    _connection.auth_type = auth_type if auth_type
    _connection.timeout = timeout if timeout
    _connection.open_timeout = open_timeout if open_timeout
    _connection.read_timeout = read_timeout if read_timeout
    _connection.ssl_options = ssl_options if ssl_options
    _connection
  else
    superclass.connection
  end
end

.custom_method_collection_url(method_name, options = {}) ⇒ Object

Raises:



63
# File 'lib/google_spreadsheets/base.rb', line 63

def custom_method_collection_url(method_name, options = {}) raise NotSupportedError.new end

.delete(id, options = {}) ⇒ Object

Raises:



64
# File 'lib/google_spreadsheets/base.rb', line 64

def delete(id, options = {})  raise NotSupportedError.new end

.element_path(id, prefix_options = {}, query_options = nil) ⇒ Object



55
56
57
58
# File 'lib/google_spreadsheets/base.rb', line 55

def element_path(id, prefix_options = {}, query_options = nil)
  prefix_options, query_options = split_options(prefix_options) if query_options.nil?
  "/feeds/#{collection_name}#{prefix(prefix_options)}#{id}#{query_string(query_options)}"
end

.exists?(id, options = {}) ⇒ Boolean

Returns:

  • (Boolean)

Raises:



65
# File 'lib/google_spreadsheets/base.rb', line 65

def exists?(id, options = {}) raise NotSupportedError.new end

.passwordObject

Avoid dup & freeze because of possible replacing with OAuth access token



8
9
10
11
12
13
14
# File 'lib/google_spreadsheets/base.rb', line 8

def password
  if _password_defined?
    _password
  elsif superclass != Object && superclass.password
    superclass.password
  end
end

Instance Method Details

#custom_method_element_url(method_name, options = {}) ⇒ Object

Raises:



68
# File 'lib/google_spreadsheets/base.rb', line 68

def custom_method_element_url(method_name, options = {})     raise NotSupportedError.new end

#custom_method_new_element_url(method_name, options = {}) ⇒ Object

Raises:



69
# File 'lib/google_spreadsheets/base.rb', line 69

def custom_method_new_element_url(method_name, options = {}) raise NotSupportedError.new end

#destroyObject



71
# File 'lib/google_spreadsheets/base.rb', line 71

def destroy() connection.delete(edit_path, self.class.headers) end

#encode(options = {}) ⇒ Object

Fix for degradation cf. github.com/rails/activeresource/pull/94



75
76
77
# File 'lib/google_spreadsheets/base.rb', line 75

def encode(options={})
  self.class.format.encode(attributes, {:root => self.class.element_name}.merge(options))
end