bitly 2.1.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -58,7 +58,7 @@ module Bitly
58
58
 
59
59
  ##
60
60
  # Shortens a long URL.
61
- # [`POST /v4/shorten`](https://dev.bitly.com/v4/#operation/createBitlink)
61
+ # [`POST /v4/shorten`](https://dev.bitly.com/api-reference/#createBitlink)
62
62
  #
63
63
  # @example
64
64
  # client.shorten(long_url: "http://example.com")
@@ -75,7 +75,7 @@ module Bitly
75
75
 
76
76
  ##
77
77
  # Creates a Bitlink with more options than #shorten.
78
- # [`POST /v4/bitlinks`](https://dev.bitly.com/v4/#operation/createFullBitlink)
78
+ # [`POST /v4/bitlinks`](https://dev.bitly.com/api-reference/#createFullBitlink)
79
79
  #
80
80
  # @example
81
81
  # bitlink = client.create_bitlink(long_url: "http://example.com", title: "An example")
@@ -96,7 +96,7 @@ module Bitly
96
96
 
97
97
  ##
98
98
  # Return information about a bitlink
99
- # [`GET /v4/bitlink/{bitlink}`](https://dev.bitly.com/v4/#operation/getBitlink)
99
+ # [`GET /v4/bitlink/{bitlink}`](https://dev.bitly.com/api-reference/#getBitlink)
100
100
  #
101
101
  # @example
102
102
  # bitlink = client.bitlink(bitlink: "bit.ly/example")
@@ -110,7 +110,7 @@ module Bitly
110
110
 
111
111
  ##
112
112
  # Return public information about a bitlink.
113
- # [`POST /v4/expand`](https://dev.bitly.com/v4/#operation/expandBitlink)
113
+ # [`POST /v4/expand`](https://dev.bitly.com/api-reference/#expandBitlink)
114
114
  #
115
115
  # @example
116
116
  # bitlink = client.expand(bitlink: "bit.ly/example")
@@ -124,7 +124,7 @@ module Bitly
124
124
 
125
125
  ##
126
126
  # Returns a list of Bitlinks sorted by clicks.
127
- # [`GET /v4/groups/{group_guid}/bitlinks/{sort}`](https://dev.bitly.com/v4/#operation/getSortedBitlinks)
127
+ # [`GET /v4/groups/{group_guid}/bitlinks/{sort}`](https://dev.bitly.com/api-reference/#getSortedBitlinks)
128
128
  #
129
129
  # The API returns a separate list of the links and the click counts, but
130
130
  # this method assigns the number of clicks for each link to the Bitlink
@@ -169,7 +169,7 @@ module Bitly
169
169
 
170
170
  ##
171
171
  # Update a Bitlink.
172
- # [`PATCH /v4/bitlink/{bitlink}`](https://dev.bitly.com/v4/#operation/updateBitlink)
172
+ # [`PATCH /v4/bitlink/{bitlink}`](https://dev.bitly.com/api-reference/#updateBitlink)
173
173
  #
174
174
  # The parameters listed below are from the documentation. Some only work
175
175
  # if you have a Bitly Pro account.
@@ -225,7 +225,7 @@ module Bitly
225
225
 
226
226
  ##
227
227
  # Get the clicks for a bitlink.
228
- # [`GET /v4/bitlink/{bitlink}/clicks`](https://dev.bitly.com/v4/#operation/getClicksForBitlink)
228
+ # [`GET /v4/bitlink/{bitlink}/clicks`](https://dev.bitly.com/api-reference/#getClicksForBitlink)
229
229
  #
230
230
  # @param bitlink [String] The Bitlink for which you want the clicks
231
231
  # @param sort [String] The data to sort on. Default and only option is
@@ -253,7 +253,7 @@ module Bitly
253
253
 
254
254
  ##
255
255
  # Get a list of organizations from the API.
256
- # [`GET /v4/organizations`](https://dev.bitly.com/v4/#operation/getOrganizations)
256
+ # [`GET /v4/organizations`](https://dev.bitly.com/api-reference/#getOrganizations)
257
257
  #
258
258
  # @example
259
259
  # organizations = client.organizations
