Sha256: c97c52bac525e07e65a800700682a5bda233abbac936e61e9faf5ff7600d9de8

Contents?: true

Size: 1001 Bytes

Versions: 24

Compression:

Stored size: 1001 Bytes

Contents

module ZendeskAppsTools
  module APIConnection
    FULL_URL     = /https?:\/\//
    URL_TEMPLATE = 'https://%s.zendesk.com/'

    def prepare_api_auth
      @subdomain ||= cache.fetch('subdomain') || get_value_from_stdin('Enter your Zendesk subdomain or full Zendesk URL:')
      @username  ||= cache.fetch('username', @subdomain) || get_value_from_stdin('Enter your username:')
      @password  ||= cache.fetch('password', @subdomain) || get_password_from_stdin('Enter your password:')

      cache.save 'subdomain' => @subdomain, 'username' => @username
    end

    def get_connection(encoding = :url_encoded)
      require 'net/http'
      require 'faraday'
      prepare_api_auth
      Faraday.new full_url do |f|
        f.request encoding if encoding
        f.adapter :net_http
        f.basic_auth @username, @password
      end
    end

    private

    def full_url
      if FULL_URL =~ @subdomain
        @subdomain
      else
        URL_TEMPLATE % @subdomain
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
zendesk_apps_tools-2.12.0 lib/zendesk_apps_tools/api_connection.rb
zendesk_apps_tools-2.11.2 lib/zendesk_apps_tools/api_connection.rb
zendesk_apps_tools-2.11.1 lib/zendesk_apps_tools/api_connection.rb
zendesk_apps_tools-2.11.0 lib/zendesk_apps_tools/api_connection.rb
zendesk_apps_tools-2.10.0 lib/zendesk_apps_tools/api_connection.rb
zendesk_apps_tools-2.9.8 lib/zendesk_apps_tools/api_connection.rb
zendesk_apps_tools-2.9.6 lib/zendesk_apps_tools/api_connection.rb
zendesk_apps_tools-2.9.5 lib/zendesk_apps_tools/api_connection.rb
zendesk_apps_tools-2.9.4 lib/zendesk_apps_tools/api_connection.rb
zendesk_apps_tools-2.9.3 lib/zendesk_apps_tools/api_connection.rb
zendesk_apps_tools-2.9.2 lib/zendesk_apps_tools/api_connection.rb
zendesk_apps_tools-2.9.1 lib/zendesk_apps_tools/api_connection.rb
zendesk_apps_tools-2.9.0 lib/zendesk_apps_tools/api_connection.rb
zendesk_apps_tools-2.8.4 lib/zendesk_apps_tools/api_connection.rb
zendesk_apps_tools-2.8.3 lib/zendesk_apps_tools/api_connection.rb
zendesk_apps_tools-2.8.2 lib/zendesk_apps_tools/api_connection.rb
zendesk_apps_tools-2.8.1 lib/zendesk_apps_tools/api_connection.rb
zendesk_apps_tools-2.8.0 lib/zendesk_apps_tools/api_connection.rb
zendesk_apps_tools-2.7.1 lib/zendesk_apps_tools/api_connection.rb
zendesk_apps_tools-2.7.0 lib/zendesk_apps_tools/api_connection.rb