Class: SimpleGoogleAuth::HttpClient
- Inherits:
-
Object
- Object
- SimpleGoogleAuth::HttpClient
- Defined in:
- lib/simple_google_auth/http_client.rb
Instance Method Summary collapse
-
#initialize(url) ⇒ HttpClient
constructor
A new instance of HttpClient.
- #request(params) ⇒ Object
Constructor Details
#initialize(url) ⇒ HttpClient
Returns a new instance of HttpClient.
3 4 5 6 7 8 9 10 11 |
# File 'lib/simple_google_auth/http_client.rb', line 3 def initialize(url) @uri = URI(url) @http = Net::HTTP.new(@uri.host, @uri.port) if @uri.scheme == "https" @http.use_ssl = true @http.verify_mode = OpenSSL::SSL::VERIFY_PEER end end |
Instance Method Details
#request(params) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/simple_google_auth/http_client.rb', line 13 def request(params) request = Net::HTTP::Post.new(@uri.request_uri) request.set_form_data(params) response = @http.request(request) if response.content_type != 'application/json' raise NonJsonResponseError, "The server responded with non-JSON content" end data = begin JSON.parse(response.body) rescue JSON::ParserError raise NonJsonResponseError, "The server responded with JSON content that was not parseable" end if response.code !~ /\A2\d\d\z/ raise ProviderError, "The server responded with error #{response.code}: #{data.inspect}" end data end |