@@ -9,7 +9,7 @@ def self.format(import, output_format)
99 when "json"
1010 JSON . generate ( import . to_h )
1111 when "pretty"
12- JSON . pretty_generate ( import . to_h )
12+ format_as_pretty ( import )
1313 when "text"
1414 format_as_text ( import )
1515 when "toon"
@@ -24,7 +24,7 @@ def self.format_collection(collection, output_format)
2424 when "json"
2525 JSON . generate ( collection . to_h )
2626 when "pretty"
27- JSON . pretty_generate ( collection . to_h )
27+ format_collection_as_pretty ( collection )
2828 when "text"
2929 format_collection_as_text ( collection )
3030 when "toon"
@@ -34,6 +34,43 @@ def self.format_collection(collection, output_format)
3434 end
3535 end
3636
37+ def self . format_as_pretty ( import )
38+ lines = [ ]
39+ lines << "Import ID: #{ import . id } "
40+ lines << "Status: #{ import . status } "
41+ lines << "Title: #{ import . title } " if import . title
42+ lines << "Format: #{ import . format } " if import . format
43+
44+ if import . entity
45+ entity_type = import . entity [ 'type' ] || import . entity [ :type ]
46+ lines << "Entity Type: #{ entity_type } " if entity_type
47+ end
48+
49+ lines << "Count: #{ import . count } " if import . count
50+
51+ if import . failed?
52+ lines << ""
53+ lines << "Failure:"
54+ lines << " Reason: #{ import . failed_reason } " if import . failed_reason
55+ lines << " Message: #{ import . failed_message } " if import . failed_message
56+ lines << " Failed At: #{ import . failed_at } " if import . failed_at
57+ end
58+
59+ if import . upload_url
60+ lines << ""
61+ lines << "Upload:"
62+ lines << " URL: #{ import . upload_url } "
63+ lines << " Valid Until: #{ import . upload_valid_until } " if import . upload_valid_until
64+ end
65+
66+ lines << ""
67+ lines << "Created: #{ import . created_at } " if import . created_at
68+ lines << "Updated: #{ import . updated_at } " if import . updated_at
69+
70+ lines . join ( "\n " )
71+ end
72+ private_class_method :format_as_pretty
73+
3774 def self . format_as_text ( import )
3875 lines = [ ]
3976 lines << "Import: #{ import . id } "
@@ -68,6 +105,37 @@ def self.format_as_text(import)
68105 end
69106 private_class_method :format_as_text
70107
108+ def self . format_collection_as_pretty ( collection )
109+ lines = [ ]
110+ lines << "Imports (#{ collection . data . length } items)"
111+ lines << ""
112+
113+ collection . data . each_with_index do |imp , idx |
114+ lines << "" if idx > 0 # Blank line between imports
115+
116+ lines << "Import ID: #{ imp . id } "
117+ lines << "Status: #{ imp . status } "
118+ lines << "Title: #{ imp . title } " if imp . title
119+ lines << "Format: #{ imp . format } " if imp . format
120+ lines << "Entity Type: #{ imp . entity [ 'type' ] } " if imp . entity && imp . entity [ 'type' ]
121+ lines << "Count: #{ imp . count } " if imp . count
122+ lines << "Created: #{ imp . created_at } " if imp . created_at
123+ lines << "Updated: #{ imp . updated_at } " if imp . updated_at
124+
125+ if imp . status == 'failed'
126+ lines << "Failed Reason: #{ imp . failed_reason } " if imp . failed_reason
127+ end
128+ end
129+
130+ if collection . has_more
131+ lines << ""
132+ lines << "Next Cursor: #{ collection . next_cursor } "
133+ end
134+
135+ lines . join ( "\n " )
136+ end
137+ private_class_method :format_collection_as_pretty
138+
71139 def self . format_collection_as_text ( collection )
72140 lines = [ "Imports (#{ collection . data . length } items):" ]
73141 collection . data . each do |imp |
0 commit comments