@@ -265,7 +265,7 @@ module Bitly
265
265
 
266
266
  ##
267
267
  # Retrieve an organization from the API.
268
- # [`GET /v4/organizations/{organization_guid}`](https://dev.bitly.com/v4/#operation/getOrganization)
268
+ # [`GET /v4/organizations/{organization_guid}`](https://dev.bitly.com/api-reference/#getOrganization)
269
269
  #
270
270
  # @example
271
271
  # organization = client.organization(organization_guid: guid)
@@ -279,7 +279,7 @@ module Bitly
279
279
 
280
280
  ##
281
281
  # Shorten counts by organization
282
- # [`GET /v4/organizations/{organization_guid}/shorten_counts`](https://dev.bitly.com/v4/#operation/getOrganizationShortenCounts)
282
+ # [`GET /v4/organizations/{organization_guid}/shorten_counts`](https://dev.bitly.com/api-reference/#getOrganizationShortenCounts)
283
283
  #
284
284
  # @example
285
285
  # shorten_counts = client.organization_shorten_counts(organization_guid: organization_guid)
@@ -294,7 +294,7 @@ module Bitly
294
294
 
295
295
  ##
296
296
  # Gets the authorized user from the API.
297
- # [`GET /v4/user`](https://dev.bitly.com/v4/#operation/getUser)
297
+ # [`GET /v4/user`](https://dev.bitly.com/api-reference/#getUser)
298
298
  #
299
299
  # @example
300
300
  # user = client.user
@@ -306,7 +306,7 @@ module Bitly
306
306
 
307
307
  ##
308
308
  # Allows you to update the authorized user's name or default group guid.
309
- # [`PATCH /v4/user`](https://dev.bitly.com/v4/#operation/updateUser)]
309
+ # [`PATCH /v4/user`](https://dev.bitly.com/api-reference/#updateUser)]
310
310
  #
311
311
  # @example
312
312
  # client.update_user(name: "New Name", default_group_guid: "aaabbb")
@@ -322,7 +322,7 @@ module Bitly
322
322
 
323
323
  ##
324
324
  # Lists groups the authorized user can see.
325
- # [`GET /v4/groups`](https://dev.bitly.com/v4/#operation/getGroups)
325
+ # [`GET /v4/groups`](https://dev.bitly.com/api-reference/#getGroups)
326
326
  #
327
327
  # @example
328
328
  # groups = client.groups
@@ -337,7 +337,7 @@ module Bitly
337
337
 
338
338
  ##
339
339
  # Fetch a particular group.
340
- # [`GET /v4/groups/{group_guid}`](https://dev.bitly.com/v4/#operation/getGroup)
340
+ # [`GET /v4/groups/{group_guid}`](https://dev.bitly.com/api-reference/#getGroup)
341
341
  #
342
342
  # @example
343
343
  # group = client.group(guid)
@@ -351,7 +351,7 @@ module Bitly
351
351
 
352
352
  ##
353
353
  # Fetch the shorten counts for a group.
354
- # [`GET /v4/groups/{group_guid}/shorten_counts`](https://dev.bitly.com/v4/#operation/getGroupShortenCounts)
354
+ # [`GET /v4/groups/{group_guid}/shorten_counts`](https://dev.bitly.com/api-reference/#getGroupShortenCounts)
355
355
  #
356
356
  # @example
357
357
  # shorten_counts = client.group_shorten_counts(guid: group_guid)
@@ -366,7 +366,7 @@ module Bitly
366
366
 
367
367
  ##
368
368
  # Fetch a group's preferences.
369
- # [`GET /v4/groups/{group_guid}/preferences`](https://dev.bitly.com/v4/#operation/getGroupPreferences)
369
+ # [`GET /v4/groups/{group_guid}/preferences`](https://dev.bitly.com/api-reference/#getGroupPreferences)
370
370
  #
371
371
  # @param group_guid [String] The group's guid
372
372
  #
@@ -377,7 +377,7 @@ module Bitly
377
377
 
378
378
  ##
379
379
  # Update a group's preferences.
