<commit_before>require 'contextio/api/lazy_attributes'

class ContextIO
  class OAuthProvider
    extend ContextIO::API::LazyAttributes

    attr_reader :api
    lazy_attributes :provider_consumer_key, :provider_consumer_secret, :type

    def initialize(api, options = {})
      required_options = [:provider_consumer_key, 'provider_consumer_key', :resource_url, 'resource_url']

      if (options.keys & required_options).empty?
        raise ArgumentError, "Either a provider_consumer_key or a resource_url is required"
      end

      @api = api

      options.each do |key, value|
        instance_variable_set("@#{key}", value)
      end
    end

    def resource_url
      @resource_url ||= build_resource_url
    end

    def delete
      api.request(:delete, resource_url)['success']
    end

    private

    def build_resource_url
      "oauth_providers/#{provider_consumer_key}"
    end

    def fetch_attributes<commit_msg>Documentation for OAuthProvider.<commit_after>require 'contextio/api/lazy_attributes'

class ContextIO
  class OAuthProvider
    extend ContextIO::API::LazyAttributes

    # (see ContextIO#api)
    attr_reader :api

    # @!attribute [r] provider_consumer_key
    #   @return [String] The consumer key associated with this provider. Will
    #     fetch from the API if necessary.
    # @!attribute [r] provider_consumer_secret
    #   @return [String] The consumer secret associated with this provider. Will
    #     fetch from the API if necessary.
    # @!attribute [r] type
    #   @return [String] The consumer key associated with this provider. Will
    #     fetch from the API if necessary.
    lazy_attributes :provider_consumer_key, :provider_consumer_secret, :type

    # (see ContextIO::OAuthProviderCollection#initialize)
    def initialize(api, options = {})
      required_options = [:provider_consumer_key, 'provider_consumer_key', :resource_url, 'resource_url']

      if (options.keys & required_options).empty?
        raise ArgumentError, "Either a provider_consumer_key or a resource_url is required"
      end

      @api = api

      options.each do |key, value|
        instance_variable_set("@#{key}", value)
      end
    end

    # @!attribute [r] resource_url
    # @return [String] The URL that will fetch attributes from the API.
    def resource_url
      @resource_url ||= build_resource_url
    end

    # Deletes the provider instance.
    #
    # @return [Boolean] Whether the deletion worked or not.
    def delete
      api.request(:delete, resource_url)['success']
    end

    private

    # Builds the path that will fetch the attributes for this provider.
    #
    # @return [String] The path of the resource.
    def build_resource_url
      "oauth_providers/#{provider_consumer_key}"
    end

    # Fetches attributes from the API for this provider.
    #
    # Defines getter methods for any attributes that come back and don't already
    # have them. This way, if the API expands, the gem will still let users get
    # attributes we didn't explicitly declare as lazy.
    def fetch_attributes
{'fraction_non_alphanumeric': 0.07829759584145549, 'fraction_numerical': 0.0, 'mean_word_length': 3.2527624309392267, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5263092', 'n_tokens_mistral': 890, 'n_tokens_neox': 853, 'n_words': 274}