Skip to content

Commit

Permalink
feat(dashboard api): add plain text content type for easy debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Jan 29, 2018
1 parent 413f999 commit 317a64d
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
50 changes: 50 additions & 0 deletions lib/pact_broker/api/decorators/dashboard_text_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
require 'ostruct'
require 'pact_broker/api/pact_broker_urls'

module PactBroker
module Api
module Decorators
class DashboardTextDecorator
include PactBroker::Api::PactBrokerUrls

Line = Struct.new(:consumer_name, :c_version, :c_tags , :provider_name, :p_version, :p_tags, :success)

def initialize(index_items)
@index_items = index_items
end

def to_json(options)
to_hash(options).to_json
end

def to_text(options)
data = items(index_items, options[:user_options][:base_url])
printer = TablePrint::Printer.new(data)
printer.table_print
end

private

attr_reader :index_items

def items(index_items, base_url)
index_items.collect do | index_item |
index_item_object(index_item)
end
end

def index_item_object(index_item)
Line.new(
index_item.consumer_name,
index_item.consumer_version_number,
index_item.tag_names.join(", "),
index_item.provider_name,
index_item.provider_version_number,
index_item.latest_verification_latest_tags.collect(&:name).join(", "),
index_item.verification_status.to_s
)
end
end
end
end
end
10 changes: 9 additions & 1 deletion lib/pact_broker/api/resources/dashboard.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'pact_broker/api/resources/base_resource'
require 'pact_broker/api/decorators/dashboard_decorator'
require 'pact_broker/api/decorators/dashboard_text_decorator'

module PactBroker
module Api
Expand All @@ -8,7 +9,10 @@ module Resources
class Dashboard < BaseResource

def content_types_provided
[["application/hal+json", :to_json]]
[
["application/hal+json", :to_json],
["text/plain", :to_text],
]
end

def allowed_methods
Expand All @@ -19,6 +23,10 @@ def to_json
PactBroker::Api::Decorators::DashboardDecorator.new(index_items).to_json(user_options: decorator_context)
end

def to_text
PactBroker::Api::Decorators::DashboardTextDecorator.new(index_items).to_text(user_options: decorator_context)
end

private

def index_items
Expand Down

0 comments on commit 317a64d

Please sign in to comment.