Class: KiriminAja::Http::Request
- Inherits:
-
Object
- Object
- KiriminAja::Http::Request
- Defined in:
- lib/kiriminaja/http/request.rb
Instance Method Summary collapse
- #delete_json(path) ⇒ Object
- #get_json(path) ⇒ Object
-
#initialize(config) ⇒ Request
constructor
A new instance of Request.
- #post_json(path, body = nil) ⇒ Object
- #request_json(path, method: "POST", body: nil, query: nil, headers: nil) ⇒ Object
Constructor Details
#initialize(config) ⇒ Request
Returns a new instance of Request.
10 11 12 |
# File 'lib/kiriminaja/http/request.rb', line 10 def initialize(config) @config = config end |
Instance Method Details
#delete_json(path) ⇒ Object
38 39 40 |
# File 'lib/kiriminaja/http/request.rb', line 38 def delete_json(path) request_json(path, method: "DELETE") end |
#get_json(path) ⇒ Object
34 35 36 |
# File 'lib/kiriminaja/http/request.rb', line 34 def get_json(path) request_json(path, method: "GET") end |
#post_json(path, body = nil) ⇒ Object
30 31 32 |
# File 'lib/kiriminaja/http/request.rb', line 30 def post_json(path, body = nil) request_json(path, method: "POST", body: body) end |
#request_json(path, method: "POST", body: nil, query: nil, headers: nil) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/kiriminaja/http/request.rb', line 14 def request_json(path, method: "POST", body: nil, query: nil, headers: nil) url = build_url(path, query) uri = URI.parse(url) http = @config.http_client || build_http(uri) req = build_request(uri, method, body, headers) response = http.request(req) unless response.is_a?(Net::HTTPSuccess) raise "Request failed: #{response.code} #{response.}" end JSON.parse(response.body) end |