Class: OrangeLib::Rest
Instance Attribute Summary collapse
Instance Method Summary
collapse
#execute_command
Methods included from Variables
#clear_variables, #interpret_string, #variable
Constructor Details
#initialize(opts = {}) ⇒ Rest
Returns a new instance of Rest.
15
16
|
# File 'lib/orange_lib/rest.rb', line 15
def initialize()
end
|
Instance Attribute Details
#request ⇒ Object
Returns the value of attribute request.
13
14
15
|
# File 'lib/orange_lib/rest.rb', line 13
def request
@request
end
|
#response ⇒ Object
Returns the value of attribute response.
12
13
14
|
# File 'lib/orange_lib/rest.rb', line 12
def response
@response
end
|
Instance Method Details
#debugErr(opts = {}) ⇒ Object
95
96
97
98
99
100
|
# File 'lib/orange_lib/rest.rb', line 95
def debugErr(opts={})
raise ArgumentError, 'opts param must an object which responds to #to_hash' unless opts.respond_to?(:to_hash)
self.class.default_options[:debug_output] = $stderr
opts = ModuleInheritableAttributes.hash_deep_dup(self.class.default_options).merge(opts.to_hash)
opts
end
|
#debugPass(opts = {}) ⇒ Object
88
89
90
91
92
93
|
# File 'lib/orange_lib/rest.rb', line 88
def debugPass(opts={})
raise ArgumentError, 'opts param must an object which responds to #to_hash' unless opts.respond_to?(:to_hash)
self.class.default_options[:debug_output] = $stdout
opts = ModuleInheritableAttributes.hash_deep_dup(self.class.default_options).merge(opts.to_hash)
opts
end
|
69
70
71
72
73
|
# File 'lib/orange_lib/rest.rb', line 69
def (h = {})
raise ArgumentError, 'Headers must an object which responds to #to_hash' unless h.respond_to?(:to_hash)
self.class.default_options[:headers] ||= {}
self.class.default_options[:headers].merge!(h.to_hash)
end
|
#Host ⇒ Object
80
81
82
|
# File 'lib/orange_lib/rest.rb', line 80
def Host
self.class.base_uri
end
|
#mergeOpt(opts = {}) ⇒ Object
22
23
24
25
|
# File 'lib/orange_lib/rest.rb', line 22
def mergeOpt(opts={})
self.class.default_options = self.class.default_options.merge(opts.to_hash)
puts self.class.default_options
end
|
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/orange_lib/rest.rb', line 27
def perform_request(http_method, path, options={}, &block)
method = eval("Net::HTTP::#{http_method.to_s.capitalize}")
options = ModuleInheritableAttributes.hash_deep_dup(self.class.default_options).merge(options.to_hash)
begin
if (!options[:debug_request].nil? && options[:debug_request].to_s.downcase.eql?("true"))
options = debugPass options
end
if (!options[:debug_request].nil? && options[:debug_request].to_s.downcase.eql?("false"))
options = debugErr options
end
(options)
process_cookies(options)
puts options
@response = HTTParty::Request.new(method, path, options).perform(&block)
rescue => e
puts "Rescued #{e.inspect}"
end
@response
end
|
#process_cookies(options) ⇒ Object
63
64
65
66
67
|
# File 'lib/orange_lib/rest.rb', line 63
def process_cookies(options)
return unless options[:cookies] || self.class.default_cookies.any?
options[:headers] ||= .dup
options[:headers]['cookie'] = cookies.merge(options.delete(:cookies) || {}).to_cookie_string
end
|
57
58
59
60
61
|
# File 'lib/orange_lib/rest.rb', line 57
def (options)
if options[:headers] && .any?
options[:headers] = .merge(options[:headers])
end
end
|
#setFollowRedirect(flag) ⇒ Object
84
85
86
|
# File 'lib/orange_lib/rest.rb', line 84
def setFollowRedirect(flag)
self.class.follow_redirects flag
end
|
#setHost(host) ⇒ Object
75
76
77
78
|
# File 'lib/orange_lib/rest.rb', line 75
def setHost(host)
raise OrangeLib::Error.new('host param is null') if host.nil?
self.class.base_uri host
end
|