Class: Access::Request
- Inherits:
-
Object
- Object
- Access::Request
- Includes:
- HTTParty
- Defined in:
- lib/access/request.rb
Instance Method Summary collapse
- #get(path, api_type, options = {}, &block) ⇒ Object
- #get_for_filter(path, api_type, filter, options = {}, &block) ⇒ Object
- #post(path, api_type, options = {}, &block) ⇒ Object
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, ={}, &block) url = set_base(api_type, path) results = self.class.get(url, headers: headers([:access_token]), query: , timeout: ([:access_timeout] || 3)) if should_return_json?([:return_json]) hashify_results?([: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, ={}, &block) url = set_base(api_type, path) results = self.class.get(url, headers: headers([:access_token]), body: filter, timeout: ([:access_timeout] || 3)) if should_return_json?([:return_json]) hashify_results?([: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, ={}, &block) url = set_base(api_type, path) results = self.class.post(url, headers: headers([:access_token]), body: .to_json, timeout: ([:access_timeout] || 10)) if should_return_json?([:return_json]) hashify_results?([: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 |