Module: Prismic::DefaultHTTPClient
- Defined in:
- lib/prismic.rb
Overview
Default HTTP client implementation, using the standard Net::HTTP library.
Class Method Summary collapse
-
.get(uri, data = {}, headers = {}) ⇒ Object
Performs a GET call and returns the result.
-
.post(uri, data = {}, headers = {}) ⇒ Object
Performs a POST call and returns the result.
- .url_encode(data) ⇒ Object
Class Method Details
.get(uri, data = {}, headers = {}) ⇒ Object
Performs a GET call and returns the result
The result must respond to
- code: returns the response's HTTP status code (as number or String)
- body: returns the response's body (as String)
579 580 581 582 583 584 585 |
# File 'lib/prismic.rb', line 579 def get(uri, data={}, headers={}) uri = URI(uri) if uri.is_a?(String) add_query(uri, data) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = uri.scheme =~ /https/i http.get(uri.request_uri, headers) end |
.post(uri, data = {}, headers = {}) ⇒ Object
Performs a POST call and returns the result
The result must respond to
- code: returns the response's HTTP status code (as number or String)
- body: returns the response's body (as String)
592 593 594 595 596 597 598 |
# File 'lib/prismic.rb', line 592 def post(uri, data={}, headers={}) uri = URI(uri) if uri.is_a?(String) add_query(uri, data) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = uri.scheme =~ /https/i http.post(uri.path, uri.query, headers) end |
.url_encode(data) ⇒ Object
600 601 602 603 604 605 606 607 608 609 610 |
# File 'lib/prismic.rb', line 600 def url_encode(data) # Can't use URI.encode_www_form (doesn't support multi-values in 1.9.2) encode = ->(k, v){ "#{k}=#{CGI::escape(v)}" } data.map { |k, vs| if vs.is_a?(Array) vs.map{|v| encode.(k, v) }.join("&") else encode.(k, vs) end }.join("&") end |