module TmSearch
Constants
- STYLE_TITLE
Public Instance Methods
Source
# File lib/tm_search.rb, line 47 def format_search(query, result) lines = [ IrcFormat.report_header(tag: "TM", title: query.to_s, style: STYLE_TITLE) ] if result[:count].zero? lines << "No registered trade marks found for that term." else lines << "#{result[:count]} matching trade mark(s) found." end lines << IrcFormat.report_footer("IP Australia trade mark search") lines.join("\n") end
Source
# File lib/tm_search.rb, line 34 def parse_results(payload) marks = Array(payload["tradeMarkIds"] || payload["results"] || payload["tradeMarks"]) { count: payload["totalCount"].to_i.positive? ? payload["totalCount"].to_i : marks.length, marks: marks } end
Source
# File lib/tm_search.rb, line 42 def registered?(query, api_key:, fetch: nil) result = search(query, api_key: api_key, fetch: fetch) result[:count].positive? end
Source
# File lib/tm_search.rb, line 17 def search(query, api_key:, fetch: nil) url = search_url body = { query: query.to_s.strip, searchType: "WORD" }.to_json headers = { "Content-Type" => "application/json", "apikey" => api_key } response = if fetch fetch.call(url, method: :post, body: body, headers: headers) else RabbotHttp.fetch(url, user_agent: "Rabbot/1.0") end parse_results(JSON.parse(response)) rescue StandardError { count: 0, marks: [] } end
Source
# File lib/tm_search.rb, line 13 def search_url "#{TmConfig::API_BASE}/search/quick" end