Sha256: 728fc773fcdf750309eae0aebcff40c91b3d949cd73702c4569de2ec0df52258
Contents?: true
Size: 1.16 KB
Versions: 1
Compression:
Stored size: 1.16 KB
Contents
require 'httparty' require 'json' module Mortise class Checker attr_reader :url, :tenon_uri, :key def initialize(url, key, options = {}) options = defaults.merge(options) @url = url @key = key @tenon_uri = options[:tenon_uri] end def raw @raw ||= JSON.parse response.body end def issues @issues ||= raw['resultSet'].map { |issue| Mortise::Issue.new(issue) } end def errors @errors ||= issues.select { |issue| issue.certainty >= 80 } end def warnings @warnings ||= issues.select { |issue| issue.certainty < 80 } end 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
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
mortise-0.2.0 | lib/mortise/checker.rb |