lib/teambox-client/teambox.rb
# Decodes response and returns appropriate API object
Decodes response and returns appropriate API object
Decodes response and returns appropriate API object
def api_unwrap(response, request={})
      data = JSON.parse(response.body) rescue nil
      if [200, 201, 202].include? response.response.code.to_i
        raise StandardError.new('Please update your Teambox') unless response.has_key?('type')
        if data['type'] == 'List'
          ResultSet.new(self, request, data['objects'], data['references'])
        else
          Teambox.create_model(data['type'], data, ResultSet.new(self, request, [], []))
        end
      else
        error_list = data ? data['errors'] : {'type' => 'UnknownError', 'message' => data}
        error_list['type'] = error_list['type'][0] if error_list['type'].is_a? Array
        error_list['message'] = error_list['message'][0] if error_list['message'].is_a? Array
        raise APIError.new(response.response.code, error_list)
      end
    end
def api_unwrap ( response , request = { } ) data = JSON . parse ( response . body ) rescue nil if [ 200 , 201 , 202 ] . include? response . response . code . to_i raise StandardError . new ( 'Please update your Teambox' ) unless response . has_key? ( 'type' ) if data [ 'type' ] == 'List' ResultSet . new ( self , request , data [ 'objects' ] , data [ 'references' ] ) else Teambox . create_model ( data [ 'type' ] , data , ResultSet . new ( self , request , [ ] , [ ] ) ) end else error_list = data ? data [ 'errors' ] : { 'type' => 'UnknownError' , 'message' => data } error_list [ 'type' ] = error_list [ 'type' ] [ 0 ] if error_list [ 'type' ] . is_a? Array error_list [ 'message' ] = error_list [ 'message' ] [ 0 ] if error_list [ 'message' ] . is_a? Array raise APIError . new ( response . response . code , error_list ) end end
Decodes response and returns appropriate API object
Decodes response and returns appropriate API object
response
<not_specific>
request
<not_specific>