Ads verification

2015-01-27

How to query against Global Brand Database's internal API

I found a interesting question on Quora and tried to answer it.


require 'net/http'
require 'uri'
require 'json'
require 'pp'
 
url = URI.parse('http://www.wipo.int/branddb/jsp/select.jsp')
req = Net::HTTP::Post.new(url.path)
req.body = URI.encode_www_form [
 ['q' , 'BRAND:sushi'],
 ['fl' , 'BRAND,SOURCE,STATUS,score,OO,HOL,ID,AD,VCS,USC,NC,IMG,ID'],
 ['hl' , 'true'],
 ['hl.requireFieldMatch' , 'true'],
 ['hl.fragsize' , '5000'],
 ['type' , 'brand'],
 ['facet' , 'true'],
 ['qi' , '2285-1422386635681'],
 ['json.nl' , 'map'],
 ['wt' , 'json'],
 ['sort' , 'score desc,AD desc'],
 ['rows' , '30'],
 ['start' , '0'],
 ['f.SOURCE.facet.limit' , '50'],
 ['f.SOURCE.facet.mincount' , '1'],
 ['f.STATUS.facet.limit' , '20'],
 ['f.STATUS.facet.mincount' , '1'],
 ['f.OO.facet.mincount' , '1'],
 ['facet.field' , 'SOURCE'],
 ['facet.field' , 'STATUS'],
 ['facet.field' , 'OO'],
 ['facet.query' , 'ITY:VERBAL'],
 ['facet.query'  , 'ITY:NONVERBAL'],
 ['facet.query' , 'ITY:COMBINED'],
 ['facet.query' , 'ITY:UNKNOWN'],
 ['facet.query' , 'ED:[* TO NOW/DAY]'],
 ['facet.query' , 'ED:[NOW/DAY-1MONTH TO NOW/DAY]'],
 ['facet.query' , 'ED:[NOW/DAY+1DAY TO *]'],
 ['facet.query' , 'ED:[NOW/DAY+1DAY TO NOW/DAY+1MONTH]'],
 ['facet.query' , 'ED:[NOW/DAY+1DAY TO NOW/DAY+6MONTHS]'],
 ['facet.query' , 'ED:[NOW/DAY+1DAY TO NOW/DAY+1YEAR]'],
]
res = Net::HTTP.new(url.host, url.port).start {|http| http.request(req) }
case res
when Net::HTTPSuccess, Net::HTTPRedirection
  # OK
  pp JSON.parse(res.body)
else
  pp res.value
end

https://gist.github.com/ymkjp/55aff114ef7c63cb14f3#file-wipo-rb

Feel free to ask about this article: @ymkjp

0 件のコメント:

コメントを投稿