class HttpClient
HTTP Client
Class (HTTPクライアント クラス)
Constants
- ENDPOINT
Public Class Methods
new()
click to toggle source
initializer (イニシャライザ)
# File lib/growthpush/http_client.rb, line 16 def initialize @conn = Faraday.new(:url => ENDPOINT) do |faraday| faraday.request :url_encoded # form-encode POST params faraday.response :logger # log requests to STDOUT faraday.adapter Faraday.default_adapter # make requests with Net::HTTP faraday.use FaradayMiddleware::ParseJson, :content_type => /\bjson$/ end end
Public Instance Methods
post(api,params,version = 1)
click to toggle source
post (POSTする) @param [String] api api identifier (API識別子) @param [Hash] params http request parameters (HTTPリクエスト パラメータ) @param [Integer] version api version (APIバージョン) @raise [GrowthPushException] exception (例外) @return [HttpResponse] http response (HTTPレスポンス)
# File lib/growthpush/http_client.rb, line 33 def post(api,params,version = 1) url = "/#{version}/#{api}" response = @conn.post do |req| req.url url req.headers['Content-Type'] = 'application/json' req.params = params end http_response = HttpResponse.new(response) if !http_response.ok? body = http_response.body raise GrowthPushException.new(body['message'], response.status) end http_response end