Sha256: 179967094a247b552484086d96a60305bea4d2d7795ca1867c3cba2e6660cf55

Contents?: true

Size: 1.08 KB

Versions: 2

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

module Crowdin
  class Configuration
    attr_accessor :api_token
    attr_accessor :project_id
    attr_accessor :organization_domain
    attr_accessor :request_timeout

    attr_accessor :enable_logger
    alias logger_enabled? enable_logger

    attr_reader :target_api_url

    def initialize
      @target_api_url = '/api/v2'
    end

    def options
      {
        headers: {},
        timeout: request_timeout,
        json:    true
      }
    end

    def headers
      {
        'Accept'        => 'application/json',
        'Authorization' => "Bearer #{api_token}",
        'Content-Type'  => 'application/json',
        'User-Agent'    => "crowdin-rb/#{Crowdin::Client::VERSION}/#{RUBY_VERSION}/#{RUBY_PLATFORM}"
      }
    end

    def base_url
      @base_url ||=
        if !!organization_domain
          if organization_domain.include?('.com')
            "https://#{organization_domain}"
          else
            "https://#{organization_domain}.api.crowdin.com"
          end
        else
          'https://api.crowdin.com'
        end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
crowdin-api-1.12.0 lib/crowdin-api/client/configuration.rb
crowdin-api-1.10.0 lib/crowdin-api/client/configuration.rb