Skip to content

Commit

Permalink
Updated support for sending files to the automations endpoint (#2)
Browse files Browse the repository at this point in the history
* added new endpoint for updating test executions

* updated ownership

* updated supported for sending files to the automations endpoint

* added new endpoints for executions and updated readme

* updated minor version given all the recent changes

---------

Co-authored-by: Chris Davis <[email protected]>
Co-authored-by: Chris Davis <[email protected]>
  • Loading branch information
3 people authored Aug 14, 2024
1 parent 1b857bf commit d06957c
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 12 deletions.
6 changes: 6 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Metrics/MethodLength:
Max: 13

AllCops:
NewCops: disable
TargetRubyVersion: 3.0
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
7 changes: 6 additions & 1 deletion lib/zephyr_ruby/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
require_relative 'connection'

require 'faraday'
require 'faraday/multipart'
require 'json'

module ZephyrRuby
Expand All @@ -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'
Expand Down
17 changes: 15 additions & 2 deletions lib/zephyr_ruby/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
20 changes: 20 additions & 0 deletions lib/zephyr_ruby/resource/test_executions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/zephyr_ruby/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module ZephyrRuby
VERSION = '0.4.0'
VERSION = '0.5.0'
end
Binary file removed zephyr_ruby-0.3.0.gem
Binary file not shown.
Binary file added zephyr_ruby-0.4.0.gem
Binary file not shown.
9 changes: 2 additions & 7 deletions zephyr_ruby.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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)})
Expand All @@ -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

0 comments on commit d06957c

Please sign in to comment.