Class: RDFMapper::HTTP
- Inherits:
-
Object
- Object
- RDFMapper::HTTP
- Defined in:
- lib/lib/util/http.rb
Overview
Basic HTTP interface, built on top of Patron library. Used by RDFMapper adapters for communication with external data sources.
Patron automatically handles cookies, redirects, timeouts. Can be substituted by any other library as long as HTTP class implements ‘get` and `post` methods.
Class Method Summary collapse
-
.get(url, options = {}) ⇒ String
Performs a ‘GET` request and returns received data.
-
.post(url, data, options = {}) ⇒ String
Performs a ‘POST` request and returns received data.
Instance Method Summary collapse
Constructor Details
#initialize(options = {}) ⇒ self
43 44 45 46 47 48 49 |
# File 'lib/lib/util/http.rb', line 43 def initialize( = {}) @session = Patron::Session.new @session. @session.timeout = 10 @session.headers['User-Agent'] = 'Mozilla / RDFMapper' @options = end |
Class Method Details
.get(url, options = {}) ⇒ String
Performs a ‘GET` request and returns received data
22 23 24 |
# File 'lib/lib/util/http.rb', line 22 def get(url, = {}) self.new().get(url.to_s) end |
.post(url, data, options = {}) ⇒ String
Performs a ‘POST` request and returns received data
34 35 36 |
# File 'lib/lib/util/http.rb', line 34 def post(url, data, = {}) self.new().post(url.to_s, data) end |
Instance Method Details
#get(url) ⇒ Object
51 52 53 |
# File 'lib/lib/util/http.rb', line 51 def get(url) @session.get(url, headers).body end |
#post(url, data) ⇒ Object
55 56 57 |
# File 'lib/lib/util/http.rb', line 55 def post(url, data) @session.post(url, data, headers).body end |