<commit_before>require "perfecta/version"
require "rest-client"
require "json"

module Perfecta
  class Client

    BASE_API_PATH = 'https://api.perfectaudience.com'

    attr_accessor :email, :password, :token

    def initialize &block
      yield self if block_given?
      @token = exchange_credentials_for_token
    end

    private 

    def exchange_credentials_for_token
      authenticate
    end

    def authenticate
      url = "#{BASE_API_PATH}/auth"<commit_msg>Expose basic public method to return CampaignReport objects<commit_after>require "perfecta/version"
require "perfecta/api_resource"
require "perfecta/campaign_report"
require "rest-client"
require "json"

module Perfecta
  class Client

    BASE_API_PATH = 'https://api.perfectaudience.com'

    attr_accessor :email, :password, :token

    def initialize &block
      yield self if block_given?
      @token = exchange_credentials_for_token
    end

    def campaign_reports
      url = "#{BASE_API_PATH}/reports/campaign_report"
      resp =  JSON.parse(RestClient.get(url, {Authorization: @token}))

      retval = []
      resp['report'].each do |report_data|
        report = CampaignReport.new report_data
        retval << report
      end

      retval
    end

    private 

    def exchange_credentials_for_token
      authenticate
    end

    def authenticate
      url = "#{BASE_API_PATH}/auth"
{'fraction_non_alphanumeric': 0.07959479015918958, 'fraction_numerical': 0.0, 'mean_word_length': 3.190909090909091, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '58121', 'n_tokens_mistral': 434, 'n_tokens_neox': 399, 'n_words': 100}