8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/straight-server-kit/resources/order_resource.rb', line 8
def self.for_gateway(gateway_id)
name = "OrderResource_#{gateway_id.to_s.to_sym.object_id}"
return StraightServerKit.const_get(name) if StraightServerKit.const_defined?(name)
klass = Class.new self do
resources do
action :create do
verb :post
path "/gateways/#{gateway_id}/orders"
body do |order|
Order::Mapping.representation_for(:create, order)
end
handler 200 do |response|
Order::Mapping.(response.body, :created)
end
handler &API_ERROR_HANDLER
end
action :find do
verb :get
path "/gateways/#{gateway_id}/orders/:id"
handler 200 do |response|
Order::Mapping.(response.body, :found)
end
handler &API_ERROR_HANDLER
end
action :cancel do
verb :post
path "/gateways/#{gateway_id}/orders/:id/cancel"
handler 200 do
true
end
handler &API_ERROR_HANDLER
end
end
end
StraightServerKit.const_set name, klass
end
|