Class: GoFlippy::HttpClient
- Inherits:
-
Object
- Object
- GoFlippy::HttpClient
- Includes:
- Logger
- Defined in:
- lib/goflippy-ruby/http_client.rb
Constant Summary collapse
- HTTP_API_KEY_HEADER =
'X-Api-Key'
Constants included from Logger
Instance Method Summary collapse
- #get(path, params = {}) ⇒ Object
-
#initialize(api_key, opts = {}) ⇒ HttpClient
constructor
A new instance of HttpClient.
- #post(path, params = {}) ⇒ Object
Methods included from Logger
debug, error, fatal, info, logger, logger=, unknown, warn
Constructor Details
#initialize(api_key, opts = {}) ⇒ HttpClient
Returns a new instance of HttpClient.
10 11 12 13 14 15 |
# File 'lib/goflippy-ruby/http_client.rb', line 10 def initialize(api_key, opts = {}) @api_key = api_key @api_uri = opts.api_uri @open_timeout = opts.open_timeout @read_timeout = opts.read_timeout end |
Instance Method Details
#get(path, params = {}) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/goflippy-ruby/http_client.rb', line 17 def get(path, params = {}) uri = uri(path, params) req = Net::HTTP::Get.new(uri.request_uri) req['Accept'] = 'application/json' req[HTTP_API_KEY_HEADER] = 'application/json' request(uri, req) end |
#post(path, params = {}) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/goflippy-ruby/http_client.rb', line 26 def post(path, params = {}) uri = uri(path, params) req = Net::HTTP::Post.new(uri.request_uri) req['Accept'] = 'application/json' req['Content-Type'] = 'application/json' req[HTTP_API_KEY_HEADER] = 'application/json' req.body = params.to_json unless params.empty? request(uri, req) end |