bitly 1.1.1 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +36 -3
- data/.rspec +3 -0
- data/.travis.yml +6 -2
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +5 -2
- data/History.txt +32 -1
- data/LICENSE.md +1 -1
- data/README.md +151 -58
- data/Rakefile +6 -9
- data/bitly.gemspec +36 -32
- data/config/env.yml.example +5 -0
- data/lib/bitly.rb +9 -7
- data/lib/bitly/api.rb +19 -0
- data/lib/bitly/api/base.rb +23 -0
- data/lib/bitly/api/bitlink.rb +342 -0
- data/lib/bitly/api/bitlink/clicks_summary.rb +35 -0
- data/lib/bitly/api/bitlink/deeplink.rb +29 -0
- data/lib/bitly/api/bitlink/link_click.rb +75 -0
- data/lib/bitly/api/bitlink/paginated_list.rb +52 -0
- data/lib/bitly/api/bsd.rb +24 -0
- data/lib/bitly/api/click_metric.rb +186 -0
- data/lib/bitly/api/client.rb +588 -0
- data/lib/bitly/api/group.rb +232 -0
- data/lib/bitly/api/group/preferences.rb +73 -0
- data/lib/bitly/api/list.rb +22 -0
- data/lib/bitly/api/oauth_app.rb +26 -0
- data/lib/bitly/api/organization.rb +104 -0
- data/lib/bitly/api/shorten_counts.rb +61 -0
- data/lib/bitly/api/user.rb +107 -0
- data/lib/bitly/error.rb +33 -0
- data/lib/bitly/http.rb +10 -0
- data/lib/bitly/http/adapters.rb +9 -0
- data/lib/bitly/http/adapters/net_http.rb +27 -0
- data/lib/bitly/http/client.rb +33 -0
- data/lib/bitly/http/request.rb +118 -0
- data/lib/bitly/http/response.rb +66 -0
- data/lib/bitly/oauth.rb +109 -0
- data/lib/bitly/version.rb +3 -1
- metadata +82 -111
- data/Manifest +0 -37
- data/lib/bitly/client.rb +0 -145
- data/lib/bitly/config.rb +0 -29
- data/lib/bitly/url.rb +0 -103
- data/lib/bitly/utils.rb +0 -57
- data/lib/bitly/v3.rb +0 -14
- data/lib/bitly/v3/bitly.rb +0 -7
- data/lib/bitly/v3/client.rb +0 -207
- data/lib/bitly/v3/country.rb +0 -13
- data/lib/bitly/v3/day.rb +0 -13
- data/lib/bitly/v3/missing_url.rb +0 -15
- data/lib/bitly/v3/oauth.rb +0 -41
- data/lib/bitly/v3/realtime_link.rb +0 -18
- data/lib/bitly/v3/referrer.rb +0 -13
- data/lib/bitly/v3/url.rb +0 -154
- data/lib/bitly/v3/user.rb +0 -135
- data/test/bitly/test_client.rb +0 -266
- data/test/bitly/test_config.rb +0 -28
- data/test/bitly/test_url.rb +0 -167
- data/test/bitly/test_utils.rb +0 -79
- data/test/fixtures/cnn.json +0 -1
- data/test/fixtures/cnn_and_google.json +0 -1
- data/test/fixtures/expand_cnn.json +0 -1
- data/test/fixtures/expand_cnn_and_google.json +0 -1
- data/test/fixtures/google_and_cnn_info.json +0 -1
- data/test/fixtures/google_info.json +0 -1
- data/test/fixtures/google_stats.json +0 -1
- data/test/fixtures/shorten_error.json +0 -1
- data/test/test_helper.rb +0 -39
data/Rakefile
CHANGED
@@ -1,11 +1,8 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rspec/core/rake_task"
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
t.ruby_opts = ['-Itest']
|
10
|
-
t.ruby_opts << '-rubygems' if defined? Gem
|
11
|
-
end
|
6
|
+
RSpec::Core::RakeTask.new(:spec)
|
7
|
+
|
8
|
+
task :default => :spec
|
data/bitly.gemspec
CHANGED
@@ -1,38 +1,42 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
3
|
lib = File.expand_path("../lib", __FILE__)
|
4
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
-
require
|
5
|
+
require "bitly/version"
|
6
6
|
|
7
7
|
Gem::Specification.new do |spec|
|
8
|
-
spec.name
|
9
|
-
spec.version
|
10
|
-
spec.authors
|
11
|
-
spec.email
|
12
|
-
|
13
|
-
spec.summary
|
14
|
-
spec.description
|
15
|
-
spec.homepage
|
16
|
-
spec.license
|
17
|
-
|
18
|
-
spec.
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
8
|
+
spec.name = "bitly"
|
9
|
+
spec.version = Bitly::VERSION
|
10
|
+
spec.authors = ["Phil Nash"]
|
11
|
+
spec.email = ["philnash@gmail.com"]
|
12
|
+
|
13
|
+
spec.summary = %q{Use the Bitly API to shorten or expand URLs}
|
14
|
+
spec.description = %q{Use the Bitly API version 4 to shorten or expand URLs. Check out the API documentation at https://dev.bitly.com/.}
|
15
|
+
spec.homepage = "https://github.com/philnash/bitly"
|
16
|
+
spec.license = "MIT"
|
17
|
+
|
18
|
+
spec.metadata = {
|
19
|
+
"bug_tracker_uri" => "https://github.com/philnash/bitly/issues",
|
20
|
+
"changelog_uri" => "https://github.com/philnash/bitly/blob/master/History.txt",
|
21
|
+
"documentation_uri" => "https://www.rubydoc.info/gems/bitly/",
|
22
|
+
"homepage_uri" => "https://github.com/philnash/bitly",
|
23
|
+
"source_code_uri" => "https://github.com/philnash/bitly"
|
24
|
+
}
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features|bin|docs)/})
|
28
|
+
end
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
|
31
|
+
spec.required_ruby_version = ">= 2.3.0"
|
32
|
+
|
29
33
|
spec.add_runtime_dependency "oauth2", "< 2.0", ">= 0.5.0"
|
30
|
-
|
31
|
-
|
32
|
-
spec.add_development_dependency "
|
33
|
-
spec.add_development_dependency "
|
34
|
-
spec.add_development_dependency "
|
35
|
-
spec.add_development_dependency "
|
36
|
-
spec.add_development_dependency "
|
37
|
-
spec.add_development_dependency "
|
34
|
+
|
35
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
36
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
37
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
38
|
+
spec.add_development_dependency "simplecov", "~> 0.17.1"
|
39
|
+
spec.add_development_dependency "webmock", "~> 3.7.6"
|
40
|
+
spec.add_development_dependency "vcr"
|
41
|
+
spec.add_development_dependency "envyable"
|
38
42
|
end
|
data/lib/bitly.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
require "bitly/version"
|
4
|
+
|
5
|
+
module Bitly
|
6
|
+
autoload :Error, "bitly/error"
|
7
|
+
autoload :OAuth, "bitly/oauth"
|
8
|
+
autoload :HTTP, "bitly/http"
|
9
|
+
autoload :API, "bitly/api"
|
10
|
+
end
|
data/lib/bitly/api.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "uri"
|
3
|
+
|
4
|
+
module Bitly
|
5
|
+
module API
|
6
|
+
BASE_URL = URI("https://api-ssl.bitly.com/v4")
|
7
|
+
|
8
|
+
autoload :Base, File.join(File.dirname(__FILE__), "api/base.rb")
|
9
|
+
autoload :Client, File.join(File.dirname(__FILE__), "api/client.rb")
|
10
|
+
autoload :ClickMetric, File.join(File.dirname(__FILE__), "api/click_metric.rb")
|
11
|
+
autoload :Bitlink, File.join(File.dirname(__FILE__), "api/bitlink.rb")
|
12
|
+
autoload :Organization, File.join(File.dirname(__FILE__), "api/organization.rb")
|
13
|
+
autoload :Group, File.join(File.dirname(__FILE__), "api/group.rb")
|
14
|
+
autoload :User, File.join(File.dirname(__FILE__), "api/user.rb")
|
15
|
+
autoload :BSD, File.join(File.dirname(__FILE__), "api/bsd.rb")
|
16
|
+
autoload :OAuthApp, File.join(File.dirname(__FILE__), "api/oauth_app.rb")
|
17
|
+
autoload :ShortenCounts, File.join(File.dirname(__FILE__), "api/shorten_counts.rb")
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "time"
|
3
|
+
|
4
|
+
module Bitly
|
5
|
+
module API
|
6
|
+
module Base
|
7
|
+
attr_reader :response
|
8
|
+
|
9
|
+
def assign_attributes(attributes)
|
10
|
+
if self.class.respond_to?(:attributes)
|
11
|
+
self.class.attributes.each do |attr|
|
12
|
+
instance_variable_set("@#{attr}", attributes[attr.to_s]) if attributes[attr.to_s]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
if self.class.respond_to?(:time_attributes)
|
16
|
+
self.class.time_attributes.each do |attr|
|
17
|
+
instance_variable_set("@#{attr}", Time.parse(attributes[attr.to_s])) if attributes[attr.to_s]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,342 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative "./base"
|
3
|
+
require_relative "./list"
|
4
|
+
|
5
|
+
module Bitly
|
6
|
+
module API
|
7
|
+
##
|
8
|
+
# A Bitlink represents a shortened link within Bitly.
|
9
|
+
class Bitlink
|
10
|
+
autoload :PaginatedList, File.join(File.dirname(__FILE__), "bitlink/paginated_list.rb")
|
11
|
+
autoload :Deeplink, File.join(File.dirname(__FILE__), "bitlink/deeplink.rb")
|
12
|
+
autoload :ClicksSummary, File.join(File.dirname(__FILE__), "bitlink/clicks_summary.rb")
|
13
|
+
autoload :LinkClick, File.join(File.dirname(__FILE__), "bitlink/link_click.rb")
|
14
|
+
|
15
|
+
include Base
|
16
|
+
|
17
|
+
class List < Bitly::API::List ; end
|
18
|
+
|
19
|
+
##
|
20
|
+
# Shortens a long url.
|
21
|
+
# [`POST /v4/shorten`](https://dev.bitly.com/v4/#operation/createBitlink)
|
22
|
+
#
|
23
|
+
# @example
|
24
|
+
# bitlink = Bitly::API::Bitlink.shorten(client: client, long_url: long_url)
|
25
|
+
#
|
26
|
+
# @param client [Bitly::API::Client] An authorized API client
|
27
|
+
# @param long_url [String] A long URL that you want shortened
|
28
|
+
# @param domain [String] The bitly domain you want to shorten, API default
|
29
|
+
# is "bit.ly"
|
30
|
+
# @param group_guid [String] The GUID of the group for which you want to
|
31
|
+
# shorten this URL
|
32
|
+
#
|
33
|
+
# @return [Bitly::API::Bitlink]
|
34
|
+
def self.shorten(client:, long_url:, domain: nil, group_guid: nil)
|
35
|
+
response = client.request(
|
36
|
+
path: "/shorten",
|
37
|
+
method: "POST",
|
38
|
+
params: {
|
39
|
+
"long_url" => long_url,
|
40
|
+
"domain" => domain,
|
41
|
+
"group_guid" => group_guid
|
42
|
+
})
|
43
|
+
new(data: response.body, client: client, response: response)
|
44
|
+
end
|
45
|
+
|
46
|
+
##
|
47
|
+
# Creates a new Bitlink from a long URL. Similar to #shorten but takes
|
48
|
+
# more parameters.
|
49
|
+
# [`POST /v4/bitlinks`](https://dev.bitly.com/v4/#operation/createFullBitlink)
|
50
|
+
#
|
51
|
+
# @example
|
52
|
+
# bitlink = Bitly::API::Bitlink.create(client: client, long_url: long_url)
|
53
|
+
#
|
54
|
+
# @param client [Bitly::API::Client] An authorized API client
|
55
|
+
# @param long_url [String] A long URL that you want shortened
|
56
|
+
# @param domain [String] The bitly domain you want to shorten, API default
|
57
|
+
# is "bit.ly"
|
58
|
+
# @param group_guid [String] The GUID of the group for which you want to
|
59
|
+
# shorten this URL
|
60
|
+
# @param title [String] A descriptive title for the link
|
61
|
+
# @param tags [Array<String>] Some tags for the Bitlink
|
62
|
+
# @param deeplinks [Array<Bitly::API::Bitlink::Deeplink>]
|
63
|
+
#
|
64
|
+
# @return [Bitly::API::Bitlink]
|
65
|
+
def self.create(client:, long_url:, domain: nil, group_guid: nil, title: nil, tags: nil, deeplinks: nil)
|
66
|
+
response = client.request(
|
67
|
+
path: "/bitlinks",
|
68
|
+
method: "POST",
|
69
|
+
params: {
|
70
|
+
"long_url" => long_url,
|
71
|
+
"domain" => domain,
|
72
|
+
"group_guid" => group_guid,
|
73
|
+
"title" => title,
|
74
|
+
"tags" => tags,
|
75
|
+
"deeplinks" => deeplinks
|
76
|
+
}
|
77
|
+
)
|
78
|
+
new(data: response.body, client: client, response: response)
|
79
|
+
end
|
80
|
+
|
81
|
+
##
|
82
|
+
# Return information about a bitlink
|
83
|
+
# [`GET /v4/bitlink/{bitlink}`](https://dev.bitly.com/v4/#operation/getBitlink)
|
84
|
+
#
|
85
|
+
# @example
|
86
|
+
# bitlink = Bitly::API::Bitlink.fetch(client: client, bitlink: "bit.ly/example")
|
87
|
+
#
|
88
|
+
# @param client [Bitly::API::Client] An authorized API client
|
89
|
+
# @param bitlink [String] The bitlink you want information about
|
90
|
+
#
|
91
|
+
# @return [Bitly::API::Bitlink]
|
92
|
+
def self.fetch(client:, bitlink:)
|
93
|
+
response = client.request(path: "/bitlinks/#{bitlink}")
|
94
|
+
new(data: response.body, client: client, response: response)
|
95
|
+
end
|
96
|
+
|
97
|
+
##
|
98
|
+
# Return public information about a bitlink
|
99
|
+
# [`POST /v4/expand`](https://dev.bitly.com/v4/#operation/expandBitlink)
|
100
|
+
#
|
101
|
+
# @example
|
102
|
+
# bitlink = Bitly::API::Bitlink.expand(client: client, bitlink: "bit.ly/example")
|
103
|
+
#
|
104
|
+
# @param client [Bitly::API::Client] An authorized API client
|
105
|
+
# @param bitlink [String] The bitlink you want information about
|
106
|
+
#
|
107
|
+
# @return [Bitly::API::Bitlink]
|
108
|
+
def self.expand(client:, bitlink:)
|
109
|
+
response = client.request(path: "/expand", method: "POST", params: { "bitlink_id" => bitlink })
|
110
|
+
new(data: response.body, client: client, response: response)
|
111
|
+
end
|
112
|
+
|
113
|
+
##
|
114
|
+
# Retrieve a list of bitlinks by group
|
115
|
+
# [`GET /v4/groups/{group_guid}/bitlinks`](https://dev.bitly.com/v4/#operation/getBitlinksByGroup)
|
116
|
+
#
|
117
|
+
# @example
|
118
|
+
# bitlinks = Bitly::API::Bitlink.list(client: client, group_guid: guid)
|
119
|
+
#
|
120
|
+
# @param client [Bitly::API::Client] An authorized API client
|
121
|
+
# @param group_guid [String] The group guid for which you want bitlinks
|
122
|
+
# @param size [Integer] The number of Bitlinks to return, max 100
|
123
|
+
# @param page [Integer] The page of bitlinks to request
|
124
|
+
# @param keyword [String] Custom keyword to filter on history entries
|
125
|
+
# @param query [String] A value to search for Bitlinks
|
126
|
+
# @param created_before [Integer] Timestamp as an integer unix epoch
|
127
|
+
# @param created_after [Integer] Timestamp as an integer unix epoch
|
128
|
+
# @param modified_after [Integer] Timestamp as an integer unix epoch
|
129
|
+
# @param archived [String] Whether or not to include archived Bitlinks.
|
130
|
+
# One of "on", "off" or "both". Defaults to "off".
|
131
|
+
# @param deeplinks [String] Filter to only Bitlinks that contain
|
132
|
+
# deeplinks. One of "on", "off" or "both". Defaults to "both".
|
133
|
+
# @param domain_deeplinks [String] Filter to only Bitlinks that contain
|
134
|
+
# deeplinks configured with a custom domain. One of "on", "off" or
|
135
|
+
# "both". Defaults to "both".
|
136
|
+
# @param campaign_guid [String] Filter to return only links for the given
|
137
|
+
# campaign GUID, can be provided
|
138
|
+
# @param channel_guid [String] Filter to return only links for the given
|
139
|
+
# channel GUID, can be provided, overrides all other parameters
|
140
|
+
# @param custom_bitlink [String] Filter to return only custom Bitlinks.
|
141
|
+
# One of "on", "off" or "both". Defaults to "both".
|
142
|
+
# @param tags [Array<String>] Filter by the given tags.
|
143
|
+
# @param encoding_login [Array<String>] Filter by the login of the
|
144
|
+
# authenticated user that created the Bitlink.
|
145
|
+
#
|
146
|
+
# @return [Bitly::API::Bitlink::PaginatedList]
|
147
|
+
def self.list(
|
148
|
+
client:,
|
149
|
+
group_guid:,
|
150
|
+
size: nil,
|
151
|
+
page: nil,
|
152
|
+
keyword: nil,
|
153
|
+
query: nil,
|
154
|
+
created_before: nil,
|
155
|
+
created_after: nil,
|
156
|
+
modified_after: nil,
|
157
|
+
archived: nil,
|
158
|
+
deeplinks: nil,
|
159
|
+
domain_deeplinks: nil,
|
160
|
+
campaign_guid: nil,
|
161
|
+
channel_guid: nil,
|
162
|
+
custom_bitlink: nil,
|
163
|
+
tags: nil,
|
164
|
+
encoding_login: nil
|
165
|
+
)
|
166
|
+
params = {
|
167
|
+
"size" => size,
|
168
|
+
"page" => page,
|
169
|
+
"keyword" => keyword,
|
170
|
+
"query" => query,
|
171
|
+
"created_before" => created_before,
|
172
|
+
"created_after" => created_after,
|
173
|
+
"modified_after" => modified_after,
|
174
|
+
"archived" => archived,
|
175
|
+
"deeplinks" => deeplinks,
|
176
|
+
"domain_deeplinks" => domain_deeplinks,
|
177
|
+
"campaign_guid" => campaign_guid,
|
178
|
+
"channel_guid" => channel_guid,
|
179
|
+
"custom_bitlink" => custom_bitlink,
|
180
|
+
"tags" => tags,
|
181
|
+
"encoding_login" => encoding_login
|
182
|
+
}
|
183
|
+
response = client.request(path: "/groups/#{group_guid}/bitlinks", params: params)
|
184
|
+
bitlinks = response.body["links"].map do |link|
|
185
|
+
new(data: link, client: client)
|
186
|
+
end
|
187
|
+
PaginatedList.new(items: bitlinks, response: response, client: client)
|
188
|
+
end
|
189
|
+
|
190
|
+
##
|
191
|
+
# Returns a list of Bitlinks sorted by clicks.
|
192
|
+
# [`GET /v4/groups/{group_guid}/bitlinks/{sort}`](https://dev.bitly.com/v4/#operation/getSortedBitlinks)
|
193
|
+
#
|
194
|
+
# The API returns a separate list of the links and the click counts, but
|
195
|
+
# this method assigns the number of clicks for each link to the Bitlink
|
196
|
+
# object and sorts the resulting list in descending order.
|
197
|
+
#
|
198
|
+
# Sorted lists are not paginated, so do not have any pagination detail.
|
199
|
+
#
|
200
|
+
# @example
|
201
|
+
# links = Bitly::API::Bitlink.sorted_list(client: client, group_guid: guid)
|
202
|
+
#
|
203
|
+
# @param client [Bitly::API::Client] An authorized API client
|
204
|
+
# @param group_guid [String] The group for which you want to return links
|
205
|
+
# @param sort [String] The data to sort on. Default and only option is
|
206
|
+
# "clicks".
|
207
|
+
# @param unit [String] A unit of time. Default is "day" and can be
|
208
|
+
# "minute", "hour", "day", "week" or "month"
|
209
|
+
# @param units [Integer] An integer representing the time units to query
|
210
|
+
# data for. pass -1 to return all units of time. Defaults to -1.
|
211
|
+
# @param unit_reference [String] An ISO-8601 timestamp, indicating the
|
212
|
+
# most recent time for which to pull metrics. Will default to current
|
213
|
+
# time.
|
214
|
+
# @param size [Integer] The number of links to be returned. Defaults to 50
|
215
|
+
#
|
216
|
+
# @returns [Bitly::API::Bitlink::List]
|
217
|
+
def self.sorted_list(client:, group_guid:, sort: "clicks", unit: nil, units: nil, unit_reference: nil, size: nil)
|
218
|
+
params = {
|
219
|
+
"unit" => unit,
|
220
|
+
"units" => units,
|
221
|
+
"unit_reference" => unit_reference,
|
222
|
+
"size" => size
|
223
|
+
}
|
224
|
+
response = client.request(path: "/groups/#{group_guid}/bitlinks/#{sort}", params: params)
|
225
|
+
link_clicks = response.body["sorted_links"]
|
226
|
+
bitlinks = response.body["links"].map do |link|
|
227
|
+
clicks = link_clicks.find { |c| c["id"] == link["id"] }["clicks"]
|
228
|
+
new(data: link, client: client, clicks: clicks)
|
229
|
+
end.sort { |a, b| b.clicks <=> a.clicks }
|
230
|
+
List.new(items: bitlinks, response: response)
|
231
|
+
end
|
232
|
+
|
233
|
+
def self.attributes
|
234
|
+
[:archived, :tags, :title, :created_by, :long_url, :client_id, :custom_bitlinks, :link, :id]
|
235
|
+
end
|
236
|
+
def self.time_attributes
|
237
|
+
[:created_at]
|
238
|
+
end
|
239
|
+
attr_reader(*(attributes + time_attributes))
|
240
|
+
attr_reader :deeplinks, :clicks
|
241
|
+
|
242
|
+
def initialize(data:, client:, response: nil, clicks: nil)
|
243
|
+
assign_attributes(data)
|
244
|
+
if data["deeplinks"]
|
245
|
+
@deeplinks = data["deeplinks"].map { |data| Deeplink.new(data: data) }
|
246
|
+
else
|
247
|
+
@deeplinks = []
|
248
|
+
end
|
249
|
+
@clicks = clicks
|
250
|
+
@client = client
|
251
|
+
@response = response
|
252
|
+
end
|
253
|
+
|
254
|
+
##
|
255
|
+
# Update the Bitlink.
|
256
|
+
# [`PATCH /v4/bitlink/{bitlink}`](https://dev.bitly.com/v4/#operation/updateBitlink)
|
257
|
+
#
|
258
|
+
# The parameters listed below are from the documentation. Some only work
|
259
|
+
# if you have a Bitly Pro account.
|
260
|
+
#
|
261
|
+
# @example
|
262
|
+
# bitlink.update(title: "New title")
|
263
|
+
#
|
264
|
+
# @param archived [Boolean]
|
265
|
+
# @param tags [Array<String>]
|
266
|
+
# @param created_at [String]
|
267
|
+
# @param title [String]
|
268
|
+
# @param deeplinks [Array<Bitly::API::Bitlink::Deeplink>]
|
269
|
+
# @param created_by [String]
|
270
|
+
# @param long_url [String]
|
271
|
+
# @param client_id [String]
|
272
|
+
# @param custom_bitlinks [Array<String>]
|
273
|
+
# @param link [String]
|
274
|
+
# @param id [String]
|
275
|
+
# @param references [Hash<String, String>]
|
276
|
+
#
|
277
|
+
# @returns [Bitly::API::Bitlink]
|
278
|
+
def update(
|
279
|
+
archived: nil,
|
280
|
+
tags: nil,
|
281
|
+
created_at: nil,
|
282
|
+
title: nil,
|
283
|
+
deeplinks: nil,
|
284
|
+
created_by: nil,
|
285
|
+
long_url: nil,
|
286
|
+
client_id: nil,
|
287
|
+
custom_bitlinks: nil,
|
288
|
+
link: nil,
|
289
|
+
id: nil,
|
290
|
+
references: nil
|
291
|
+
)
|
292
|
+
@response = @client.request(
|
293
|
+
path: "/bitlinks/#{@id}",
|
294
|
+
method: "PATCH",
|
295
|
+
params: {
|
296
|
+
"archived" => archived,
|
297
|
+
"tags" => tags,
|
298
|
+
"created_at" => created_at,
|
299
|
+
"title" => title,
|
300
|
+
"deeplinks" => deeplinks,
|
301
|
+
"created_by" => created_by,
|
302
|
+
"long_url" =>long_url ,
|
303
|
+
"client_id" => client_id,
|
304
|
+
"custom_bitlinks" => custom_bitlinks,
|
305
|
+
"link" => link,
|
306
|
+
"id" => id,
|
307
|
+
"references" => references
|
308
|
+
}
|
309
|
+
)
|
310
|
+
assign_attributes(@response.body)
|
311
|
+
self
|
312
|
+
end
|
313
|
+
|
314
|
+
# [`GET /v4/bitlink/{bitlink}/clicks/summary`](https://dev.bitly.com/v4/#operation/getClicksSummaryForBitlink)
|
315
|
+
#
|
316
|
+
# @return [Bitly::API::Bitlink::ClicksSummary]
|
317
|
+
def clicks_summary(unit: nil, units: nil, unit_reference: nil, size: nil)
|
318
|
+
ClicksSummary.fetch(client: @client, bitlink: id, unit: unit, units: units, unit_reference: unit_reference, size: size)
|
319
|
+
end
|
320
|
+
|
321
|
+
##
|
322
|
+
# Get the clicks for the bitlink.
|
323
|
+
# [`GET /v4/bitlink/{bitlink}/clicks`](https://dev.bitly.com/v4/#operation/getClicksForBitlink)
|
324
|
+
#
|
325
|
+
# @param sort [String] The data to sort on. Default and only option is
|
326
|
+
# "clicks".
|
327
|
+
# @param unit [String] A unit of time. Default is "day" and can be
|
328
|
+
# "minute", "hour", "day", "week" or "month"
|
329
|
+
# @param units [Integer] An integer representing the time units to query
|
330
|
+
# data for. pass -1 to return all units of time. Defaults to -1.
|
331
|
+
# @param unit_reference [String] An ISO-8601 timestamp, indicating the
|
332
|
+
# most recent time for which to pull metrics. Will default to current
|
333
|
+
# time.
|
334
|
+
# @param size [Integer] The number of links to be returned. Defaults to 50
|
335
|
+
#
|
336
|
+
# @return [Bitly::API::Bitlink::LinkClick::List]
|
337
|
+
def link_clicks(unit: nil, units: nil, unit_reference: nil, size: nil)
|
338
|
+
LinkClick.list(client: @client, bitlink: id, unit: unit, units: units, unit_reference: unit_reference, size: size)
|
339
|
+
end
|
340
|
+
end
|
341
|
+
end
|
342
|
+
end
|