Class: Dropbox::API::Raw

Inherits:
Object
  • Object
show all
Defined in:
lib/dropbox-api/client/raw.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Raw

Returns a new instance of Raw.



8
9
10
# File 'lib/dropbox-api/client/raw.rb', line 8

def initialize(options = {})
  @connection = options[:connection]
end

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



6
7
8
# File 'lib/dropbox-api/client/raw.rb', line 6

def connection
  @connection
end

Class Method Details

.add_method(method, action, options = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/dropbox-api/client/raw.rb', line 12

def self.add_method(method, action, options = {})
  # Add the default root bit, but allow it to be disabled by a config option
  root = options[:root] == false ? '' : "options[:root] ||= Dropbox::API::Config.mode"
  self.class_eval <<-STR
    def #{options[:as] || action}(options = {})
      #{root}
      request(:#{options[:endpoint] || 'main'}, :#{method}, "#{action}", options)
    end
  STR
end

Instance Method Details

#request(endpoint, method, action, data = {}) ⇒ Object



23
24
25
26
27
28
# File 'lib/dropbox-api/client/raw.rb', line 23

def request(endpoint, method, action, data = {})
  action.sub! ':root', data.delete(:root) if action.match ':root'
  action.sub! ':path', Dropbox::API::Util.escape(data.delete(:path)) if action.match ':path'
  action = Dropbox::API::Util.remove_double_slashes(action)
  connection.send(method, endpoint, action, data)
end