Skip to content

Conversation

@redroot
Copy link

@redroot redroot commented Jan 26, 2022

Adds the ability to send a POST to /deals/upsert as specified here https://developers.getbase.com/docs/rest/reference/deals and equivalent for contacts

validate_type!(deal)

attributes = sanitize(deal)
query_string = URI.encode_www_form(filters)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i was trying to find a way on encoding the hash without using Rails only methods (like Object.to_query) or a new gem like Addressable, this seems to do the trick, but other opinions welcome

it 'calls the upsert route with encoded filters' do
filters = { name: 'unique_name', 'custom_fields[external_id]': 'unique-1' }
attributes = filters.merge('custom_fields[category]': 'bags')
expect(client.deals.upsert(filters, attributes)).to be_instance_of BaseCRM::Deal
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these tests seems to require an Access Token and actually attempt to hit a running API, is that expected?

@redroot redroot changed the title Add deal upsert route Add first upsert methods for Deals and Contact Jan 26, 2022

attributes = sanitize(deal)
query_string = URI.encode_www_form(filters)
_, _, root = @client.post("/contacts/upsert?#{query_string}", attributes)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 If the intention of upsert is to be idempotent, then you should use a PUT.

The difference between PUT and POST is that PUT is idempotent: calling it once or several times successively has the same effect (that is no side effect), where successive identical POST may have additional effects, like passing an order several times.

MDN Docs

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That may be so, but according to the docs it Zendesk Sell's case its a POST https://developers.getbase.com/docs/rest/reference/deals

filters = { last_name: 'unique_name', 'custom_fields[external_id]': 'unique-1' }
contact = create(:contact, last_name: 'unique_name', custom_fields: { external_id: 'unique-1'})
expect(client.contacts.upsert(filters, contact)).to be_instance_of BaseCRM::Contact
end
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 This test seems to cover the "update" path, but we are missing the "insert" path.
If the endpoint does an upsert both scenarios should be tested

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, waiting on some guidance on the test suite in general here #83 (comment) before i improve this but i agree

filters = { name: 'unique_name', 'custom_fields[external_id]': 'unique-1' }
deal = create(:deal, name: 'unique_name', custom_fields: { external_id: 'unique-1'})
expect(client.deals.upsert(filters, deal)).to be_instance_of BaseCRM::Deal
end
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above

@redroot
Copy link
Author

redroot commented Aug 3, 2022

@struniu hi! any chance of a review / update on whether this gem is maintained still?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants