Skip to content

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

Open
wants to merge 24 commits into
base: kizen
Choose a base branch
from
Open

Update kizen.rb #115

wants to merge 24 commits into from

Conversation

doctordav011
Copy link

Added 4 new triggers and 8 new actions

@bennettgo
Copy link
Contributor

@doctordav011 Could you fix the hound comments first!

@@ -783,6 +1532,21 @@
[res['full_name'].presence || 'unknown', res['id']]
end
end,

Copy link

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']
Copy link

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')
},

Copy link

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')
},

Copy link

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
}
},
Copy link

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) {
Copy link

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}")
Copy link

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',
Copy link

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) {
Copy link

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: ->() {
Copy link

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
Copy link

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
Copy link

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,
Copy link

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',
Copy link

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}")
Copy link

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,

Copy link

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,

Copy link

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
Copy link

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>"
Copy link

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: {
Copy link

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)
Copy link

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
)
Copy link

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,
Copy link

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
Copy link

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',
Copy link

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
}
},
Copy link

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,
Copy link

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': [
Copy link

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,
Copy link

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
Copy link

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"]
Copy link

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"]}")
Copy link

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|
Copy link

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,

Copy link

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
Copy link

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
Copy link

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
Copy link

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
Copy link

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|
Copy link

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
Copy link

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(
Copy link

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',
Copy link

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',
Copy link

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
Copy link

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,
Copy link

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'}
Copy link

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,
Copy link

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(
Copy link

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__)/,
Copy link

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']
Copy link

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'],
Copy link

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|
Copy link

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|
Copy link

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]

Copy link
Contributor

@bennettgo bennettgo left a 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!

Comment on lines 59 to 73
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,
Copy link
Contributor

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

Copy link
Author

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

Comment on lines +75 to +90
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,
Copy link
Contributor

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.

Copy link
Author

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|
Copy link
Contributor

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?

Copy link
Author

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|
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here

Copy link
Author

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|
Copy link
Contributor

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?

Copy link
Author

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
Copy link
Contributor

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

Copy link
Author

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
Copy link
Contributor

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

  1. Contact by ID
  2. Contact by email
  3. Company by name
  4. Deal by name

Copy link
Author

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
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove all puts

Copy link
Author

Choose a reason for hiding this comment

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

Done

@doctordav011 doctordav011 requested a review from bennettgo May 26, 2020 21:01
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