short_io 0.1.5 → 0.1.9

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: e6346ca31672e979ac234744e9119b29cc07986ce270fcd7178801ac0a35f9fe
4
- data.tar.gz: 9ffbe3bbeea7ec37b12731a93dc14e340bc9d072021dc3802aeeba4aee59934d
3
+ metadata.gz: d35d4b4870871ee21159f3e60963f1ae02af40dccdb9bc0ee518a65593c2b190
4
+ data.tar.gz: f7ed37b624cebc677b3139356007818c1c654972ea0f49b83be553c6fe660736
5
5
  SHA512:
6
- metadata.gz: e1956a2e4f68e837cdaeba4041de51c1bef13487cabc676f55e5545071cf6919bd0737e48b0167e6bbf426e9e43920c3fd857ec585f56c00f7da6e8c9fb8022a
7
- data.tar.gz: 0eb85ba43c57eddfb3776a9a2eae2dc193ffd45e3511c90c2cc46d165b54f89d64a82f07f8a6b7b4a23aee9ef3a3e4dfca053f25b757f9d3f0abf516f35873f6
6
+ metadata.gz: fc8411a577139d9341cbe90b536ce6d042da4c36621f029d2a4c4588a5406ec8c9c1d4f9e87e73dfd426d7ceeff18640f5233a07451625db73219fce3f82bd13
7
+ data.tar.gz: a4bd6d18d129e60ac8f9e50f9244e1c883d1ca411bbbd9217cc4fbbacd8ef4e50ba6def774fb3c9ff9a16a7b929cb9fe5a137e236947b9af9976cf01b2b6ba7b
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,4 +1,32 @@
1
- 0.1.4 (2021-01-25)
1
+ 0.1.9 (2021-02-03)
2
+ ------------------
3
+
4
+ * add documentation
5
+ * update version to [0.1.9](https://rubygems.org/gems/short_io/versions/0.1.9)
6
+
7
+ 0.1.8 (2021-02-03)
8
+ ------------------
9
+
10
+ * add webmock gem
11
+ * add test for add_domain and domain list methods
12
+ * add `:host_name`, `:api_key`, and `:options` attr_reader
13
+ * update version to [0.1.8](https://rubygems.org/gems/short_io/versions/0.1.8)
14
+
15
+ 0.1.7 (2021-01-25)
16
+ ------------------
17
+
18
+ * add test
19
+ * add memoization
20
+ * add check_variables method to raise error when `nil` or `empty` on host name or api_key
21
+ * update version to [0.1.7](https://rubygems.org/gems/short_io/versions/0.1.7)
22
+
23
+ 0.1.6 (2021-01-25)
24
+ ------------------
25
+
26
+ * fix version on CHANGELOG.md
27
+ * update version to [0.1.6](https://rubygems.org/gems/short_io/versions/0.1.6)
28
+
29
+ 0.1.5 (2021-01-25)
2
30
  ------------------
3
31
 
4
32
  * fix CHANGELOG.md path
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.5)
4
+ short_io (0.1.9)
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,6 +1,8 @@
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
+
5
+ A Ruby gem to use with [short.io](https://short.io)
4
6
 
5
7
  [Short IO documentation](https://developers.short.io/docs/deleting-a-domain)
6
8
 
@@ -3,20 +3,48 @@ 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
10
  REQUEST_TYPE = 'application/json'
9
11
  SHORT_IO_BASE_URL = 'https://api.short.io/domains/'
12
+
13
+ attr_reader :host_name, :api_key, :options
10
14
 
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/'
15
+ def initialize(host_name, api_key, options={})
16
+ @host_name ||= host_name
17
+ @api_key ||= api_key
18
+ @short_io_base_url ||= SHORT_IO_BASE_URL
19
+ @options ||= options
20
+ options_default_value
21
+ check_variables
22
+ end
23
+
24
+ # Options Default Value
25
+ #
26
+ # @return [Hash] return default options in Hash if no value provided.
27
+
28
+ def options_default_value
29
+ @options = {
30
+ hide_referer: options.key?(:hide_referer) ? options[:hide_referer] : false,
31
+ https_link: options.key?(:https_link) ? options[:https_link] : false,
32
+ link_type: options.key?(:link_type) ? options[:link_type] : 'random'
33
+ }
34
+ end
35
+
36
+ # Check Variables
37
+ #
38
+ # @raise [HostNameError] if no Host Name provided.
39
+ # @raise [ApiKeyError] if no API Key provided.
40
+
41
+ def check_variables
42
+ raise ShortIo::HostNameError.new(host_name: 'Please provide a host name') if (@host_name.nil? || @host_name.empty?)
43
+ raise ShortIo::ApiKeyError.new(api_key: 'Please provide an API key') if (@api_key.nil? || @api_key.empty?)
18
44
  end
19
45
 
46
+ # Prepare request
47
+
20
48
  def setup
21
49
  @url = URI(SHORT_IO_BASE_URL)
22
50
  @http = Net::HTTP.new(@url.host, @url.port)
@@ -24,6 +52,30 @@ module ShortIo
24
52
  @http.verify_mode = OpenSSL::SSL::VERIFY_NONE
25
53
  end
26
54
 
55
+ # Add new domain
56
+ #
57
+ # @return [JSON] return in JSON format.
58
+ #
59
+ # @example
60
+ # ShortIo::ShortUrl.new('example.com', 'YOUR_API_KEY').add_domain
61
+ # {
62
+ # linkType: 'random',
63
+ # state: 'configured',
64
+ # cloaking: false,
65
+ # setupType: 'dns',
66
+ # httpsLinks: false,
67
+ # id: 91576,
68
+ # hostname: 'yourdomain.com',
69
+ # UserId: 9346,
70
+ # updatedAt: '2022-02-03T10:22:47.010Z',
71
+ # createdAt: '2022-02-03T10:22:46.649Z',
72
+ # provider: null,
73
+ # unicodeHostname: 'urdomain.com',
74
+ # clientStorage: null
75
+ # }
76
+ #
77
+ # @see https://developers.short.io/docs/adding-a-domain
78
+
27
79
  def add_domain
28
80
  setup
29
81
 
@@ -32,15 +84,23 @@ module ShortIo
32
84
  request["content-type"] = REQUEST_TYPE
33
85
  request["authorization"] = @api_key
34
86
  request.body = JSON.generate(
35
- {"hideReferer":"#{@hide_referer}",
36
- "httpsLinks":"#{@https_link}",
37
- "hostname":"#{@host_name}",
38
- "linkType":"#{@link_type}"}
87
+ {
88
+ "hideReferer":"#{@options[:hide_referer]}",
89
+ "httpsLinks":"#{@options[:https_link]}",
90
+ "hostname":"#{@host_name}",
91
+ "linkType":"#{@options[:link_type]}"
92
+ }
39
93
  )
40
94
  response = @http.request(request)
41
95
  return response.read_body
42
96
  end
43
97
 
98
+ # Domain List
99
+ #
100
+ # @return [JSON] return domain list in JSON format.
101
+ #
102
+ # @see https://developers.short.io/docs/getting-a-list-of-domains
103
+
44
104
  def domain_list
45
105
  setup
46
106
  request = Net::HTTP::Get.new(@url)
@@ -1,3 +1,3 @@
1
1
  module ShortIo
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.9"
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.5
4
+ version: 0.1.9
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-02 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: