Class: Kinu::HttpClient
- Inherits:
-
Object
- Object
- Kinu::HttpClient
- Defined in:
- lib/kinu/http_client.rb
Defined Under Namespace
Classes: UploadFile
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(base_uri, method, path, params, multipart: false) ⇒ HttpClient
constructor
A new instance of HttpClient.
- #run ⇒ Object
Constructor Details
#initialize(base_uri, method, path, params, multipart: false) ⇒ HttpClient
Returns a new instance of HttpClient.
15 16 17 18 19 20 21 |
# File 'lib/kinu/http_client.rb', line 15 def initialize(base_uri, method, path, params, multipart: false) @base_uri = base_uri @method = method @path = path @params = params @multipart = multipart end |
Class Method Details
.multipart_post(base_uri, path, params) ⇒ Object
11 12 13 |
# File 'lib/kinu/http_client.rb', line 11 def self.multipart_post(base_uri, path, params) new(base_uri, :post, path, params, multipart: true).run end |
.post(base_uri, path, params) ⇒ Object
7 8 9 |
# File 'lib/kinu/http_client.rb', line 7 def self.post(base_uri, path, params) new(base_uri, :post, path, params).run end |
Instance Method Details
#run ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/kinu/http_client.rb', line 23 def run response = connection.send(@method, @path, @params, "User-Agent" => Kinu::USER_AGENT) case response.status when 400 raise BadRequestError.new(response) when 400...500 raise ClientError.new(response) when 500...600 raise ServerError.new(response) end case response.headers['content-type'] when 'application/json' JSON.parse(response.body) else response.body end end |