Class: Mock::Bandwidth::Decorator

Inherits:
Object
  • Object
show all
Defined in:
lib/mock/bandwidth/decorator.rb

Constant Summary collapse

ENDPOINTS =
{
  messaging_v2: Mock::Bandwidth::Schemas::MessagingV2
}

Class Method Summary collapse

Class Method Details

.call(body, request) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/mock/bandwidth/decorator.rb', line 13

def call(body, request)
  body = JSON.parse(body)

  case request.status
  when 400..600
    return body
  end

  schema = url_from(body, request)
  # return body decorate if needed
  return ENDPOINTS[schema].for(body, request) if schema

  body
end

.url_from(body, request) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/mock/bandwidth/decorator.rb', line 28

def url_from(body, request)
  url = request.url.path

  case url
  when %r{\/api\/v2\/users\/\d+\/messages}
    :messaging_v2
  end
end