<commit_before>require "actionkit_connector/version"

module ActionKitConnector
  class Connector
    include HTTParty

    def initialize(username, password, base_url)
      @auth = {username: username, password: password}
      @base_url = base_url
    end

    def list_petition_pages(offset=0, limit=20)
      target = "#{@base_url}/petitionpage/"
      options = {
          basic_auth: @auth,
          query: {
              _limit: limit,
              _offset: offset
          }
      }
      self.class.get(target, options)
    end

    def petition_page(id)
      target = "#{@base_url}/petitionpage/#{id}/"
      self.class.get(target, {basic_auth: @auth})
    end

    def create_petition_page(name, title, lang, canonical_url)
      target = "#{@base_url}/petitionpage/"
      options = {
          basic_auth: @auth,
          headers: {
              'Content-type' => 'application/json'
          },
          :body => {
              :type => "petitionpage",
              :hidden => false,
              :name => name,
              :title => title,
              :lang => lang,
              :canonical_url => canonical_url
          }.to_json,
          format: :json
      }
      self.class.post(target, options)
    end

    def create_action(page_name, email)
      target = "#{@base_url}/action/"
      options = {
          basic_auth: @auth,<commit_msg>Reworking AK connector to allow changing properties.<commit_after>require "actionkit_connector/version"

module ActionKitConnector
  class Connector
    include HTTParty

    attr_accessor :username
    attr_accessor :password
    attr_accessor :base_url

    # Initializes a connector to the ActionKit API.
    # A new connection is created on each call, so there
    # no need to worry about resource utilization.
    #
    # @param [String] username The username of your ActionKit user.
    # @param [String] password The password for your ActionKit user.
    # @param [String] base_url The base url of your ActionKit instance.
    def initialize(username, password, base_url)
      self.username = username
      self.password = password
      self.base_url = base_url
    end

    def auth
      {username: self.username, password: <PASSWORD>}
    end

    # Lists petition pages in your instance.
    #
    # @param [Int] offset The number of records to skip.
    # @param [Int] limit  The maximum number of results to return.
    def list_petition_pages(offset=0, limit=20)
      target = "#{self.base_url}/petitionpage/"
      options = {
          basic_auth: self.auth,
          query: {
              _limit: limit,
              _offset: offset
          }
      }
      self.class.get(target, options)
    end

    # Returns the information for a single PetitionPage.
    #
    # @param [Int] id The ID of the page to return.
    def petition_page(id)
      target = "#{self.base_url}/petitionpage/#{id}/"
      self.class.get(target, {basic_auth: self.auth})
    end

    # Create a petition page in your ActionKit instance.
    #
    # @param [String] name          The name of the page.
    # @param [String] title         The title of the page.
    # @param [URI]    lang          The URI string for the language of this page in the form of /rest/v1/language/{id}
    # @param [URL]    canonical_url The canonical URL for this page.
    def create_petition_page(name, title, lang, canonical_url)
      target = "#{self.base_url}/petitionpage/"
      options = {
          basic_auth: self.auth,
          headers: {
              'Content-type' => 'application/json'
          },
          :body => {
              :type => "petitionpage",
              :hidden => false,
              :name => name,
              :title => title,
              :lang => lang,
              :canonical_url => canonical_url
          }.to_json,
          format: :json
      }
      self.class.post(target, options)
    end

    # Creates an action which associates a user with a page.
    #
    # @param [String] page_name The ActionKit name of the page on which the action is being taken.
    # @param [String] email     The email address of the person taking action.
    def create_action(page_name, email)
      target = "#{self.base_url}/action/"
      options = {
          basic_auth: self.auth,
{'fraction_non_alphanumeric': 0.09731621936989499, 'fraction_numerical': 0.001633605600933489, 'mean_word_length': 2.0614285714285714, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 20, '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': '1330098', 'n_tokens_mistral': 1238, 'n_tokens_neox': 1202, 'n_words': 366}