lib/siren_client/entity.rb in siren_client-0.3.0 vs lib/siren_client/entity.rb in siren_client-1.0.0

- old
+ new

@@ -14,12 +14,15 @@ if data.class == String unless data.class == String && data.length > 0 raise InvalidURIError, 'An invalid url was passed to SirenClient::Entity.new.' end begin - SirenClient.logger.debug "GET #{data}" - @payload = HTTParty.get(data, @config).parsed_response + resp = generate_raw_response(:get, data, @config) + if resp.parsed_response.nil? + raise InvalidResponseError.new "Response could not be parsed. Code=#{resp.code} Message=\"#{resp.message}\" Body=#{resp.body}" + end + @payload = resp.parsed_response rescue URI::InvalidURIError => e raise InvalidURIError, e.message rescue JSON::ParserError => e raise InvalidResponseError, e.message end @@ -37,12 +40,12 @@ if @entities[i].href.empty? @entities[i] else if next_response_is_raw? disable_raw_response - @entities[i].with_raw_response.go - else + @entities[i].with_raw_response.go + else @entities[i].go end end end @@ -70,11 +73,11 @@ ### Entity sub-links only def go return if self.href.empty? if next_response_is_raw? disable_raw_response - generate_raw_response(self.href, @config) + generate_raw_response(:get, self.href, @config) else self.class.new(self.href, @config) end end @@ -101,10 +104,10 @@ if method_str == underscore_name(key) if next_response_is_raw? disable_raw_response return link.with_raw_response.go else - return link.go + return link.go end end end # Does it match an action, if so return the action. @actions.each do |key, action|