380
- # [`PATCH /v4/groups/{group_guid}/preferences`](https://dev.bitly.com/v4/#operation/updateGroupPreferences)
380
+ # [`PATCH /v4/groups/{group_guid}/preferences`](https://dev.bitly.com/api-reference/#updateGroupPreferences)
381
381
  #
382
382
  # @param group_guid [String] The group's guid
383
383
  # @param domain_preference [String] The new domain preference for this
@@ -391,7 +391,7 @@ module Bitly
391
391
 
392
392
  ##
393
393
  # Allows you to update a group's name, organization or BSDs.
394
- # [`PATCH /v4/groups/{group_guid}`](https://dev.bitly.com/v4/#operation/updateGroup)
394
+ # [`PATCH /v4/groups/{group_guid}`](https://dev.bitly.com/api-reference/#updateGroup)
395
395
  #
396
396
  # @example
397
397
  # client.update_group(group_guid: group_guid, name: "New Name", organization_guid: "aaabbb")
@@ -413,7 +413,7 @@ module Bitly
413
413
 
414
414
  ##
415
415
  # Retrieve a list of bitlinks by group
416
- # [`GET /v4/groups/{group_guid}/bitlinks`](https://dev.bitly.com/v4/#operation/getBitlinksByGroup)
416
+ # [`GET /v4/groups/{group_guid}/bitlinks`](https://dev.bitly.com/api-reference/#getBitlinksByGroup)
417
417
  #
418
418
  # @example
419
419
  # bitlinks = client.group_bitlinks(group_guid: guid)
@@ -484,22 +484,9 @@ module Bitly
484
484
  )
485
485
  end
486
486
 
487
- ##
488
- # Deletes a group.
489
- # [`DELETE /v4/groups/{group_guid}`](https://dev.bitly.com/v4/#operation/deleteGroup)
490
- #
491
- # @example
492
- # client.delete_group(group_guid: group_guid)
493
- #
494
- # @return [Nil]
495
- def delete_group(group_guid:)
496
- group = Group.new(data: { "guid" => group_guid }, client: self)
497
- group.delete
498
- end
499
-
500
487
  ##
501
488
  # Gets the referring networks for the group.
502
- # [`GET /v4/groups/{group_guid}/referring_networks`](https://dev.bitly.com/v4/#operation/GetGroupMetricsByReferringNetworks)
489
+ # [`GET /v4/groups/{group_guid}/referring_networks`](https://dev.bitly.com/api-reference/#GetGroupMetricsByReferringNetworks)
503
490
  #
504
491
  # @param group_guid [String] The guid of the group
505
492
  # @param unit [String] A unit of time. Default is "day" and can be
@@ -525,7 +512,7 @@ module Bitly
525
512
 
526
513
  ##
527
514
  # Gets the country click metrics for the group.
528
- # [`GET /v4/groups/{group_guid}/countries`](https://dev.bitly.com/v4/#operation/getGroupMetricsByCountries)
515
+ # [`GET /v4/groups/{group_guid}/countries`](https://dev.bitly.com/api-reference/#getGroupMetricsByCountries)
529
516
  #
530
517
  # @param group_guid [String] The guid of the group
531
518
  # @param unit [String] A unit of time. Default is "day" and can be
@@ -551,7 +538,7 @@ module Bitly
551
538
 
552
539
  ##
553
540
  # Fetch Branded Short Domains (BSDs).
554
- # [`GET /v4/bsds`](https://dev.bitly.com/v4/#operation/getBSDs)
541
+ # [`GET /v4/bsds`](https://dev.bitly.com/api-reference/#getBSDs)
555
542
  #
556
543
  # @example
557
544
  # bsds = client.bsds
@@ -562,15 +549,15 @@ module Bitly
562
549
  end
563
550
 
564
551
  ##
565
- # Fetch OAuth application by client ID
566
- # [`GET /v4/apps/{client_id}`)](https://dev.bitly.com/v4/#operation/getOAuthApp)
567
- #
552
+ # Fetch a qr code by ID
553
+ # [`GET /v4/qr-codes/{qrcode_id}`](https://dev.bitly.com/api-reference/#getQRCodeByIdPublic)
554
+ #
568
555
  # @example
