lib/sendgrid/web/client.rb in sendgrid-web-0.0.1 vs lib/sendgrid/web/client.rb in sendgrid-web-0.0.5

- old
+ new

@@ -1,33 +1,67 @@ class Sendgrid::Web::Client + + # Sets the global configuration object shared between all clients. + # You can use it like so: + # + # Sendgrid::Web::Client.configure do |config| + # config.username = 'foo' + # config.password = 'bar' + # end + # + # @return [Sendgrid::Web::Configurator] def self.configure(&block) @@config = Sendgrid::Web::Configurator.new(&block) end + # Retrieve the current global configuration object and if none + # exists, then create an empty one. + # + # @see #config def self.config - @@config + @@config ||= Sendgrid::Web::Configurator.new end + # Returns the configured +root_url+. + def self.base_uri + config.root_url + end + + # Retrieve the current global configuration object and if none + # exists, then create an empty one. + # + # @see .config def config @@config ||= Sendgrid::Web::Configurator.new end private + class API + include ::HTTParty + base_uri Sendgrid::Web::Client.config.root_url + end + def config=(configurator) @@config = configurator end def connection - @connection ||= Faraday.new(:url => config.root_url) do |faraday| - faraday.request :url_encoded - faraday.adapter :typhoeus - end + @connection = API end - def default_params - { - api_user: config.username, - api_key: config.password + def default_params(additions = {}) + defaults = { + query: { + api_user: config.username, + api_key: config.password + } } + defaults[:query].merge!(additions) + defaults end + + def craft_response(response) + Sendgrid::Web::Response.new(response.code, response.body) + end + end