Class: Lcoveralls::CoverallsRequest
- Inherits:
-
Net::HTTP::Post
- Object
- Net::HTTP::Post
- Lcoveralls::CoverallsRequest
- Defined in:
- lib/lcoveralls/coveralls_request.rb
Overview
Encapsulates a Coveralls (coverall.io) HTTP POST request.
Class Method Summary collapse
-
.boundary_chr(index) ⇒ String
Returns one of the 74 valid MIME boundary characters.
Instance Method Summary collapse
-
#initialize(job, path = '/api/v1/jobs') ⇒ CoverallsRequest
constructor
Initializes a new CoverallsRequest instance.
Constructor Details
#initialize(job, path = '/api/v1/jobs') ⇒ CoverallsRequest
Initializes a new CoverallsRequest instance.
30 31 32 33 34 35 36 37 38 39 |
# 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 |
Class Method Details
.boundary_chr(index) ⇒ String
Returns one of the 74 valid MIME boundary characters.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# 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 |