Class: Bintray::Client::Ruby::Resources::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/bintray/client/ruby/resources/base.rb

Direct Known Subclasses

Repositories

Instance Method Summary collapse

Constructor Details

#initialize(conn) ⇒ Base

Returns a new instance of Base.



8
9
10
# File 'lib/bintray/client/ruby/resources/base.rb', line 8

def initialize(conn)
	@conn = conn
end

Instance Method Details

#create_route(*route) ⇒ Object



29
30
31
# File 'lib/bintray/client/ruby/resources/base.rb', line 29

def create_route(*route)
	File.join(route.flatten.compact.map(&:to_s))
end

#parse_response(response) ⇒ Object



24
25
26
27
# File 'lib/bintray/client/ruby/resources/base.rb', line 24

def parse_response(response)
	return handle_error(response) if response.status >= 300
	handle_ok(response)
end

#request(http_method, path, query_params = {}, payload = {}, headers = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/bintray/client/ruby/resources/base.rb', line 12

def request(http_method, path, query_params = {}, payload = {}, headers = {})
	@conn.send(http_method) do |req|
		req.url(path)
		set_url_query_params(req, query_params)
		set_headers(req, headers)
		if payload.present?
			req.headers['Content-Type'] = 'application/json'
			req.body = JSON.dump(payload)
		end
	end
end