CaptEmulation / clash-of-clans-api

:star::star::star: Clash of Clans :rage1: API NodeJS helper
MIT License
64 stars 25 forks source link

Clan Leader #8

Closed bruno-miguelito closed 6 years ago

bruno-miguelito commented 6 years ago

How can I filter the Clan Leader? You could have the option: clan.leader

CaptEmulation commented 6 years ago

I am looking at https://developer.clashofclans.com/#/documentation and I don't see this option... please tell me more....

Choubakawa commented 6 years ago

You can parse the memberlist and find the member with role equals to "leader" :)

CaptEmulation commented 6 years ago

My intention with this repo is be a simple layer over existing API. Since there is no way to request this kind of filtering, it must be done after the request, e.g.

const promiseLeader = client
  .clanMembersByTag('#ABC123')
  .then(response => response.items)
  .then(clanMembers => clanMembers.find(m => m.role === 'leader'));

(untested)

Choubakawa commented 6 years ago

100% agree with you ! This is what I was thinking when I said parse the memberlist.

I should have mentioned it in my message.

bruno-miguelito commented 6 years ago

For me it did not work, return [object Promise]. But it was something of the sort that was asking if he had how to do it

CaptEmulation commented 6 years ago

For me it did not work, return [object Promise]. But it was something of the sort that was asking if he had how to do it

returning a promise is not a bug, but an intended feature.

client
  .clanMembersByTag('#UPC2UQ')
  .then(response => response.memberList)
  .then(clanMembers => clanMembers.find(m => m.role === 'leader'))
  .then(leader => console.log(leader));

^ tested, works

CaptEmulation commented 6 years ago

All right.... I am going to close this issue as the code I posted works for me. I am trying to keep this library simple and focus just on requests and not data transformation.