Sha256: 3a2bdd4d4142a786eb6961855054c1e9ed34745b45633b3bd664922c2fe03db7
Contents?: true
Size: 972 Bytes
Versions: 11
Compression:
Stored size: 972 Bytes
Contents
require 'httparty' require 'cgi' module Gurney class Api def initialize(base_url:, token:) @base_url = base_url @token = token end def post_dependencies(dependencies:, branch:, project_id:) data = { dependencies: dependencies } url = base_url url.gsub! '<project_id>', CGI.escape(project_id) url.gsub! '<branch>', CGI.escape(branch) post_json(url, data.to_json) end private attr_reader :base_url, :token def post_json(url, json) response = HTTParty.post(url, body: json, headers: { 'X-AuthToken' => @token, 'Content-Type': 'application/json'}, ) unless response.success? if response.code == 404 raise ApiError.new("#{response.code} api url is probably wrong") else raise ApiError.new("#{response.code} #{response.body}") end end end end class ApiError < Exception end end
Version data entries
11 entries across 11 versions & 1 rubygems