Method: Bitly::API::Bitlink.sorted_list
- Defined in:
- lib/bitly/api/bitlink.rb
.sorted_list(client:, group_guid:, sort: "clicks", unit: nil, units: nil, unit_reference: nil, size: nil) ⇒ Object
Returns a list of Bitlinks sorted by clicks. [‘GET /v4/groups/group_guid/bitlinks/sort`](dev.bitly.com/v4/#operation/getSortedBitlinks)
The API returns a separate list of the links and the click counts, but this method assigns the number of clicks for each link to the Bitlink object and sorts the resulting list in descending order.
Sorted lists are not paginated, so do not have any pagination detail.
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/bitly/api/bitlink.rb', line 220 def self.sorted_list(client:, group_guid:, sort: "clicks", unit: nil, units: nil, unit_reference: nil, size: nil) params = { "unit" => unit, "units" => units, "unit_reference" => unit_reference, "size" => size } response = client.request(path: "/groups/#{group_guid}/bitlinks/#{sort}", params: params) link_clicks = response.body["sorted_links"] bitlinks = response.body["links"].map do |link| clicks = link_clicks.find { |c| c["id"] == link["id"] }["clicks"] new(data: link, client: client, clicks: clicks) end.sort { |a, b| b.clicks <=> a.clicks } List.new(items: bitlinks, response: response) end |