lanej / zendesk2

Zendesk API V2 client using Cistern
http://lanej.io/zendesk2/
MIT License
25 stars 28 forks source link

"next_page" on collection doesn't seem to work #12

Closed seemantk closed 11 years ago

seemantk commented 11 years ago

Here's my irb session:

>> zd = Zendesk2::Client.new(subdomain: config['host'], username: config['user'], password: config['password'])
=> #<Zendesk2::Client::Real:0x007f8c83b3f9b8 @url="https://engineyard.zendesk.com", @logger=#<Logger:0x007f8c83b3f508 @progname=nil, @level=0, @default_formatter=#<Logger::Formatter:0x007f8c83b3f4e0 @datetime_format=nil>, @formatter=nil, @logdev=nil>, @username="eyzendesk@gmail.com", @auth_token="VewkijpijOkDorfUcUct", @connection=#<Faraday::Connection:0x007f8c83b3f3a0 @headers={}, @params={}, @options={}, @ssl={:verify=>false}, @parallel_manager=nil, @default_parallel_manager=nil, @builder=#<Faraday::Builder:0x007f8c83b3f260 @handlers=[Faraday::Request::BasicAuthentication, Faraday::Response::RaiseError, FaradayMiddleware::ParseJson, Faraday::Request::Multipart, FaradayMiddleware::EncodeJson, Zendesk2::Logger, Faraday::Adapter::NetHttp]>, @url_prefix=#<URI::HTTPS:0x007f8c83b3efe0 URL:https://engineyard.zendesk.com/>, @proxy=nil>>
>> zd.users.search(:email => 'anurag@hitfix.com')
=> #<Zendesk2::Client::Users:0x7f8c81ad0088 attributes={next_page_link:nil,previous_page_link:nil,count:1}>
>> user = zd.users.search(:email => 'anurag@hitfix.com').first
or=> #<Zendesk2::Client::User:0x7f8c8208f0a0 attributes={url:"https://engineyard.zendesk.com/api/v2/users/205426458.json",id:205426458,external_id:"8e8db720a51013c3f789ab5d96c9ba183505d03b",name:"Anurag Jain",alias:"",created_at:2012-04-25 18:16:53 UTC,updated_at:2012-12-29 06:05:08 UTC,active:true,verified:true,shared:false,locale_id:1,time_zone:"Pacific Time (US & Canada)",last_login_at:2012-12-29 06:05:08 UTC,email:"anurag@hitfix.com",phone:"",signature:"",details:"",notes:"",organization_id:20297761,role:"end-user",custom_role_id:nil,moderator:false,ticket_restriction:"requested",only_private_comments:false,tags:[],suspended:false,photo:nil}>
>> org = user.organization
=> #<Zendesk2::Client::Organization:0x7f8c82121d38 attributes={url:"https://engineyard.zendesk.com/api/v2/organizations/20297761.json",id:20297761,external_id:nil,name:"HitFix",created_at:2011-08-15 19:08:15 UTC,updated_at:2012-11-01 17:30:48 UTC,domain_names:[],details:"Cloud-Support: premium",notes:"CEE - Kevin French\r\n\r\n**\r\nRESPOND PROMPTLY - many complaints regarding SLAs being missed.\r\n**\r\n\r\nhttp://cloud.engineyard.com/admin/accounts/9382\r\n\r\nEliot (non-technical contact): 617-372-4185\r\n\r\nKevin French is the CE for this account.  Feel free to CC if any tickets do a nosedive or otherwise require white glove treatment.",group_id:nil,shared_tickets:true,shared_comments:true,tags:[]}>
>> zd.tickets.search(:organization_id => org.id)
=> #<Zendesk2::Client::Tickets:0x7f8c8218f978 attributes={next_page_link:"https://engineyard.zendesk.com/api/v2/search.json?page=2&query=%22organization_id%3A20297761+type%3Aticket%22",previous_page_link:nil,count:142}>
>> tix = zd.tickets.search(:organization_id => org.id)
ti=> #<Zendesk2::Client::Tickets:0x7f8c83b88000 attributes={next_page_link:"https://engineyard.zendesk.com/api/v2/search.json?page=2&query=%22organization_id%3A20297761+type%3Aticket%22",previous_page_link:nil,count:142}>
>> tix.next_page_link
=> "https://engineyard.zendesk.com/api/v2/search.json?page=2&query=%22organization_id%3A20297761+type%3Aticket%22"
>> tix.next_page
=> #<Zendesk2::Client::Tickets:0x7f8c83b85170 attributes={next_page_link:"https://engineyard.zendesk.com/api/v2/tickets.json?page=3&query=%22organization_id%3A20297761+type%3Aticket%22",previous_page_link:"https://engineyard.zendesk.com/api/v2/tickets.json?page=1&query=%22organization_id%3A20297761+type%3Aticket%22",count:52919}>

