Skip to content

Fetch QR codes from API#89

Merged
philnash merged 1 commit intophilnash:mainfrom
ssaunier:qrcodes
Feb 18, 2025
Merged

Fetch QR codes from API#89
philnash merged 1 commit intophilnash:mainfrom
ssaunier:qrcodes

Conversation

@ssaunier
Copy link
Contributor

Migrating away from Bitly to a custom developed tool, I relied on Bitly API to download all bitlinks from my account. I also wanted to export the QR codes and the gem did not provide the capability yet, even if the endpoints are there.

This PR adds a new Qrcode model to the gem, with some capability to retrieve QR codes:

require "bitly"

client = Bitly::API::Client.new(token: "[REDACTED]")
group = client.groups.first

qrcodes = []
response = group.qrcodes
while response
  response.each do |qrcode|
    next if qrcode.qr_code_type != "bitlink"

    qrcodes << {
      created: qrcode.created,
      slug: URI.parse(qrcode.serialized_content).path.gsub(/^\//, ""),
      long_url: qrcode.long_urls.first,
      title: qrcode.title,
      total_scans: qrcode.scans_summary.total_scans
    }
  end
  response = response.next_page
end

# `qrcodes` Array now contains all QR codes, and can be dumped to a CSV for instance.

@philnash philnash merged commit f15acd5 into philnash:main Feb 18, 2025
8 of 9 checks passed
@philnash
Copy link
Owner

Thanks for this! I've pushed these updates as version 3.1.0 of the gem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants