Class: Orange::Rest
- Inherits:
-
Object
- Object
- Orange::Rest
- Includes:
- HTTParty
- Defined in:
- lib/hung_secondGem/orange.rb
Instance Attribute Summary collapse
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #debugErr(opts = {}) ⇒ Object
- #debugPass(opts = {}) ⇒ Object
- #headers(h = {}) ⇒ Object
- #Host ⇒ Object
-
#initialize(opts = {}) ⇒ Rest
constructor
A new instance of Rest.
- #mergeOpt(opts = {}) ⇒ Object
-
#perform_request(http_method, path, options = {}, &block) ⇒ Object
:nodoc:.
-
#process_cookies(options) ⇒ Object
:nodoc:.
- #process_headers(options) ⇒ Object
- #setFollowRedirect(flag) ⇒ Object
- #setHost(host) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Rest
Returns a new instance of Rest.
11 12 |
# File 'lib/hung_secondGem/orange.rb', line 11 def initialize() end |
Instance Attribute Details
#request ⇒ Object (readonly)
Returns the value of attribute request.
9 10 11 |
# File 'lib/hung_secondGem/orange.rb', line 9 def request @request end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
8 9 10 |
# File 'lib/hung_secondGem/orange.rb', line 8 def response @response end |
Instance Method Details
#debugErr(opts = {}) ⇒ Object
89 90 91 92 93 |
# File 'lib/hung_secondGem/orange.rb', line 89 def debugErr(opts={}) self.class.[:debug_output] = $stderr opts = ModuleInheritableAttributes.hash_deep_dup(self.class.).merge(opts.to_hash) opts end |
#debugPass(opts = {}) ⇒ Object
83 84 85 86 87 |
# File 'lib/hung_secondGem/orange.rb', line 83 def debugPass(opts={}) self.class.[:debug_output] = $stdout opts = ModuleInheritableAttributes.hash_deep_dup(self.class.).merge(opts.to_hash) opts end |
#headers(h = {}) ⇒ Object
65 66 67 68 69 |
# File 'lib/hung_secondGem/orange.rb', line 65 def headers(h = {}) raise ArgumentError, 'Headers must an object which responds to #to_hash' unless h.respond_to?(:to_hash) self.class.[:headers] ||= {} self.class.[:headers].merge!(h.to_hash) end |
#Host ⇒ Object
75 76 77 |
# File 'lib/hung_secondGem/orange.rb', line 75 def Host self.class.base_uri end |
#mergeOpt(opts = {}) ⇒ Object
18 19 20 21 |
# File 'lib/hung_secondGem/orange.rb', line 18 def mergeOpt(opts={}) self.class. = self.class..merge(opts.to_hash) puts self.class. end |
#perform_request(http_method, path, options = {}, &block) ⇒ Object
:nodoc:
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/hung_secondGem/orange.rb', line 23 def perform_request(http_method, path, ={}, &block) #:nodoc: method = eval("Net::HTTP::#{http_method.to_s.capitalize}") = ModuleInheritableAttributes.hash_deep_dup(self.class.).merge(.to_hash) begin if (![:debug_request].nil? && [:debug_request].to_s.downcase.eql?("true")) = debugPass end if (![:debug_request].nil? && [:debug_request].to_s.downcase.eql?("false")) = debugErr end process_headers() () puts @response = HTTParty::Request.new(method, path, ).perform(&block) rescue => e puts "Rescued #{e.inspect}" end @response end |
#process_cookies(options) ⇒ Object
:nodoc:
59 60 61 62 63 |
# File 'lib/hung_secondGem/orange.rb', line 59 def () #:nodoc: return unless [:cookies] || self.class..any? [:headers] ||= headers.dup [:headers]['cookie'] = .merge(.delete(:cookies) || {}). end |
#process_headers(options) ⇒ Object
53 54 55 56 57 |
# File 'lib/hung_secondGem/orange.rb', line 53 def process_headers() if [:headers] && headers.any? [:headers] = headers.merge([:headers]) end end |
#setFollowRedirect(flag) ⇒ Object
79 80 81 |
# File 'lib/hung_secondGem/orange.rb', line 79 def setFollowRedirect(flag) self.class.follow_redirects flag end |
#setHost(host) ⇒ Object
71 72 73 |
# File 'lib/hung_secondGem/orange.rb', line 71 def setHost(host) self.class.base_uri host end |