Sha256: df10e64ec6a3893e169d38fbbeafcc14bbcec4dfc80607effaa2162e9263cf7d

Contents?: true

Size: 1.31 KB

Versions: 15

Compression:

Stored size: 1.31 KB

Contents

require 'haveapi/go_client/authentication/base'

module HaveAPI::GoClient
  class Authentication::Token < Authentication::Base
    register :token

    # HTTP header the token is sent in
    # @return [String]
    attr_reader :http_header

    # Query parameter the token is sent in
    # @return [String]
    attr_reader :query_parameter

    # Resource for token manipulation
    # @return [Resource]
    attr_reader :resource

    def initialize(api_version, name, desc)
      super
      @http_header = desc[:http_header]
      @query_parameter = desc[:query_parameter]
      @resource = Resource.new(
        api_version,
        :token,
        desc[:resources][:token],
        prefix: 'auth_token'
      )
      resource.resolve_associations
    end

    def generate(gen)
      ErbTemplate.render_to_if_changed(
        'authentication/token.go',
        {
          package: gen.package,
          auth: self
        },
        File.join(gen.dst, 'auth_token.go')
      )

      resource.generate(gen)
    end

    # @return [Action]
    def request_action
      @request_action ||= resource.actions.detect { |a| a.name == 'request' }
    end

    # @return [Array<Action>]
    def custom_actions
      @custom_actions ||= resource.actions.reject do |a|
        %w[request renew revoke].include?(a.name)
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
haveapi-go-client-0.26.0 lib/haveapi/go_client/authentication/token.rb
haveapi-go-client-0.25.0 lib/haveapi/go_client/authentication/token.rb
haveapi-go-client-0.24.0 lib/haveapi/go_client/authentication/token.rb
haveapi-go-client-0.23.7 lib/haveapi/go_client/authentication/token.rb
haveapi-go-client-0.23.6 lib/haveapi/go_client/authentication/token.rb
haveapi-go-client-0.23.5 lib/haveapi/go_client/authentication/token.rb
haveapi-go-client-0.23.4 lib/haveapi/go_client/authentication/token.rb
haveapi-go-client-0.23.3 lib/haveapi/go_client/authentication/token.rb
haveapi-go-client-0.23.2 lib/haveapi/go_client/authentication/token.rb
haveapi-go-client-0.23.1 lib/haveapi/go_client/authentication/token.rb
haveapi-go-client-0.23.0 lib/haveapi/go_client/authentication/token.rb
haveapi-go-client-0.22.1 lib/haveapi/go_client/authentication/token.rb
haveapi-go-client-0.22.0 lib/haveapi/go_client/authentication/token.rb
haveapi-go-client-0.21.1 lib/haveapi/go_client/authentication/token.rb
haveapi-go-client-0.21.0 lib/haveapi/go_client/authentication/token.rb