Sha256: a645e88455fb8217fcc20e82d8ed7f60239d0c48784690e2be3569b351ec0edb

Contents?: true

Size: 1.94 KB

Versions: 2

Compression:

Stored size: 1.94 KB

Contents

# frozen_string_literal: true

require_relative 'resource/automations'
require_relative 'resource/environments'
require_relative 'resource/folders'
require_relative 'resource/healthcheck'
require_relative 'resource/links'
require_relative 'resource/priorities'
require_relative 'resource/projects'
require_relative 'resource/statuses'
require_relative 'resource/test_cases'
require_relative 'resource/test_cycles'
require_relative 'resource/test_executions'
require_relative 'resource/test_plans'
require_relative 'connection'

require 'faraday'
require 'json'

module ZephyrRuby
  # Client provides methods for interacting with all zephyr scale endpoints
  class Client
    include ZephyrRuby::Client::Resource::Automations
    include ZephyrRuby::Client::Resource::Environments
    include ZephyrRuby::Client::Resource::Folders
    include ZephyrRuby::Client::Resource::HealthCheck
    include ZephyrRuby::Client::Resource::Links
    include ZephyrRuby::Client::Resource::Priorities
    include ZephyrRuby::Client::Resource::Projects
    include ZephyrRuby::Client::Resource::Statuses
    include ZephyrRuby::Client::Resource::TestCases
    include ZephyrRuby::Client::Resource::TestCycles
    include ZephyrRuby::Client::Resource::TestExecutions
    include ZephyrRuby::Client::Resource::TestPlans
    include ZephyrRuby::Connection

    def initialize(api_token)
      @base_url = 'https://api.zephyrscale.smartbear.com/v2'
      @api_token = api_token
      @client = Faraday.new(@base_url, builder: build_middleware)
      @headers = {
        'Authorization' => "Bearer #{@api_token}",
        'Content-Type' => 'application/json'
      }
    end

    attr_reader :base_url

    def request(method, path, params, headers = @headers)
      path = URI.parse("#{@base_url}#{path}").normalize.to_s
      @client.send(method, path, params, headers)
    end

    def build_middleware
      Faraday::RackBuilder.new do |builder|
        builder.response :json
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
zephyr_ruby-0.2.0 lib/zephyr_ruby/client.rb
zephyr_ruby-0.1.0 lib/zephyr_ruby/client.rb