Class: Phenoscape::Request
- Inherits:
-
Object
- Object
- Phenoscape::Request
- Defined in:
- lib/phenoscaperb/request.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#acchd ⇒ Object
Returns the value of attribute acchd.
-
#args ⇒ Object
Returns the value of attribute args.
-
#endpt ⇒ Object
Returns the value of attribute endpt.
-
#options ⇒ Object
Returns the value of attribute options.
-
#ret ⇒ Object
Returns the value of attribute ret.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
Instance Method Summary collapse
-
#initialize(endpt, args, verbose, options, ret, acchd = "application/json") ⇒ Request
constructor
A new instance of Request.
- #perform ⇒ Object
Constructor Details
#initialize(endpt, args, verbose, options, ret, acchd = "application/json") ⇒ Request
Returns a new instance of Request.
23 24 25 26 27 28 29 30 |
# File 'lib/phenoscaperb/request.rb', line 23 def initialize(endpt, args, verbose, , ret, acchd = "application/json") self.endpt = endpt self.args = args self.verbose = verbose self. = self.ret = ret self.acchd = acchd end |
Instance Attribute Details
#acchd ⇒ Object
Returns the value of attribute acchd.
21 22 23 |
# File 'lib/phenoscaperb/request.rb', line 21 def acchd @acchd end |
#args ⇒ Object
Returns the value of attribute args.
17 18 19 |
# File 'lib/phenoscaperb/request.rb', line 17 def args @args end |
#endpt ⇒ Object
Returns the value of attribute endpt.
16 17 18 |
# File 'lib/phenoscaperb/request.rb', line 16 def endpt @endpt end |
#options ⇒ Object
Returns the value of attribute options.
19 20 21 |
# File 'lib/phenoscaperb/request.rb', line 19 def @options end |
#ret ⇒ Object
Returns the value of attribute ret.
20 21 22 |
# File 'lib/phenoscaperb/request.rb', line 20 def ret @ret end |
#verbose ⇒ Object
Returns the value of attribute verbose.
18 19 20 |
# File 'lib/phenoscaperb/request.rb', line 18 def verbose @verbose end |
Instance Method Details
#perform ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/phenoscaperb/request.rb', line 32 def perform if verbose conn = Faraday.new(:url => Phenoscape.base_url, :request => self. || []) do |f| f.response :logger f.use FaradayMiddleware::RaiseHttpException f..params_encoder = Faraday::FlatParamsEncoder f.adapter Faraday.default_adapter end else conn = Faraday.new(:url => Phenoscape.base_url, :request => self. || []) do |f| f.use FaradayMiddleware::RaiseHttpException f..params_encoder = Faraday::FlatParamsEncoder f.adapter Faraday.default_adapter end end conn.headers[:user_agent] = make_ua conn.headers["X-USER-AGENT"] = make_ua if !self.acchd.nil? conn.headers["Accept"] = self.acchd end res = conn.get self.endpt, self.args if !res.headers['content-type'].match(/json/).nil? out = MultiJson.load(res.body) else case self.ret when "hash" out = Nokogiri::XML(res.body).to_hash when "text" out = res.body when "noko" out = Nokogiri::XML(res.body) end end return out end |