The count field has gone from 142 to 52919, which is the aggregate count of all Engine Yard tickets. Proof:

>> tix = zd.tickets.search(:organization_id => org.id)
=> #<Zendesk2::Client::Tickets:0x7f8c83a92920 attributes={next_page_link:"https://engineyard.zendesk.com/api/v2/search.json?page=2&query=%22organization_id%3A20297761+type%3Aticket%22",previous_page_link:nil,count:142}>
>> tix.map { |t| t.id }
=> [28792, 27833, 28873, 28574, 29363, 29424, 29110, 28778, 28780, 30104, 30442, 29118, 32891, 31603, 31644, 31418, 32079, 31896, 32351, 32562, 32542, 32422, 32856, 32869, 35066, 35635, 34442, 34656, 34774, 33573, 33625, 34138, 35043, 35065, 35630, 33419, 35401, 34436, 35058, 35338, 35650, 35957, 36120, 37582, 36235, 36140, 35840, 36197, 37707, 37879, 37581, 36861, 38893, 38587, 38441, 39266, 37069, 38690, 38764, 39344, 39407, 41238, 39505, 39766, 39656, 39688, 40200, 40381, 40652, 41237, 41832, 42060, 42196, 42305, 40313, 43904, 43466, 44094, 44078, 44427, 41257, 46942, 46456, 47118, 43905, 45372, 44995, 47428, 47227, 47424, 48381, 48420, 47718, 48693, 48744, 48556, 48789, 49933, 39955, 48378]
>> tix.next_page.map { |t| t.id }
=> [191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 224, 225, 226, 227, 228, 229, 230, 231, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294]
seemantk commented 11 years ago

Rescinded previous comment. I tried replacing the next_page_link with a URI.unescaped version. That version just keeps returning the same 100 results back, and keeps the count at total # of tickets for everyone everywhere ever.

seemantk commented 11 years ago

Hi Josh,

The url is now fetched. However, the returned results are of the entire set of tickets:

>> u = zendesk.users.search(email: 'anurag@hitfix.com').first
=> #<Zendesk2::Client::User:0x7faaaab56998 attributes={url:"https://engineyard.zendesk.com/api/v2/users/205426458.json",id:205426458,external_id:"8e8db720a51013c3f789ab5d96c9ba183505d03b",name:"Anurag Jain",alias:"",created_at:2012-04-25 18:16:53 UTC,updated_at:2012-12-29 06:05:08 UTC,active:true,verified:true,shared:false,locale_id:1,time_zone:"Pacific Time (US & Canada)",last_login_at:2012-12-29 06:05:08 UTC,email:"anurag@hitfix.com",phone:"",signature:"",details:"",notes:"",organization_id:20297761,role:"end-user",custom_role_id:nil,moderator:false,ticket_restriction:"requested",only_private_comments:false,tags:[],suspended:false,photo:nil}>
>> t = zendesk.tickets.search(organization_id: u.organization_id)
=> #<Zendesk2::Client::Tickets:0x7faaaabd2b60 attributes={count:145,next_page_link:"https://engineyard.zendesk.com/api/v2/search.json?page=2&query=%22organization_id%3A20297761+type%3Aticket%22",previous_page_link:nil}>
>> t2 = t.next_page
=> #<Zendesk2::Client::Tickets:0x7faaaab33308 attributes={count:53037,next_page_link:"https://engineyard.zendesk.com/api/v2/tickets.json?page=3&query=%22organization_id%3A20297761+type%3Aticket%22",previous_page_link:"https://engineyard.zendesk.com/api/v2/tickets.json?page=1&query=%22organization_id%3A20297761+type%3Aticket%22"}>

(Note the count: attribute in both search results)

Further, the actual ticket in the first page is accurate, but the actual ticket in the next_page is the actual first ticket ever filed, I think (https://support.cloud.engineyard.com/tickets/190 is a test one):

>> t[0]
=> #<Zendesk2::Client::Ticket:0x7faaaabd2a48 attributes={url:"https://engineyard.zendesk.com/api/v2/tickets/28792.json",id:28792,external_id:"",via:{"channel"=>"web", "source"=>{"from"=>{}, "to"=>{}, "rel"=>nil}},created_at:2011-09-01 17:03:47 UTC,updated_at:2011-10-02 08:27:21 UTC,type:"",subject:"solr connection keeps flaking",description:"Hi,\r\nOur application connects to the utilities server for solr search. This is an integral part of the process, and for some reason, it keeps failing periodically. If I kill the solr process, it restarts very soon thereafter, but soon just sits there, while connections to http://domU-12-31-39-01-C5-C1.compute-1.internal:8983/solr (internally) start timing out.\r\n\r\nThis is urgent because \r\n1. search functionality on our site is down\r\n2. our editors cannot publish anything.\r\n\r\nAny help here is greatly appreciated.\r\n\r\nThanks,\r\nAnu\r\n",priority:"urgent",status:"closed",recipient:"",requester_id:76644918,submitter_id:76644918,assignee_id:14523051,organization_id:20297761,group_id:20008808,collaborator_ids:[],forum_topic_id:nil,problem_id:nil,has_incidents:false,due_at:nil,tags:["cat_customer_education", "high", "prod_appcloud", "survey", "survey_notified", "this_took_over_an_hour_"],custom_fields:[{"id"=>20767583, "value"=>nil}, {"id"=>20012603, "value"=>"high"}, {"id"=>20011112, "value"=>"this_took_over_an_hour_"}, {"id"=>20013206, "value"=>"prod_appcloud"}, {"id"=>20957676, "value"=>nil}, {"id"=>22191568, "value"=>nil}, {"id"=>20407851, "value"=>nil}, {"id"=>20012528, "value"=>"cat_customer_education"}, {"id"=>20305226, "value"=>false}, {"id"=>20348056, "value"=>nil}, {"id"=>20212126, "value"=>false}, {"id"=>20348007, "value"=>nil}, {"id"=>20829523, "value"=>nil}, {"id"=>20936928, "value"=>nil}, {"id"=>20820013, "value"=>nil}, {"id"=>20820018, "value"=>nil}],satisfaction_rating:{"score"=>"good", "comment"=>""},sharing_agreement_ids:[]}>
>> t2[0]
=> #<Zendesk2::Client::Ticket:0x7faaaab28b88 attributes={url:"https://engineyard.zendesk.com/api/v2/tickets/191.json",id:191,external_id:"",via:{"channel"=>"web", "source"=>{"from"=>{}, "to"=>{}, "rel"=>nil}},created_at:2009-08-20 18:23:58 UTC,updated_at:2010-02-23 08:02:09 UTC,type:"question",subject:"Custom Chef Script",description:"Hello,\r\nI know that writing custom chef scripts is outside of the scope of Flex beta support.  How much would your professional services team charge to write a Chef script that I could use with the Flex EY deployment process to make the following changes to the server after boot:\r\n\r\n1) I've added the PHP package to my application's requirements, however, the default configuration of PHP has one parameter set to off in the default php.ini file.  I need a script to set allow_fopen_url permissions in php.ini file \r\n\r\n2) I need to set +w permissions on two directories.\r\n\r\nJust curious how much and how long this would take, so I can see if it's more cost-effective to have you assist with this rather than me researching how to build the scripts.\r\n\r\nThanks,\r\n\r\nRob\r\n\r\n",priority:"normal",status:"closed",recipient:"",requester_id:3299237,submitter_id:3299237,assignee_id:2532369,organization_id:36499,group_id:45544,collaborator_ids:[],forum_topic_id:nil,problem_id:nil,has_incidents:false,due_at:nil,tags:["audited", "billing_complete", "easy", "non-billable", "php"],custom_fields:[{"id"=>20767583, "value"=>nil}, {"id"=>20012603, "value"=>nil}, {"id"=>20011112, "value"=>nil}, {"id"=>20013206, "value"=>nil}, {"id"=>20957676, "value"=>nil}, {"id"=>22191568, "value"=>nil}, {"id"=>20407851, "value"=>nil}, {"id"=>20012528, "value"=>nil}, {"id"=>20305226, "value"=>nil}, {"id"=>20348056, "value"=>nil}, {"id"=>20212126, "value"=>nil}, {"id"=>20348007, "value"=>nil}, {"id"=>20829523, "value"=>nil}, {"id"=>20936928, "value"=>nil}, {"id"=>20820013, "value"=>nil}, {"id"=>20820018, "value"=>nil}],satisfaction_rating:nil,sharing_agreement_ids:[]}>