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

Version Path
gurney_client-0.3.0 lib/gurney/api.rb
gurney_client-0.2.3 lib/gurney/api.rb
gurney_client-0.2.2 lib/gurney/api.rb
gurney_client-0.2.1 lib/gurney/api.rb
gurney_client-0.2.0 lib/gurney/api.rb
gurney_client-0.1.6 lib/gurney/api.rb
gurney_client-0.1.5 lib/gurney/api.rb
gurney_client-0.1.4 lib/gurney/api.rb
gurney_client-0.1.3 lib/gurney/api.rb
gurney_client-0.1.2 lib/gurney/api.rb
gurney_client-0.1.1 lib/gurney/api.rb