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

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

Instance Method Summary collapse

Instance Method Details

#apiObject



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

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

#log(path, url, str) ⇒ Object



48
49
50
51
# File 'lib/ts_json_api/requestor/private_methods.rb', line 48

def log(path, url, str)
	f = Logging::File.new(relative_path: path, url: url)
	f.write str
end

#perfom_request(partial_url) ⇒ Object



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

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, Errno::ECONNRESET => e
		raise ServerBrokeConnection.new exception: e

	rescue RestClient::Exceptions::EXCEPTIONS_MAP[401] => e
		raise AccessTokenRefused.new exception: e

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

	end
end

#send_json_request_and_deliver_response(path, partial_url) ⇒ Object



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

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

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

log(path, url, json)

JSON.parse(json)
end