Last active
August 26, 2016 15:51
-
-
Save dpawluk/61d8ed3d93651b382a0c21d97a6c60bd to your computer and use it in GitHub Desktop.
comments.json resource with system/via and data not relevant to the example stripped. Shows how to filter this comments page using the ruby client and built-in ruby functions. The example comments follow this pattern: foo = private, bar = public
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # This script assumes you have instantiated a ZendeskAPI::Client and assigned it to 'client' | |
| ticket = client.tickets.find(:id => 4060) | |
| comments = ticket.comments.fetch | |
| # Iterate over comments and show comment value and value for the 'public' attribute (using example json public comments are 'bar' and private are 'foo') | |
| comments.each do |c| | |
| puts "the comment value is #{c.body}" | |
| puts "the comments 'public' attribute is #{c.public}" | |
| end;nil | |
| # Iterate over comments with select() which takes a comparison and filters out any items where the comparison does not match | |
| # var_filtered = array.select {|iteratee| iteratee.predicate == filter_criteria} | |
| public_comments = comments.select {|c| c.public == true} | |
| # Should only output comments with 'bar' in value (and description) | |
| public_comments.each do |c| | |
| puts c.body | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "comments": [ | |
| { | |
| "id": 152304242507, | |
| "type": "Comment", | |
| "author_id": 481734407, | |
| "body": "This is the first comment on the request.\n\ndantheman", | |
| "html_body": "<div class=\"zd-comment\">\n<p dir=\"auto\">This is the first comment on the request.</p>\n<p dir=\"auto\">dantheman</p>\n</div>", | |
| "public": true, | |
| }, | |
| { | |
| "id": 152653101188, | |
| "type": "Comment", | |
| "author_id": 481734407, | |
| "body": "foo", | |
| "html_body": "<div class=\"zd-comment\"><p dir=\"auto\">foo</p></div>", | |
| "public": false, | |
| }, | |
| { | |
| "id": 152304381087, | |
| "type": "Comment", | |
| "author_id": 481734407, | |
| "body": "bar\n\ndantheman", | |
| "html_body": "<div class=\"zd-comment\">\n<p dir=\"auto\">bar</p>\n<p dir=\"auto\">dantheman</p>\n</div>", | |
| "public": true, | |
| }, | |
| { | |
| "id": 152304398147, | |
| "type": "Comment", | |
| "author_id": 481734407, | |
| "body": "bar\n\ndantheman", | |
| "html_body": "<div class=\"zd-comment\">\n<p dir=\"auto\">bar</p>\n<p dir=\"auto\">dantheman</p>\n</div>", | |
| "public": true, | |
| }, | |
| { | |
| "id": 152304427667, | |
| "type": "Comment", | |
| "author_id": 481734407, | |
| "body": "foo", | |
| "html_body": "<div class=\"zd-comment\"><p dir=\"auto\">foo</p></div>", | |
| "public": false, | |
| }, | |
| { | |
| "id": 152304462487, | |
| "type": "Comment", | |
| "author_id": 481734407, | |
| "body": "foo", | |
| "html_body": "<div class=\"zd-comment\"><p dir=\"auto\">foo</p></div>", | |
| "public": false, | |
| }, | |
| { | |
| "id": 152304485047, | |
| "type": "Comment", | |
| "author_id": 481734407, | |
| "body": "bar\n\ndantheman", | |
| "html_body": "<div class=\"zd-comment\">\n<p dir=\"auto\">bar</p>\n<p dir=\"auto\">dantheman</p>\n</div>", | |
| "public": true, | |
| }, | |
| { | |
| "id": 152653288548, | |
| "type": "Comment", | |
| "author_id": 481734407, | |
| "body": "foo", | |
| "html_body": "<div class=\"zd-comment\"><p dir=\"auto\">foo</p></div>", | |
| "public": false, | |
| }, | |
| { | |
| "id": 152304541607, | |
| "type": "Comment", | |
| "author_id": 481734407, | |
| "body": "bar\n\ndantheman", | |
| "html_body": "<div class=\"zd-comment\">\n<p dir=\"auto\">bar</p>\n<p dir=\"auto\">dantheman</p>\n</div>", | |
| "public": true, | |
| }, | |
| { | |
| "id": 152304567787, | |
| "type": "Comment", | |
| "author_id": 481734407, | |
| "body": "foo", | |
| "html_body": "<div class=\"zd-comment\"><p dir=\"auto\">foo</p></div>", | |
| "public": false, | |
| }, | |
| { | |
| "id": 152653365708, | |
| "type": "Comment", | |
| "author_id": 481734407, | |
| "body": "foo", | |
| "html_body": "<div class=\"zd-comment\"><p dir=\"auto\">foo</p></div>", | |
| "public": false, | |
| } | |
| ], | |
| "next_page": null, | |
| "previous_page": null, | |
| "count": 11 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment