-
Notifications
You must be signed in to change notification settings - Fork 53
Update kizen.rb #115
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
base: kizen
Are you sure you want to change the base?
Update kizen.rb #115
Conversation
@doctordav011 Could you fix the hound comments first! |
@@ -783,6 +1532,21 @@ | |||
[res['full_name'].presence || 'unknown', res['id']] | |||
end | |||
end, | |||
|
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.
Layout/TrailingWhitespace: Trailing whitespace detected.
order_status: lambda do |connection| | ||
[ | ||
# Display name, value | ||
['paid', 'paid'] |
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.
Style/WordArray: Use %w or %W for an array of words.
url = 'https://app.kizen.com/api/lead-source-custom-source-type' | ||
get(url)['results'].pluck('name', 'id') | ||
}, | ||
|
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.
Layout/TrailingWhitespace: Trailing whitespace detected.
url = 'https://app.kizen.com/api/activity-type?fields=id,name,created' | ||
get(url).pluck('name', 'id') | ||
}, | ||
|
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.
Layout/TrailingWhitespace: Trailing whitespace detected.
] | ||
end | ||
} | ||
}, |
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.
Layout/IndentHash: Indent the right brace the same as the start of the line where the left brace is.
} | ||
}, | ||
|
||
dedup: ->(contacts) { |
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.
Style/Lambda: Use the lambda method for multiline lambdas.
activity_id = input['activities'] | ||
puts activity_id | ||
page ||= 1 | ||
response = get("https://app.kizen.com/api/logged-activity?activity_type_id=#{activity_id}") |
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.
Metrics/LineLength: Line is too long. [95/80]
contacts = get("https://app.kizen.com/api/client-field-revision") | ||
.params( | ||
order_by: 'updated_at', | ||
order_type: 'asc', |
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.
Layout/TrailingWhitespace: Trailing whitespace detected.
input_fields: ->() { | ||
}, | ||
|
||
poll: ->(connection, input, last_updated_since) { |
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.
Style/Lambda: Use the lambda method for multiline lambdas.
Lint/UnusedBlockArgument: Unused block argument - connection. If it's necessary, use _ or _connection as an argument name to indicate that it won't be used.
|
||
updated_contact: { #This is new | ||
|
||
input_fields: ->() { |
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.
Style/Lambda: Use the lambda method for multiline lambdas.
Style/EmptyLambdaParameter: Omit parentheses for the empty lambda parameters.
Layout/SpaceInsideBlockBraces: Space inside empty braces detected.
end | ||
}, | ||
|
||
new_logged_activity: {# I'm having trouble parsing the output on this |
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.
Layout/AlignHash: Align the elements of a hash literal if they span more than one line.
Layout/SpaceBeforeComment: Put a space before an end-of-line comment.
|
||
}, | ||
|
||
updated_contact: {# This is new |
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.
Layout/AlignHash: Align the elements of a hash literal if they span more than one line.
Layout/SpaceBeforeComment: Put a space before an end-of-line comment.
response = get("https://app.kizen.com/api/scheduled-activity?activity_type=#{activity_id}") | ||
.params(order_by: 'created', | ||
order_type: 'asc', | ||
page: page, |
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.
Layout/AlignHash: Align the elements of a hash literal if they span more than one line.
page ||= 1 | ||
response = get("https://app.kizen.com/api/scheduled-activity?activity_type=#{activity_id}") | ||
.params(order_by: 'created', | ||
order_type: 'asc', |
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.
Layout/AlignHash: Align the elements of a hash literal if they span more than one line.
page_size = 50 | ||
activity_id = input['activities'] | ||
page ||= 1 | ||
response = get("https://app.kizen.com/api/scheduled-activity?activity_type=#{activity_id}") |
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.
Metrics/LineLength: Line is too long. [99/80]
dedup: lambda do |contact| | ||
contact['id'] | ||
end, | ||
|
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.
Layout/TrailingWhitespace: Trailing whitespace detected.
can_poll_more: records.size >= page_size | ||
} | ||
end, | ||
|
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.
Layout/TrailingWhitespace: Trailing whitespace detected.
per_page: page_size | ||
) | ||
records = response&.[]('results') || [] | ||
page = records.size >= page_size ? page + 1 : 1 |
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.
Layout/TrailingWhitespace: Trailing whitespace detected.
title: 'New Order', | ||
subtitle: 'New Order in Kizen', | ||
description: lambda do | ||
"New <span class='provider'>Order</span> in <span class='provider'>Kizen</span>" |
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.
Metrics/LineLength: Line is too long. [88/80]
@@ -744,9 +1284,210 @@ | |||
get("https://api.kizen.com/#{input['object']}?page=1&page_size=1") | |||
.dig('results', 0) | |||
end | |||
}, | |||
new_order: { |
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.
Layout/TrailingWhitespace: Trailing whitespace detected.
.params(order_by: 'created', | ||
order_type: 'asc', | ||
page: page, | ||
per_page: page_size) |
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.
Layout/AlignHash: Align the elements of a hash literal if they span more than one line.
order_type: 'asc', | ||
page: page, | ||
per_page: page_size | ||
) |
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.
Layout/ClosingParenthesisIndentation: Align ) with (.
Layout/MultilineMethodCallBraceLayout: Closing method call brace must be on the same line as the last argument when opening brace is on the same line as the first argument.
response = get("https://app.kizen.com/api/commerce/orders") | ||
.params(order_by: 'created', | ||
order_type: 'asc', | ||
page: page, |
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.
Layout/AlignHash: Align the elements of a hash literal if they span more than one line.
.params(order_by: 'created', | ||
order_type: 'asc', | ||
page: page, | ||
per_page: page_size |
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.
Layout/AlignHash: Align the elements of a hash literal if they span more than one line.
page ||= 1 | ||
response = get("https://app.kizen.com/api/commerce/orders") | ||
.params(order_by: 'created', | ||
order_type: 'asc', |
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.
Layout/AlignHash: Align the elements of a hash literal if they span more than one line.
] | ||
end | ||
} | ||
}, |
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.
Layout/IndentHash: Indent the right brace the same as the start of the line where the left brace is.
[ | ||
{ name: 'email', optional: false }, | ||
{ name: 'order_status', | ||
optional: false, |
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.
Layout/TrailingWhitespace: Trailing whitespace detected.
'created': input['created'], | ||
'client': { 'email': input['email'] }, | ||
'upload': true, | ||
'line_items': [ |
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.
Layout/AlignHash: Align the elements of a hash literal if they span more than one line.
'order_number': input['order_number'], | ||
'created': input['created'], | ||
'client': { 'email': input['email'] }, | ||
'upload': true, |
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.
Layout/AlignHash: Align the elements of a hash literal if they span more than one line.
end | ||
}, | ||
|
||
create_order: { # This is new |
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.
Layout/AlignHash: Align the elements of a hash literal if they span more than one line.
|
||
execute: lambda do |connection, input| | ||
results = get("https://app.kizen.com/api/deal?search=#{input["name"]}") | ||
records = results["results"] |
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.
Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
end, | ||
|
||
execute: lambda do |connection, input| | ||
results = get("https://app.kizen.com/api/deal?search=#{input["name"]}") |
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.
Style/StringLiteralsInInterpolation: Prefer single-quoted strings inside interpolations.
] | ||
end, | ||
|
||
execute: lambda do |connection, input| |
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.
Lint/UnusedBlockArgument: Unused block argument - connection. If it's necessary, use _ or _connection as an argument name to indicate that it won't be used.
} | ||
] | ||
end, | ||
|
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.
Layout/TrailingWhitespace: Trailing whitespace detected.
end | ||
}, | ||
|
||
find_deal_by_name: { # This is new |
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.
Layout/AlignHash: Align the elements of a hash literal if they span more than one line.
object_definitions['contact_fields_output'] | ||
end | ||
}, | ||
find_company_by_name: { # This is new |
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.
Layout/AlignHash: Align the elements of a hash literal if they span more than one line.
properties: object_definitions['contact_fields_trigger_output'] } | ||
end | ||
}, | ||
find_contact_by_id: { # This is new |
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.
Layout/AlignHash: Align the elements of a hash literal if they span more than one line.
] | ||
end, | ||
}, | ||
find_contact_by_email: { # This is new |
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.
Layout/AlignHash: Align the elements of a hash literal if they span more than one line.
object_definitions['log_activity_input'] | ||
end, | ||
|
||
execute: lambda do |_connection, input| |
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.
Metrics/BlockLength: Block has too many lines. [28/25]
}, | ||
log_activity: { # This is new |
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.
Layout/AlignHash: Align the elements of a hash literal if they span more than one line.
end, | ||
execute: lambda do |_connection, input| | ||
post('https://app.kizen.com/api/lead-source-custom-source') | ||
.payload( |
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.
Layout/MultilineMethodCallIndentation: Use 2 (not 5) spaces for indenting an expression spanning multiple lines.
[ | ||
{ name: 'client_id', Label: 'Contact ID', optional: false }, | ||
{ name: 'source', | ||
Label: 'Custom Lead Source', |
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.
Layout/TrailingWhitespace: Trailing whitespace detected.
input_fields: lambda do | ||
[ | ||
{ name: 'client_id', Label: 'Contact ID', optional: false }, | ||
{ name: 'source', |
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.
Layout/TrailingWhitespace: Trailing whitespace detected.
end, | ||
}, | ||
|
||
add_custom_lead_source: { # This is new here |
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.
Layout/AlignHash: Align the elements of a hash literal if they span more than one line.
[ | ||
{ name: 'id'} | ||
] | ||
end, |
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.
Style/TrailingCommaInHashLiteral: Avoid comma after the last item of a hash.
end, | ||
output_fields: lambda do | ||
[ | ||
{ name: 'id'} |
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.
Layout/SpaceInsideHashLiteralBraces: Space inside } missing.
"#{input["property_label1"]}"=> input["property_input1"], | ||
"#{input["property_label2"]}"=> input["property_input2"]} | ||
) | ||
end, |
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.
Layout/TrailingWhitespace: Trailing whitespace detected.
end, | ||
execute: lambda do |_connection, input| | ||
post('https://app.kizen.com/api/interaction') | ||
.payload( |
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.
Layout/MultilineMethodCallIndentation: Use 2 (not 5) spaces for indenting an expression spanning multiple lines.
|
||
inject_special_characters: lambda do |input| | ||
input.gsub( | ||
/(__hyp__|__lt__|__gt__|__excl__|__at__|__hashtag__|__dollar__|\__percent__|__pwr__|__amper__|__star__|__lbracket__|__rbracket__|__plus__|__eq__|__rcrbrack__|__lcrbrack__|__semicol__|__apost__|__bckquot__|__tilde__|__comma__|__period__|__qmark__|__pipe__|__colon__|__quote__|__slash__|__bslash__)/, |
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.
Metrics/LineLength: Line is too long. [306/80]
'name': input['name'], | ||
'properties': { | ||
"#{input['property_label1']}" => input['property_input1'], | ||
"#{input['property_label2']}" => input['property_input2'] |
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.
Style/UnneededInterpolation: Prefer to_s over string interpolation.
'client_id': input['client_id'], | ||
'name': input['name'], | ||
'properties': { | ||
"#{input['property_label1']}" => input['property_input1'], |
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.
Style/UnneededInterpolation: Prefer to_s over string interpolation.
'\"' => '__quote__') | ||
end, | ||
|
||
inject_special_characters: lambda do |input| |
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.
Metrics/BlockLength: Block has too many lines. [30/25]
end | ||
end, | ||
|
||
replace_special_characters: lambda do |input| |
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.
Metrics/BlockLength: Block has too many lines. [28/25]
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.
Please try to fix some of the hound comments and there are some alignment issues!
format_payload: lambda do |payload| | ||
if payload.is_a?(Array) | ||
payload.map do |array_value| | ||
call('format_payload', array_value) | ||
end | ||
elsif payload.is_a?(Hash) | ||
payload.map do |key, value| | ||
key = call('inject_special_characters', key) | ||
if value.is_a?(Array) || value.is_a?(Hash) | ||
value = call('format_payload', value) | ||
end | ||
{ key => value } | ||
end.inject(:merge) | ||
end | ||
end, |
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.
This has been replaced with the format_input
method
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.
deleted format_payload method and changed to format_input
format_schema: lambda do |schema| | ||
if schema.is_a?(Array) | ||
schema.map do |array_value| | ||
call('format_schema', array_value) | ||
end | ||
elsif schema.is_a?(Hash) | ||
schema.map do |key, value| | ||
if %w[name].include?(key.to_s) | ||
value = call('replace_special_characters', value.to_s) | ||
elsif %w[properties toggle_field].include?(key.to_s) | ||
value = call('format_schema', value) | ||
end | ||
{ key => value } | ||
end.inject(:merge) | ||
end | ||
end, |
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 have done away with this method. This can be seen in the object_input
method as standard input fields do not have special characters anyway.
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.
If I change these references to object_input, the object input method does not have the correct 'cases' for the other objects(activities, interactions, etc.).
end | ||
end, | ||
|
||
replace_special_characters: lambda do |input| |
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 not need this method anymore. Instead, we do a simple replacement of -
s with _
s when we retrieve custom fields in the get_custom_fields
method. When we are preparing the payload, we use format_input
to switch everything back. Could your actions and triggers use format_input
and get_custom_fields
instead?
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'm not sure how to do this.
'\"' => '__quote__') | ||
end, | ||
|
||
inject_special_characters: lambda do |input| |
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.
Same here
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'm not sure how to do this.
) | ||
end, | ||
|
||
format_response: lambda do |payload| |
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.
This has been replaced with the format_output
method. Could we use format_output
in the new actions and triggers?
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.
Deleted format_response and changed references to format_output
@@ -632,8 +858,312 @@ | |||
get("https://api.kizen.com/#{input['object']}?page=1&page_size=1") | |||
.dig('results', 0) | |||
end | |||
} | |||
}, | |||
log_interaction: { # This is new |
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.
Can we group log activity
and log interaction
together? into log event
action. This can be easily done by following the patterns in the create_object
and update_object
steps
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 don't really want to do this. It is important to have all possible actions shown to the end user on the very first screen(https://www.workato.com/integrations/kizen) so they can see how many actions and triggers are possible.
] | ||
end | ||
}, | ||
find_contact_by_email: { # This is new |
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.
Can we group Find contact by email
,Find contact by id
, Find company by name
and Find deal by name
into a single Search object
action? This can be easily done by following the patterns in the create_object
and update_object
steps
It could be Search objects
with object selection for
- Contact by ID
- Contact by email
- Company by name
- Deal by name
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 don't really want to do this. It is important to have all possible actions shown to the end user on the very first screen(https://www.workato.com/integrations/kizen) so they can see how many actions and triggers are possible.
execute: lambda do |_connection, input| | ||
results = get("https://app.kizen.com/api/client?email=#{input['email']}") | ||
records = results['results'] | ||
puts records |
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.
Remove all puts
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.
Done
Added 4 new triggers and 8 new actions