Coder Social home page Coder Social logo

hubspot_stub's Introduction

HubspotStub

This gem provides a stub server to connecte with Hubspot and use Hubspot APIs. Currently, the following APIs are connected:

Installation

Add this line to your application's Gemfile:

gem 'hubspot_stub'

And then execute:

$ bundle

Or install it yourself as:

$ gem install hubspot_stub

Usage

Rspec callbacks should be added in such way:

RSpec.configure do |config|
  config.before(:suite) do
    HubspotStub.boot
  end

  config.around(:each) do |example|
    HubspotStub.clear_store

    ClimateControl.modify(
      BASE_URL = "https://api.hubapi.com/"
      BASE_SUBMISSIONS_URL = "https://api.hsforms.com"
    ) do
      example.run
    end

    HubspotStub.clear_store
  end

Hubspot Forms

To use the Hubspot Forms API, you'll need to create two environment variables that can be stubbed out in your specs.

  • HUBSPOT_API_URL
  • HUBSPOT_API_SUBMISSIONS_URL

After overriding the your API endpoint environment variables, you will have a stubbed out that Hubspot server that can store configuration in memory.

For example, to create a form with fields you can use the following code:

HubspotStub.create_form(
    {
      "formType": "hubspot",
      "id": "381e0ca4-0549-445c-82e6-e30f78e5e7d0",
      "name": "Company Signup",
      "createdAt": "2023-09-08 19:56:19 UTC",
      "updatedAt": "2023-09-08 19:56:19 UTC",
      "archived": false,
      "fieldGroups": [
        {
          "groupType": "default_group",
          "richTextType": "text",
          "fields": [
            {
              "fieldType": "single_line_text",
              "objectTypeId": "0-1",
              "name": "firstname",
              "label": "Your first name",
              "required": false,
              "hidden": false
            },
            {
              "fieldType": "single_line_text",
              "objectTypeId": "0-1",
              "name": "lastname",
              "label": "Your last name",
              "required": false,
              "hidden": false
            }
          ]
        },
        {
          "groupType": "default_group",
          "richTextType": "text",
          "fields": [
            {
              "fieldType": "email",
              "objectTypeId": "0-1",
              "name": "email",
              "label": "Your email",
              "required": true,
              "hidden": false,
              "validation": {
                "blockedEmailDomains": [

                ],
                "useDefaultBlockList": false
              }
            }
          ]
        },
        {
          "groupType": "default_group",
          "richTextType": "text",
          "fields": [
            {
              "fieldType": "single_line_text",
              "objectTypeId": "0-2",
              "name": "name",
              "label": "Your company name",
              "required": false,
              "hidden": false
            }
          ]
        },
        {
          "groupType": "default_group",
          "richTextType": "text",
          "fields": [
            {
              "fieldType": "single_line_text",
              "objectTypeId": "0-2",
              "name": "city",
              "label": "Company city",
              "required": false,
              "hidden": false
            }
          ]
        },
        {
          "groupType": "default_group",
          "richTextType": "text",
          "fields": [
            {
              "fieldType": "single_line_text",
              "objectTypeId": "0-1",
              "name": "jobtitle",
              "label": "Your role",
              "required": false,
              "hidden": false
            }
          ]
        }
      ],
      "configuration": {
        "language": "en",
        "cloneable": true,
        "postSubmitAction": {
          "type": "thank_you",
          "value": "Thanks for submitting the form."
        },
        "editable": true,
        "archivable": true,
        "recaptchaEnabled": false,
        "notifyContactOwner": false,
        "notifyRecipients": [
          "27968940"
        ],
        "createNewContactForNewEmail": false,
        "prePopulateKnownValues": true,
        "allowLinkToResetKnownValues": false
      },
      "displayOptions": {
        "renderRawHtml": false,
        "theme": "default_style",
        "submitButtonText": "Submit",
        "style": {
          "fontFamily": "arial, helvetica, sans-serif",
          "backgroundWidth": "100%",
          "labelTextColor": "#212D3A",
          "labelTextSize": "13px",
          "helpTextColor": "#7C98B6",
          "helpTextSize": "11px",
          "legalConsentTextColor": "#33475B",
          "legalConsentTextSize": "14px",
          "submitColor": "#FF7A59",
          "submitAlignment": "left",
          "submitFontColor": "#FFFFFF",
          "submitSize": "12px"
        },
        "cssClass": "hs-form stacked"
      },
      "legalConsentOptions": {
        "type": "none"
      }
    }
)

To access or edit the created forms on the server, use the forms method:

HubspotStub.forms

There are several pre-configured forms that can be customized based on your needs:

HubspotStub::ArchivedForm.merge(name: "Old Archived Form")
HubspotStub::SsmpleForm.merge(name: "Sign Up Form")

Be sure to clear all of the created forms between test runs:

HubspotStub.clear_store

hubspot_stub's People

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.