bitly 2.0.2 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8f5ca773433a54eb91817b7a7167b625d04cb33701afbb97a5bc4df3831dd429
4
- data.tar.gz: 8b97a419154acad1eeb030c8f918c85022ad7a607db44d379cc0ef4cf4f737f7
3
+ metadata.gz: '095c28dc60c45e049f9fde01119376322ea8438ca0b9074479de7bd903af55ed'
4
+ data.tar.gz: 59df185cab7f082fbdfedc7bc857c79a4bba69b9913d3b91e40effb4852e852e
5
5
  SHA512:
6
- metadata.gz: 52a578ae00f4b4d1016202cb9212fbf8af3fbc1b8d99161b03fe7f97dd383677bdf6f867ff44d19575e566932727e932ba06d8c39883a2a2ff48daec968b5525
7
- data.tar.gz: 73053a5be2a75f261d1036893e1e3159abc822829455fa890956cfb8818c08c57d5000dcdcf8d32719c156d65a52b7d26ab8de046f202c7ceb120f0cdae39b22
6
+ metadata.gz: dc18dd77b07180334af8adb1961fcefc32b56b2920c7400d6d6e04e33fff054cf1086499defae0cf0c88388afbc4cddd167d365ba87ca3be553d0508a3dc104a
7
+ data.tar.gz: 77b804e7d11ba3f82ca7a5329357261a75b592e94b3eb761f120fd0380a0ddca62ee1f717601885e936b5f5e081d6f01f086ef3b4e04d464237167f535497359
@@ -0,0 +1,34 @@
1
+ on:
2
+ push:
3
+ branches:
4
+ - main
5
+ pull_request:
6
+ types: [opened, synchronize, reopened]
7
+ name: SonarCloud Analysis
8
+ jobs:
9
+ sonarcloud:
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - uses: actions/checkout@v2
13
+ with:
14
+ # Disabling shallow clone is recommended for improving relevancy of reporting
15
+ fetch-depth: 0
16
+ - name: Set up Ruby ${{ matrix.ruby }}
17
+ uses: ruby/setup-ruby@v1
18
+ with:
19
+ ruby-version: "3.1"
20
+ - name: "Install dependencies"
21
+ run: bundle install
22
+ - name: Run tests for coverage
23
+ run: bundle exec rspec
24
+ env:
25
+ COVERAGE: json
26
+ - name: fix code coverage paths
27
+ working-directory: ./coverage
28
+ run: |
29
+ sed -i 's@'$GITHUB_WORKSPACE'@/github/workspace/@g' coverage.json
30
+ - name: SonarCloud Scan
31
+ uses: sonarsource/sonarcloud-github-action@master
32
+ env:
33
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34
+ SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
data/Gemfile CHANGED
@@ -4,3 +4,7 @@ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
5
  # Specify your gem's dependencies in bitly.gemspec
6
6
  gemspec
7
+
8
+ group :development do
9
+ gem 'rspec', '< 3.10.0'
10
+ end
data/History.txt CHANGED
@@ -1,6 +1,17 @@
1
1
  === Ongoing
2
2
 
