Class: Cardreader::Lang
- Inherits:
-
Object
- Object
- Cardreader::Lang
- Defined in:
- lib/cardreader/lang.rb
Instance Method Summary collapse
-
#initialize(key) ⇒ Lang
constructor
A new instance of Lang.
- #post(text) ⇒ Object
Constructor Details
#initialize(key) ⇒ Lang
Returns a new instance of Lang.
4 5 6 |
# File 'lib/cardreader/lang.rb', line 4 def initialize(key) @key = key end |
Instance Method Details
#post(text) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/cardreader/lang.rb', line 8 def post(text) uri = URI.parse("https://language.googleapis.com/v1beta1/documents:analyzeEntities?key=#{@key}") request = Net::HTTP::Post.new(uri) request.content_type = "application/json" request.body = "" request.body = "{ 'document':{ 'type':'PLAIN_TEXT', 'content': '#{text}' } }" = { use_ssl: uri.scheme == "https", } response = Net::HTTP.start(uri.hostname, uri.port, ) do |http| http.request(request) end JSON.parse(response.body)["entities"] end |