569
- # app = client.oauth_app(client_id: "client_id")
570
- #
571
- # @return Bitly::API::OAuthApp
572
- def oauth_app(client_id:)
573
- OAuthApp.fetch(client: self, client_id: client_id)
556
+ # qrcode = client.qrcode(qrcode_id: "a1b2c3")
557
+ #
558
+ # @return [Bitly::API::Qrcode]
559
+ def qrcode(qrcode_id:)
560
+ Qrcode.fetch(client: self, qrcode_id: qrcode_id)
574
561
  end
575
562
 
576
563
  private
@@ -33,7 +33,7 @@ module Bitly
33
33
  ##
34
34
  # Creates a new Bitly::API::Group::Preferences object from the data,
35
35
  # API client and optional response.
36
- # [`GET /v4/groups/{group_guid}/preferences`](https://dev.bitly.com/v4/#operation/getGroupPreferences)
36
+ # [`GET /v4/groups/{group_guid}/preferences`](https://dev.bitly.com/api-reference/#updateGroupPreferences)
37
37
  #
38
38
  # @example
39
39
  # preferences = Bitly::API::Group::Preferences.new(data: data, client: client)
@@ -49,7 +49,7 @@ module Bitly
49
49
 
50
50
  ##
51
51
  # Updates the preferences via the API
52
- # [`PATCH /v4/groups/{group_guid}/preferences`](https://dev.bitly.com/v4/#operation/updateGroupPreferences)
52
+ # [`PATCH /v4/groups/{group_guid}/preferences`](https://dev.bitly.com/api-reference/#updateGroupPreferences)
53
53
  #
54
54
  # @example
55
55
  # preferences.update(domain_preference: 'bit.ly')
@@ -21,7 +21,7 @@ module Bitly
21
21
  # Get a list of groups from the API. It receives an authorized
22
22
  # `Bitly::API::Client` object and uses it to request the `/groups`
23
23
  # endpoint, optionally passing an organization guid.
24
- # [`GET /v4/groups`](https://dev.bitly.com/v4/#operation/getGroups)
24
+ # [`GET /v4/groups`](https://dev.bitly.com/api-reference/#getGroups)
25
25
  #
26
26
  # @example
27
27
  # groups = Bitly::API::Group.list(client: client)
@@ -44,7 +44,7 @@ module Bitly
44
44
  # Retrieve a group from the API. It receives an authorized
45
45
  # `Bitly::API::Client` object and a group guid and uses it to request
46
46
  # the `/groups/:group_guid` endpoint.
47
- # [`GET /v4/groups/{group_guid}`](https://dev.bitly.com/v4/#operation/getGroup)
47
+ # [`GET /v4/groups/{group_guid}`](https://dev.bitly.com/api-reference/#getGroup)
48
48
  #
49
49
  # @example
50
50
  # group = Bitly::API::Group.fetch(client: client, guid: guid)
@@ -93,7 +93,7 @@ module Bitly
93
93
 
94
94
  ##
95
95
  # Fetch the organization for the group.
96
- # [`GET /v4/organizations/{organization_guid}`)](https://dev.bitly.com/v4/#operation/getOrganization)
96
+ # [`GET /v4/organizations/{organization_guid}`)](https://dev.bitly.com/api-reference/#getOrganization)
97
97
  #
98
98
  # @return [Bitly::API::Organization]
99
99
  def organization
@@ -102,7 +102,7 @@ module Bitly
102
102
 
103
103
  ##
104
104
  # Fetch the group's preferences.
105
- # [`GET /v4/groups/{group_guid}/preferences`](https://dev.bitly.com/v4/#operation/getGroupPreferences)
105
+ # [`GET /v4/groups/{group_guid}/preferences`](https://dev.bitly.com/api-reference/#getGroupPreferences)
106
106
  #
107
107
  # @return [Bitly::API::Group::Preferences]
108
108
  def preferences
@@ -111,7 +111,7 @@ module Bitly
111
111
 
112
112
  ##
113
113
  # Fetch the group's tags
114
- # [`GET /v4/groups/{group_guid}/tags`](https://dev.bitly.com/v4/#operation/getGroupTags)
114
+ # [`GET /v4/groups/{group_guid}/tags`](https://dev.bitly.com/api-reference/#getGroupTags)
115
115
  #
