-
-
Save jacobbednarz/6e714cbfc75995587b0b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Example | |
module Api | |
class Client | |
attr_accessor :client | |
def initialize(options = {}) | |
# Providing that we have both the username and the password, use it | |
# otherwise we will run through the available authentication sources to | |
# find our user details. | |
options[:username] ||= user_credentials[:username] | |
options[:password] ||= user_credentials[:password] | |
@client = build_connection(options) | |
response = @client.get 'sites.json' | |
fail InvalidUserCredentials, 'Invalid user credentials' if response.status == 401 | |
end | |
def build_connection(options = {}) | |
# Build our connection using a proxy and correct SSL options. | |
@client = Faraday.new(url: Example.cloud_api_endpoint, ssl: ssl_opts) do |c| | |
c.adapter Faraday.default_adapter | |
c.headers['User-Agent'] = "Example SDK (#{Example::VERSION})" | |
c.basic_auth(options[:username], options[:password]) | |
c.proxy = proxy_opts if proxy? | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment