Module: TyphoeusOAuth::ModuleExtension::InstanceMethods

Defined in:
lib/typhoeus_oauth/module_extension.rb

Instance Method Summary collapse

Instance Method Details

#define_remote_method_with_oauth(name, args = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/typhoeus_oauth/module_extension.rb', line 15

def define_remote_method_with_oauth(name, args = {})
  @remote_defaults  ||= {}
  
  # allow user to set :oauth_consumer to nil for non-oauth request
  args[:oauth_consumer] = @remote_defaults[:oauth_consumer] unless args.has_key? :oauth_consumer
  args[:oauth_token] = @remote_defaults[:oauth_token] unless args.has_key? :oauth_token
  
  define_remote_method_without_oauth(name, args.reject {|k,v| v.nil?}  )
end

#remote_proxy_object_with_oauth(url, method, options) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/typhoeus_oauth/module_extension.rb', line 25

def remote_proxy_object_with_oauth(url, method, options)
  unless options.has_key? :oauth_consumer
    remote_proxy_object_without_oauth(url, method, options)
  else
    easy = Typhoeus.get_easy_object

    easy.url                   = url
    easy.method                = method
    easy.headers               = options[:headers] if options.has_key?(:headers)
    easy.headers["User-Agent"] = (options[:user_agent] || Typhoeus::USER_AGENT)
    easy.params                = options[:params] if options[:params]
    easy.request_body          = options[:body] if options[:body]
    easy.timeout               = options[:timeout] if options[:timeout]
    if options.has_key?(:oauth_token_key) && options.has_key?(:oauth_token_secret)
      options[:oauth_token] ||= OAuth::AccessToken.new(options[:oauth_consumer], options[:oauth_token_key], options[:oauth_token_secret])
    end
    easy.oauth!(options[:oauth_consumer], options[:oauth_token])
    easy.set_headers

    proxy = Typhoeus::RemoteProxyObject.new(clear_memoized_proxy_objects, easy, options)
    set_memoized_proxy_object(method, url, options, proxy)
  end
end