Class: PartyResource::Route

Inherits:
Object
  • Object
show all
Includes:
Buildable
Defined in:
lib/party_resource/route.rb

Constant Summary collapse

VERBS =
[:get, :post, :put, :delete]

Instance Method Summary collapse

Methods included from Buildable

#builder

Constructor Details

#initialize(options = {}) ⇒ Route

Returns a new instance of Route.



9
10
11
# File 'lib/party_resource/route.rb', line 9

def initialize(options = {})
  @options = transform_options(options)
end

Instance Method Details

#call(context, *args) ⇒ Object

Raises:

  • (ArgumentError)


13
14
15
16
17
18
19
20
21
22
23
# File 'lib/party_resource/route.rb', line 13

def call(context, *args)
  options = args.pop if args.last.is_a?(Hash) && args.size == expected_args.size + 1
  raise ArgumentError, "wrong number of arguments (#{args.size} for #{expected_args.size})" unless expected_args.size == args.size
  begin
    builder.call(parsed_response(context, args, options), context, included(context))
  rescue Exceptions::Error => e
    name = e.class.name.split(/::/).last
    return @options[:rescue][name] if @options[:rescue].has_key?(name)
    raise
  end
end

#connectorObject



29
30
31
# File 'lib/party_resource/route.rb', line 29

def connector
  PartyResource::Connector.lookup(@options[:connector])
end

#parsed_response(context, args, options) ⇒ Object



25
26
27
# File 'lib/party_resource/route.rb', line 25

def parsed_response(context, args, options)
  connector.fetch(request(context, args, options)).parsed_response
end