Class: GitMarkdown::Api::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/git/markdown/api/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(base_url:, token:) ⇒ Client

Returns a new instance of Client.



6
7
8
9
# File 'lib/git/markdown/api/client.rb', line 6

def initialize(base_url:, token:)
  @base_url = base_url
  @token = token
end

Instance Method Details

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



11
12
13
14
15
16
17
18
# File 'lib/git/markdown/api/client.rb', line 11

def get(path, params = {})
  uri = build_uri(path, params)
  request = Net::HTTP::Get.new(uri)
  set_headers(request)

  response = http_request(uri, request)
  Response.new(response)
end

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



20
21
22
23
24
25
26
27
28
29
# File 'lib/git/markdown/api/client.rb', line 20

def post(path, body = {})
  uri = build_uri(path, {})
  request = Net::HTTP::Post.new(uri)
  set_headers(request)
  request["Content-Type"] = "application/json"
  request.body = JSON.generate(body)

  response = http_request(uri, request)
  Response.new(response)
end