116
116
  # @return [Array<String>]
117
117
  def tags
@@ -123,7 +123,7 @@ module Bitly
123
123
  # If you update the organization guid and have already loaded the
124
124
  # organization, it is nilled out so it can be reloaded with the correct
125
125
  # guid
126
- # [`PATCH /v4/groups/{group_guid}`](https://dev.bitly.com/v4/#operation/updateGroup)
126
+ # [`PATCH /v4/groups/{group_guid}`](https://dev.bitly.com/api-reference/#updateGroup)
127
127
  #
128
128
  # @example
129
129
  # group.update(name: "New Name", organization_guid: "aaabbb")
@@ -147,22 +147,9 @@ module Bitly
147
147
  self
148
148
  end
149
149
 
150
- ##
151
- # Deletes the group.
152
- # [`DELETE /v4/groups/{group_guid}`](https://dev.bitly.com/v4/#operation/deleteGroup)
153
- #
154
- # @example
155
- # group.delete
156
- #
157
- # @return [Nil]
158
- def delete
159
- @response = @client.request(path: "/groups/#{guid}", method: "DELETE")
160
- return nil
161
- end
162
-
163
150
  ##
164
151
  # Get the shorten counts for the group.
165
- # # [`GET /v4/groups/{group_guid}/shorten_counts`](https://dev.bitly.com/v4/#operation/getGroupShortenCounts)
152
+ # # [`GET /v4/groups/{group_guid}/shorten_counts`](https://dev.bitly.com/api-reference/#getGroupShortenCounts)
166
153
  #
167
154
  # @return [Bitly::API::ShortenCounts]
168
155
  def shorten_counts
@@ -171,16 +158,25 @@ module Bitly
171
158
 
172
159
  ##
173
160
  # Gets the Bitlinks for the group.
174
- # [`GET /v4/groups/{group_guid}/bitlinks`](https://dev.bitly.com/v4/#operation/getBitlinksByGroup)
161
+ # [`GET /v4/groups/{group_guid}/bitlinks`](https://dev.bitly.com/api-reference/#getBitlinksByGroup)
175
162
  #
176
163
  # @return [Bitly::API::Bitlink::List]
177
164
  def bitlinks
178
165
  Bitly::API::Bitlink.list(client: @client, group_guid: guid)
179
166
  end
180
167
 
168
+ ##
169
+ # Gets the QR Codes for the group.
170
+ # [`GET /v4/groups/{group_guid}/qr-codes`](https://dev.bitly.com/api-reference/#listQRMinimal)
171
+ #
172
+ # @return [Bitly::API::Qrcode::List]
173
+ def qrcodes
174
+ Bitly::API::Qrcode.list_by_group(client: @client, group_guid: guid)
175
+ end
176
+
181
177
  ##
182
178
  # Gets the referring networks for the group.
183
- # [`GET /v4/groups/{group_guid}/referring_networks`](https://dev.bitly.com/v4/#operation/GetGroupMetricsByReferringNetworks)
179
+ # [`GET /v4/groups/{group_guid}/referring_networks`](https://dev.bitly.com/api-reference/#GetGroupMetricsByReferringNetworks)
184
180
  #
185
181
  # @param unit [String] A unit of time. Default is "day" and can be
186
182
  # "minute", "hour", "day", "week" or "month"
@@ -205,7 +201,7 @@ module Bitly
205
201
 
206
202
  ##
207
203
  # Gets the country click metrics for the group.
208
- # [`GET /v4/groups/{group_guid}/countries`](https://dev.bitly.com/v4/#operation/getGroupMetricsByCountries)
204
+ # [`GET /v4/groups/{group_guid}/countries`](https://dev.bitly.com/api-reference/#getGroupMetricsByCountries)
209
205
  #
210
206
  # @param unit [String] A unit of time. Default is "day" and can be
211
207
  # "minute", "hour", "day", "week" or "month"
@@ -229,4 +225,4 @@ module Bitly
229
225
  end
230
226
  end
231
227
  end
232
- end
228
+ end
@@ -18,7 +18,7 @@ module Bitly
18
18
  # Get a list of organizations from the API. It receives an authorized
