Skip to content

Commit 317a64d

Browse files
committed
feat(dashboard api): add plain text content type for easy debugging
1 parent 413f999 commit 317a64d

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
require 'ostruct'
2+
require 'pact_broker/api/pact_broker_urls'
3+
4+
module PactBroker
5+
module Api
6+
module Decorators
7+
class DashboardTextDecorator
8+
include PactBroker::Api::PactBrokerUrls
9+
10+
Line = Struct.new(:consumer_name, :c_version, :c_tags , :provider_name, :p_version, :p_tags, :success)
11+
12+
def initialize(index_items)
13+
@index_items = index_items
14+
end
15+
16+
def to_json(options)
17+
to_hash(options).to_json
18+
end
19+
20+
def to_text(options)
21+
data = items(index_items, options[:user_options][:base_url])
22+
printer = TablePrint::Printer.new(data)
23+
printer.table_print
24+
end
25+
26+
private
27+
28+
attr_reader :index_items
29+
30+
def items(index_items, base_url)
31+
index_items.collect do | index_item |
32+
index_item_object(index_item)
33+
end
34+
end
35+
36+
def index_item_object(index_item)
37+
Line.new(
38+
index_item.consumer_name,
39+
index_item.consumer_version_number,
40+
index_item.tag_names.join(", "),
41+
index_item.provider_name,
42+
index_item.provider_version_number,
43+
index_item.latest_verification_latest_tags.collect(&:name).join(", "),
44+
index_item.verification_status.to_s
45+
)
46+
end
47+
end
48+
end
49+
end
50+
end

lib/pact_broker/api/resources/dashboard.rb

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require 'pact_broker/api/resources/base_resource'
22
require 'pact_broker/api/decorators/dashboard_decorator'
3+
require 'pact_broker/api/decorators/dashboard_text_decorator'
34

45
module PactBroker
56
module Api
@@ -8,7 +9,10 @@ module Resources
89
class Dashboard < BaseResource
910

1011
def content_types_provided
11-
[["application/hal+json", :to_json]]
12+
[
13+
["application/hal+json", :to_json],
14+
["text/plain", :to_text],
15+
]
1216
end
1317

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

26+
def to_text
27+
PactBroker::Api::Decorators::DashboardTextDecorator.new(index_items).to_text(user_options: decorator_context)
28+
end
29+
2230
private
2331

2432
def index_items

0 commit comments

Comments
 (0)