Class: NicInfo::CommonJson
- Inherits:
-
Object
- Object
- NicInfo::CommonJson
- Defined in:
- lib/nicinfo/common_json.rb
Overview
deals with common JSON RDAP structures
Instance Method Summary collapse
- #display_as_events_actors(asEventActors) ⇒ Object
- #display_events(objectclass) ⇒ Object
- #display_links(cn, objectclass) ⇒ Object
- #display_port43(objectclass) ⇒ Object
- #display_public_ids(objectclass) ⇒ Object
- #display_remarks(objectclass) ⇒ Object
- #display_simple_links(links) ⇒ Object
- #display_status(objectclass) ⇒ Object
- #display_string_array(json_name, display_name, json_data, data_amount) ⇒ Object
-
#initialize(config) ⇒ CommonJson
constructor
A new instance of CommonJson.
- #process_entities(objectclass) ⇒ Object
Constructor Details
#initialize(config) ⇒ CommonJson
Returns a new instance of CommonJson.
62 63 64 |
# File 'lib/nicinfo/common_json.rb', line 62 def initialize config @config = config end |
Instance Method Details
#display_as_events_actors(asEventActors) ⇒ Object
177 178 179 180 181 182 183 184 |
# File 'lib/nicinfo/common_json.rb', line 177 def display_as_events_actors asEventActors asEventActors.each do |asEventActor| item_name = NicInfo::capitalize( asEventActor.eventAction ) item_value = Time.parse( asEventActor.eventDate ).rfc2822 item_value << " by #{asEventActor.entity_cn}" @config.logger.datum item_name, item_value end end |
#display_events(objectclass) ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/nicinfo/common_json.rb', line 158 def display_events objectclass events = objectclass[ "events" ] if events if events.instance_of?( Array ) events.each do |event| item_name = NicInfo::capitalize( event[ "eventAction" ] ) item_value = Time.parse( event[ "eventDate" ] ).rfc2822 actor = event[ "eventActor" ] if actor item_value << " by #{actor}" end @config.logger.datum item_name, item_value end else @config.conf_msgs << "'events' is not an array." end end end |
#display_links(cn, objectclass) ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/nicinfo/common_json.rb', line 145 def display_links cn, objectclass links = NicInfo::get_links objectclass, @config if links @config.logger.extra "Links", "-- for #{cn} --" @config.logger.extra "Reference", NicInfo::get_self_link( links ) @config.logger.extra "More", NicInfo::get_alternate_link( links ) @config.logger.extra "About", NicInfo::get_about_link( links ) @config.logger.extra "TOS", NicInfo::get_tos_link( links ) @config.logger.extra "(C)", NicInfo::get_copyright_link( links ) @config.logger.extra "License", NicInfo::get_license_link( links ) end end |
#display_port43(objectclass) ⇒ Object
141 142 143 |
# File 'lib/nicinfo/common_json.rb', line 141 def display_port43 objectclass @config.logger.extra "Port 43 Whois", objectclass[ "port43" ] end |
#display_public_ids(objectclass) ⇒ Object
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/nicinfo/common_json.rb', line 186 def display_public_ids objectclass public_ids = objectclass[ "publicIds" ] if public_ids if public_ids.instance_of?( Array ) public_ids.each do |public_id| if public_id.instance_of?( Hash ) item_name = "Public ID" item_value = public_id[ "identifier" ] = public_id[ "type" ] item_value << " (#{authority})" if @config.logger.datum item_name, item_value else @config.conf_msgs << "public id in array 'publicIds' is not an object." end end else @config.conf_msgs << "'publicIds' is not an array." end end end |
#display_remarks(objectclass) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/nicinfo/common_json.rb', line 77 def display_remarks objectclass remarks = objectclass[ "remarks" ] if remarks excessive_notice = @config.factory.new_notices.is_excessive_notice(remarks) if (excessive_notice && (@config.logger.data_amount != NicInfo::DataAmount::EXTRA_DATA)) @config.logger.datum "Excessive Remarks", "Use \"-V\" or \"--data extra\" to see them." else if remarks.instance_of?(Array) remarks.each do |remark| if remark.instance_of?(Hash) title = remark["title"] @config.logger.datum "Remarks", "-- #{title} --" if title descriptions = NicInfo::get_descriptions remark, @config i = 1 descriptions.each do |line| if !title && i == 1 @config.logger.datum "Remarks", line elsif i != 1 || title @config.logger.datum i.to_s, line end i = i + 1 end if descriptions links = NicInfo::get_links remark, @config if links @config.logger.datum "More", NicInfo::get_alternate_link(links) @config.logger.datum "About", NicInfo::get_about_link(links) @config.logger.datum "TOS", NicInfo::get_tos_link(links) @config.logger.datum "(C)", NicInfo::get_copyright_link(links) @config.logger.datum "License", NicInfo::get_license_link(links) end else @config.conf_msgs << "remark is not an object." end end else @config.conf_msgs << "'remarks' is not an array." end end end end |
#display_simple_links(links) ⇒ Object
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/nicinfo/common_json.rb', line 207 def display_simple_links links if links if links.instance_of?( Array ) alternate = NicInfo.get_alternate_link links @config.logger.prose NicInfo::DataAmount::NORMAL_DATA, "More", alternate, NicInfo::AttentionType::SECONDARY if alternate about = NicInfo.get_about_link links @config.logger.prose NicInfo::DataAmount::NORMAL_DATA, "About", about, NicInfo::AttentionType::SECONDARY if about tos = NicInfo.get_tos_link links @config.logger.prose NicInfo::DataAmount::NORMAL_DATA, "TOS", tos, NicInfo::AttentionType::SECONDARY if tos copyright = NicInfo.get_copyright_link links @config.logger.prose NicInfo::DataAmount::NORMAL_DATA, "(C)", copyright, NicInfo::AttentionType::SECONDARY if copyright license = NicInfo.get_license_link links @config.logger.prose NicInfo::DataAmount::NORMAL_DATA, "License", license, NicInfo::AttentionType::SECONDARY if license else @config.conf_msgs << "'links' is not an array." end end end |
#display_status(objectclass) ⇒ Object
137 138 139 |
# File 'lib/nicinfo/common_json.rb', line 137 def display_status objectclass display_string_array "status", "Status", objectclass, DataAmount::NORMAL_DATA end |
#display_string_array(json_name, display_name, json_data, data_amount) ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/nicinfo/common_json.rb', line 118 def display_string_array json_name, display_name, json_data, data_amount arr = json_data[ json_name ] if arr if arr.instance_of?( Array ) new_arr = Array.new arr.each do |str| if str.instance_of?( String ) new_arr << NicInfo::capitalize( str ) else @config.conf_msgs << "value in string array is not a string." end end @config.logger.info data_amount, display_name, new_arr.join( ", " ) else @config.conf_msgs << "'#{json_name}' is not an array." end end end |
#process_entities(objectclass) ⇒ Object
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/nicinfo/common_json.rb', line 66 def process_entities objectclass entities = Array.new json_entities = NicInfo::get_entitites( objectclass ) json_entities.each do |json_entity| entity = @config.factory.new_entity entity.process( json_entity ) entities << entity end if json_entities return entities end |