Sha256: 305098fcb705f132df26d42df5034d2623a26351c5506ceca73948be8e7d32bb

Contents?: true

Size: 1.43 KB

Versions: 1

Compression:

Stored size: 1.43 KB

Contents

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 ||= 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 = API
  end

  def default_params(additions = {})
    params = Sendgrid::Web::Parameters.new
    defaults = {
      query: {
        api_user: config.username,
        api_key:  config.password
      }
    }
    params.replace(defaults)
    params[:query].merge!(additions)
    params
  end

  def craft_response(response)
    Sendgrid::Web::Response.new(response.code, response.body)
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sendgrid-web-0.1.0 lib/sendgrid/web/client.rb