HubSpot / hubspot-api-ruby

HubSpot API Ruby Client Libraries for V3 version of the API
Apache License 2.0
111 stars 51 forks source link

Fix "LoadError: cannot load such file" everywhere - Remove dynamic requiring for API methods #323

Open rusikf opened 2 months ago

rusikf commented 2 months ago

Hi Hubspot Team!

On calling most API methods with invalid params We don't have validation because of dynamic requiring files Idea :bulb: - Can we remove the dynamic code required?

The ability to see the raw backtrace/logs/validation errors is much better than LoadError

Note: Everything works if pass valid parameters.

hubspot_client.crm.associations.v4.basic_api.create(object_type: 'CONTACT', object_id: nil)
# LoadError: cannot load such file -- hubspot/codegen/crm/associations/v4/models/object_id
hubspot_client.crm.associations.v4.basic_api.create
# LoadError: cannot load such file -- hubspot/codegen/crm/associations/v4/models/object_type
hubspot_client.crm.contacts.basic_api.update
# LoadError: cannot load such file -- hubspot/codegen/crm/contacts/models/contact_id

Thanks!

Samsinite commented 1 month ago

I agree. I also want to point out that the meta programming done in this library has multiple issues, including the one mentioned:

Then instead of something like:

def api_classes
  %i[
    pipeline_stages
    pipeline_stage_audits
    pipelines
    pipeline_audits
  ].freeze
end

It becomes:

api_classes :pipeline_stages,
            :pipeline_stage_audits,
            :pipelines,
            :pipeline_audits

I'm sure other solutions also exist.