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_hashify ⇒ Object
readonly
Returns the value of attribute use_hashify.
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
- #put(path, api_type, 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_hashify ⇒ Object (readonly)
Returns the value of attribute use_hashify.
5 6 7 |
# File 'lib/access/request.rb', line 5 def use_hashify @use_hashify end |
Instance Method Details
#base_setup(path, api_type, options) ⇒ Object
7 8 9 10 11 12 13 14 |
# 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).to_s) @use_hashify = hashify_results?(.delete(:hashify).to_s) @debug_output = .delete(:access_debug_output).to_s || Access.config.access_debug_output end |
#delete(path, api_type, options = {}, &block) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/access/request.rb', line 58 def delete(path, api_type, ={}, &block) base_setup(path, api_type, ) results = self.class.delete(url, headers: headers, body: .to_json, timeout: timeout, debug_output: (@debug_output == 'true' ? $stdout : nil)) if return_json use_hashify ? 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
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/access/request.rb', line 16 def get(path, api_type, ={}, &block) base_setup(path, api_type, ) results = self.class.get(url, headers: headers, query: , timeout: timeout, debug_output: (@debug_output == 'true' ? $stdout : nil)) if return_json use_hashify ? 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
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/access/request.rb', line 44 def post(path, api_type, ={}, &block) base_setup(path, api_type, ) results = self.class.post(url, headers: headers, body: .to_json, timeout: timeout, debug_output: (@debug_output == 'true' ? $stdout : nil)) if return_json use_hashify ? 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
72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/access/request.rb', line 72 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, debug_output: (@debug_output == 'true' ? $stdout : nil)) if return_json use_hashify ? results.hashify : results else block.call results end rescue Net::ReadTimeout, Net::OpenTimeout raise Access::Error::Timeout rescue EOFError raise Access::Error::NoData end |
#put(path, api_type, options = {}, &block) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/access/request.rb', line 30 def put(path, api_type, ={}, &block) base_setup(path, api_type, ) results = self.class.put(url, headers: headers, body: .to_json, timeout: timeout, debug_output: (@debug_output == 'true' ? $stdout : nil)) if return_json use_hashify ? results.hashify : results else block.call results end rescue Net::ReadTimeout, Net::OpenTimeout raise Access::Error::Timeout rescue EOFError raise Access::Error::NoData end |