Module: Restforce::Concerns::Verbs

Included in:
API, BatchAPI, CompositeAPI
Defined in:
lib/restforce/concerns/verbs.rb

Instance Method Summary collapse

Instance Method Details

#define_api_verb(verb) ⇒ Object

Internal: Defines a method to handle HTTP requests with the passed in verb to a salesforce api endpoint.

verb - Symbol name of the verb (e.g. :get).

Examples

define_api_verb :get
# => api_get 'sobjects'

Returns nil.



60
61
62
63
64
65
# File 'lib/restforce/concerns/verbs.rb', line 60

def define_api_verb(verb)
  define_method :"api_#{verb}" do |*args, &block|
    args[0] = api_path(args[0])
    send(verb, *args, &block)
  end
end

#define_verb(verb) ⇒ Object

Internal: Defines a method to handle HTTP requests with the passed in verb.

verb - Symbol name of the verb (e.g. :get).

Examples

define_verb :get
# => get '/services/data/v24.0/sobjects'

Returns nil.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/restforce/concerns/verbs.rb', line 33

def define_verb(verb)
  define_method verb do |*args, &block|
    retries = options[:authentication_retries]
    begin
      connection.send(verb, *args, &block)
    rescue Restforce::UnauthorizedError
      if retries.positive?
        retries -= 1
        connection.url_prefix = options[:instance_url]
        retry
      end
      raise
    end
  end
end

#define_verbs(*verbs) ⇒ Object

Internal: Define methods to handle a verb.

verbs - A list of verbs to define methods for.

Examples

define_verbs :get, :post

Returns nil.



15
16
17
18
19
20
# File 'lib/restforce/concerns/verbs.rb', line 15

def define_verbs(*verbs)
  verbs.each do |verb|
    define_verb(verb)
    define_api_verb(verb)
  end
end