Class: Access::Request
- Inherits:
-
Object
- Object
- Access::Request
- Includes:
- HTTParty
- Defined in:
- lib/access/request.rb
Instance Attribute Summary collapse
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#return_json ⇒ Object
readonly
Returns the value of attribute return_json.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
-
#use_hasify ⇒ Object
readonly
Returns the value of attribute use_hasify.
Instance Method Summary collapse
- #base_setup(path, api_type, options) ⇒ Object
- #delete(path, api_type, options = {}, &block) ⇒ Object
- #get(path, api_type, options = {}, &block) ⇒ Object
- #post(path, api_type, options = {}, &block) ⇒ Object
- #post_for_filter(path, api_type, filter, options = {}, &block) ⇒ Object
Instance Attribute Details
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
5 6 7 |
# File 'lib/access/request.rb', line 5 def headers @headers end |
#return_json ⇒ Object (readonly)
Returns the value of attribute return_json.
5 6 7 |
# File 'lib/access/request.rb', line 5 def return_json @return_json end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
5 6 7 |
# File 'lib/access/request.rb', line 5 def timeout @timeout end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
5 6 7 |
# File 'lib/access/request.rb', line 5 def url @url end |
#use_hasify ⇒ Object (readonly)
Returns the value of attribute use_hasify.
5 6 7 |
# File 'lib/access/request.rb', line 5 def use_hasify @use_hasify end |
Instance Method Details
#base_setup(path, api_type, options) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/access/request.rb', line 7 def base_setup(path, api_type, ) @url = set_base(path, api_type, .delete(:api_environment)) @headers = set_headers .delete(:access_token) @timeout = .delete(:access_timeout) || Access.config.access_timeout @return_json = should_return_json?(.delete(:return_json)) @use_hasify = hashify_results?(.delete(:hashify)) end |
#delete(path, api_type, options = {}, &block) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/access/request.rb', line 43 def delete(path, api_type, ={}, &block) base_setup(path, api_type, ) results = self.class.delete(url, headers: headers, body: .to_json, timeout: timeout) if return_json use_hasify ? results.hashify : results else block.call results end rescue Net::ReadTimeout, Net::OpenTimeout raise Access::Error::Timeout rescue EOFError raise Access::Error::NoData end |
#get(path, api_type, options = {}, &block) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/access/request.rb', line 15 def get(path, api_type, ={}, &block) base_setup(path, api_type, ) results = self.class.get(url, headers: headers, query: , timeout: timeout) if return_json use_hasify ? results.hashify : results else block.call results end rescue Net::ReadTimeout, Net::OpenTimeout raise Access::Error::Timeout rescue EOFError raise Access::Error::NoData end |
#post(path, api_type, options = {}, &block) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/access/request.rb', line 29 def post(path, api_type, ={}, &block) base_setup(path, api_type, ) results = self.class.post(url, headers: headers, body: .to_json, timeout: timeout) if return_json use_hasify ? results.hashify : results else block.call results end rescue Net::ReadTimeout, Net::OpenTimeout raise Access::Error::Timeout rescue EOFError raise Access::Error::NoData end |
#post_for_filter(path, api_type, filter, options = {}, &block) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/access/request.rb', line 57 def post_for_filter(path, api_type, filter, ={}, &block) base_setup(path, api_type, ) results = self.class.post(url, headers: headers, body: filter, timeout: timeout) if return_json use_hasify ? results.hashify : results else block.call results end rescue Net::ReadTimeout, Net::OpenTimeout raise Access::Error::Timeout rescue EOFError raise Access::Error::NoData end |