Module: TsJsonApi::Requestor::PrivateMethods::ClassMethods

Defined in:
lib/ts_json_api/requestor/private_methods.rb

Instance Method Summary collapse

Instance Method Details

#apiObject



21
22
23
# File 'lib/ts_json_api/requestor/private_methods.rb', line 21

def api
@@api ||= RestClient::Resource.new(Configure.server_url, user: Configure.username, password: Configure.password, timeout: 20, headers: { accept: "application/json;version=#{Configure.api_version}"})
end

#perfom_request(partial_url) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/ts_json_api/requestor/private_methods.rb', line 25

def perfom_request(partial_url)
	begin
		api[partial_url].get

	rescue RestClient::Exceptions::EXCEPTIONS_MAP[400] => e
	raise ApiLimitExceededException.new exception: e

rescue RestClient::Exceptions::EXCEPTIONS_MAP[404] => e
	raise ResourceNotFound.new exception: e

	rescue RestClient::ServerBrokeConnection => e
		raise ServerBrokeConnection.new exception: e

	rescue RestClient::Exception => e
		raise Exception.new exception: e

	end
end

#send_json_request_and_deliver_response(file_type, partial_url) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/ts_json_api/requestor/private_methods.rb', line 9

def send_json_request_and_deliver_response(file_type, partial_url)
url = "#{Configure.server_url}#{partial_url}"

 response = perfom_request(partial_url)
json = response.to_str
json.gsub!(/[^\x20-\x7e]/,'')

log(file_type, url, json)

JSON.parse(json)
end