Class: Access::Request

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/access/request.rb

Instance Method Summary collapse

Instance Method Details

#get(path, api_type, options = {}, &block) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/access/request.rb', line 5

def get(path, api_type, options={}, &block)
  url = set_base(api_type, path)
  results = self.class.get(url, headers: headers(options[:access_token]), query: options, timeout: (options[:access_timeout] || 3))
  if should_return_json?(options[:return_json])
    hashify_results?(options[:hashify]) ? results.hashify : results
  else
    block.call results
  end
rescue Net::ReadTimeout, Net::OpenTimeout
  # block.call({"message"=>"Request Timeout Error", "status"=>408})
  raise Access::Error::Timeout
end

#get_for_filter(path, api_type, filter, options = {}, &block) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/access/request.rb', line 31

def get_for_filter(path, api_type, filter, options={}, &block)
  url = set_base(api_type, path)
  results = self.class.get(url, headers: headers(options[:access_token]), body: filter, timeout: (options[:access_timeout] || 3))
  if should_return_json?(options[:return_json])
    hashify_results?(options[:hashify]) ? results.hashify : results
  else
    block.call results
  end
rescue Net::ReadTimeout, Net::OpenTimeout
  raise Access::Error::Timeout
end

#post(path, api_type, options = {}, &block) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/access/request.rb', line 18

def post(path, api_type, options={}, &block)
  url = set_base(api_type, path)
  results = self.class.post(url, headers: headers(options[:access_token]), body: options.to_json, timeout: (options[:access_timeout] || 10))
  if should_return_json?(options[:return_json])
    hashify_results?(options[:hashify]) ? results.hashify : results
  else
    block.call results
  end
rescue Net::ReadTimeout, Net::OpenTimeout
  # block.call({"message"=>"Request Timeout Error", "status"=>408})
  raise Access::Error::Timeout
end