class Parasut::HttpClient

Public Class Methods

get(endpoint, query_parameters={}, headers={}, parse_json=true) click to toggle source

end post

# File lib/parasut/http_client.rb, line 43
def get(endpoint, query_parameters={}, headers={}, parse_json=true)

    # The url
    url="#{@@url_base}/#{endpoint}"

    handle_headers(headers)

    # Request
    request=Faraday.get(url, query_parameters, headers)

    # Return
    parse_json ? JSON.parse(request.body).with_indifferent_access : request.body    

end
handle_headers(headers) click to toggle source
# File lib/parasut/http_client.rb, line 10
def handle_headers(headers)

    # Append json content type if not exists
    headers.merge!({'Content-type': 'application/json'}) if headers['Content-type'].nil?

    # Handle access token header
    Her::Middleware::OAuthProviderHeader.add_header(headers)
    
end
post(endpoint, body={}, headers={}, parse_json=true) click to toggle source

 end handle_headers

# File lib/parasut/http_client.rb, line 22
def post(endpoint, body={}, headers={}, parse_json=true)

    # The url
    url="#{@@url_base}/#{endpoint}"

    handle_headers(headers)

    # Convert body to json if hash provided
    body=body.to_json if body.is_a?(Hash)

    # Execute the request
    request=Faraday.post(url, body, headers)

    # Return
    parse_json ? JSON.parse(request.body).with_indifferent_access : request.body    

end
put(endpoint, query_parameters={}, headers={}, parse_json=true) click to toggle source

end get

# File lib/parasut/http_client.rb, line 60
def put(endpoint, query_parameters={}, headers={}, parse_json=true)

    # The url
    url="#{@@url_base}/#{endpoint}"

    handle_headers(headers)

    # Request
    request=Faraday.put(url, query_parameters, headers)

    # Return
    parse_json ? JSON.parse(request.body).with_indifferent_access : request.body    

end