Class: YamlRpc::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/yamlrpc/client.rb

Constant Summary collapse

DEFAULT_FORM_DATA_ROOT =
:yamlrpc
DEFAULT_OPEN_TIMEOUT =

2 minutes

120
DEFAULT_READ_TIMEOUT =

2 minutes

120

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, options = {}) ⇒ Client

  • uri Root url, ie. “my.com/something/”; YamlRpc#some_method(:foo => ‘bar’) will POST to my.com/something/some_method with { :foo => ‘bar’ } params

  • options

    • :form_data_root Default to :yamlrpc, meaning all params are passed inside :yamlrpc form field

    • :open_timeout Open timeout

    • :read_timeout Read timeout

    • :user Basic http auth, user name

    • :password Basic http auth, password



51
52
53
54
55
56
57
58
59
# File 'lib/yamlrpc/client.rb', line 51

def initialize(uri, options = {})
  @open_timeout   = options[:open_timeout]
  @read_timeout   = options[:read_timeout]
  @user           = options[:user]
  @password       = options[:password]
  @permanent_data = options[:permanent_data]
  @uri            = URI.parse(uri.to_s)
  @form_data_root = options[:form_data_root] || DEFAULT_FORM_DATA_ROOT
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(uri, *args) ⇒ Object

  • uri Method name (mainly) or full uri (to support redirects to other domains)

  • args Arguments, nil or Hash of values



63
64
65
66
67
68
69
70
71
72
# File 'lib/yamlrpc/client.rb', line 63

def method_missing(uri, *args)
  args = args.first if args.size == 1 && args.first.is_a?(Hash)
  uri = URI.parse(uri.to_s)
  if uri.host.nil?
    uri.host = @uri.host
    uri.port = @uri.port
  end
  uri.path = "#{@uri.path}#{uri.path}" unless uri.path =~ /^\//
  post(uri, args)
end

Instance Attribute Details

#form_data_rootObject

Returns the value of attribute form_data_root.



37
38
39
# File 'lib/yamlrpc/client.rb', line 37

def form_data_root
  @form_data_root
end

#open_timeoutObject

Returns the value of attribute open_timeout.



38
39
40
# File 'lib/yamlrpc/client.rb', line 38

def open_timeout
  @open_timeout
end

#passwordObject

Returns the value of attribute password.



41
42
43
# File 'lib/yamlrpc/client.rb', line 41

def password
  @password
end

#permanent_dataObject

Returns the value of attribute permanent_data.



42
43
44
# File 'lib/yamlrpc/client.rb', line 42

def permanent_data
  @permanent_data
end

#read_timeoutObject

Returns the value of attribute read_timeout.



39
40
41
# File 'lib/yamlrpc/client.rb', line 39

def read_timeout
  @read_timeout
end

#uriObject

Returns the value of attribute uri.



36
37
38
# File 'lib/yamlrpc/client.rb', line 36

def uri
  @uri
end

#userObject

Returns the value of attribute user.



40
41
42
# File 'lib/yamlrpc/client.rb', line 40

def user
  @user
end