19
19
  # `Bitly::API::Client` object and uses it to request the `/organizations`
20
20
  # endpoint.
21
- # [`GET /v4/organizations`](https://dev.bitly.com/v4/#operation/getOrganizations)
21
+ # [`GET /v4/organizations`](https://dev.bitly.com/api-reference/#getOrganizations)
22
22
  #
23
23
  # @example
24
24
  # organizations = Bitly::API::Organization.list(client: client)
@@ -38,7 +38,7 @@ module Bitly
38
38
  # Retrieve an organization from the API. It receives an authorized
39
39
  # `Bitly::API::Client` object and an organization guid and uses it to
40
40
  # request the `/organizations/:organization_guid` endpoint.
41
- # [`GET /v4/organizations/{organization_guid}`](https://dev.bitly.com/v4/#operation/getOrganization)
41
+ # [`GET /v4/organizations/{organization_guid}`](https://dev.bitly.com/api-reference/#getOrganization)
42
42
  #
43
43
  # @example
44
44
  # organization = Bitly::API::Organization.fetch(client: client, organization_guid: guid)
@@ -90,7 +90,7 @@ module Bitly
90
90
 
91
91
  ##
92
92
  # Shorten counts by organization
93
- # [`GET /v4/organizations/{organization_guid}/shorten_counts`](https://dev.bitly.com/v4/#operation/getOrganizationShortenCounts)
93
+ # [`GET /v4/organizations/{organization_guid}/shorten_counts`](https://dev.bitly.com/api-reference/#getOrganizationShortenCounts)
94
94
  #
95
95
  # @example
