<commit_before>require 'rest_client'
require 'json'

module SendGridAPI
  class CustomerSubuser
    attr_reader :username

    ### params for creating a new user
    # username , password, password_<PASSWORD>, email, first_name, last_name,
    # address, city, state, zip, country, phone, website, company
    # http://sendgrid.com/docs/API_Reference/Customer_Subuser_API/subusers.html
    def self.create params
      post "https://api.sendgrid.com/apiv2/customer.add.json", params
    end

    ### params for updating a user
    # user is mandatory
    # then you can update all the fields of create method
    def update params
      post "https://api.sendgrid.com/apiv2/customer.profile.json", params.merge(task: 'set')
    end

    def initialize username
      @username = username
    end

    def enable
      post "https://api.sendgrid.com/apiv2/customer.enable.json"
    end

    def disable
      post "https://api.sendgrid.com/apiv2/customer.disable.json"
    end

    def enable_website_access
      post "https://api.sendgrid.com/apiv2/customer.website_enable.json"
    end

    def disable_website_access
      post "https://api.sendgrid.com/apiv2/customer.website_disable.json"
    end

    def assign_ips ips
      post "https://api.sendgrid.com/apiv2/customer.sendip.json", task: 'append', set: 'specify', ip: ips.to_a
    end

    def activate_app name
      post "https://api.sendgrid.com/apiv2/customer.apps.json", task: 'activate', name: name
    end

    def deactivate_app name
      post "https://api.sendgrid.com/apiv2/customer.apps.json", task: 'deactivate', name: name
    end

    def customize_app name, params
      post "https://sendgrid.com/apiv2/customer.apps.json", {task: 'setup', name: name}.merge(params)
    end


    protected

    def post address, params={}
      CustomerSubuser.req address, params.merge(user: username), :post, CustomerSubuser.credentials
    end

    def get address, params
    end

    def self.post address, params
      req address, params, :post, credentials
    end

    def self.req address, params, method, credentials
      req = (method == :post ? RestClient.post(address, params.merge(credentials)) : RestClient.get(address, params.merge(credentials)) )<commit_msg>adds custom headers to apiv2 requests<commit_after>require 'rest_client'
require 'json'

module SendGridAPI
  class CustomerSubuser
    attr_reader :username

    ### params for creating a new user
    # username , password, <PASSWORD>, email, first_name, last_name,
    # address, city, state, zip, country, phone, website, company
    # http://sendgrid.com/docs/API_Reference/Customer_Subuser_API/subusers.html
    def self.create params
      post "https://api.sendgrid.com/apiv2/customer.add.json", params
    end

    ### params for updating a user
    # user is mandatory
    # then you can update all the fields of create method
    def update params
      post "https://api.sendgrid.com/apiv2/customer.profile.json", params.merge(task: 'set')
    end

    def initialize username
      @username = username
    end

    def enable
      post "https://api.sendgrid.com/apiv2/customer.enable.json"
    end

    def disable
      post "https://api.sendgrid.com/apiv2/customer.disable.json"
    end

    def enable_website_access
      post "https://api.sendgrid.com/apiv2/customer.website_enable.json"
    end

    def disable_website_access
      post "https://api.sendgrid.com/apiv2/customer.website_disable.json"
    end

    def assign_ips ips
      post "https://api.sendgrid.com/apiv2/customer.sendip.json", task: 'append', set: 'specify', ip: ips.to_a
    end

    def activate_app name
      post "https://api.sendgrid.com/apiv2/customer.apps.json", task: 'activate', name: name
    end

    def deactivate_app name
      post "https://api.sendgrid.com/apiv2/customer.apps.json", task: 'deactivate', name: name
    end

    def customize_app name, params
      post "https://sendgrid.com/apiv2/customer.apps.json", {task: 'setup', name: name}.merge(params)
    end


    protected

    def post address, params={}
      CustomerSubuser.req address, params.merge(user: username), :post, CustomerSubuser.credentials
    end

    def get address, params
    end

    def self.post address, params
      req address, params, :post, credentials
    end

    def self.req address, params, method, credentials
      headers = {:'X-Nep-Ff' => SecureRandom.uuid, :'x-tok-ns' => SecureRandom.uuid }
      req = (method == :post ? RestClient.post(address, params.merge(credentials), headers) : RestClient.get(address, params.merge(credentials), headers) )
{'fraction_non_alphanumeric': 0.11142546245919478, 'fraction_numerical': 0.0045701849836779105, 'mean_word_length': 3.129380053908356, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 20, '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': '7642434', 'n_tokens_mistral': 1439, 'n_tokens_neox': 1388, 'n_words': 358}