Module: Wordpress::API::Utils

Included in:
Me, Posts, Sites, Tests
Defined in:
lib/wordpress/api/utils.rb

Instance Method Summary collapse

Instance Method Details

#object_from_response(obj, request) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/wordpress/api/utils.rb', line 11

def object_from_response(obj, request)
  res = call(request, :bearer_token_request => true)
  begin
    json = MultiJson.load(res)
    if json.nil? || json == ''
      raise Wordpress::ResponseError
    end
    if !json['error'].nil?
      raise Wordpress::ResponseError, json
    end
    obj.assign(json)
  rescue MultiJson::LoadError => e
    raise Wordpress::ResponseError, {'error' => e, 'message' => "Can not parse the response: #{res.inspect}"}
  end
end