Sha256: 0b397e07145513fd0a9c5b79f20bc1674f365d8174ab9dfc786f56878b553b13

Contents?: true

Size: 945 Bytes

Versions: 3

Compression:

Stored size: 945 Bytes

Contents

# frozen_string_literal: true

# Token object
class Fastly
  class Token < Base
    attr_accessor :id, :access_token, :user_id, :services, :name,  :scope, :created_at, :last_used_at, :expires_at, :ip, :user_agent
    
    private

    def self.get_path(*_args)
      '/tokens'
    end

    def self.post_path(*_args)
      '/tokens'
    end
    
    def self.delete_path(opts)
      "/tokens/#{opts.id}"
    end
  end

  def new_token(opts)
    if client.fully_authed?
      opts[:username] = client.user
      opts[:password] = client.password
      opts[:include_auth] = false
      
      token = create(Token, opts)
      token.nil? ? nil : token
    else
      raise ArgumentError, "Required options missing. Please pass :api_key, :user and :password." 
    end
  end

  def customer_tokens(opts)
    hash = client.get("/customer/#{opts[:customer_id]}/tokens")
    hash.map { |token_hash| Token.new(token_hash, Fastly::Fetcher) }
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
fastly-3.0.2 lib/fastly/token.rb
fastly-3.0.1 lib/fastly/token.rb
fastly-3.0.0 lib/fastly/token.rb