96
96
  # shorten_counts = organization.shorten_counts
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+ require "cgi"
3
+ require "uri"
4
+
5
+ module Bitly
6
+ module API
7
+ class PaginatedList < Bitly::API::List
8
+ attr_reader :next_url, :prev_url, :size, :page, :total
9
+
10
+ def initialize(response: , client:)
11
+ @client = client
12
+ super(items: items_from_response(response: response), response: response)
13
+ if response.body["pagination"]
14
+ pagination = response.body["pagination"]
15
+ @next_url = pagination["next"]
16
+ @prev_url = pagination["prev"]
17
+ @size = pagination["size"]
18
+ @page = pagination["page"]
19
+ @total = pagination["total"]
20
+ end
21
+ end
22
+
23
+ def has_next_page?
24
+ !next_url.nil? && !next_url.empty?
25
+ end
26
+
27
+ def has_prev_page?
28
+ !prev_url.nil? && !prev_url.empty?
29
+ end
30
+
31
+ def next_page
32
+ has_next_page? ? get_page(uri: URI(next_url)) : nil
33
+ end
34
+
35
+ def prev_page
36
+ has_prev_page? ? get_page(uri: URI(prev_url)) : nil
37
+ end
38
+
39
+ def item_key
40
+ raise NotImplementedError
41
+ end
42
+
43
+ def item_factory(item)
44
+ raise NotImplementedError
45
+ end
46
+
47
+ private
48
+
49
+ def get_page(uri:)
50
+ response = @client.request(path: uri.path.gsub(/\/v4/, ""), params: CGI.parse(uri.query))
51
+ self.class.new(response: response, client: @client)
52
+ end
53
+
54
+ def items_from_response(response:)
55
+ response.body[item_key].map do |item|
56
+ item_factory(item)
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+ require_relative "../paginated_list"
3
+
4
+ module Bitly
5
+ module API
6
+ class Qrcode
7
+ class PaginatedList < Bitly::API::PaginatedList
8
+ def item_key
9
+ "qr_codes"
10
+ end
11
+
12
+ def item_factory(data)
13
+ Qrcode.new(data: data, client: @client)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+ require_relative "../base"
3
+
4
+ module Bitly
5
+ module API
6
+ class Qrcode
7
+ class ScansSummary
8
+ include Base
9
+
10
+ def self.fetch(client:, qrcode_id:, unit: nil, units: nil, unit_reference: nil)
11
+ response = client.request(
12
+ path: "/qr-codes/#{qrcode_id}/scans/summary",
13
+ params: {
14
+ "unit" => unit,
15
+ "units" => units,
16
+ "unit_reference" => unit_reference
17
+ }
18
+ )
19
+ new(data: response.body, response: response)
20
+ end
21
+
22
+ def self.attributes
23
+ [:units, :unit, :unit_reference, :total_scans]
24
+ end
25
+ attr_reader(*attributes)
26
+
27
+ def initialize(data:, response: nil)
28
+ assign_attributes(data)
29
+ @response = response
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,104 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "./base"
4
+ require_relative "./list"
5
+
6
+ module Bitly
7
+ module API
8
+ class Qrcode
9
+ autoload :PaginatedList, File.join(File.dirname(__FILE__), "qrcode/paginated_list.rb")
10
+ autoload :ScansSummary, File.join(File.dirname(__FILE__), "qrcode/scans_summary.rb")
11
+
12
+ include Base
13
+
14
+ class List < Bitly::API::List ; end
15
+
16
+ def self.attributes
17
+ [:qrcode_id, :title, :archived, :serialized_content, :long_urls, :bitlink_id, :qr_code_type, :render_customizations]
18
+ end
19
+ def self.time_attributes
20
+ [:created, :updated]
21
+ end
22
+ attr_reader(*(attributes + time_attributes))
23
+
24
+ ##
25
+ # 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.
26
+ # [`GET /v4/groups/{group_guid}/qr-codes`](https://dev.bitly.com/api-reference/#listQRMinimal)
27
+ #
28
+ # @example
29
+ # qrcodes = Bitly::API::Qrcode.list(client: client, group_guid: guid)
30
+ #
31
+ # @param client [Bitly::API::Client] An authorized API client
32
+ # @param group_guid [String] The group guid for which you want qr codes
33
+ # @param size [Integer] The number of QR Codes to return, default 50.
34
+ # @param archived [String] Whether or not to include archived QRCodes.
35
+ # One of "on", "off" or "both". Defaults to "off".
36
+ # @param archived [String] a filter value if the QRCode has any render customizations (like color or shape changes).
37
+ # One of "on", "off" or "both". Defaults to "both".
38
+ #
39
+ # @return [Bitly::API::Qrcode::PaginatedList]
40
+ def self.list_by_group(
41
+ client:,
42
+ group_guid:,
43
+ size: nil,
44
+ archived: nil,
45
+ has_render_customizations: nil
46
+ )
47
+ params = {
48
+ "size" => size,
49
+ "archived" => archived,
50
+ "has_render_customizations" => has_render_customizations
51
+ }
52
+ response = client.request(path: "/groups/#{group_guid}/qr-codes", params: params)
53
+ PaginatedList.new(response: response, client: client)
54
+ end
55
+
56
+ ##
57
+ # Return information about a QR Code
58
+ # [`GET /v4/qr-codes/{qrcode_id}`](https://dev.bitly.com/api-reference/#getQRCodeByIdPublic)
59
+ #
60
+ # @example
61
+ # qrcode = Bitly::API::Qrcode.fetch(client: client, qrcode_id: "a1b2c3")
62
+ #
63
+ # @param client [Bitly::API::Client] An authorized API client
64
+ # @param qrcode_id [String] The qrcode id you want information about
65
+ #
66
+ # @return [Bitly::API::Qrcode]
67
+ def self.fetch(client:, qrcode_id:)
68
+ response = client.request(path: "/qr-codes/#{qrcode_id}")
69
+ new(data: response.body, client: client, response: response)
70
+ end
71
+
72
+ # [`GET /v4/qr-codes/{qrcode_id}/scans/summary`](https://dev.bitly.com/api-reference/#getScanMetricsForQRCode)
73
+ #
74
+ # @return [Bitly::API::Qrcode::ScansSummary]
75
+ def scans_summary(unit: nil, units: nil, unit_reference: nil)
76
+ ScansSummary.fetch(client: @client, qrcode_id: @qrcode_id, unit: unit, units: units, unit_reference: unit_reference)
77
+ end
78
+
79
+ ##
80
+ # Return the SVG or PNG image of a QR Code
81
+ # [`GET /v4/qr-codes/{qrcode_id}/image`](https://dev.bitly.com/api-reference/#getQRCodeImagePublic)
82
+ #
83
+ # @param client [Bitly::API::Client] An authorized API client
84
+ # @param format [String] "svg" or "png". Default "svg"
85
+ #
86
+ # @return [String]
87
+ def image(format: nil)
88
+ params = format.nil? ? {} : {format: format}
89
+ response = @client.request(path: "/qr-codes/#{qrcode_id}/image", params: params)
90
+ response.body["qr_code_image"]
91
+ end
92
+
93
+ def initialize(data:, client:, response: nil)
94
+ assign_attributes(data)
95
+ @client = client
96
+ @response = response
97
+ end
98
+
99
+ def bitlink
100
+ Bitlink.fetch(client: @client, bitlink: @bitlink_id)
101
+ end
102
+ end
103
+ end
104
+ end
@@ -17,7 +17,7 @@ module Bitly
17
17
 