3
- ...
3
+ === 3.0.0 / 2022-11-08
4
+
5
+ * **Breaking** Removes Group DELETE and Oauth Apps endpoints
6
+ * Updates all URLs in the documentation
7
+ * Adds click_metrics_by_country to Bitlink instances
8
+ * Adds request options and proxy options to the Net::HTTP adapter
9
+
10
+ === 2.1.0 / 2022-10-21
11
+
12
+ * Strips protocol from the start of a bitlink when fetching/expanding (fixes #80)
13
+ * Adds SonarCloud quality check GitHub Action
14
+ * Uses verifying doubles in tests over generic doubles
4
15
 
5
16
  === 2.0.2 / 2022-10-18
6
17
 
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  A Ruby gem for using the version 4 [Bitly API](https://dev.bitly.com/) to shorten links, expand short links and view metrics across users, links and organizations.
4
4
 
5
- [![Gem version](https://badge.fury.io/rb/bitly.svg)](https://rubygems.org/gems/bitly) ![Build status](https://github.com/philnash/bitly/workflows/tests/badge.svg) [![Maintainability](https://api.codeclimate.com/v1/badges/f8e078b468c1f2aeca53/maintainability)](https://codeclimate.com/github/philnash/bitly/maintainability) [![Inline docs](https://inch-ci.org/github/philnash/bitly.svg?branch=master)](https://inch-ci.org/github/philnash/bitly)
5
+ [![Gem version](https://badge.fury.io/rb/bitly.svg)](https://rubygems.org/gems/bitly) ![Build status](https://github.com/philnash/bitly/workflows/tests/badge.svg) [![Maintainability](https://api.codeclimate.com/v1/badges/f8e078b468c1f2aeca53/maintainability)](https://codeclimate.com/github/philnash/bitly/maintainability) [![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=philnash_bitly&metric=sqale_rating)](https://sonarcloud.io/summary/new_code?id=philnash_bitly) [![Inline docs](https://inch-ci.org/github/philnash/bitly.svg?branch=master)](https://inch-ci.org/github/philnash/bitly)
6
6
 
7
7
  * [Installation](#installation)
8
8
  * [Usage](#usage)
@@ -18,7 +18,9 @@ A Ruby gem for using the version 4 [Bitly API](https://dev.bitly.com/) to shorte
18
18
  * [Custom Bitlinks](#custom-bitlinks)
19
19
  * [Campaigns](#campaigns)
20
20
  * [BSDs (Branded Short Domains)](#bsds-branded-short-domains)
21
- * [OAuth Apps](#oauth-apps)
21
+ * [Webhooks](#webhooks)
22
+ * [Customising HTTP requests](#customising-http-requests)
23
+ * [Build your own adapter](#build-your-own-adapter)
22
24
  * [Development](#development)
23
25
  * [Contributing](#contributing)
24
26
  * [License](#license)
@@ -86,86 +88,127 @@ bitlink.long_url
86
88
 
87
89
  ## Available API Endpoints
88
90
 
89
- This gem supports the following active v4 API endpoints for the[Bitly API](https://dev.bitly.com/v4_documentation.html).
91
+ This gem supports the following active v4 API endpoints for the[Bitly API](https://dev.bitly.com/api-reference).
90
92
 
91
93
  ### Groups
92
94
 
93
95
  [Groups documentation](docs/groups.md)
94
96
 
95
- - [x] [Retrieve groups (`GET /v4/groups`)](https://dev.bitly.com/v4/#operation/getGroups)
96
- - [x] [Retrieve group (`GET /v4/groups/{group_guid}`)](https://dev.bitly.com/v4/#operation/getGroup)
97
- - [x] [Update group (`PATCH /v4/groups/{group_guid}`)](https://dev.bitly.com/v4/#operation/updateGroup)
98
- - [x] [Delete group (`DELETE /v4/groups/{group_guid}`)](https://dev.bitly.com/v4/#operation/deleteGroup)
99
- - [x] [Retrieve tags by group (`GET /v4/groups/{group_guid}/tags`)](https://dev.bitly.com/v4/#operation/getGroupTags)
100
- - [x] [Retrieve group preferences (`GET /v4/groups/{group_guid}/preferences`)](https://dev.bitly.com/v4/#operation/getGroupPreferences)
101
- - [x] [Update group preferences (`PATCH /v4/groups/{group_guid}/preferences`)](https://dev.bitly.com/v4/#operation/updateGroupPreferences)
102
- - [x] [Retrieve Bitlinks by group (`GET /v4/groups/{group_guid}/bitlinks`)](https://dev.bitly.com/v4/#operation/getBitlinksByGroup)
103
- - [x] [Retrieve sorted Bitlinks by group (`GET /v4/groups/{group_guid}/bitlinks/{sort}`)](https://dev.bitly.com/v4/#operation/getSortedBitlinks)
104
- - [x] [Retrieve group shorten counts (`GET /v4/groups/{group_guid}/shorten_counts`)](https://dev.bitly.com/v4/#operation/getGroupShortenCounts)
105
- - [x] [Retrieve click metrics for a group by referring networks (`GET /v4/groups/{group_guid}/referring_networks`)](https://dev.bitly.com/v4/#operation/GetGroupMetricsByReferringNetworks)
106
- - [x] [Retrieve click metrics for a group by countries (`GET /v4/groups/{group_guid}/countries`)](https://dev.bitly.com/v4/#operation/getGroupMetricsByCountries)
97
+ - [x] [Retrieve groups (`GET /v4/groups`)](https://dev.bitly.com/api-reference/#getGroups)
98
+ - [x] [Retrieve group (`GET /v4/groups/{group_guid}`)](https://dev.bitly.com/api-reference/#getGroup)
99
+ - [x] [Update group (`PATCH /v4/groups/{group_guid}`)](https://dev.bitly.com/api-reference/#updateGroup)
100
+ - [x] [Retrieve tags by group (`GET /v4/groups/{group_guid}/tags`)](https://dev.bitly.com/api-reference/#getGroupTags)
101
+ - [x] [Retrieve group preferences (`GET /v4/groups/{group_guid}/preferences`)](https://dev.bitly.com/api-reference/#getGroupPreferences)
102
+ - [x] [Update group preferences (`PATCH /v4/groups/{group_guid}/preferences`)](https://dev.bitly.com/api-reference/#updateGroupPreferences)
103
+ - [x] [Retrieve Bitlinks by group (`GET /v4/groups/{group_guid}/bitlinks`)](https://dev.bitly.com/api-reference/#getBitlinksByGroup)
104
+ - [x] [Retrieve sorted Bitlinks by group (`GET /v4/groups/{group_guid}/bitlinks/{sort}`)](https://dev.bitly.com/api-reference/#getSortedBitlinks)
105
+ - [x] [Retrieve group shorten counts (`GET /v4/groups/{group_guid}/shorten_counts`)](https://dev.bitly.com/api-reference/#getGroupShortenCounts)
106
+ - [x] [Retrieve click metrics for a group by referring networks (`GET /v4/groups/{group_guid}/referring_networks`)](https://dev.bitly.com/api-reference/#GetGroupMetricsByReferringNetworks)
107
+ - [x] [Retrieve click metrics for a group by countries (`GET /v4/groups/{group_guid}/countries`)](https://dev.bitly.com/api-reference/#getGroupMetricsByCountries)
108
+ - [ ] __[premium]__ [Retrieve click metrics for a group by city (`GET /v4/groups/{group_guid}/cities`)](https://dev.bitly.com/api-reference/#getGroupMetricsByCities)
109
+ - [ ] __[premium]__ [Get group overrides (`GET /v4/groups/{group_guid}/overrides`)](https://dev.bitly.com/api-reference/#getOverridesForGroups)
107
110
 
108
111
  ### Organizations
109
112
 
110
113
  [Organizations documentation](docs/organizations.md)
111
114
 
112
- - [x] [Retrieve organizations (`GET /v4/organizations`)](https://dev.bitly.com/v4/#operation/getOrganizations)
113
- - [x] [Retrieve organization (`GET /v4/organizations/{organization_guid}`)](https://dev.bitly.com/v4/#operation/getOrganization)
114
- - [x] [Retrieve organization shorten counts (`GET /v4/organizations/{organization_guid}/shorten_counts`)](https://dev.bitly.com/v4/#operation/getOrganizationShortenCounts)
115
+ - [x] [Retrieve organizations (`GET /v4/organizations`)](https://dev.bitly.com/api-reference/#getOrganizations)
116
+ - [x] [Retrieve organization (`GET /v4/organizations/{organization_guid}`)](https://dev.bitly.com/api-reference/#getOrganization)
117
+ - [x] [Retrieve organization shorten counts (`GET /v4/organizations/{organization_guid}/shorten_counts`)](https://dev.bitly.com/api-reference/#getOrganizationShortenCounts)
115
118
 
116
119
  ### Users
117
120
 
118
121
  [Users documentation](docs/users.md)
119
122
 
120
- - [x] [Retrieve user (`GET /v4/user`)](https://dev.bitly.com/v4/#operation/getUser)
121
- - [x] [Update user (`PATCH /v4/user`)](https://dev.bitly.com/v4/#operation/updateUser)
123
+ - [x] [Retrieve user (`GET /v4/user`)](https://dev.bitly.com/api-reference/#getUser)
124
+ - [x] [Update user (`PATCH /v4/user`)](https://dev.bitly.com/api-reference/#updateUser)
122
125
 
123
126
  ### Bitlinks
124
127
 
125
128
  [Bitlinks documentation](docs/bitlinks.md)
126
129
 
127
- - [x] [Shorten a link (`POST /v4/shorten`)](https://dev.bitly.com/v4/#operation/createBitlink)
128
- - [x] [Expand a Bitlink (`POST /v4/expand`)](https://dev.bitly.com/v4/#operation/expandBitlink)
129
- - [x] [Retrieve a Bitlink (`GET /v4/bitlink/{bitlink}`)](https://dev.bitly.com/v4/#operation/getBitlink)
130
- - [x] [Create a Bitlink (`POST /v4/bitlinks`)](https://dev.bitly.com/v4/#operation/createFullBitlink)
131
- - [x] [Update a Bitlink (`PATCH /v4/bitlink/{bitlink}`)](https://dev.bitly.com/v4/#operation/updateBitlink)
132
- - [x] [Get clicks for a Bitlink (`GET /v4/bitlink/{bitlink}/clicks`)](https://dev.bitly.com/v4/#operation/getClicksForBitlink)
133
- - [x] [Get clicks summary for a Bitlink (`GET /v4/bitlink/{bitlink}/clicks/summary`)](https://dev.bitly.com/v4/#operation/getClicksSummaryForBitlink)
134
- - [x] [Get metrics for a Bitlink by countries (`GET /v4/bitlinks/{bitlink}/countries`)](https://dev.bitly.com/v4/#operation/getMetricsForBitlinkByCountries)
135
- - [x] [Get metrics for a Bitlink by referrers (`GET /v4/bitlinks/{bitlink}/referrers`)](https://dev.bitly.com/v4/#operation/getMetricsForBitlinkByReferrers)
136
- - [x] [Get metrics for a Bitlink by referring domains (`GET /v4/bitlinks/{bitlink}/referring_domains`)](https://dev.bitly.com/v4/#operation/getMetricsForBitlinkByReferringDomains)
137
- - [x] [Get metrics for a Bitlink by referrers by domain (`GET /v4/bitlinks/{bitlink}/referrers_by_domains`)](https://dev.bitly.com/v4/#operation/getMetricsForBitlinkByReferrersByDomains)
138
- - [ ] __[premium]__ [Get a QR code for a Bitlink (`GET /v4/{bitlink}/qr`)](https://dev.bitly.com/v4/#operation/getBitlinkQRCode)
130
+ - [x] [Shorten a link (`POST /v4/shorten`)](https://dev.bitly.com/api-reference/#createBitlink)
131
+ - [x] [Expand a Bitlink (`POST /v4/expand`)](https://dev.bitly.com/api-reference/#expandBitlink)
132
+ - [x] [Retrieve a Bitlink (`GET /v4/bitlinks/{bitlink}`)](https://dev.bitly.com/api-reference/#getBitlink)
133
+ - [x] [Create a Bitlink (`POST /v4/bitlinks`)](https://dev.bitly.com/api-reference/#createFullBitlink)
134
+ - [x] [Update a Bitlink (`PATCH /v4/bitlinks/{bitlink}`)](https://dev.bitly.com/api-reference/#updateBitlink)
135
+ - [ ] [Delete an unedited hash Bitlink (`DELETE /v4/bitlinks/{bitlink}`)](https://dev.bitly.com/api-reference/#deleteBitlink)
136
+ - [x] [Get clicks for a Bitlink (`GET /v4/bitlinks/{bitlink}/clicks`)](https://dev.bitly.com/api-reference/#getClicksForBitlink)
137
+ - [x] [Get clicks summary for a Bitlink (`GET /v4/bitlinks/{bitlink}/clicks/summary`)](https://dev.bitly.com/api-reference/#getClicksSummaryForBitlink)
138
+ - [x] [Get metrics for a Bitlink by countries (`GET /v4/bitlinks/{bitlink}/countries`)](https://dev.bitly.com/api-reference/#getMetricsForBitlinkByCountries)
139
+ - [x] [Get metrics for a Bitlink by referrers (`GET /v4/bitlinks/{bitlink}/referrers`)](https://dev.bitly.com/api-reference/#getMetricsForBitlinkByReferrers)
140
+ - [x] [Get metrics for a Bitlink by referring domains (`GET /v4/bitlinks/{bitlink}/referring_domains`)](https://dev.bitly.com/api-reference/#getMetricsForBitlinkByReferringDomains)
141
+ - [x] [Get metrics for a Bitlink by referrers by domain (`GET /v4/bitlinks/{bitlink}/referrers_by_domains`)](https://dev.bitly.com/api-reference/#getMetricsForBitlinkByReferrersByDomains)
142
+ - [ ] __[premium]__ [Get metrics for a Bitlink by city (`GET /v4/bitlinks/{bitlink}/cities`)](https://dev.bitly.com/api-reference/#getMetricsForBitlinkByCities)
143
+ - [ ] __[premium]__ [Get metrics for a Bitlink by device type (`GET /v4/bitlinks/{bitlink}/devices`)](https://dev.bitly.com/api-reference/#getMetricsForBitlinkByDevices)
144
+ - [ ] __[premium]__ [Retrieve a QR code for a Bitlink (`GET /v4/bitlinks/{bitlink}/qr`)](https://dev.bitly.com/api-reference/#getBitlinkQRCode)
145
+ - [ ] __[premium]__ [Update a QR code (`PATCH /v4/bitlinks/{bitlink}/qr`)](https://dev.bitly.com/api-reference/#updateBitlinkQRCode)
146
+ - [ ] __[premium]__ [Create a QR code (`POST /v4/bitlinks/{bitlink}/qr`)](https://dev.bitly.com/api-reference/#createBitlinkQRCode)
139
147
 
140
148
  ### Custom Bitlinks
141
149
 
142
- - [ ] [Add custom Bitlink (`POST /v4/custom_bitlinks`)](https://dev.bitly.com/v4/#operation/addCustomBitlink)
143
- - [ ] __[premium]__ [Retrieve custom Bitlink (`GET /v4/custom_bitlinks/{custom_bitlink}`)](https://dev.bitly.com/v4/#operation/getCustomBitlink)
144
- - [ ] __[premium]__ [Update custom Bitlink (`PATCH /v4/custom_bitlink/{custom_bitlink}`)](https://dev.bitly.com/v4/#operation/updateCustomBitlink)
145
- - [ ] __[premium]__ [Get metrics for a custom Bitlink by destination (`GET /v4/custom_bitlinks/{custom_bitlink}/clicks_by_destination`)](https://dev.bitly.com/v4/#operation/getCustomBitlinkMetricsByDestination)
150
+ - [ ] [Add custom Bitlink (`POST /v4/custom_bitlinks`)](https://dev.bitly.com/api-reference/#addCustomBitlink)
151
+ - [ ] __[premium]__ [Retrieve custom Bitlink (`GET /v4/custom_bitlinks/{custom_bitlink}`)](https://dev.bitly.com/api-reference/#getCustomBitlink)
152
+ - [ ] __[premium]__ [Update custom Bitlink (`PATCH /v4/custom_bitlinks/{custom_bitlink}`)](https://dev.bitly.com/api-reference/#updateCustomBitlink)
153
+ - [ ] __[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)
154
+ - [ ] __[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
155
 
147
156
  ### Campaigns
148
157
 
149
- - [ ] __[premium]__ [Retrieve campaigns (`GET /v4/campaigns`)](https://dev.bitly.com/v4/#operation/getCampaigns)
150
- - [ ] __[premium]__ [Create campaign (`POST /v4/campaigns`)](https://dev.bitly.com/v4/#operation/createCampaign)
151
- - [ ] __[premium]__ [Retrieve campaign (`GET /v4/campaigns/{campaign_guid}`)](https://dev.bitly.com/v4/#operation/getCampaign)
152
- - [ ] __[premium]__ [Update campaign (`PATCH /v4/campaigns/{campaign_guid}`)](https://dev.bitly.com/v4/#operation/updateCampaign)
153
- - [ ] __[premium]__ [Retrieve channels (`GET /v4/channels`)](https://dev.bitly.com/v4/#operation/getChannels)
154
- - [ ] __[premium]__ [Create channel (`POST /v4/channels`)](https://dev.bitly.com/v4/#operation/createChannel)
155
- - [ ] __[premium]__ [Retrieve channel (`GET /v4/channels/{channel_guid}`)](https://dev.bitly.com/v4/#operation/getChannel)
156
- - [ ] __[premium]__ [Update channel (`PATCH /v4/channels/{channel_guid}`)](https://dev.bitly.com/v4/#operation/updateChannel)
158
+ - [ ] __[premium]__ [Retrieve campaigns (`GET /v4/campaigns`)](https://dev.bitly.com/api-reference/#getCampaigns)
159
+ - [ ] __[premium]__ [Create campaign (`POST /v4/campaigns`)](https://dev.bitly.com/api-reference/#createCampaign)
160
+ - [ ] __[premium]__ [Retrieve campaign (`GET /v4/campaigns/{campaign_guid}`)](https://dev.bitly.com/api-reference/#getCampaign)
161
+ - [ ] __[premium]__ [Update campaign (`PATCH /v4/campaigns/{campaign_guid}`)](https://dev.bitly.com/api-reference/#updateCampaign)
162
+ - [ ] __[premium]__ [Retrieve channels (`GET /v4/channels`)](https://dev.bitly.com/api-reference/#getChannels)
163
+ - [ ] __[premium]__ [Create channel (`POST /v4/channels`)](https://dev.bitly.com/api-reference/#createChannel)
164
+ - [ ] __[premium]__ [Retrieve channel (`GET /v4/channels/{channel_guid}`)](https://dev.bitly.com/api-reference/#getChannel)
165
+ - [ ] __[premium]__ [Update channel (`PATCH /v4/channels/{channel_guid}`)](https://dev.bitly.com/api-reference/#updateChannel)
157
166
 
158
167
  ### BSDs (Branded Short Domains)
159
168
 
160
169
  [Branded Short Domains documentation](docs/branded_short_domains.md)
161
170
 
162
- - [x] [Retrieve BSDs (`GET /v4/bsds`)](https://dev.bitly.com/v4/#operation/getBSDs)
171
+ - [x] [Retrieve BSDs (`GET /v4/bsds`)](https://dev.bitly.com/api-reference/#getBSDs)
163
172
 
164
- ### OAuth Apps
173
+ ### Webhooks
165
174
 
166
- [OAuth Apps documentation](docs/oauth_apps.md)
175
+ - [ ] __[premium]__ [Get webhooks (`GET /v4/organizations/{organization_guid}/webhooks`)](https://dev.bitly.com/api-reference/#getWebhooks)
176
+ - [ ] __[premium]__ [Create a webhook (`POST /v4/webhooks`)](https://dev.bitly.com/api-reference/#createWebhook)
177
+ - [ ] __[premium]__ [Retrieve a webhook (`GET /v4/webhooks/{webhook_guid}`)](https://dev.bitly.com/api-reference/#getWebhook)
178
+ - [ ] __[premium]__ [Update a webhook (`POST /v4/webhooks/{webhook_guid`)](https://dev.bitly.com/api-reference/#updateWebhook)
179
+ - [ ] __[premium]__ [Delete a webhook (`DELETE /v4/webhooks/{webhook_guid}`)](https://dev.bitly.com/api-reference/#deleteWebhook)
180
+ - [ ] __[premium]__ [Verify a webhook (`POST /v4/webhooks/{webhook_guid}/verify`)](https://dev.bitly.com/api-reference/#verifyWebhook)
167
181
 
168
- - [x] [Retrieve OAuth App (`GET /v4/apps/{client_id}`)](https://dev.bitly.com/v4/#operation/getOAuthApp)
182
+ ## Customising HTTP requests
183
+
184
+ This gem comes with an HTTP client that can use different adapters. It ships with a `Net::HTTP` adapter that it uses by default.
185
+
186
+ 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:
187
+
188
+ ```ruby
189
+ adapter = Bitly::HTTP::Adapters::NetHTTP.new(request_options: { read_timeout: 1 })
190
+ http_client = Bitly::HTTP::Client.new(adapter)
191
+ api_client = Bitly::API::Client.new(http: http_client, token: token)
192
+ ```
193
+
194
+ Similarly, you can use an HTTP proxy with the adapter by passing the proxy variables to the adapter's constructor.
195
+
196
+ ```ruby
197
+ adapter = Bitly::HTTP::Adapters::NetHTTP.new(proxy_addr: "example.com", proxy_port: 80, proxy_user: "username", proxy_pass: "password")
198
+ http_client = Bitly::HTTP::Client.new(adapter)
199
+ api_client = Bitly::API::Client.new(http: http_client, token: token)
200
+ ```
201
+
202
+ ### Build your own adapter
203
+
204
+ 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:
205
+
206
+ 1. The response status code
207
+ 2. The body of the response as a string
208
+ 3. The response headers as a hash
209
+ 4. A boolean denoting whether the response was a success or not
210
+
211
+ See `./src/bitly/http/adapters/net_http.rb` for an example.
169
212
 
170
213
  ## Development
171
214
 
data/bitly.gemspec CHANGED
@@ -35,7 +35,8 @@ Gem::Specification.new do |spec|
35
35
  spec.add_development_dependency "bundler", "~> 2.0"
36
36
  spec.add_development_dependency "rake", "~> 13.0"
37
37
  spec.add_development_dependency "rspec", "~> 3.0"
38
- spec.add_development_dependency "simplecov", "~> 0.17.1"
38
+ spec.add_development_dependency "simplecov", "~> 0.21"
39
+ spec.add_development_dependency "simplecov_json_formatter", "~> 0.1"
39
40
  spec.add_development_dependency "webmock", "~> 3.7.6"
40
41
  spec.add_development_dependency "vcr"
41
42
  spec.add_development_dependency "envyable"
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  require_relative "../base"
3
+ require_relative "./utils"
3
4
 
4
5
  module Bitly
5
6
  module API
@@ -8,6 +9,7 @@ module Bitly
8
9
  include Base
9
10
 
10
11
  def self.fetch(client:, bitlink:, unit: nil, units: nil, unit_reference: nil, size: nil)
12
+ bitlink = Utils.normalise_bitlink(bitlink: bitlink)
11
13
  response = client.request(
12
14
  path: "/bitlinks/#{bitlink}/clicks/summary",
13
15
  params: {
@@ -1,7 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
  require "time"
3
3
  require_relative "../base"
4
- require_relative '../list'
4
+ require_relative "../list"
5
+ require_relative "./utils"
5
6
 
6
7
  module Bitly
7
8
  module API
@@ -21,7 +22,7 @@ module Bitly
21
22
 
22
23
  ##
23
24
  # Get the clicks for a bitlink.
24
- # [`GET /v4/bitlink/{bitlink}/clicks`](https://dev.bitly.com/v4/#operation/getClicksForBitlink)
25
+ # [`GET /v4/bitlink/{bitlink}/clicks`](https://dev.bitly.com/api-reference/#getClicksForBitlink)
25
26
  #
26
27
  # @param client [Bitly::API::Client] An authorized API client
27
28
  # @param bitlink [String] The Bitlink for which you want the clicks
@@ -38,6 +39,7 @@ module Bitly
38
39
  #
39
40
  # @return [Bitly::API::Bitlink::LinkClick::List]
40
41
  def self.list(client:, bitlink:, unit: nil, units: nil, size: nil, unit_reference: nil)
42
+ bitlink = Utils.normalise_bitlink(bitlink: bitlink)
41
43
  response = client.request(
42
44
  path: "/bitlinks/#{bitlink}/clicks",
43
45
  params: {
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bitly
4
+ module API
5
+ class Bitlink
6
+ module Utils
7
+ def self.normalise_bitlink(bitlink:)
8
+ bitlink.gsub(/^https?:\/\//, "")
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  require_relative "./base"
3
3
  require_relative "./list"
4
+ require_relative "./bitlink/utils"
4
5
 
5
6
  module Bitly
6
7
  module API
@@ -18,7 +19,7 @@ module Bitly
18
19
 
19
20
  ##
20
21
  # Shortens a long url.
21
- # [`POST /v4/shorten`](https://dev.bitly.com/v4/#operation/createBitlink)
22
+ # [`POST /v4/shorten`](https://dev.bitly.com/api-reference/#createBitlink)
22
23
  #
23
24
  # @example
24
25
  # bitlink = Bitly::API::Bitlink.shorten(client: client, long_url: long_url)
@@ -46,7 +47,7 @@ module Bitly
46
47
  ##
47
48
  # Creates a new Bitlink from a long URL. Similar to #shorten but takes
48
49
  # more parameters.
49
- # [`POST /v4/bitlinks`](https://dev.bitly.com/v4/#operation/createFullBitlink)
50
+ # [`POST /v4/bitlinks`](https://dev.bitly.com/api-reference/#createFullBitlink)
50
51
  #
51
52
  # @example
52
53
  # bitlink = Bitly::API::Bitlink.create(client: client, long_url: long_url)
@@ -80,7 +81,7 @@ module Bitly
80
81
 
81
82
  ##
82
83
  # Return information about a bitlink
83
- # [`GET /v4/bitlink/{bitlink}`](https://dev.bitly.com/v4/#operation/getBitlink)
84
+ # [`GET /v4/bitlinks/{bitlink}`](https://dev.bitly.com/api-reference/#getBitlink)
84
85
  #
85
86
  # @example
86
87
  # bitlink = Bitly::API::Bitlink.fetch(client: client, bitlink: "bit.ly/example")
@@ -90,13 +91,14 @@ module Bitly
90
91
  #
91
92
  # @return [Bitly::API::Bitlink]
92
93
  def self.fetch(client:, bitlink:)
94
+ bitlink = Utils.normalise_bitlink(bitlink: bitlink)
93
95
  response = client.request(path: "/bitlinks/#{bitlink}")
94
96
  new(data: response.body, client: client, response: response)
95
97
  end
96
98
 
97
99
  ##
98
100
  # Return public information about a bitlink
99
- # [`POST /v4/expand`](https://dev.bitly.com/v4/#operation/expandBitlink)
101
+ # [`POST /v4/expand`](https://dev.bitly.com/api-reference/#expandBitlink)
100
102
  #
101
103
  # @example
102
104
  # bitlink = Bitly::API::Bitlink.expand(client: client, bitlink: "bit.ly/example")
@@ -106,13 +108,14 @@ module Bitly
106
108
  #
107
109
  # @return [Bitly::API::Bitlink]
108
110
  def self.expand(client:, bitlink:)
111
+ bitlink = Utils.normalise_bitlink(bitlink: bitlink)
109
112
  response = client.request(path: "/expand", method: "POST", params: { "bitlink_id" => bitlink })
110
113
  new(data: response.body, client: client, response: response)
111
114
  end
112
115
 
113
116
  ##
114
117
  # Retrieve a list of bitlinks by group
115
- # [`GET /v4/groups/{group_guid}/bitlinks`](https://dev.bitly.com/v4/#operation/getBitlinksByGroup)
118
+ # [`GET /v4/groups/{group_guid}/bitlinks`](https://dev.bitly.com/api-reference/#getBitlinksByGroup)
116
119
  #
117
120
  # @example
118
121
  # bitlinks = Bitly::API::Bitlink.list(client: client, group_guid: guid)
@@ -189,7 +192,7 @@ module Bitly
189
192
 
190
193
  ##
191
194
  # Returns a list of Bitlinks sorted by clicks.
192
- # [`GET /v4/groups/{group_guid}/bitlinks/{sort}`](https://dev.bitly.com/v4/#operation/getSortedBitlinks)
195
+ # [`GET /v4/groups/{group_guid}/bitlinks/{sort}`](https://dev.bitly.com/api-reference/#getSortedBitlinks)
193
196
  #
194
197
  # The API returns a separate list of the links and the click counts, but
195
198
  # this method assigns the number of clicks for each link to the Bitlink
@@ -241,6 +244,7 @@ module Bitly
241
244
 
242
245
  def initialize(data:, client:, response: nil, clicks: nil)
243
246
  assign_attributes(data)
247
+ @id = Utils.normalise_bitlink(bitlink: @id)
244
248
  if data["deeplinks"]
245
249
  @deeplinks = data["deeplinks"].map { |data| Deeplink.new(data: data) }
246
250
  else
@@ -253,7 +257,7 @@ module Bitly
253
257
 
254
258
  ##
255
259
  # Update the Bitlink.
256
- # [`PATCH /v4/bitlink/{bitlink}`](https://dev.bitly.com/v4/#operation/updateBitlink)
260
+ # [`PATCH /v4/bitlinks/{bitlink}`](https://dev.bitly.com/api-reference/#getClicksSummaryForBitlink)
257
261
  #
258
262
  # The parameters listed below are from the documentation. Some only work
259
263
  # if you have a Bitly Pro account.
@@ -311,7 +315,7 @@ module Bitly
311
315
  self
312
316
  end
313
317
 
314
- # [`GET /v4/bitlink/{bitlink}/clicks/summary`](https://dev.bitly.com/v4/#operation/getClicksSummaryForBitlink)
318
+ # [`GET /v4/bitlinks/{bitlink}/clicks/summary`](https://dev.bitly.com/api-reference/#getClicksSummaryForBitlink)
315
319
  #
316
320
  # @return [Bitly::API::Bitlink::ClicksSummary]
317
321
  def clicks_summary(unit: nil, units: nil, unit_reference: nil, size: nil)
@@ -320,7 +324,7 @@ module Bitly
320
324
 
321
325
  ##
322
326
  # Get the clicks for the bitlink.
323
- # [`GET /v4/bitlink/{bitlink}/clicks`](https://dev.bitly.com/v4/#operation/getClicksForBitlink)
327
+ # [`GET /v4/bitlinks/{bitlink}/clicks`](https://dev.bitly.com/api-reference/#getClicksForBitlink)
324
328
  #
325
329
  # @param sort [String] The data to sort on. Default and only option is
326
330
  # "clicks".
@@ -337,6 +341,24 @@ module Bitly
337
341
  def link_clicks(unit: nil, units: nil, unit_reference: nil, size: nil)
338
342
  LinkClick.list(client: @client, bitlink: id, unit: unit, units: units, unit_reference: unit_reference, size: size)
339
343
  end
344
+
345
+ ##
346
+ # Get metrics for a Bitlink by country
347
+ # [`GET /v4/bitlinks/{bitlink}/countries`](https://dev.bitly.com/api-reference/#getMetricsForBitlinkByCountries)
348
+ #
349
+ # @param unit [String] A unit of time. Default is "day" and can be
350
+ # "minute", "hour", "day", "week" or "month"
351
+ # @param units [Integer] An integer representing the time units to query
352
+ # data for. pass -1 to return all units of time. Defaults to -1.
353
+ # @param unit_reference [String] An ISO-8601 timestamp, indicating the
354
+ # most recent time for which to pull metrics. Will default to current
355
+ # time.
356
+ # @param size [Integer] The number of links to be returned. Defaults to 50
357
+ #
358
+ # @return [Bitly::API::ClickMetric::List]
359
+ def click_metrics_by_country(unit: nil, units: nil, unit_reference: nil, size: nil)
360
+ ClickMetric.list_countries_by_bitlink(client: @client, bitlink: id, unit: unit, units: units, unit_reference: unit_reference, size: size)
361
+ end
340
362
  end
341
363
  end
342
364
  end
data/lib/bitly/api/bsd.rb CHANGED
@@ -8,7 +8,7 @@ module Bitly
8
8
 
9
9
  ##
10
10
  # Fetch Branded Short Domains (BSDs).
11
- # [`GET /v4/bsds`](https://dev.bitly.com/v4/#operation/getBSDs)
11
+ # [`GET /v4/bsds`](https://dev.bitly.com/api-reference/#getBSDs)
12
12
  #
13
13
  # @example
14
14
  # bsds = Bitly::API::BSD.list(client: client)
@@ -1,7 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
  require "time"
3
3
  require_relative "./base"
4
- require_relative './list'
4
+ require_relative "./list"
5
+ require_relative "./bitlink/utils"
5
6
 
6
7
  module Bitly
7
8
  module API
@@ -35,7 +36,7 @@ module Bitly
35
36
 
36
37
  ##
37
38
  # Gets the referring networks for the group.
38
- # [`GET /v4/groups/{group_guid}/referring_networks`](https://dev.bitly.com/v4/#operation/GetGroupMetricsByReferringNetworks)
39
+ # [`GET /v4/groups/{group_guid}/referring_networks`](https://dev.bitly.com/api-reference/#GetGroupMetricsByReferringNetworks)
39
40
  #
40
41
  # @param client [Bitly::API::Client] An authorized API client
41
42
  # @param group_guid [String] The guid of the group
@@ -62,7 +63,7 @@ module Bitly
62
63
 
63
64
  ##
64
65
  # Gets the country click metrics for the group.
65
- # [`GET /v4/groups/{group_guid}/countries`](https://dev.bitly.com/v4/#operation/getGroupMetricsByCountries)
66
+ # [`GET /v4/groups/{group_guid}/countries`](https://dev.bitly.com/api-reference/#getGroupMetricsByCountries)
66
67
  #
67
68
  # @param client [Bitly::API::Client] An authorized API client
68
69
  # @param group_guid [String] The guid of the group
@@ -88,6 +89,7 @@ module Bitly
88
89
  end
89
90
 
90
91
  def self.list_referrers(client:, bitlink:, unit: nil, units: nil, size: nil, unit_reference: nil)
92
+ bitlink = Bitlink::Utils.normalise_bitlink(bitlink: bitlink)
91
93
  list_metrics(
92
94
  client: client,
93
95
  path: "/bitlinks/#{bitlink}/referrers",
@@ -98,7 +100,24 @@ module Bitly
98
100
  )
99
101
  end
100
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]
101
119
  def self.list_countries_by_bitlink(client:, bitlink:, unit: nil, units: nil, size: nil, unit_reference: nil)
120
+ bitlink = Bitlink::Utils.normalise_bitlink(bitlink: bitlink)
102
121
  list_metrics(
103
122
  client: client,
104
123
  path: "/bitlinks/#{bitlink}/countries",
@@ -110,6 +129,7 @@ module Bitly
110
129
  end
111
130
 
112
131
  def self.list_referring_domains(client:, bitlink:, unit: nil, units: nil, size: nil, unit_reference: nil)
132
+ bitlink = Bitlink::Utils.normalise_bitlink(bitlink: bitlink)
113
133
  list_metrics(
114
134
  client: client,
115
135
  path: "/bitlinks/#{bitlink}/referring_domains",
@@ -121,6 +141,7 @@ module Bitly
121
141
  end
122
142
 
123
143
  def self.list_referrers_by_domain(client:, bitlink:, unit: nil, units: nil, size: nil, unit_reference: nil)
144
+ bitlink = Bitlink::Utils.normalise_bitlink(bitlink: bitlink)
124
145
  response = client.request(
125
146
  path: "/bitlinks/#{bitlink}/referrers_by_domains",
126
147
  params: {
@@ -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
@@ -561,18 +548,6 @@ module Bitly
561
548
  BSD.list(client: self)
562
549
  end
563
550
 
564
- ##
565
- # Fetch OAuth application by client ID
566
- # [`GET /v4/apps/{client_id}`)](https://dev.bitly.com/v4/#operation/getOAuthApp)
567
- #
568
- # @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)
574
- end
575
-
576
551
  private
577
552
 
578
553
  def default_headers
@@ -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,7 +158,7 @@ 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
@@ -180,7 +167,7 @@ module Bitly
180
167
 
181
168
  ##
182
169
  # Gets the referring networks for the group.
183
- # [`GET /v4/groups/{group_guid}/referring_networks`](https://dev.bitly.com/v4/#operation/GetGroupMetricsByReferringNetworks)
170
+ # [`GET /v4/groups/{group_guid}/referring_networks`](https://dev.bitly.com/api-reference/#GetGroupMetricsByReferringNetworks)
184
171
  #
185
172
  # @param unit [String] A unit of time. Default is "day" and can be
186
173
  # "minute", "hour", "day", "week" or "month"
@@ -205,7 +192,7 @@ module Bitly
205
192
 
206
193
  ##
207
194
  # Gets the country click metrics for the group.
208
- # [`GET /v4/groups/{group_guid}/countries`](https://dev.bitly.com/v4/#operation/getGroupMetricsByCountries)
195
+ # [`GET /v4/groups/{group_guid}/countries`](https://dev.bitly.com/api-reference/#getGroupMetricsByCountries)
209
196
  #
210
197
  # @param unit [String] A unit of time. Default is "day" and can be
211
198
  # "minute", "hour", "day", "week" or "month"
@@ -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
@@ -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
@@ -13,7 +13,6 @@ module Bitly
13
13
  autoload :Group, File.join(File.dirname(__FILE__), "api/group.rb")
14
14
  autoload :User, File.join(File.dirname(__FILE__), "api/user.rb")
15
15
  autoload :BSD, File.join(File.dirname(__FILE__), "api/bsd.rb")
16
- autoload :OAuthApp, File.join(File.dirname(__FILE__), "api/oauth_app.rb")
17
16
  autoload :ShortenCounts, File.join(File.dirname(__FILE__), "api/shorten_counts.rb")
18
17
  end
19
18
  end
@@ -6,8 +6,18 @@ module Bitly
6
6
  module HTTP
7
7
  module Adapters
8
8
  class NetHTTP
9
+ DEFAULT_OPTS = { use_ssl: true }
10
+
11
+ def initialize(proxy_addr: nil, proxy_port: nil, proxy_user: nil, proxy_pass: nil, request_opts: {})
12
+ @request_opts = DEFAULT_OPTS.merge(request_opts)
13
+ @proxy_addr = proxy_addr
14
+ @proxy_port = proxy_port
15
+ @proxy_user = proxy_user
16
+ @proxy_pass = proxy_pass
17
+ end
18
+
9
19
  def request(request)
10
- Net::HTTP.start(request.uri.host, request.uri.port, use_ssl: true) do |http|
20
+ Net::HTTP.start(request.uri.host, request.uri.port, @proxy_addr, @proxy_port, @proxy_user, @proxy_pass, @request_opts) do |http|
11
21
  method = Object.const_get("Net::HTTP::#{request.method.capitalize}")
12
22
  full_path = request.uri.path
13
23
  full_path += "?#{request.uri.query}" if request.uri.query
data/lib/bitly/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bitly
4
- VERSION = "2.0.2"
4
+ VERSION = "3.0.0"
5
5
  end
@@ -0,0 +1,6 @@
1
+ sonar.organization=philnash
2
+ sonar.projectKey=philnash_bitly
3
+
4
+ sonar.sources=lib
5
+ sonar.tests=spec
6
+ sonar.ruby.coverage.reportPaths=coverage/coverage.json
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bitly
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Phil Nash
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-18 00:00:00.000000000 Z
11
+ date: 2022-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oauth2
@@ -78,14 +78,28 @@ dependencies:
78
78
  requirements:
79
79
  - - "~>"
80
80
  - !ruby/object:Gem::Version
81
- version: 0.17.1
81
+ version: '0.21'
82
82
  type: :development
83
83
  prerelease: false
84
84
  version_requirements: !ruby/object:Gem::Requirement
85
85
  requirements:
86
86
  - - "~>"
87
87
  - !ruby/object:Gem::Version
88
- version: 0.17.1
88
+ version: '0.21'
89
+ - !ruby/object:Gem::Dependency
90
+ name: simplecov_json_formatter
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '0.1'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '0.1'
89
103
  - !ruby/object:Gem::Dependency
90
104
  name: webmock
91
105
  requirement: !ruby/object:Gem::Requirement
@@ -137,6 +151,7 @@ extensions: []
137
151
  extra_rdoc_files: []
138
152
  files:
139
153
  - ".github/FUNDING.yml"
154
+ - ".github/workflows/sonarcloud.yml"
140
155
  - ".github/workflows/tests.yml"
141
156
  - ".gitignore"
142
157
  - ".rspec"
@@ -156,13 +171,13 @@ files:
156
171
  - lib/bitly/api/bitlink/deeplink.rb
157
172
  - lib/bitly/api/bitlink/link_click.rb
158
173
  - lib/bitly/api/bitlink/paginated_list.rb
174
+ - lib/bitly/api/bitlink/utils.rb
159
175
  - lib/bitly/api/bsd.rb
160
176
  - lib/bitly/api/click_metric.rb
161
177
  - lib/bitly/api/client.rb
162
178
  - lib/bitly/api/group.rb
163
179
  - lib/bitly/api/group/preferences.rb
164
180
  - lib/bitly/api/list.rb
165
- - lib/bitly/api/oauth_app.rb
166
181
  - lib/bitly/api/organization.rb
167
182
  - lib/bitly/api/shorten_counts.rb
168
183
  - lib/bitly/api/user.rb
@@ -175,6 +190,7 @@ files:
175
190
  - lib/bitly/http/response.rb
176
191
  - lib/bitly/oauth.rb
177
192
  - lib/bitly/version.rb
193
+ - sonar-project.properties
178
194
  homepage: https://github.com/philnash/bitly
179
195
  licenses:
180
196
  - MIT
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
- require_relative "./base"
3
-
4
- module Bitly
5
- module API
6
- class OAuthApp
7
- include Base
8
-
9
- def self.attributes
10
- [:name, :description, :link, :client_id]
11
- end
12
- attr_reader(*attributes)
13
-
14
- def self.fetch(client:, client_id:)
15
- response = client.request(path: "/apps/#{client_id}")
16
- new(data: response.body, client: client, response: response)
17
- end
18
-
19
- def initialize(data:, client:, response: nil)
20
- assign_attributes(data)
21
- @client = client
22
- @response = response
23
- end
24
- end
25
- end
26
- end