Module: Bosonnlp::Util
- Included in:
- Bosonnlp, MultipleHandler
- Defined in:
- lib/bosonnlp/util.rb
Overview
‘Utils’
Instance Method Summary collapse
-
#_http_request(method, url, *args) ⇒ Object
:query, :body, :header, :follow_redirect.
- #get_hash_args(*args) ⇒ Object
Instance Method Details
#_http_request(method, url, *args) ⇒ Object
:query, :body, :header, :follow_redirect
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/bosonnlp/util.rb', line 14 def _http_request(method, url, *args) request_args = get_hash_args(*args) url = get_url url unless url.to_s.start_with?('http://') request_args[:header] = @head request_args[:body] = \ JSON.dump(request_args[:body]) if request_args[:body] res = @http_session.request(method, url, request_args) status = res.status raise HTTPError, 'HTTPError: %s %s'\ % [status, (JSON.load(res.content)['message'] rescue res.reason)]\ if status >= 400 && status < 600 res end |
#get_hash_args(*args) ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'lib/bosonnlp/util.rb', line 4 def get_hash_args(*args) if Hash === args[-1] h = args[-1] else h = {} end h end |