lib/mortise/checker.rb in mortise-0.1.0 vs lib/mortise/checker.rb in mortise-0.2.0

- old
+ new

@@ -13,14 +13,11 @@ @tenon_uri = options[:tenon_uri] end def raw - @raw ||= JSON.parse HTTParty.post(tenon_uri, - body: { url: url, key: key }, - headers: { 'Content-Type' => 'application/x-www-form-urlencoded', - 'Cache-Control' => 'no-cache' }).body + @raw ||= JSON.parse response.body end def issues @issues ||= raw['resultSet'].map { |issue| Mortise::Issue.new(issue) } end @@ -35,8 +32,20 @@ private def defaults { tenon_uri: 'https://tenon.io/api/' } + end + + def response + fail(ERRORS[tenon_response.code], tenon_response.body) if tenon_response.code != 200 + + tenon_response + end + + def tenon_response + @tenon_response ||= HTTParty.post(tenon_uri, body: { url: url, key: key }, + headers: { 'Content-Type' => 'application/x-www-form-urlencoded', + 'Cache-Control' => 'no-cache' }) end end end