Class: Cudan::BaseCudan
- Inherits:
-
Object
- Object
- Cudan::BaseCudan
- Defined in:
- lib/cudan/base_cudan.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#showbody ⇒ Object
Returns the value of attribute showbody.
Instance Method Summary collapse
- #do_expect(expect) ⇒ Object
- #do_message ⇒ Object
- #do_query(query) ⇒ Object
- #execute(query, expect, url, method = GET, body = nil) ⇒ Object
- #fetch(url, method = GET, body = nil) ⇒ Object
-
#initialize ⇒ BaseCudan
constructor
A new instance of BaseCudan.
- #set_header(key, value) ⇒ Object
Constructor Details
#initialize ⇒ BaseCudan
Returns a new instance of BaseCudan.
8 9 10 11 |
# File 'lib/cudan/base_cudan.rb', line 8 def initialize @headers = {} @showbody = false end |
Instance Attribute Details
#showbody ⇒ Object
Returns the value of attribute showbody.
12 13 14 |
# File 'lib/cudan/base_cudan.rb', line 12 def showbody @showbody end |
Instance Method Details
#do_expect(expect) ⇒ Object
58 59 60 |
# File 'lib/cudan/base_cudan.rb', line 58 def do_expect expect @query_result.include? expect end |
#do_message ⇒ Object
50 51 52 53 54 |
# File 'lib/cudan/base_cudan.rb', line 50 def Logger.log 'failure:' Logger.log "query: #{@query}" Logger.log @query_result.gsub(/^(.*)$/){|r| "\t" + r} end |
#do_query(query) ⇒ Object
55 56 57 |
# File 'lib/cudan/base_cudan.rb', line 55 def do_query query @response.include? query ? query : '' end |
#execute(query, expect, url, method = GET, body = nil) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/cudan/base_cudan.rb', line 39 def execute query, expect, url, method=GET, body=nil @query = query fetch(url, method, body) @query_result = do_query(query) r = do_expect(expect) unless r exit 1 else end end |
#fetch(url, method = GET, body = nil) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/cudan/base_cudan.rb', line 16 def fetch url, method=GET, body=nil host, port, path = Util::parse_url(url) @post_string = body if method == GET req = Net::HTTP::Get::new(path, @headers) elsif method == POST req = Net::HTTP::Post::new(path, @headers) end response = nil Net::HTTP.start(host, port) do |http| @starttime = Time::now response = http.request(req, @post_string) @response_time = Time::now - @starttime end if response @response = response.body.to_s else @response = '' end if @showbody Logger.log(@response, 2) end end |
#set_header(key, value) ⇒ Object
13 14 15 |
# File 'lib/cudan/base_cudan.rb', line 13 def set_header key, value @headers[key] = value end |