<commit_before>require 'faraday'
require 'faraday_middleware'
require 'faraday/response/raise_cindy_error'

module Cindy
  class Client

    def initialize(sendy_url, api_key = nil)
      @url = sendy_url
      @key = api_key || ENV['SENDY_API_KEY']
    end

    def subscribe(list_id, email, name = nil)
      response = connection.post "subscribe" do |req|
        params = {list: list_id, email: email, boolean: true}
        params[:name] = name if name
        req.body = params
      end

      !!(response.body =~ /^1$/)
    end

    def unsubscribe(list_id, email)
      response = connection.post "unsubscribe", {list: list_id, email: email, boolean: true}

      !!(response.body =~ /^1$/)
    end

    def subscription_status(list_id, email)
      response = connection.post "api/subscribers/subscription-status.php" do |req|
        req.body = {list_id: list_id, email: email, api_key: @key}
      end

      response.body
    end
<commit_msg>adds support for campaign creation<commit_after>require 'faraday'
require 'faraday_middleware'
require 'faraday/response/raise_cindy_error'

module Cindy
  class Client

    def initialize(sendy_url, api_key = nil)
      @url = sendy_url
      @key = api_key || ENV['SENDY_API_KEY']
    end

    def create_campaign(opts={})
      post_opts     = {}
      req_opts      = %i(from_name from_email reply_to subject html_text)
      optional_opts = %i(plain_text list_ids brand_id send_campaign)

      req_opts.each do |opt|
        post_opts[opt] = opts.delete(opt) || raise(ArgumentError, "opt :#{opt} required")
      end
      post_opts.merge!(Hash[optional_opts.zip(opts.values_at(*optional_opts))])

      response = connection.post "api/campaigns/create.php" do |req|
        req.body = post_opts
      end

      response.body
    end

    def subscribe(list_id, email, name = nil)
      response = connection.post "subscribe" do |req|
        params = {list: list_id, email: email, boolean: true}
        params[:name] = name if name
        req.body = params
      end

      !!(response.body =~ /^1$/)
    end

    def unsubscribe(list_id, email)
      response = connection.post "unsubscribe", {list: list_id, email: email, boolean: true}

      !!(response.body =~ /^1$/)
    end

    def subscription_status(list_id, email)
      response = connection.post "api/subscribers/subscription-status.php" do |req|
        req.body = {list_id: list_id, email: email, api_key: @key}
      end

      response.body
    end

{'fraction_non_alphanumeric': 0.11406690850463523, 'fraction_numerical': 0.0016122531237404273, 'mean_word_length': 2.866043613707165, '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': '3263143', 'n_tokens_mistral': 832, 'n_tokens_neox': 801, 'n_words': 199}