Module: SisRuby::GetHelper
- Included in:
- Endpoint, ResultEnumerable
- Defined in:
- lib/sis_ruby/get_helper.rb
Instance Method Summary collapse
-
#create_headers(specify_content_type, auth_token = nil) ⇒ Object
Creates the header for a request.
-
#typhoeus_get(query) ⇒ Object
Returns a Typhoeus response.
-
#validate_response_success(response) ⇒ Object
Raises an error on response failure.
Instance Method Details
#create_headers(specify_content_type, auth_token = nil) ⇒ Object
Creates the header for a request.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/sis_ruby/get_helper.rb', line 9 def create_headers(specify_content_type, auth_token = nil) headers = { 'Accept' => 'application/json' } if auth_token headers['x-auth-token'] = auth_token end if specify_content_type headers['Content-Type'] = 'application/json' end headers end |
#typhoeus_get(query) ⇒ Object
Returns a Typhoeus response.
35 36 37 38 |
# File 'lib/sis_ruby/get_helper.rb', line 35 def typhoeus_get(query) # TODO: Simplify w/Typhoeus.get ? Typhoeus::Request.new(url, params: query, headers: get_headers(true) ).run end |
#validate_response_success(response) ⇒ Object
Raises an error on response failure.
27 28 29 30 31 |
# File 'lib/sis_ruby/get_helper.rb', line 27 def validate_response_success(response) unless response.code.between?(200, 299) raise BadResponseError.new(response) end end |