Sha256: 3c278dc3d0cb9c8c02e2df164c8026df79cbfca756311b23e4d8c63281385d44

Contents?: true

Size: 1.66 KB

Versions: 21

Compression:

Stored size: 1.66 KB

Contents

class PropertiesController < ApplicationController
  before_action :authorize
  before_action :property, only: %i[show destroy]

  def index
    @properties = Services::Hubspot::Properties::GetAll.new.call
  end

  def new
    @property = Hubspot::Crm::Properties::Property.new(
      type: 'string', group_name: 'contactinformation', field_type: 'text'
    )
  end

  def create
    Services::Hubspot::Properties::Create.new(property_params).call
    redirect_to :properties
  rescue Hubspot::Crm::Properties::ApiError => e
    error_message = JSON.parse(e.response_body)['message']
    redirect_to new_property_path, flash: { error: error_message }
  end

  def update
    Services::Hubspot::Properties::Update.new(params[:id], property_params).call
    redirect_to :properties
  rescue Hubspot::Crm::Properties::ApiError => e
    error_message = JSON.parse(e.response_body)['message']
    redirect_to property_path(params[:id]), flash: { error: error_message }
  end

  def destroy
    Services::Hubspot::Properties::Destroy.new(params[:id]).call
    redirect_back(fallback_location: properties_path, notice: "Property ##{@property.name} was successfully destroyed.")
  end

  private

  def property
    @property ||= Services::Hubspot::Properties::GetByName.new(params[:id]).call
  end

  def property_params
    params.require(:property).permit(%i[name label description group_name type field_type]).to_hash
  end

  def authorize
    redirect_to login_path if session['tokens'].blank?

    session['tokens'] = Services::Authorization::Tokens::Refresh.new(tokens: session['tokens'], request: request).call
    Services::Authorization::AuthorizeHubspot.new(tokens: session['tokens']).call
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
hubspot-api-client-9.0.0 sample-apps/contacts-app/app/controllers/properties_controller.rb
hubspot-api-client-8.0.1 sample-apps/contacts-app/app/controllers/properties_controller.rb
hubspot-api-client-8.0.0 sample-apps/contacts-app/app/controllers/properties_controller.rb
hubspot-api-client-7.3.0 sample-apps/contacts-app/app/controllers/properties_controller.rb
hubspot-api-client-7.2.0 sample-apps/contacts-app/app/controllers/properties_controller.rb
hubspot-api-client-7.1.1 sample-apps/contacts-app/app/controllers/properties_controller.rb
hubspot-api-client-7.1.0 sample-apps/contacts-app/app/controllers/properties_controller.rb
hubspot-api-client-7.0.0 sample-apps/contacts-app/app/controllers/properties_controller.rb
hubspot-api-client-6.0.0 sample-apps/contacts-app/app/controllers/properties_controller.rb
hubspot-api-client-5.0.0 sample-apps/contacts-app/app/controllers/properties_controller.rb
hubspot-api-client-4.0.0 sample-apps/contacts-app/app/controllers/properties_controller.rb
hubspot-api-client-3.3.0 sample-apps/contacts-app/app/controllers/properties_controller.rb
hubspot-api-client-3.2.0 sample-apps/contacts-app/app/controllers/properties_controller.rb
hubspot-api-client-3.1.1 sample-apps/contacts-app/app/controllers/properties_controller.rb
hubspot-api-client-3.1.0.pre.beta sample-apps/contacts-app/app/controllers/properties_controller.rb
hubspot-api-client-3.0.0.pre.beta sample-apps/contacts-app/app/controllers/properties_controller.rb
hubspot-api-client-2.3.2 sample-apps/contacts-app/app/controllers/properties_controller.rb
hubspot-api-client-2.3.1 sample-apps/contacts-app/app/controllers/properties_controller.rb
hubspot-api-client-2.2.0 sample-apps/contacts-app/app/controllers/properties_controller.rb
hubspot-api-client-2.1.0 sample-apps/contacts-app/app/controllers/properties_controller.rb