-
Notifications
You must be signed in to change notification settings - Fork 130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow setting label_ids
on a message
#231
Changes from 1 commit
2bd17ce
d736143
950a7ab
e40e7ce
145c1d1
a320a89
ca7a37e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
label_ids
on a message
Right now there is no way to set a `label` on a `message`. API accepts `label_ids` as an array of string of label ids. This PR also add `UPDATABLE_ATTRIBUTES` to just allow few attributes to be updated allowed by API instead of having all attributes to be updated.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,10 @@ class Message | |
has_n_of_attribute :events, :event | ||
has_n_of_attribute :files, :file | ||
attribute :folder, :folder | ||
attribute :folder_id, :string | ||
|
||
has_n_of_attribute :labels, :label | ||
has_n_of_attribute :label_ids, :string | ||
|
||
transfer :api, to: %i[events files folder labels] | ||
|
||
|
@@ -46,6 +49,16 @@ def unread? | |
unread | ||
end | ||
|
||
UPDATABLE_ATTRIBUTES = %i[label_ids folder_id starred unread].freeze | ||
def update(data) | ||
unupdatable_attributes = data.keys.reject { |name| UPDATABLE_ATTRIBUTES.include?(name) } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think about extracting a private method, something named like def update(data)
if unupdatable_attributes?(data)
raise ArgumentError, # message
else
super(data)
end
end ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make sense. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have added a new class to filter attributes here e40e7ce I think we are going to need this class everywhere where we don't want to send unwanted params to server. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh this is beautiful ✨ |
||
unless unupdatable_attributes.empty? | ||
raise ArgumentError, "Cannot update #{unupdatable_attributes} only " \ | ||
"#{UPDATABLE_ATTRIBUTES} are updatable" | ||
end | ||
super(data) | ||
end | ||
|
||
def expanded | ||
return self unless headers.nil? | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to add
starred
andunread
attributes here also? I'm not familiar with the DSL so I'm just looking at the pattern.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am going to check with these attributes and see what's happening. If we don't need it I will remove them from here. Thanks for the point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do have
started
andunread
define above the file so we are good. Thelabel_ids
was the missing one.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are actually here https://github.com/nylas/nylas-ruby/pull/231/files#diff-6027b1238ffa1b9852b7b40018edcbabL31-L32