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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eeae1a268f6b5060f6df86afd2af9156137a49c889fda818774b7e9b285a7c4d
4
- data.tar.gz: 102a515ab66654bb4e211b158a10c6273a1ffbdc6fa5de628a57c9ea19e5374f
3
+ metadata.gz: b501e26aa3a32c19f90bb55620f0a7ec11603a861676eefa40d6f412448085d2
4
+ data.tar.gz: a72bb745a6f65bca47290fee7d783ae24ed44de296dce5492da3e5e6e734fbe9
5
5
  SHA512:
6
- metadata.gz: b19f0eb932a6f64fba5f528b4d04380ac103397223cd2618e571baa4c83eec5f982bf74692b6535da7c8092b745f7b55e06e9fc15dd9ef68989d2be2fc1aa324
7
- data.tar.gz: b6e1734c29a6256a262e322658900c6743352b6a0397ea5427de5fba2fa71a0796e9ad1d4e963a3a22e52a3fa5faf4180674c9ed6830f9513e84498d2551bf30
6
+ metadata.gz: 357d0b28e2f88b5e035865bd748bbc832cb3a34bb609e74c346e2f862164a56a6bf4d5a0860ece3c49a12746b9833657852f35376a378a0cba83232ed11a5f77
7
+ data.tar.gz: 97ba7f73234f850b3e219233121b33f3b3a14804b0732fc177884fe622628558b79fce2e96a63cf2881c063d17e7ffb564624ce5218fbc03a91c7088ec62e3d4
data/.gitignore CHANGED
@@ -6,3 +6,5 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ .env
10
+ .envrc
data/.travis.yml CHANGED
@@ -1,6 +1,8 @@
1
- ---
2
1
  language: ruby
3
2
  cache: bundler
4
3
  rvm:
5
- - 2.7.1
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.6 (2021-01-25)
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 (2021-01-25)
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 (2021-01-25)
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 (2021-01-25)
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 (2021-01-25)
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 (2021-01-25)
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 (2021-01-25)
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
@@ -5,3 +5,9 @@ gemspec
5
5
 
6
6
  gem "rake", "~> 12.0"
7
7
  gem "minitest", "~> 5.0"
8
+
9
+ group :test do
10
+ gem 'simplecov', require: false
11
+ gem 'codecov', require: false
12
+ gem 'webmock'
13
+ end
data/Gemfile.lock CHANGED
@@ -1,21 +1,44 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- short_io (0.1.6)
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
- # ShortIoShortBrandedUrl
1
+ # ShortIo
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/short_io`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ [![Gem Version](https://badge.fury.io/rb/short_io.svg)](https://badge.fury.io/rb/short_io) | [![Build Status](https://app.travis-ci.com/yosefbennywidyo/short_io.svg?branch=main)](https://app.travis-ci.com/yosefbennywidyo/short_io) | [![codecov](https://codecov.io/gh/yosefbennywidyo/short_io/branch/main/graph/badge.svg?token=MBMxFB57mZ)](https://codecov.io/gh/yosefbennywidyo/short_io)
4
4
 
5
- [Short IO documentation](https://developers.short.io/docs/deleting-a-domain)
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
 
@@ -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 = 'application/json'
9
- SHORT_IO_BASE_URL = 'https://api.short.io/domains/'
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 = 'example.com', api_key = 'API_KEY', options={})
12
- @host_name = host_name
13
- @api_key = api_key
14
- @hide_referer = options.key?(:hide_referer) ? options[:hide_referer] : false
15
- @https_link = options.key?(:https_link) ? options[:https_link] : false
16
- @link_type = options.key?(:link_type) ? options[:link_type] : 'random'
17
- @short_io_base_url = 'https://api.short.io/domains/'
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
- def setup
21
- @url = URI(SHORT_IO_BASE_URL)
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
- {"hideReferer":"#{@hide_referer}",
36
- "httpsLinks":"#{@https_link}",
37
- "hostname":"#{@host_name}",
38
- "linkType":"#{@link_type}"}
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)
@@ -1,3 +1,3 @@
1
1
  module ShortIo
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.10"
3
3
  end
data/lib/short_io.rb CHANGED
@@ -3,5 +3,7 @@ require "short_io/short_url"
3
3
 
4
4
  module ShortIo
5
5
  class Error < StandardError; end
6
+ class HostNameError < Error; end
7
+ class ApiKeyError < Error; end
6
8
  # Your code goes here...
7
9
  end
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.6
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-01-25 00:00:00.000000000 Z
11
+ date: 2022-02-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: