lanej / zendesk2

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

Empty attributes: organization.tickets and user.tickets #13

Closed seemantk closed 11 years ago

seemantk commented 11 years ago

When loading an organization or user, it would be great if organization.tickets simply ran a query like tickets.search(:organization_id = self.id) automatically. Same for the tickets attribute in users.

Adding more detail to this, you're right that the underlying array is populated, but the attributes are empty:

u = zendesk.users.search(email: 'anurag@hitfix.com').first
=> #<Zendesk2::Client::User:0x7fe7914ffe68 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}>
>> u.organization.tickets
=> #<Zendesk2::Client::Tickets:0x7fe79151b898 attributes={}>
>> o = u.organization
=> #<Zendesk2::Client::Organization:0x7fe79101cd38 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:[]}>
>> o.tickets
=> #<Zendesk2::Client::Tickets:0x7fe79152e718 attributes={}>
lanej commented 11 years ago

organization.tickets already exists

http://rdoc.info/gems/zendesk2/Zendesk2/Client/Organization:tickets

lanej commented 11 years ago

so does user.requested_tickets

http://rdoc.info/gems/zendesk2/Zendesk2/Client/User:requested_tickets

seemantk commented 11 years ago

The attributes are empty, as you can see below. The underlying array is, however, populated.

u = zendesk.users.search(email: 'anurag@hitfix.com').first
=> #<Zendesk2::Client::User:0x7fe7914ffe68 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}>
>> u.organization.tickets
=> #<Zendesk2::Client::Tickets:0x7fe79151b898 attributes={}>
>> o = u.organization
=> #<Zendesk2::Client::Organization:0x7fe79101cd38 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:[]}>
>> o.tickets
=> #<Zendesk2::Client::Tickets:0x7fe79152e718 attributes={}>
lanej commented 11 years ago

requires a all call after it

seemantk commented 11 years ago

Here's what I see in irb:

>> u = zendesk.users.search(email: 'anurag@hitfix.com')
=> #<Zendesk2::Client::Users:0x7faaaab5cc30 attributes={count:1,next_page_link:nil,previous_page_link:nil}>
>> u = u.first
=> #<Zendesk2::Client::User:0x7faaaab5cb90 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 = u.organization.tickets.all
=> #<Zendesk2::Client::Tickets:0x7faaaabf36d0 attributes={count:53037,next_page_link:"https://engineyard.zendesk.com/api/v2/tickets.json?page=2",previous_page_link:nil}>
>> t.size
=> 100
>> t[0]
=> #<Zendesk2::Client::Ticket:0x7faaaabf0db8 attributes={url:"https://engineyard.zendesk.com/api/v2/tickets/79.json",id:79,external_id:"",via:{"channel"=>"web", "source"=>{"from"=>{}, "to"=>{}, "rel"=>nil}},created_at:2009-07-02 19:55:16 UTC,updated_at:2009-07-06 21:01:26 UTC,type:"incident",subject:"Frozen Instance, cannot delete environment",description:"See subject.",priority:"high",status:"closed",recipient:"",requester_id:2716300,submitter_id:2716300,assignee_id:2532399,organization_id:32724,group_id:42428,collaborator_ids:[],forum_topic_id:nil,problem_id:nil,has_incidents:false,due_at:nil,tags:["medium"],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:[]}>
>> u.organization_id
=> 20297761

It's similar to the next_page bug.