Class: MmJsonClient::HttpClient::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/mm_json_client/http_client/client.rb

Overview

A helper class to handle lower level HTTP calls for the API.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, endpoint, options = {}) ⇒ Client

Returns a new instance of Client.



9
10
11
12
13
# File 'lib/mm_json_client/http_client/client.rb', line 9

def initialize(url, endpoint, options = {})
  @url = url
  @endpoint = endpoint
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/mm_json_client/http_client/client.rb', line 7

def options
  @options
end

Instance Method Details

#post(data) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/mm_json_client/http_client/client.rb', line 15

def post(data)
  new_http(URI(@url)).start do |http|
    req = Net::HTTP::Post.new(@endpoint)
    req.body = data
    configure_content_type(req)

    http.request(req)
  end
end