1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/actionwebservice/lib/action_web_service/client/base.rb
Leon Breedt 5f3f44e76f ensure clients can handle APIs with named parameter signatures,
and test for this


git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@680 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2005-02-19 09:07:35 +00:00

39 lines
993 B
Ruby

module ActionWebService # :nodoc:
module Client # :nodoc:
class ClientError < StandardError # :nodoc:
end
class Base # :nodoc:
def initialize(api, endpoint_uri)
@api = api
@endpoint_uri = endpoint_uri
end
def method_missing(name, *args) # :nodoc:
call_name = method_name(name)
return super(name, *args) if call_name.nil?
perform_invocation(call_name, args)
end
protected
def perform_invocation(method_name, args) # :nodoc:
raise NotImplementedError, "use a protocol-specific client"
end
private
def method_name(name)
if @api.has_api_method?(name.to_sym)
name.to_s
elsif @api.has_public_api_method?(name.to_s)
@api.api_method_name(name.to_s).to_s
else
nil
end
end
def lookup_class(klass)
klass.is_a?(Hash) ? klass.values[0] : klass
end
end
end
end