Skip to content

Add dry types to client (and also refactored dry types on job)#23

Merged
abreckner merged 6 commits intomasterfrom
dry-type-client
Apr 30, 2020
Merged

Add dry types to client (and also refactored dry types on job)#23
abreckner merged 6 commits intomasterfrom
dry-type-client

Conversation

@abreckner
Copy link
Contributor

@abreckner abreckner commented Apr 30, 2020

Unfortunately I found that when you use String keys on a dry types hash schema, you can't specify optional parameters (it just ignores them). The DSL needs to be defined with symbols so you can put the (?) at the end to make it optional.

You can however use with_key_transform(&:to_sym) option at the end which will convert your string keys to symbols automatically.

I updated the old job schema as well to reflect what I found with the client schema.

Even thought the keys are converted to symbols, when you export them to XML they are converted back to strings in any case (:ClientID becomes <ClientID></ClientID>).

if there are missing attributes we now raise a Dry::Types::ConstraintError which will need to be handled in whomever is using this gem.

end

def add(access_token:, xero_tenant_id:, client:)
validated_client = XpmRuby::Schema::Client::Add[client]
Copy link
Contributor

Choose a reason for hiding this comment

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

Schema::Client::Add[client]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

end
end
end
end
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be able to remove the XpmRuby prefix here too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

@bedrock-adam bedrock-adam left a comment

Choose a reason for hiding this comment

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

Nice 👍 🚀

@abreckner
Copy link
Contributor Author

@subskii BTW it's implicit in this code, but I thought I would make it explicit that if there are missing attributes we now raise a Dry::Types::ConstraintError which will need to be handled in whomever is using this gem (e.g. the StaffController you made).

@abreckner abreckner merged commit 6da4a3d into master Apr 30, 2020
@abreckner abreckner deleted the dry-type-client branch May 1, 2020 05:14
lankz pushed a commit that referenced this pull request Jun 10, 2025
* Need to use symbols so we can define optional attributes

* Add client schema and spec

* Use validated client to send to XPM

* Rubocop fix

* code review feedback

* code review updates
lankz pushed a commit that referenced this pull request Jun 10, 2025
* Need to use symbols so we can define optional attributes

* Add client schema and spec

* Use validated client to send to XPM

* Rubocop fix

* code review feedback

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants