class Lcoveralls::CoverallsRequest
Encapsulates a Coveralls (coverall.io) HTTP POST request.
Public Class Methods
boundary_chr(index)
click to toggle source
Returns one of the 74 valid MIME boundary characters.
@param index [Integer] Index of the boundary character to fetch. Must be
between 0 and 73. *Note*, although indices between 0 and 73 are valid according to the MIME standard, only indices between 0 and 61 are valid for HTTP headers. If index is outside the range 0 to 73, this method will raise a RuntimeError.
@return [String] a valid MIME boundary character.
# File lib/lcoveralls/coveralls_request.rb, line 50 def self.boundary_chr(index) case index when 0..9 index.to_s when 10..35 ('a'.ord + index - 10).chr when 36..61 ('A'.ord + index - 36).chr when 62..73 "'()+_,-./:=?"[index - 62] else raise "Invalid boundary index #{index}" end end
new(job, path='/api/v1/jobs')
click to toggle source
Initializes a new CoverallsRequest
instance.
@param job [Hash] The fields of a Coveralls API request. Can be any type
that can be passed to +JSON#generate+.
@param path Optional HTTP request path.
Calls superclass method
# File lib/lcoveralls/coveralls_request.rb, line 30 def initialize(job, path='/api/v1/jobs') super path @boundary = (1..70).map { self.class.boundary_chr(rand(62)) }.join set_content_type "multipart/form-data, boundary=#{@boundary}" @body = "--#{@boundary}\r\n" + "Content-Disposition: form-data; name=\"json_file\"; filename=\"json_file\"\r\n" + "Content-Type: application/json\r\n\r\n" + JSON::generate(job) + "\r\n--#{@boundary}--\r\n" end