Class: Bitly::API::Qrcode

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/bitly/api/qrcode.rb,
lib/bitly/api/qrcode/scans_summary.rb,
lib/bitly/api/qrcode/paginated_list.rb

Defined Under Namespace

Classes: List, PaginatedList, ScansSummary

Instance Attribute Summary

Attributes included from Base

#response

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Base

#assign_attributes

Constructor Details

#initialize(data:, client:, response: nil) ⇒ Qrcode

Returns a new instance of Qrcode.



93
94
95
96
97
# File 'lib/bitly/api/qrcode.rb', line 93

def initialize(data:, client:, response: nil)
  assign_attributes(data)
  @client = client
  @response = response
end

Class Method Details

.attributesObject



16
17
18
# File 'lib/bitly/api/qrcode.rb', line 16

def self.attributes
  [:qrcode_id, :title, :archived, :serialized_content, :long_urls, :bitlink_id, :qr_code_type, :render_customizations]
end

.fetch(client:, qrcode_id:) ⇒ Bitly::API::Qrcode

Return information about a QR Code [‘GET /v4/qr-codes/qrcode_id`](dev.bitly.com/api-reference/#getQRCodeByIdPublic)

Examples:

qrcode = Bitly::API::Qrcode.fetch(client: client, qrcode_id: "a1b2c3")

Parameters:

  • client (Bitly::API::Client)

    An authorized API client

  • qrcode_id (String)

    The qrcode id you want information about

Returns:



67
68
69
70
# File 'lib/bitly/api/qrcode.rb', line 67

def self.fetch(client:, qrcode_id:)
  response = client.request(path: "/qr-codes/#{qrcode_id}")
  new(data: response.body, client: client, response: response)
end

.list_by_group(client:, group_guid:, size: nil, archived: nil, has_render_customizations: nil) ⇒ Bitly::API::Qrcode::PaginatedList

Retrieves a list of QR codes matching the filter settings. Values are in reverse chronological order. The pagination occurs by calling the next link in the pagination response object. [‘GET /v4/groups/group_guid/qr-codes`](dev.bitly.com/api-reference/#listQRMinimal)

Examples:

qrcodes = Bitly::API::Qrcode.list(client: client, group_guid: guid)

Parameters:

  • client (Bitly::API::Client)

    An authorized API client

  • group_guid (String)

    The group guid for which you want qr codes

  • size (Integer) (defaults to: nil)

    The number of QR Codes to return, default 50.

  • archived (String) (defaults to: nil)

    Whether or not to include archived QRCodes. One of “on”, “off” or “both”. Defaults to “off”.

  • archived (String) (defaults to: nil)

    a filter value if the QRCode has any render customizations (like color or shape changes). One of “on”, “off” or “both”. Defaults to “both”.

Returns:



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/bitly/api/qrcode.rb', line 40

def self.list_by_group(
  client:,
  group_guid:,
  size: nil,
  archived: nil,
  has_render_customizations: nil
)
  params = {
    "size" => size,
    "archived" => archived,
    "has_render_customizations" => has_render_customizations
  }
  response = client.request(path: "/groups/#{group_guid}/qr-codes", params: params)
  PaginatedList.new(response: response, client: client)
end

.time_attributesObject



19
20
21
# File 'lib/bitly/api/qrcode.rb', line 19

def self.time_attributes
  [:created, :updated]
end

Instance Method Details



99
100
101
# File 'lib/bitly/api/qrcode.rb', line 99

def bitlink
  Bitlink.fetch(client: @client, bitlink: @bitlink_id)
end

#image(format: nil) ⇒ String

Return the SVG or PNG image of a QR Code [‘GET /v4/qr-codes/qrcode_id/image`](dev.bitly.com/api-reference/#getQRCodeImagePublic)

Parameters:

  • client (Bitly::API::Client)

    An authorized API client

  • format (String) (defaults to: nil)

    “svg” or “png”. Default “svg”

Returns:

  • (String)


87
88
89
90
91
# File 'lib/bitly/api/qrcode.rb', line 87

def image(format: nil)
  params = format.nil? ? {} : {format: format}
  response = @client.request(path: "/qr-codes/#{qrcode_id}/image", params: params)
  response.body["qr_code_image"]
end

#scans_summary(unit: nil, units: nil, unit_reference: nil) ⇒ Bitly::API::Qrcode::ScansSummary

[‘GET /v4/qr-codes/qrcode_id/scans/summary`](dev.bitly.com/api-reference/#getScanMetricsForQRCode)



75
76
77
# File 'lib/bitly/api/qrcode.rb', line 75

def scans_summary(unit: nil, units: nil, unit_reference: nil)
  ScansSummary.fetch(client: @client, qrcode_id: @qrcode_id, unit: unit, units: units, unit_reference: unit_reference)
end