Class: SimpleHttpClient

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_http_client.rb

Constant Summary collapse

CONTENT_TYPE =
{ 'Content-Type' => 'application/json' }
ACCEPT =
{ 'Accept' => 'application/json' }

Instance Method Summary collapse

Constructor Details

#initialize(base_url) ⇒ SimpleHttpClient

Returns a new instance of SimpleHttpClient.



9
10
11
# File 'lib/simple_http_client.rb', line 9

def initialize(base_url)
  @uri = URI.parse(base_url)
end

Instance Method Details

#delete(path, header = {}) ⇒ Object



18
19
20
21
# File 'lib/simple_http_client.rb', line 18

def delete(path, header = {})
  request = Net::HTTP::Delete.new("/#{path}")
  non_body_request(request, header)
end

#get(path, header = {}) ⇒ Object



13
14
15
16
# File 'lib/simple_http_client.rb', line 13

def get(path, header = {})
  request = Net::HTTP::Get.new("/#{path}")
  non_body_request(request, header)
end

#post(path, body, header = {}) ⇒ Object



23
24
25
26
# File 'lib/simple_http_client.rb', line 23

def post(path, body, header = {})
  request = Net::HTTP::Post.new(path)
  body_request(request, body, header)
end

#put(path, body, header = {}) ⇒ Object



28
29
30
31
# File 'lib/simple_http_client.rb', line 28

def put(path, body, header = {})
  request = Net::HTTP::Put.new(path)
  body_request(request, body, header)
end