short_io 0.1.6 → 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.travis.yml +4 -2
- data/CHANGELOG.md +38 -7
- data/Gemfile +6 -0
- data/Gemfile.lock +24 -1
- data/README.md +5 -3
- data/lib/short_io/short_url.rb +160 -17
- data/lib/short_io/version.rb +1 -1
- data/lib/short_io.rb +2 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b501e26aa3a32c19f90bb55620f0a7ec11603a861676eefa40d6f412448085d2
|
|
4
|
+
data.tar.gz: a72bb745a6f65bca47290fee7d783ae24ed44de296dce5492da3e5e6e734fbe9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 357d0b28e2f88b5e035865bd748bbc832cb3a34bb609e74c346e2f862164a56a6bf4d5a0860ece3c49a12746b9833657852f35376a378a0cba83232ed11a5f77
|
|
7
|
+
data.tar.gz: 97ba7f73234f850b3e219233121b33f3b3a14804b0732fc177884fe622628558b79fce2e96a63cf2881c063d17e7ffb564624ce5218fbc03a91c7088ec62e3d4
|
data/.travis.yml
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
---
|
|
2
1
|
language: ruby
|
|
3
2
|
cache: bundler
|
|
4
3
|
rvm:
|
|
5
|
-
|
|
4
|
+
- 2.7.1
|
|
6
5
|
before_install: gem install bundler -v 2.1.4
|
|
6
|
+
env:
|
|
7
|
+
global:
|
|
8
|
+
secure: N+Yyasma8STO5NFjdcmCrn44Zf7x8SbNs6y4bv/FkB5PwcjHYG2sVU/aRB9u8V5F1TuPC7ZPHu74Q9oXgPq2GBnspCNcdvZKzFKLS7euMF+YOeXYSEl7slVvPSq9muuu5lu0cNJbflbTmSElHMXpshamSJxbr9joSvLZMDnJseHXJ+qPKEByB7YQEAFSThbStlgU3oZbRudbM65UBlwxAZ3PZnQ9voYkqPbPkH41SPhtwhLdIOVNR5EK84yypP8rOCCABsxXtfY7vM/ZQpyt/+Ty4cGHDjhiuxypwRFePr2vOqL/w9C2lRNsTRIDrt/krAh0XojIqeObn8d9ZXj+/59OGtAX5YGYKzfMg5Elar24dxUtgKoduD1MLbMBFhB6C8Ch7ULAGvtBDYFYE+0SaMguMr4ZdbxfsNDXIVHYsezLT27ZhSya8/ZOuHcWnveVTl7gktYaY8gdasyNm/uAP99m7/fFgyPYrSaxzLJXAx4EMFxHQtkNTpowETRYE9GFB77NI2QB4cH/5KeOjsvykm8ipmY5Uyfofqm5DV+vHW3zradgzeDogjgoByFlmtCmBpcnAlbmwygxZP303DlVy1pDjizbvITB5beb3HlHzvGbxFjgwvKvnDibjmsrY9NDz5Qzo7hOaJegenUrdgA8wZwV6JOD2Paz6UqKzi1x+2U=
|
data/CHANGELOG.md
CHANGED
|
@@ -1,39 +1,70 @@
|
|
|
1
|
-
0.1.
|
|
1
|
+
0.1.10 (2022-02-10)
|
|
2
|
+
------------------
|
|
3
|
+
|
|
4
|
+
* add delete and update method
|
|
5
|
+
* initialize using four (4) parameters
|
|
6
|
+
* setup method using two (2) default parameters
|
|
7
|
+
* add documentation for domain_list, update, and delete
|
|
8
|
+
* update version to [0.1.10](https://rubygems.org/gems/short_io/versions/0.1.10)
|
|
9
|
+
|
|
10
|
+
0.1.9 (2022-02-03)
|
|
11
|
+
------------------
|
|
12
|
+
|
|
13
|
+
* add documentation
|
|
14
|
+
* update version to [0.1.9](https://rubygems.org/gems/short_io/versions/0.1.9)
|
|
15
|
+
|
|
16
|
+
0.1.8 (2022-02-03)
|
|
17
|
+
------------------
|
|
18
|
+
|
|
19
|
+
* add webmock gem
|
|
20
|
+
* add test for add_domain and domain list methods
|
|
21
|
+
* add `:host_name`, `:api_key`, and `:options` attr_reader
|
|
22
|
+
* update version to [0.1.8](https://rubygems.org/gems/short_io/versions/0.1.8)
|
|
23
|
+
|
|
24
|
+
0.1.7 (2022-01-25)
|
|
25
|
+
------------------
|
|
26
|
+
|
|
27
|
+
* add test
|
|
28
|
+
* add memoization
|
|
29
|
+
* add check_variables method to raise error when `nil` or `empty` on host name or api_key
|
|
30
|
+
* update version to [0.1.7](https://rubygems.org/gems/short_io/versions/0.1.7)
|
|
31
|
+
|
|
32
|
+
0.1.6 (2022-01-25)
|
|
2
33
|
------------------
|
|
3
34
|
|
|
4
35
|
* fix version on CHANGELOG.md
|
|
5
36
|
* update version to [0.1.6](https://rubygems.org/gems/short_io/versions/0.1.6)
|
|
6
37
|
|
|
7
|
-
0.1.5 (
|
|
38
|
+
0.1.5 (2022-01-25)
|
|
8
39
|
------------------
|
|
9
40
|
|
|
10
41
|
* fix CHANGELOG.md path
|
|
11
42
|
* update version to [0.1.5](https://rubygems.org/gems/short_io/versions/0.1.5)
|
|
12
43
|
|
|
13
|
-
0.1.4 (
|
|
44
|
+
0.1.4 (2022-01-25)
|
|
14
45
|
------------------
|
|
15
46
|
|
|
16
47
|
* add CHANGELOG.md
|
|
17
48
|
* update version to [0.1.4](https://rubygems.org/gems/short_io/versions/0.1.4)
|
|
18
49
|
|
|
19
|
-
0.1.3 (
|
|
50
|
+
0.1.3 (2022-01-25)
|
|
20
51
|
------------------
|
|
21
52
|
|
|
22
53
|
* add Gemfile.lock
|
|
23
54
|
* update version to [0.1.3](https://rubygems.org/gems/short_io/versions/0.1.3)
|
|
24
55
|
|
|
25
|
-
0.1.2 (
|
|
56
|
+
0.1.2 (2022-01-25)
|
|
26
57
|
------------------
|
|
27
58
|
|
|
28
59
|
* fix sample usage on README.md
|
|
29
60
|
* update version to [0.1.2](https://rubygems.org/gems/short_io/versions/0.1.2)
|
|
30
61
|
|
|
31
|
-
0.1.1 (
|
|
62
|
+
0.1.1 (2022-01-25)
|
|
32
63
|
------------------
|
|
33
64
|
|
|
34
65
|
* update version to [0.1.1](https://rubygems.org/gems/short_io/versions/0.1.1) (no changes)
|
|
35
66
|
|
|
36
|
-
0.1.0 (
|
|
67
|
+
0.1.0 (2022-01-25)
|
|
37
68
|
------------------
|
|
38
69
|
|
|
39
70
|
* [YANKED](https://rubygems.org/gems/short_io/versions/0.1.0) Start create `short_io` gem
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,21 +1,44 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
short_io (0.1.
|
|
4
|
+
short_io (0.1.10)
|
|
5
5
|
|
|
6
6
|
GEM
|
|
7
7
|
remote: https://rubygems.org/
|
|
8
8
|
specs:
|
|
9
|
+
addressable (2.8.0)
|
|
10
|
+
public_suffix (>= 2.0.2, < 5.0)
|
|
11
|
+
codecov (0.6.0)
|
|
12
|
+
simplecov (>= 0.15, < 0.22)
|
|
13
|
+
crack (0.4.5)
|
|
14
|
+
rexml
|
|
15
|
+
docile (1.4.0)
|
|
16
|
+
hashdiff (1.0.1)
|
|
17
|
+
json (2.6.1)
|
|
9
18
|
minitest (5.15.0)
|
|
19
|
+
public_suffix (4.0.6)
|
|
10
20
|
rake (12.3.3)
|
|
21
|
+
rexml (3.2.5)
|
|
22
|
+
simplecov (0.16.1)
|
|
23
|
+
docile (~> 1.1)
|
|
24
|
+
json (>= 1.8, < 3)
|
|
25
|
+
simplecov-html (~> 0.10.0)
|
|
26
|
+
simplecov-html (0.10.2)
|
|
27
|
+
webmock (3.14.0)
|
|
28
|
+
addressable (>= 2.8.0)
|
|
29
|
+
crack (>= 0.3.2)
|
|
30
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
|
11
31
|
|
|
12
32
|
PLATFORMS
|
|
13
33
|
ruby
|
|
14
34
|
|
|
15
35
|
DEPENDENCIES
|
|
36
|
+
codecov
|
|
16
37
|
minitest (~> 5.0)
|
|
17
38
|
rake (~> 12.0)
|
|
18
39
|
short_io!
|
|
40
|
+
simplecov
|
|
41
|
+
webmock
|
|
19
42
|
|
|
20
43
|
BUNDLED WITH
|
|
21
44
|
2.1.4
|
data/README.md
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
#
|
|
1
|
+
# ShortIo
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://badge.fury.io/rb/short_io) | [](https://app.travis-ci.com/yosefbennywidyo/short_io) | [](https://codecov.io/gh/yosefbennywidyo/short_io)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
A Ruby gem to use with [short.io](https://short.io)
|
|
6
|
+
|
|
7
|
+
[ShortIo gem documentation](https://rubydoc.info/gems/short_io)
|
|
6
8
|
|
|
7
9
|
## Installation
|
|
8
10
|
|
data/lib/short_io/short_url.rb
CHANGED
|
@@ -3,27 +3,82 @@ require 'net/http'
|
|
|
3
3
|
require 'openssl'
|
|
4
4
|
require 'json'
|
|
5
5
|
|
|
6
|
+
# @author Yosef Benny Widyokarsono
|
|
6
7
|
module ShortIo
|
|
8
|
+
# Add domain and list domains registerd to Short.io
|
|
7
9
|
class ShortUrl
|
|
8
|
-
REQUEST_TYPE
|
|
9
|
-
SHORT_IO_BASE_URL
|
|
10
|
+
REQUEST_TYPE = 'application/json'
|
|
11
|
+
SHORT_IO_BASE_URL = 'https://api.short.io/domains/'
|
|
12
|
+
SHORT_IO_API_BASE_URL = 'https://api.short.io/api/domains'
|
|
13
|
+
|
|
14
|
+
attr_reader :host_name, :api_key, :options
|
|
10
15
|
|
|
11
|
-
def initialize(host_name
|
|
12
|
-
@host_name
|
|
13
|
-
@api_key
|
|
14
|
-
@
|
|
15
|
-
@
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
def initialize(host_name, api_key, short_io_base_url=SHORT_IO_BASE_URL, options={})
|
|
17
|
+
@host_name ||= host_name
|
|
18
|
+
@api_key ||= api_key
|
|
19
|
+
@short_io_base_url ||= short_io_base_url
|
|
20
|
+
@options ||= options
|
|
21
|
+
unless options.key?(:domain_id)
|
|
22
|
+
options_default_value
|
|
23
|
+
check_variables
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Options Default Value
|
|
28
|
+
#
|
|
29
|
+
# @return [Hash] return default options in Hash if no value provided.
|
|
30
|
+
|
|
31
|
+
def options_default_value
|
|
32
|
+
@options = {
|
|
33
|
+
hide_referer: options.key?(:hide_referer) ? options[:hide_referer] : false,
|
|
34
|
+
https_link: options.key?(:https_link) ? options[:https_link] : false,
|
|
35
|
+
link_type: options.key?(:link_type) ? options[:link_type] : 'random'
|
|
36
|
+
}
|
|
18
37
|
end
|
|
19
38
|
|
|
20
|
-
|
|
21
|
-
|
|
39
|
+
# Check Variables
|
|
40
|
+
#
|
|
41
|
+
# @raise [HostNameError] if no Host Name provided.
|
|
42
|
+
# @raise [ApiKeyError] if no API Key provided.
|
|
43
|
+
|
|
44
|
+
def check_variables
|
|
45
|
+
raise ShortIo::HostNameError.new(host_name: 'Please provide a host name') if (@host_name.nil? || @host_name.empty?)
|
|
46
|
+
raise ShortIo::ApiKeyError.new(api_key: 'Please provide an API key') if (@api_key.nil? || @api_key.empty?)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Prepare request
|
|
50
|
+
|
|
51
|
+
def setup(action=nil, base_url=SHORT_IO_BASE_URL)
|
|
52
|
+
@url = action.nil? ? URI(base_url) : URI(base_url + action)
|
|
22
53
|
@http = Net::HTTP.new(@url.host, @url.port)
|
|
23
54
|
@http.use_ssl = true
|
|
24
55
|
@http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
25
56
|
end
|
|
26
57
|
|
|
58
|
+
# Add new domain
|
|
59
|
+
#
|
|
60
|
+
# @return [JSON] return in JSON format.
|
|
61
|
+
#
|
|
62
|
+
# @example
|
|
63
|
+
# ShortIo::ShortUrl.new('example.com', 'YOUR_API_KEY').add_domain
|
|
64
|
+
# {
|
|
65
|
+
# linkType: 'random',
|
|
66
|
+
# state: 'configured',
|
|
67
|
+
# cloaking: false,
|
|
68
|
+
# setupType: 'dns',
|
|
69
|
+
# httpsLinks: false,
|
|
70
|
+
# id: 91576,
|
|
71
|
+
# hostname: 'yourdomain.com',
|
|
72
|
+
# UserId: 9346,
|
|
73
|
+
# updatedAt: '2022-02-03T10:22:47.010Z',
|
|
74
|
+
# createdAt: '2022-02-03T10:22:46.649Z',
|
|
75
|
+
# provider: null,
|
|
76
|
+
# unicodeHostname: 'urdomain.com',
|
|
77
|
+
# clientStorage: null
|
|
78
|
+
# }
|
|
79
|
+
#
|
|
80
|
+
# @see https://developers.short.io/docs/adding-a-domain
|
|
81
|
+
|
|
27
82
|
def add_domain
|
|
28
83
|
setup
|
|
29
84
|
|
|
@@ -32,20 +87,108 @@ module ShortIo
|
|
|
32
87
|
request["content-type"] = REQUEST_TYPE
|
|
33
88
|
request["authorization"] = @api_key
|
|
34
89
|
request.body = JSON.generate(
|
|
35
|
-
{
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
90
|
+
{
|
|
91
|
+
"hideReferer":"#{@options[:hide_referer]}",
|
|
92
|
+
"httpsLinks":"#{@options[:https_link]}",
|
|
93
|
+
"hostname":"#{@host_name}",
|
|
94
|
+
"linkType":"#{@options[:link_type]}"
|
|
95
|
+
}
|
|
39
96
|
)
|
|
40
97
|
response = @http.request(request)
|
|
41
98
|
return response.read_body
|
|
42
99
|
end
|
|
43
100
|
|
|
101
|
+
# Delete a domain
|
|
102
|
+
#
|
|
103
|
+
# @return [JSON] return in JSON format.
|
|
104
|
+
#
|
|
105
|
+
# @example
|
|
106
|
+
# ShortIo::ShortUrl.new('example.com', 'YOUR_API_KEY', {domain_id: YOUR_DOMAIN_ID}).delete_domain
|
|
107
|
+
# response:
|
|
108
|
+
# {
|
|
109
|
+
# success: true
|
|
110
|
+
# }
|
|
111
|
+
#
|
|
112
|
+
# @see https://developers.short.io/docs/deleting-a-domain
|
|
113
|
+
|
|
114
|
+
def delete_domain
|
|
115
|
+
setup("delete/#{@options[:domain_id]}")
|
|
116
|
+
|
|
117
|
+
request = Net::HTTP::Post.new(@url)
|
|
118
|
+
request["authorization"] = @api_key
|
|
119
|
+
|
|
120
|
+
response = @http.request(request)
|
|
121
|
+
return response.read_body
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
# Udpadating a domain
|
|
125
|
+
#
|
|
126
|
+
# @return [JSON] return in JSON format.
|
|
127
|
+
#
|
|
128
|
+
# @example
|
|
129
|
+
# ShortIo::ShortUrl.new('example.com', 'YOUR_API_KEY', {domain_id: YOUR_DOMAIN_ID, root_redirect_url: 'YOUR_LINK'}).update_domain
|
|
130
|
+
# response:
|
|
131
|
+
# {
|
|
132
|
+
# success: true
|
|
133
|
+
# }
|
|
134
|
+
#
|
|
135
|
+
# @see https://developers.short.io/docs/updating-a-domain
|
|
136
|
+
|
|
137
|
+
def update_domain
|
|
138
|
+
setup("settings/#{@options[:domain_id]}")
|
|
139
|
+
|
|
140
|
+
request = Net::HTTP::Post.new(@url)
|
|
141
|
+
request["accept"] = REQUEST_TYPE
|
|
142
|
+
request["content-type"] = REQUEST_TYPE
|
|
143
|
+
request["authorization"] = @api_key
|
|
144
|
+
request.body = JSON.generate({ 'rootRedirect': "#{@options[:root_redirect_url]}" })
|
|
145
|
+
|
|
146
|
+
response = @http.request(request)
|
|
147
|
+
return response.read_body
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
# Domain List
|
|
151
|
+
#
|
|
152
|
+
# @return [JSON] return domain list in JSON format.
|
|
153
|
+
#
|
|
154
|
+
# @example
|
|
155
|
+
# ShortIo::ShortUrl.new('example.com', 'YOUR_API_KEY').domain_list
|
|
156
|
+
# response:
|
|
157
|
+
# {
|
|
158
|
+
# id: 7252,
|
|
159
|
+
# hostname: 'yrbrand.co',
|
|
160
|
+
# title: null,
|
|
161
|
+
# segmentKey: null,
|
|
162
|
+
# linkType: 'increment',
|
|
163
|
+
# state: 'not_configured',
|
|
164
|
+
# provider: 'cloudflare',
|
|
165
|
+
# redirect404: 'https://short.cm',
|
|
166
|
+
# hideReferer: 1,
|
|
167
|
+
# caseSensitive: true,
|
|
168
|
+
# exportEnabled: true,
|
|
169
|
+
# cloaking: false,
|
|
170
|
+
# jsRedir: true,
|
|
171
|
+
# incrementCounter: 'A',
|
|
172
|
+
# setupType: 'js',
|
|
173
|
+
# autodeletePeriod: 1,
|
|
174
|
+
# httpsLinks: true,
|
|
175
|
+
# clientStorage: '{"configurationHidden":false}',
|
|
176
|
+
# integrationGA: null,
|
|
177
|
+
# integrationFB: null,
|
|
178
|
+
# integrationAdroll: null,
|
|
179
|
+
# integrationGTM: null,
|
|
180
|
+
# createdAt: '2017-12-07T08:24:41.000Z',
|
|
181
|
+
# updatedAt: '2019-12-24T13:08:30.000Z',
|
|
182
|
+
# TeamId: 1381,
|
|
183
|
+
# unicodeHostname: 'yrbrand.co'
|
|
184
|
+
# }
|
|
185
|
+
#
|
|
186
|
+
# @see https://developers.short.io/docs/getting-a-list-of-domains
|
|
187
|
+
|
|
44
188
|
def domain_list
|
|
45
|
-
setup
|
|
189
|
+
setup(nil, SHORT_IO_API_BASE_URL)
|
|
46
190
|
request = Net::HTTP::Get.new(@url)
|
|
47
191
|
request["accept"] = REQUEST_TYPE
|
|
48
|
-
request["content-type"] = REQUEST_TYPE
|
|
49
192
|
request["authorization"] = @api_key
|
|
50
193
|
|
|
51
194
|
response = @http.request(request)
|
data/lib/short_io/version.rb
CHANGED
data/lib/short_io.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: short_io
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.10
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Yosef Benny Widyokarsono
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2022-
|
|
11
|
+
date: 2022-02-10 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description:
|
|
14
14
|
email:
|