Module: BaiduOcr::Request
- Defined in:
- lib/baidu_ocr/request.rb
Constant Summary collapse
- API_URL =
"http://apis.baidu.com/apistore/idlocr/ocr"
Class Method Summary collapse
Class Method Details
.send_request(opt = {}) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/baidu_ocr/request.rb', line 11 def send_request(opt = {}) headers = { apiKey: opt.delete(:apikey) } params = opt respone = RestClient.post API_URL, params, headers if respone.code == 200 body = JSON.parse respone.body return words(body['retData']) if body['errNum'].to_i == 0 puts "识别不成功: #{body['errMsg']}" end end |
.words(text) ⇒ Object
22 23 24 |
# File 'lib/baidu_ocr/request.rb', line 22 def words(text) text.collect{|k| k['word']}.join("\n") end |