bitly 2.1.0 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/sonarcloud.yml +4 -8
- data/.github/workflows/tests.yml +1 -1
- data/Gemfile +4 -0
- data/History.txt +12 -1
- data/README.md +118 -65
- data/lib/bitly/api/base.rb +1 -1
- data/lib/bitly/api/bitlink/link_click.rb +1 -1
- data/lib/bitly/api/bitlink/paginated_list.rb +7 -41
- data/lib/bitly/api/bitlink.rb +29 -14
- data/lib/bitly/api/bsd.rb +1 -1
- data/lib/bitly/api/click_metric.rb +18 -2
- data/lib/bitly/api/client.rb +30 -43
- data/lib/bitly/api/group/preferences.rb +2 -2
- data/lib/bitly/api/group.rb +20 -24
- data/lib/bitly/api/organization.rb +3 -3
- data/lib/bitly/api/paginated_list.rb +61 -0
- data/lib/bitly/api/qrcode/paginated_list.rb +18 -0
- data/lib/bitly/api/qrcode/scans_summary.rb +34 -0
- data/lib/bitly/api/qrcode.rb +104 -0
- data/lib/bitly/api/shorten_counts.rb +2 -2
- data/lib/bitly/api/user.rb +2 -2
- data/lib/bitly/api.rb +1 -1
- data/lib/bitly/http/adapters/net_http.rb +11 -1
- data/lib/bitly/version.rb +1 -1
- metadata +7 -4
- data/lib/bitly/api/oauth_app.rb +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c3f7e8ce05cc1176818efa7b83c94fd1e6f6bcc7ce4caefdfc7f719aab18bbd9
|
4
|
+
data.tar.gz: 38593047cf4f4b02b6e45a457cce9d698e3f11b3bc06337d1ebcc0953ba1cb28
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34f1f1d76f0f984f4ba22069aee1280332c1fe5deead1bb2572257dad0ebbb8a97e9c7e642d4270bc495fe5aafde7ba6ce7e98980685e4a37ecbec58b74ad074
|
7
|
+
data.tar.gz: 4f772f32325b0fc59c76ceef45634aee7ea0f0c4a81985051ca09286b4c570c92077cb1e05b233c2d8287987ffb3636f6386a125e214810b20837adc86509662
|
@@ -4,9 +4,9 @@ on:
|
|
4
4
|
- main
|
5
5
|
pull_request:
|
6
6
|
types: [opened, synchronize, reopened]
|
7
|
-
name:
|
7
|
+
name: SonarQube Analysis
|
8
8
|
jobs:
|
9
|
-
|
9
|
+
sonarqube:
|
10
10
|
runs-on: ubuntu-latest
|
11
11
|
steps:
|
12
12
|
- uses: actions/checkout@v2
|
@@ -23,12 +23,8 @@ jobs:
|
|
23
23
|
run: bundle exec rspec
|
24
24
|
env:
|
25
25
|
COVERAGE: json
|
26
|
-
- name:
|
27
|
-
|
28
|
-
run: |
|
29
|
-
sed -i 's@'$GITHUB_WORKSPACE'@/github/workspace/@g' coverage.json
|
30
|
-
- name: SonarCloud Scan
|
31
|
-
uses: sonarsource/sonarcloud-github-action@master
|
26
|
+
- name: SonarQube Scan
|
27
|
+
uses: SonarSource/sonarqube-scan-action@v5.0.0
|
32
28
|
env:
|
33
29
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
34
30
|
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
data/.github/workflows/tests.yml
CHANGED
data/Gemfile
CHANGED
data/History.txt
CHANGED
@@ -1,6 +1,17 @@
|
|
1
1
|
=== Ongoing
|
2
2
|
|
3
|
-
|
3
|
+
=== 3.1.0 / 2025-02-18
|
4
|
+
|
5
|
+
* Adds `Qrcode` class and methods to fetch qrcodes and list qrcodes by group as well as get a summary of scans and retrieve an image
|
6
|
+
* Adds Ruby 3.4 to test matrix
|
7
|
+
* Updates to latest SonarQube scanner
|
8
|
+
|
9
|
+
=== 3.0.0 / 2022-11-08
|
10
|
+
|
11
|
+
* **Breaking** Removes Group DELETE and Oauth Apps endpoints
|
12
|
+
* Updates all URLs in the documentation
|
13
|
+
* Adds click_metrics_by_country to Bitlink instances
|
14
|
+
* Adds request options and proxy options to the Net::HTTP adapter
|
4
15
|
|
5
16
|
=== 2.1.0 / 2022-10-21
|
6
17
|
|
data/README.md
CHANGED
@@ -4,25 +4,29 @@ A Ruby gem for using the version 4 [Bitly API](https://dev.bitly.com/) to shorte
|
|
4
4
|
|
5
5
|
[](https://rubygems.org/gems/bitly)  [](https://codeclimate.com/github/philnash/bitly/maintainability) [](https://sonarcloud.io/summary/new_code?id=philnash_bitly) [](https://inch-ci.org/github/philnash/bitly)
|
6
6
|
|
7
|
-
* [
|
8
|
-
* [
|
9
|
-
* [
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
* [
|
14
|
-
* [
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
* [
|
23
|
-
* [
|
24
|
-
* [
|
25
|
-
* [
|
7
|
+
* [Bitly](#bitly)
|
8
|
+
* [Installation](#installation)
|
9
|
+
* [Usage](#usage)
|
10
|
+
* [Authentication](#authentication)
|
11
|
+
* [Creating an API client](#creating-an-api-client)
|
12
|
+
* [Shorten a link](#shorten-a-link)
|
13
|
+
* [Expand a link](#expand-a-link)
|
14
|
+
* [Available API Endpoints](#available-api-endpoints)
|
15
|
+
* [Groups](#groups)
|
16
|
+
* [Organizations](#organizations)
|
17
|
+
* [Users](#users)
|
18
|
+
* [Bitlinks](#bitlinks)
|
19
|
+
* [QR codes](#qr-codes)
|
20
|
+
* [Custom Bitlinks](#custom-bitlinks)
|
21
|
+
* [Campaigns](#campaigns)
|
22
|
+
* [BSDs (Branded Short Domains)](#bsds-branded-short-domains)
|
23
|
+
* [Webhooks](#webhooks)
|
24
|
+
* [Customising HTTP requests](#customising-http-requests)
|
25
|
+
* [Build your own adapter](#build-your-own-adapter)
|
26
|
+
* [Development](#development)
|
27
|
+
* [Contributing](#contributing)
|
28
|
+
* [License](#license)
|
29
|
+
* [Code of Conduct](#code-of-conduct)
|
26
30
|
|
27
31
|
## Installation
|
28
32
|
|
@@ -46,6 +50,8 @@ $ gem install bitly
|
|
46
50
|
|
47
51
|
## Usage
|
48
52
|
|
53
|
+
For a quick introduction, read this blog post on [how to use the Bitly API in Ruby](https://philna.sh/blog/2022/11/09/how-to-use-the-bitly-api-in-ruby/).
|
54
|
+
|
49
55
|
### Authentication
|
50
56
|
|
51
57
|
All API endpoints require authentication with an OAuth token. You can get your own OAuth token from the [Bitly console](https://app.bitly.com/). Click on the account drop down menu, then _Profile Settings_ then _Generic Access Token_. Fill in your password and you can generate an OAuth access token.
|
@@ -86,86 +92,133 @@ bitlink.long_url
|
|
86
92
|
|
87
93
|
## Available API Endpoints
|
88
94
|
|
89
|
-
This gem supports the following active v4 API endpoints for the[Bitly API](https://dev.bitly.com/
|
95
|
+
This gem supports the following active v4 API endpoints for the[Bitly API](https://dev.bitly.com/api-reference).
|
90
96
|
|
91
97
|
### Groups
|
92
98
|
|
93
99
|
[Groups documentation](docs/groups.md)
|
94
100
|
|
95
|
-
- [x] [Retrieve groups (`GET /v4/groups`)](https://dev.bitly.com/
|
96
|
-
- [x] [Retrieve group (`GET /v4/groups/{group_guid}`)](https://dev.bitly.com/
|
97
|
-
- [x] [Update group (`PATCH /v4/groups/{group_guid}`)](https://dev.bitly.com/
|
98
|
-
- [x] [
|
99
|
-
- [x] [Retrieve
|
100
|
-
- [x] [
|
101
|
-
- [x] [
|
102
|
-
- [x] [Retrieve Bitlinks by group (`GET /v4/groups/{group_guid}/bitlinks`)](https://dev.bitly.com/
|
103
|
-
- [x] [Retrieve
|
104
|
-
- [x] [Retrieve group
|
105
|
-
- [x] [Retrieve click metrics for a group by
|
106
|
-
- [
|
101
|
+
- [x] [Retrieve groups (`GET /v4/groups`)](https://dev.bitly.com/api-reference/#getGroups)
|
102
|
+
- [x] [Retrieve group (`GET /v4/groups/{group_guid}`)](https://dev.bitly.com/api-reference/#getGroup)
|
103
|
+
- [x] [Update group (`PATCH /v4/groups/{group_guid}`)](https://dev.bitly.com/api-reference/#updateGroup)
|
104
|
+
- [x] [Retrieve tags by group (`GET /v4/groups/{group_guid}/tags`)](https://dev.bitly.com/api-reference/#getGroupTags)
|
105
|
+
- [x] [Retrieve group preferences (`GET /v4/groups/{group_guid}/preferences`)](https://dev.bitly.com/api-reference/#getGroupPreferences)
|
106
|
+
- [x] [Update group preferences (`PATCH /v4/groups/{group_guid}/preferences`)](https://dev.bitly.com/api-reference/#updateGroupPreferences)
|
107
|
+
- [x] [Retrieve Bitlinks by group (`GET /v4/groups/{group_guid}/bitlinks`)](https://dev.bitly.com/api-reference/#getBitlinksByGroup)
|
108
|
+
- [x] [Retrieve sorted Bitlinks by group (`GET /v4/groups/{group_guid}/bitlinks/{sort}`)](https://dev.bitly.com/api-reference/#getSortedBitlinks)
|
109
|
+
- [x] [Retrieve group shorten counts (`GET /v4/groups/{group_guid}/shorten_counts`)](https://dev.bitly.com/api-reference/#getGroupShortenCounts)
|
110
|
+
- [x] [Retrieve click metrics for a group by referring networks (`GET /v4/groups/{group_guid}/referring_networks`)](https://dev.bitly.com/api-reference/#GetGroupMetricsByReferringNetworks)
|
111
|
+
- [x] [Retrieve click metrics for a group by countries (`GET /v4/groups/{group_guid}/countries`)](https://dev.bitly.com/api-reference/#getGroupMetricsByCountries)
|
112
|
+
- [X] [Retrieve QR codes for a group (`GET /v4/groups/{group_guid}/qr-codes`)](https://dev.bitly.com/api-reference/#listQRMinimal)
|
113
|
+
- [ ] __[premium]__ [Retrieve click metrics for a group by city (`GET /v4/groups/{group_guid}/cities`)](https://dev.bitly.com/api-reference/#getGroupMetricsByCities)
|
114
|
+
- [ ] __[premium]__ [Get group overrides (`GET /v4/groups/{group_guid}/overrides`)](https://dev.bitly.com/api-reference/#getOverridesForGroups)
|
107
115
|
|
108
116
|
### Organizations
|
109
117
|
|
110
118
|
[Organizations documentation](docs/organizations.md)
|
111
119
|
|
112
|
-
- [x] [Retrieve organizations (`GET /v4/organizations`)](https://dev.bitly.com/
|
113
|
-
- [x] [Retrieve organization (`GET /v4/organizations/{organization_guid}`)](https://dev.bitly.com/
|
114
|
-
- [x] [Retrieve organization shorten counts (`GET /v4/organizations/{organization_guid}/shorten_counts`)](https://dev.bitly.com/
|
120
|
+
- [x] [Retrieve organizations (`GET /v4/organizations`)](https://dev.bitly.com/api-reference/#getOrganizations)
|
121
|
+
- [x] [Retrieve organization (`GET /v4/organizations/{organization_guid}`)](https://dev.bitly.com/api-reference/#getOrganization)
|
122
|
+
- [x] [Retrieve organization shorten counts (`GET /v4/organizations/{organization_guid}/shorten_counts`)](https://dev.bitly.com/api-reference/#getOrganizationShortenCounts)
|
115
123
|
|
116
124
|
### Users
|
117
125
|
|
118
126
|
[Users documentation](docs/users.md)
|
119
127
|
|
120
|
-
- [x] [Retrieve user (`GET /v4/user`)](https://dev.bitly.com/
|
121
|
-
- [x] [Update user (`PATCH /v4/user`)](https://dev.bitly.com/
|
128
|
+
- [x] [Retrieve user (`GET /v4/user`)](https://dev.bitly.com/api-reference/#getUser)
|
129
|
+
- [x] [Update user (`PATCH /v4/user`)](https://dev.bitly.com/api-reference/#updateUser)
|
122
130
|
|
123
131
|
### Bitlinks
|
124
132
|
|
125
133
|
[Bitlinks documentation](docs/bitlinks.md)
|
126
134
|
|
127
|
-
- [x] [Shorten a link (`POST /v4/shorten`)](https://dev.bitly.com/
|
128
|
-
- [x] [Expand a Bitlink (`POST /v4/expand`)](https://dev.bitly.com/
|
129
|
-
- [x] [Retrieve a Bitlink (`GET /v4/
|
130
|
-
- [x] [Create a Bitlink (`POST /v4/bitlinks`)](https://dev.bitly.com/
|
131
|
-
- [x] [Update a Bitlink (`PATCH /v4/
|
132
|
-
- [
|
133
|
-
- [x] [Get clicks
|
134
|
-
- [x] [Get
|
135
|
-
- [x] [Get metrics for a Bitlink by
|
136
|
-
- [x] [Get metrics for a Bitlink by
|
137
|
-
- [x] [Get metrics for a Bitlink by
|
138
|
-
- [
|
135
|
+
- [x] [Shorten a link (`POST /v4/shorten`)](https://dev.bitly.com/api-reference/#createBitlink)
|
136
|
+
- [x] [Expand a Bitlink (`POST /v4/expand`)](https://dev.bitly.com/api-reference/#expandBitlink)
|
137
|
+
- [x] [Retrieve a Bitlink (`GET /v4/bitlinks/{bitlink}`)](https://dev.bitly.com/api-reference/#getBitlink)
|
138
|
+
- [x] [Create a Bitlink (`POST /v4/bitlinks`)](https://dev.bitly.com/api-reference/#createFullBitlink)
|
139
|
+
- [x] [Update a Bitlink (`PATCH /v4/bitlinks/{bitlink}`)](https://dev.bitly.com/api-reference/#updateBitlink)
|
140
|
+
- [ ] [Delete an unedited hash Bitlink (`DELETE /v4/bitlinks/{bitlink}`)](https://dev.bitly.com/api-reference/#deleteBitlink)
|
141
|
+
- [x] [Get clicks for a Bitlink (`GET /v4/bitlinks/{bitlink}/clicks`)](https://dev.bitly.com/api-reference/#getClicksForBitlink)
|
142
|
+
- [x] [Get clicks summary for a Bitlink (`GET /v4/bitlinks/{bitlink}/clicks/summary`)](https://dev.bitly.com/api-reference/#getClicksSummaryForBitlink)
|
143
|
+
- [x] [Get metrics for a Bitlink by countries (`GET /v4/bitlinks/{bitlink}/countries`)](https://dev.bitly.com/api-reference/#getMetricsForBitlinkByCountries)
|
144
|
+
- [x] [Get metrics for a Bitlink by referrers (`GET /v4/bitlinks/{bitlink}/referrers`)](https://dev.bitly.com/api-reference/#getMetricsForBitlinkByReferrers)
|
145
|
+
- [x] [Get metrics for a Bitlink by referring domains (`GET /v4/bitlinks/{bitlink}/referring_domains`)](https://dev.bitly.com/api-reference/#getMetricsForBitlinkByReferringDomains)
|
146
|
+
- [x] [Get metrics for a Bitlink by referrers by domain (`GET /v4/bitlinks/{bitlink}/referrers_by_domains`)](https://dev.bitly.com/api-reference/#getMetricsForBitlinkByReferrersByDomains)
|
147
|
+
- [ ] __[premium]__ [Get metrics for a Bitlink by city (`GET /v4/bitlinks/{bitlink}/cities`)](https://dev.bitly.com/api-reference/#getMetricsForBitlinkByCities)
|
148
|
+
- [ ] __[premium]__ [Get metrics for a Bitlink by device type (`GET /v4/bitlinks/{bitlink}/devices`)](https://dev.bitly.com/api-reference/#getMetricsForBitlinkByDevices)
|
149
|
+
|
150
|
+
### QR codes
|
151
|
+
|
152
|
+
[QR codes documentation](docs/qrcodes.md)
|
153
|
+
|
154
|
+
- [x] [Retrieve a QR code (`GET /v4/qr-codes/{qrcode_id}`)](https://dev.bitly.com/api-reference/#getQRCodeByIdPublic)
|
155
|
+
- [x] [Retrieve the scans summary for a QR code (`GET /v4/qr-codes/{qrcode_id}/scans/summary`)](https://dev.bitly.com/api-reference/#getScanMetricsSummaryForQRCode)
|
156
|
+
- [x] [Retrieve a QR code image (`GET /v4/qr-codes/{qrcode_id}/image`)](https://dev.bitly.com/api-reference/#getQRCodeImagePublic)
|
139
157
|
|
140
158
|
### Custom Bitlinks
|
141
159
|
|
142
|
-
- [ ] [Add custom Bitlink (`POST /v4/custom_bitlinks`)](https://dev.bitly.com/
|
143
|
-
- [ ] __[premium]__ [Retrieve custom Bitlink (`GET /v4/custom_bitlinks/{custom_bitlink}`)](https://dev.bitly.com/
|
144
|
-
- [ ] __[premium]__ [Update custom Bitlink (`PATCH /v4/
|
145
|
-
- [ ] __[premium]__ [Get metrics for a custom Bitlink by destination (`GET /v4/custom_bitlinks/{custom_bitlink}/clicks_by_destination`)](https://dev.bitly.com/
|
160
|
+
- [ ] [Add custom Bitlink (`POST /v4/custom_bitlinks`)](https://dev.bitly.com/api-reference/#addCustomBitlink)
|
161
|
+
- [ ] __[premium]__ [Retrieve custom Bitlink (`GET /v4/custom_bitlinks/{custom_bitlink}`)](https://dev.bitly.com/api-reference/#getCustomBitlink)
|
162
|
+
- [ ] __[premium]__ [Update custom Bitlink (`PATCH /v4/custom_bitlinks/{custom_bitlink}`)](https://dev.bitly.com/api-reference/#updateCustomBitlink)
|
163
|
+
- [ ] __[premium]__ [Get metrics for a custom Bitlink by destination (`GET /v4/custom_bitlinks/{custom_bitlink}/clicks_by_destination`)](https://dev.bitly.com/api-reference/#getCustomBitlinkMetricsByDestination)
|
164
|
+
- [ ] __[premium]__ [Get clicks for a custom Bitlin's entire history (`GET /v4/custom_bitlinks/{custom_bitlink}/clicks`)](https://dev.bitly.com/api-reference/#getClicksForCustomBitlink)
|
146
165
|
|
147
166
|
### Campaigns
|
148
167
|
|
149
|
-
- [ ] __[premium]__ [Retrieve campaigns (`GET /v4/campaigns`)](https://dev.bitly.com/
|
150
|
-
- [ ] __[premium]__ [Create campaign (`POST /v4/campaigns`)](https://dev.bitly.com/
|
151
|
-
- [ ] __[premium]__ [Retrieve campaign (`GET /v4/campaigns/{campaign_guid}`)](https://dev.bitly.com/
|
152
|
-
- [ ] __[premium]__ [Update campaign (`PATCH /v4/campaigns/{campaign_guid}`)](https://dev.bitly.com/
|
153
|
-
- [ ] __[premium]__ [Retrieve channels (`GET /v4/channels`)](https://dev.bitly.com/
|
154
|
-
- [ ] __[premium]__ [Create channel (`POST /v4/channels`)](https://dev.bitly.com/
|
155
|
-
- [ ] __[premium]__ [Retrieve channel (`GET /v4/channels/{channel_guid}`)](https://dev.bitly.com/
|
156
|
-
- [ ] __[premium]__ [Update channel (`PATCH /v4/channels/{channel_guid}`)](https://dev.bitly.com/
|
168
|
+
- [ ] __[premium]__ [Retrieve campaigns (`GET /v4/campaigns`)](https://dev.bitly.com/api-reference/#getCampaigns)
|
169
|
+
- [ ] __[premium]__ [Create campaign (`POST /v4/campaigns`)](https://dev.bitly.com/api-reference/#createCampaign)
|
170
|
+
- [ ] __[premium]__ [Retrieve campaign (`GET /v4/campaigns/{campaign_guid}`)](https://dev.bitly.com/api-reference/#getCampaign)
|
171
|
+
- [ ] __[premium]__ [Update campaign (`PATCH /v4/campaigns/{campaign_guid}`)](https://dev.bitly.com/api-reference/#updateCampaign)
|
172
|
+
- [ ] __[premium]__ [Retrieve channels (`GET /v4/channels`)](https://dev.bitly.com/api-reference/#getChannels)
|
173
|
+
- [ ] __[premium]__ [Create channel (`POST /v4/channels`)](https://dev.bitly.com/api-reference/#createChannel)
|
174
|
+
- [ ] __[premium]__ [Retrieve channel (`GET /v4/channels/{channel_guid}`)](https://dev.bitly.com/api-reference/#getChannel)
|
175
|
+
- [ ] __[premium]__ [Update channel (`PATCH /v4/channels/{channel_guid}`)](https://dev.bitly.com/api-reference/#updateChannel)
|
157
176
|
|
158
177
|
### BSDs (Branded Short Domains)
|
159
178
|
|
160
179
|
[Branded Short Domains documentation](docs/branded_short_domains.md)
|
161
180
|
|
162
|
-
- [x] [Retrieve BSDs (`GET /v4/bsds`)](https://dev.bitly.com/
|
181
|
+
- [x] [Retrieve BSDs (`GET /v4/bsds`)](https://dev.bitly.com/api-reference/#getBSDs)
|
182
|
+
|
183
|
+
### Webhooks
|
184
|
+
|
185
|
+
- [ ] __[premium]__ [Get webhooks (`GET /v4/organizations/{organization_guid}/webhooks`)](https://dev.bitly.com/api-reference/#getWebhooks)
|
186
|
+
- [ ] __[premium]__ [Create a webhook (`POST /v4/webhooks`)](https://dev.bitly.com/api-reference/#createWebhook)
|
187
|
+
- [ ] __[premium]__ [Retrieve a webhook (`GET /v4/webhooks/{webhook_guid}`)](https://dev.bitly.com/api-reference/#getWebhook)
|
188
|
+
- [ ] __[premium]__ [Update a webhook (`POST /v4/webhooks/{webhook_guid`)](https://dev.bitly.com/api-reference/#updateWebhook)
|
189
|
+
- [ ] __[premium]__ [Delete a webhook (`DELETE /v4/webhooks/{webhook_guid}`)](https://dev.bitly.com/api-reference/#deleteWebhook)
|
190
|
+
- [ ] __[premium]__ [Verify a webhook (`POST /v4/webhooks/{webhook_guid}/verify`)](https://dev.bitly.com/api-reference/#verifyWebhook)
|
191
|
+
|
192
|
+
## Customising HTTP requests
|
193
|
+
|
194
|
+
This gem comes with an HTTP client that can use different adapters. It ships with a `Net::HTTP` adapter that it uses by default.
|
195
|
+
|
196
|
+
If you want to control the connection, you can create your own instance of the `Net::HTTP` adapter and pass it options for an HTTP proxy or options that control the request. For example, to control the `read_timeout` you can do this:
|
197
|
+
|
198
|
+
```ruby
|
199
|
+
adapter = Bitly::HTTP::Adapters::NetHTTP.new(request_options: { read_timeout: 1 })
|
200
|
+
http_client = Bitly::HTTP::Client.new(adapter)
|
201
|
+
api_client = Bitly::API::Client.new(http: http_client, token: token)
|
202
|
+
```
|
203
|
+
|
204
|
+
Similarly, you can use an HTTP proxy with the adapter by passing the proxy variables to the adapter's constructor.
|
205
|
+
|
206
|
+
```ruby
|
207
|
+
adapter = Bitly::HTTP::Adapters::NetHTTP.new(proxy_addr: "example.com", proxy_port: 80, proxy_user: "username", proxy_pass: "password")
|
208
|
+
http_client = Bitly::HTTP::Client.new(adapter)
|
209
|
+
api_client = Bitly::API::Client.new(http: http_client, token: token)
|
210
|
+
```
|
211
|
+
|
212
|
+
### Build your own adapter
|
163
213
|
|
164
|
-
|
214
|
+
If you want even more control over the request, you can build your own adapter. An HTTP adapter within this gem must have a `request` instance method that receives a `Bitly::HTTP::Request` object and returns an array of four objects:
|
165
215
|
|
166
|
-
|
216
|
+
1. The response status code
|
217
|
+
2. The body of the response as a string
|
218
|
+
3. The response headers as a hash
|
219
|
+
4. A boolean denoting whether the response was a success or not
|
167
220
|
|
168
|
-
|
221
|
+
See `./src/bitly/http/adapters/net_http.rb` for an example.
|
169
222
|
|
170
223
|
## Development
|
171
224
|
|
data/lib/bitly/api/base.rb
CHANGED
@@ -22,7 +22,7 @@ module Bitly
|
|
22
22
|
|
23
23
|
##
|
24
24
|
# Get the clicks for a bitlink.
|
25
|
-
# [`GET /v4/bitlink/{bitlink}/clicks`](https://dev.bitly.com/
|
25
|
+
# [`GET /v4/bitlink/{bitlink}/clicks`](https://dev.bitly.com/api-reference/#getClicksForBitlink)
|
26
26
|
#
|
27
27
|
# @param client [Bitly::API::Client] An authorized API client
|
28
28
|
# @param bitlink [String] The Bitlink for which you want the clicks
|
@@ -1,52 +1,18 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "uri"
|
2
|
+
require_relative "../paginated_list"
|
4
3
|
|
5
4
|
module Bitly
|
6
5
|
module API
|
7
6
|
class Bitlink
|
8
|
-
class PaginatedList < Bitly::API::
|
9
|
-
|
10
|
-
|
11
|
-
def initialize(items:, response: , client:)
|
12
|
-
super(items: items, response: response)
|
13
|
-
@client = client
|
14
|
-
if response.body["pagination"]
|
15
|
-
pagination = response.body["pagination"]
|
16
|
-
@next_url = pagination["next"]
|
17
|
-
@prev_url = pagination["prev"]
|
18
|
-
@size = pagination["size"]
|
19
|
-
@page = pagination["page"]
|
20
|
-
@total = pagination["total"]
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def has_next_page?
|
25
|
-
!next_url.nil? && !next_url.empty?
|
26
|
-
end
|
27
|
-
|
28
|
-
def has_prev_page?
|
29
|
-
!prev_url.nil? && !prev_url.empty?
|
7
|
+
class PaginatedList < Bitly::API::PaginatedList
|
8
|
+
def item_key
|
9
|
+
"links"
|
30
10
|
end
|
31
11
|
|
32
|
-
def
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
def prev_page
|
37
|
-
has_prev_page? ? get_page(uri: URI(prev_url)) : nil
|
38
|
-
end
|
39
|
-
|
40
|
-
private
|
41
|
-
|
42
|
-
def get_page(uri:)
|
43
|
-
response = @client.request(path: uri.path.gsub(/\/v4/, ""), params: CGI.parse(uri.query))
|
44
|
-
bitlinks = response.body["links"].map do |link|
|
45
|
-
Bitlink.new(data: link, client: @client)
|
46
|
-
end
|
47
|
-
self.class.new(items: bitlinks, response: response, client: @client)
|
12
|
+
def item_factory(data)
|
13
|
+
Bitlink.new(data: data, client: @client)
|
48
14
|
end
|
49
15
|
end
|
50
16
|
end
|
51
17
|
end
|
52
|
-
end
|
18
|
+
end
|
data/lib/bitly/api/bitlink.rb
CHANGED
@@ -19,7 +19,7 @@ module Bitly
|
|
19
19
|
|
20
20
|
##
|
21
21
|
# Shortens a long url.
|
22
|
-
# [`POST /v4/shorten`](https://dev.bitly.com/
|
22
|
+
# [`POST /v4/shorten`](https://dev.bitly.com/api-reference/#createBitlink)
|
23
23
|
#
|
24
24
|
# @example
|
25
25
|
# bitlink = Bitly::API::Bitlink.shorten(client: client, long_url: long_url)
|
@@ -47,7 +47,7 @@ module Bitly
|
|
47
47
|
##
|
48
48
|
# Creates a new Bitlink from a long URL. Similar to #shorten but takes
|
49
49
|
# more parameters.
|
50
|
-
# [`POST /v4/bitlinks`](https://dev.bitly.com/
|
50
|
+
# [`POST /v4/bitlinks`](https://dev.bitly.com/api-reference/#createFullBitlink)
|
51
51
|
#
|
52
52
|
# @example
|
53
53
|
# bitlink = Bitly::API::Bitlink.create(client: client, long_url: long_url)
|
@@ -81,7 +81,7 @@ module Bitly
|
|
81
81
|
|
82
82
|
##
|
83
83
|
# Return information about a bitlink
|
84
|
-
# [`GET /v4/
|
84
|
+
# [`GET /v4/bitlinks/{bitlink}`](https://dev.bitly.com/api-reference/#getBitlink)
|
85
85
|
#
|
86
86
|
# @example
|
87
87
|
# bitlink = Bitly::API::Bitlink.fetch(client: client, bitlink: "bit.ly/example")
|
@@ -98,7 +98,7 @@ module Bitly
|
|
98
98
|
|
99
99
|
##
|
100
100
|
# Return public information about a bitlink
|
101
|
-
# [`POST /v4/expand`](https://dev.bitly.com/
|
101
|
+
# [`POST /v4/expand`](https://dev.bitly.com/api-reference/#expandBitlink)
|
102
102
|
#
|
103
103
|
# @example
|
104
104
|
# bitlink = Bitly::API::Bitlink.expand(client: client, bitlink: "bit.ly/example")
|
@@ -115,7 +115,7 @@ module Bitly
|
|
115
115
|
|
116
116
|
##
|
117
117
|
# Retrieve a list of bitlinks by group
|
118
|
-
# [`GET /v4/groups/{group_guid}/bitlinks`](https://dev.bitly.com/
|
118
|
+
# [`GET /v4/groups/{group_guid}/bitlinks`](https://dev.bitly.com/api-reference/#getBitlinksByGroup)
|
119
119
|
#
|
120
120
|
# @example
|
121
121
|
# bitlinks = Bitly::API::Bitlink.list(client: client, group_guid: guid)
|
@@ -184,15 +184,12 @@ module Bitly
|
|
184
184
|
"encoding_login" => encoding_login
|
185
185
|
}
|
186
186
|
response = client.request(path: "/groups/#{group_guid}/bitlinks", params: params)
|
187
|
-
|
188
|
-
new(data: link, client: client)
|
189
|
-
end
|
190
|
-
PaginatedList.new(items: bitlinks, response: response, client: client)
|
187
|
+
PaginatedList.new(response: response, client: client)
|
191
188
|
end
|
192
189
|
|
193
190
|
##
|
194
191
|
# Returns a list of Bitlinks sorted by clicks.
|
195
|
-
# [`GET /v4/groups/{group_guid}/bitlinks/{sort}`](https://dev.bitly.com/
|
192
|
+
# [`GET /v4/groups/{group_guid}/bitlinks/{sort}`](https://dev.bitly.com/api-reference/#getSortedBitlinks)
|
196
193
|
#
|
197
194
|
# The API returns a separate list of the links and the click counts, but
|
198
195
|
# this method assigns the number of clicks for each link to the Bitlink
|
@@ -257,7 +254,7 @@ module Bitly
|
|
257
254
|
|
258
255
|
##
|
259
256
|
# Update the Bitlink.
|
260
|
-
# [`PATCH /v4/
|
257
|
+
# [`PATCH /v4/bitlinks/{bitlink}`](https://dev.bitly.com/api-reference/#getClicksSummaryForBitlink)
|
261
258
|
#
|
262
259
|
# The parameters listed below are from the documentation. Some only work
|
263
260
|
# if you have a Bitly Pro account.
|
@@ -315,7 +312,7 @@ module Bitly
|
|
315
312
|
self
|
316
313
|
end
|
317
314
|
|
318
|
-
# [`GET /v4/
|
315
|
+
# [`GET /v4/bitlinks/{bitlink}/clicks/summary`](https://dev.bitly.com/api-reference/#getClicksSummaryForBitlink)
|
319
316
|
#
|
320
317
|
# @return [Bitly::API::Bitlink::ClicksSummary]
|
321
318
|
def clicks_summary(unit: nil, units: nil, unit_reference: nil, size: nil)
|
@@ -324,7 +321,7 @@ module Bitly
|
|
324
321
|
|
325
322
|
##
|
326
323
|
# Get the clicks for the bitlink.
|
327
|
-
# [`GET /v4/
|
324
|
+
# [`GET /v4/bitlinks/{bitlink}/clicks`](https://dev.bitly.com/api-reference/#getClicksForBitlink)
|
328
325
|
#
|
329
326
|
# @param sort [String] The data to sort on. Default and only option is
|
330
327
|
# "clicks".
|
@@ -341,6 +338,24 @@ module Bitly
|
|
341
338
|
def link_clicks(unit: nil, units: nil, unit_reference: nil, size: nil)
|
342
339
|
LinkClick.list(client: @client, bitlink: id, unit: unit, units: units, unit_reference: unit_reference, size: size)
|
343
340
|
end
|
341
|
+
|
342
|
+
##
|
343
|
+
# Get metrics for a Bitlink by country
|
344
|
+
# [`GET /v4/bitlinks/{bitlink}/countries`](https://dev.bitly.com/api-reference/#getMetricsForBitlinkByCountries)
|
345
|
+
#
|
346
|
+
# @param unit [String] A unit of time. Default is "day" and can be
|
347
|
+
# "minute", "hour", "day", "week" or "month"
|
348
|
+
# @param units [Integer] An integer representing the time units to query
|
349
|
+
# data for. pass -1 to return all units of time. Defaults to -1.
|
350
|
+
# @param unit_reference [String] An ISO-8601 timestamp, indicating the
|
351
|
+
# most recent time for which to pull metrics. Will default to current
|
352
|
+
# time.
|
353
|
+
# @param size [Integer] The number of links to be returned. Defaults to 50
|
354
|
+
#
|
355
|
+
# @return [Bitly::API::ClickMetric::List]
|
356
|
+
def click_metrics_by_country(unit: nil, units: nil, unit_reference: nil, size: nil)
|
357
|
+
ClickMetric.list_countries_by_bitlink(client: @client, bitlink: id, unit: unit, units: units, unit_reference: unit_reference, size: size)
|
358
|
+
end
|
344
359
|
end
|
345
360
|
end
|
346
|
-
end
|
361
|
+
end
|
data/lib/bitly/api/bsd.rb
CHANGED
@@ -36,7 +36,7 @@ module Bitly
|
|
36
36
|
|
37
37
|
##
|
38
38
|
# Gets the referring networks for the group.
|
39
|
-
# [`GET /v4/groups/{group_guid}/referring_networks`](https://dev.bitly.com/
|
39
|
+
# [`GET /v4/groups/{group_guid}/referring_networks`](https://dev.bitly.com/api-reference/#GetGroupMetricsByReferringNetworks)
|
40
40
|
#
|
41
41
|
# @param client [Bitly::API::Client] An authorized API client
|
42
42
|
# @param group_guid [String] The guid of the group
|
@@ -63,7 +63,7 @@ module Bitly
|
|
63
63
|
|
64
64
|
##
|
65
65
|
# Gets the country click metrics for the group.
|
66
|
-
# [`GET /v4/groups/{group_guid}/countries`](https://dev.bitly.com/
|
66
|
+
# [`GET /v4/groups/{group_guid}/countries`](https://dev.bitly.com/api-reference/#getGroupMetricsByCountries)
|
67
67
|
#
|
68
68
|
# @param client [Bitly::API::Client] An authorized API client
|
69
69
|
# @param group_guid [String] The guid of the group
|
@@ -100,6 +100,22 @@ module Bitly
|
|
100
100
|
)
|
101
101
|
end
|
102
102
|
|
103
|
+
##
|
104
|
+
# Get metrics for a Bitlink by country
|
105
|
+
# [`GET /v4/bitlinks/{bitlink}/countries`](https://dev.bitly.com/api-reference/#getMetricsForBitlinkByCountries)
|
106
|
+
#
|
107
|
+
# @param client [Bitly::API::Client] An authorized API client
|
108
|
+
# @param bitlink [String] The bitlink you want information about
|
109
|
+
# @param unit [String] A unit of time. Default is "day" and can be
|
110
|
+
# "minute", "hour", "day", "week" or "month"
|
111
|
+
# @param units [Integer] An integer representing the time units to query
|
112
|
+
# data for. pass -1 to return all units of time. Defaults to -1.
|
113
|
+
# @param unit_reference [String] An ISO-8601 timestamp, indicating the
|
114
|
+
# most recent time for which to pull metrics. Will default to current
|
115
|
+
# time.
|
116
|
+
# @param size [Integer] The number of links to be returned. Defaults to 50
|
117
|
+
#
|
118
|
+
# @return [Bitly::API::ClickMetric::List]
|
103
119
|
def self.list_countries_by_bitlink(client:, bitlink:, unit: nil, units: nil, size: nil, unit_reference: nil)
|
104
120
|
bitlink = Bitlink::Utils.normalise_bitlink(bitlink: bitlink)
|
105
121
|
list_metrics(
|