Class: Basecamp3::ResponseParser

Inherits:
Object
  • Object
show all
Defined in:
lib/basecamp3/response_parser.rb

Overview

The basecamp response parser

Class Method Summary collapse

Class Method Details

.parse(response, model) ⇒ Basecamp3::Model, ...

Parses the given response to the given wrapper model.

Parameters:

  • response (Hash)

    The hash with data which should be parsed to the wrapper model

  • model (Class)

    The class of the model

Returns:

Raises:

  • (StandardError)

    raises an error for unsupported response type



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/basecamp3/response_parser.rb', line 11

def self.parse(response, model)
  case response
  when Hash
    map_object(response, model)
  when Array
    response.map do |item|
      map_object(item, model)
    end
  when NilClass
    nil
  else
    raise 'Unsupported response type'
  end
end