Sha256: 5fe704101b79300d7d8110d4de69921c5a237b34649970513b796a3cfb6ebb69

Contents?: true

Size: 1.42 KB

Versions: 17

Compression:

Stored size: 1.42 KB

Contents

require_relative '../version'
require 'openssl'

module Asana
  class HttpClient
    # Internal: Adds environment information to a Faraday request.
    class EnvironmentInfo
      # Internal: The default user agent to use in all requests to the API.
      USER_AGENT = "ruby-asana v#{Asana::VERSION}".freeze

      def initialize(user_agent = nil)
        @user_agent = user_agent || USER_AGENT
        @openssl_version = OpenSSL::OPENSSL_VERSION
        @client_version = Asana::VERSION
        @os = os
      end

      # Public: Augments a Faraday connection with information about the
      # environment.
      def configure(builder)
        builder.headers[:user_agent] = @user_agent
        builder.headers[:"X-Asana-Client-Lib"] = header
      end

      private

      def header
        { os: @os,
          language: 'ruby',
          language_version: RUBY_VERSION,
          version: @client_version,
          openssl_version: @openssl_version }
          .map { |k, v| "#{k}=#{v}" }.join('&')
      end

      # rubocop:disable Metrics/MethodLength
      def os
        if RUBY_PLATFORM =~ /win32/ || RUBY_PLATFORM =~ /mingw/
          'windows'
        elsif RUBY_PLATFORM =~ /linux/
          'linux'
        elsif RUBY_PLATFORM =~ /darwin/
          'darwin'
        elsif RUBY_PLATFORM =~ /freebsd/
          'freebsd'
        else
          'unknown'
        end
      end
      # rubocop:enable Metrics/MethodLength
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
asana-2.0.1 lib/asana/http_client/environment_info.rb
asana-2.0.0 lib/asana/http_client/environment_info.rb
asana-1.0.0 lib/asana/http_client/environment_info.rb
asana-0.10.13 lib/asana/http_client/environment_info.rb
asana-0.10.12 lib/asana/http_client/environment_info.rb
asana-0.10.3 lib/asana/http_client/environment_info.rb
asana-0.10.2 lib/asana/http_client/environment_info.rb
asana-0.10.1 lib/asana/http_client/environment_info.rb
asana-0.10.0 lib/asana/http_client/environment_info.rb
asana-0.9.3 lib/asana/http_client/environment_info.rb
asana-0.9.2 lib/asana/http_client/environment_info.rb
asana-0.9.1 lib/asana/http_client/environment_info.rb
asana-0.9.0 lib/asana/http_client/environment_info.rb
asana-0.8.1 lib/asana/http_client/environment_info.rb
asana-0.8.0 lib/asana/http_client/environment_info.rb
asana-0.6.3 lib/asana/http_client/environment_info.rb
asana-0.6.2 lib/asana/http_client/environment_info.rb