Class: TogoWS::Client

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

Constant Summary collapse

MAX_REDIRECTS =
5
USER_AGENT =
"togows/#{VERSION}".freeze

Instance Method Summary collapse

Constructor Details

#initialize(base_url, timeout) ⇒ Client

Returns a new instance of Client.



11
12
13
14
# File 'lib/togows/client.rb', line 11

def initialize(base_url, timeout)
  @base_url = base_url
  @timeout = timeout
end

Instance Method Details

#get(path) ⇒ Object



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

def get(path)
  uri = URI.parse(URLBuilder.full_url(@base_url, path))
  request(uri) do |http, request_uri|
    req = Net::HTTP::Get.new(request_uri)
    apply_headers(req)
    http.request(req)
  end
end

#post(path, body) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/togows/client.rb', line 25

def post(path, body)
  uri = URI.parse(URLBuilder.full_url(@base_url, path))
  request(uri) do |http, request_uri|
    req = Net::HTTP::Post.new(request_uri)
    apply_headers(req)
    req["Content-Type"] = "text/plain"
    req.body = body
    http.request(req)
  end
end