18
18
  ##
19
19
  # Shorten counts by group
20
- # [`GET /v4/groups/{group_guid}/shorten_counts`](https://dev.bitly.com/v4/#operation/getGroupShortenCounts)
20
+ # [`GET /v4/groups/{group_guid}/shorten_counts`](https://dev.bitly.com/api-reference/#getGroupShortenCounts)
21
21
  #
22
22
  # @example
23
23
  # shorten_counts = Bitly::API::ShortenCounts.by_group(client: client, group_guid: group_guid)
@@ -34,7 +34,7 @@ module Bitly
34
34
 
35
35
  ##
36
36
  # Shorten counts by organization
37
- # [`GET /v4/organizations/{organization_guid}/shorten_counts`](https://dev.bitly.com/v4/#operation/getOrganizationShortenCounts)
37
+ # [`GET /v4/organizations/{organization_guid}/shorten_counts`](https://dev.bitly.com/api-reference/#getOrganizationShortenCounts)
38
38
  #
39
39
  # @example
40
40
  # shorten_counts = Bitly::API::ShortenCounts.by_organization(client: client, organization_guid: organization_guid)
@@ -18,7 +18,7 @@ module Bitly
18
18
  include Base
19
19
  ##
20
20
  # Gets the authorized user from the API.
21
- # [`GET /v4/user`](https://dev.bitly.com/v4/#operation/getUser)
21
+ # [`GET /v4/user`](https://dev.bitly.com/api-reference/#getUser)
22
22
  #
23
23
  # @example
24
24
  # user = Bitly::API::User.fetch(client: client)
@@ -79,7 +79,7 @@ module Bitly
79
79
  # Allows you to update the authorized user's name or default group guid.
80
80
  # If you update the default group ID and have already loaded the default
81
81
  # group, it is nilled out so it can be reloaded with the correct ID.
82
- # [`PATCH /v4/user`](https://dev.bitly.com/v4/#operation/updateUser)]
82
+ # [`PATCH /v4/user`](https://dev.bitly.com/api-reference/#updateUser).
83
83
  #
84
84
  # @example
85
85
  # user.update(name: "New Name", default_group_guid: "aaabbb")
data/lib/bitly/api.rb CHANGED
@@ -9,11 +9,11 @@ module Bitly
9
9
  autoload :Client, File.join(File.dirname(__FILE__), "api/client.rb")
10
10
  autoload :ClickMetric, File.join(File.dirname(__FILE__), "api/click_metric.rb")
11
11
  autoload :Bitlink, File.join(File.dirname(__FILE__), "api/bitlink.rb")
12
+ autoload :Qrcode, File.join(File.dirname(__FILE__), "api/qrcode.rb")
12
13
  autoload :Organization, File.join(File.dirname(__FILE__), "api/organization.rb")
13
14
  autoload :Group, File.join(File.dirname(__FILE__), "api/group.rb")
14
15
  autoload :User, File.join(File.dirname(__FILE__), "api/user.rb")
15
16
  autoload :BSD, File.join(File.dirname(__FILE__), "api/bsd.rb")
16
- autoload :OAuthApp, File.join(File.dirname(__FILE__), "api/oauth_app.rb")
17
17
  autoload :ShortenCounts, File.join(File.dirname(__FILE__), "api/shorten_counts.rb")
18
18
  end
19
19
  end