diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..806badf --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,6 @@ +Metrics/MethodLength: + Max: 13 + +AllCops: + NewCops: disable + TargetRubyVersion: 3.0 diff --git a/README.md b/README.md index a2966ac..2f71d3c 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,9 @@ If bundler is not being used to manage dependencies, install the gem by executin ## Usage -This gem provides access to the Zephyr Scale REST API. +To get started all you need to do is set your zephyr API access token and instantiate the client. + +For API endpoint usage see the official REST API documentation [here](https://support.smartbear.com/zephyr-scale-cloud/api-docs/#section/Introduction). ```ruby require 'zephyr_ruby' diff --git a/lib/zephyr_ruby/client.rb b/lib/zephyr_ruby/client.rb index ad14317..a261d2a 100644 --- a/lib/zephyr_ruby/client.rb +++ b/lib/zephyr_ruby/client.rb @@ -16,6 +16,7 @@ require_relative 'connection' require 'faraday' +require 'faraday/multipart' require 'json' module ZephyrRuby @@ -39,7 +40,11 @@ class Client def initialize(api_token) @base_url = 'https://api.zephyrscale.smartbear.com/v2' @api_token = api_token - @client = Faraday.new(@base_url, builder: build_middleware) + @client = Faraday.new(@base_url) do |f| + f.request :multipart + f.request :url_encoded + f.adapter Faraday.default_adapter + end @headers = { 'Authorization' => "Bearer #{@api_token}", 'Content-Type' => 'application/json' diff --git a/lib/zephyr_ruby/connection.rb b/lib/zephyr_ruby/connection.rb index 069b515..51c655b 100644 --- a/lib/zephyr_ruby/connection.rb +++ b/lib/zephyr_ruby/connection.rb @@ -8,8 +8,21 @@ def get(path, params = {}) request :get, path, params end - def post(path, body) - body = body.to_json if body.is_a?(Hash) + def post(path, body, file_path = nil) + if file_path + mime_type = case File.extname(file_path).downcase + when '.json' then 'application/json' + when '.xml' then 'application/xml' + when '.zip' then 'application/zip' + else 'application/octet-stream' + end + + file = Faraday::UploadIO.new(file_path, mime_type) + body = { file: file }.merge(body) if body.is_a?(Hash) + elsif body.is_a?(Hash) + body = body.to_json + end + request :post, path, body end diff --git a/lib/zephyr_ruby/resource/test_executions.rb b/lib/zephyr_ruby/resource/test_executions.rb index 95941af..d71d3a3 100644 --- a/lib/zephyr_ruby/resource/test_executions.rb +++ b/lib/zephyr_ruby/resource/test_executions.rb @@ -28,6 +28,26 @@ def create_test_execution_link(test_execution_id, body) def update_test_execution(test_execution_id, body) put "/testexecutions/#{test_execution_id}", body end + + def get_test_steps(test_execution_id) + get "/testexecutions/#{test_execution_id}/teststeps" + end + + def update_test_steps(test_execution_id, body) + put "/testexecutions/#{test_execution_id}/teststeps", body + end + + def sync_test_execution(test_execution_id) + post "/testexecutions/#{test_execution_id}/teststeps/sync" + end + + def get_test_execution_links(test_execution_id) + get "/testexecutions/#{test_execution_id}/links" + end + + def create_test_execution_issue_link(test_execution_id, body) + post "/testexecutions/#{test_execution_id}/links/issues", body + end end end end diff --git a/lib/zephyr_ruby/version.rb b/lib/zephyr_ruby/version.rb index cc58d67..d01f517 100644 --- a/lib/zephyr_ruby/version.rb +++ b/lib/zephyr_ruby/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module ZephyrRuby - VERSION = '0.4.0' + VERSION = '0.5.0' end diff --git a/zephyr_ruby-0.3.0.gem b/zephyr_ruby-0.3.0.gem deleted file mode 100644 index f9d55f5..0000000 Binary files a/zephyr_ruby-0.3.0.gem and /dev/null differ diff --git a/zephyr_ruby-0.4.0.gem b/zephyr_ruby-0.4.0.gem new file mode 100644 index 0000000..2b4b519 Binary files /dev/null and b/zephyr_ruby-0.4.0.gem differ diff --git a/zephyr_ruby.gemspec b/zephyr_ruby.gemspec index c001493..b1c4882 100644 --- a/zephyr_ruby.gemspec +++ b/zephyr_ruby.gemspec @@ -10,11 +10,9 @@ Gem::Specification.new do |spec| spec.summary = 'Zephyr REST API Client for Ruby' spec.description = "Allows users to use Zephyr's REST API" spec.license = 'MIT' - spec.required_ruby_version = '>= 2.6.0' - spec.homepage = 'https://github.com/chrisdavis180/zephyr_ruby' + spec.required_ruby_version = '>= 3.0' + spec.homepage = 'https://github.com/cdavis-personal/zephyr_ruby' - # Specify which files should be added to the gem when it is released. - # The `git ls-files -z` loads the files in the RubyGem that have been added into git. spec.files = Dir.chdir(__dir__) do `git ls-files -z`.split("\x0").reject do |f| (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)}) @@ -27,7 +25,4 @@ Gem::Specification.new do |spec| spec.add_dependency 'faraday', '~> 1.7', '>= 1.7.0' spec.add_dependency 'json', '~> 2.3', '>= 2.3.0' spec.add_dependency 'rspec', '~> 3.7', '>= 3.7.0' - - # For more information and examples about making a new gem, check out our - # guide at: https://bundler.io/guides/creating_gem.html end