lib/ltp/cloud/sdk/client.rb in ltp-cloud-sdk-0.1.0 vs lib/ltp/cloud/sdk/client.rb in ltp-cloud-sdk-0.1.1
- old
+ new
@@ -22,21 +22,25 @@
api_key: api_key,
format: 'plain'
}.merge data
end
- def request(service, payload)
- res = RestClient.get(uri(service), params: payload)
+ def request(service, payload, timeout)
+ res = RestClient::Request.execute(method: :get,
+ url: uri(service),
+ timeout: timeout,
+ headers: { params: payload }
+ )
res.body
end
def uri(service)
"#{END_POINT}#{service}"
end
- def analysis(text)
- payload = request_payload({ text: URI::encode(text), pattern: 'ws' })
- res = request 'analysis', payload
+ def analysis(text, timeout = 5)
+ payload = request_payload({ text: CGI::escape(text), pattern: 'ws' })
+ res = request 'analysis', payload, timeout
res.split(' ')
end
end
end
end
\ No newline at end of file