short_io 0.1.9 → 0.1.10

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: d35d4b4870871ee21159f3e60963f1ae02af40dccdb9bc0ee518a65593c2b190
4
- data.tar.gz: f7ed37b624cebc677b3139356007818c1c654972ea0f49b83be553c6fe660736
3
+ metadata.gz: b501e26aa3a32c19f90bb55620f0a7ec11603a861676eefa40d6f412448085d2
4
+ data.tar.gz: a72bb745a6f65bca47290fee7d783ae24ed44de296dce5492da3e5e6e734fbe9
5
5
  SHA512:
6
- metadata.gz: fc8411a577139d9341cbe90b536ce6d042da4c36621f029d2a4c4588a5406ec8c9c1d4f9e87e73dfd426d7ceeff18640f5233a07451625db73219fce3f82bd13
7
- data.tar.gz: a4bd6d18d129e60ac8f9e50f9244e1c883d1ca411bbbd9217cc4fbbacd8ef4e50ba6def774fb3c9ff9a16a7b929cb9fe5a137e236947b9af9976cf01b2b6ba7b
6
+ metadata.gz: 357d0b28e2f88b5e035865bd748bbc832cb3a34bb609e74c346e2f862164a56a6bf4d5a0860ece3c49a12746b9833657852f35376a378a0cba83232ed11a5f77
7
+ data.tar.gz: 97ba7f73234f850b3e219233121b33f3b3a14804b0732fc177884fe622628558b79fce2e96a63cf2881c063d17e7ffb564624ce5218fbc03a91c7088ec62e3d4
data/CHANGELOG.md CHANGED
@@ -1,10 +1,19 @@
1
- 0.1.9 (2021-02-03)
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)
2
11
  ------------------
3
12
 
4
13
  * add documentation
5
14
  * update version to [0.1.9](https://rubygems.org/gems/short_io/versions/0.1.9)
6
15
 
7
- 0.1.8 (2021-02-03)
16
+ 0.1.8 (2022-02-03)
8
17
  ------------------
9
18
 
10
19
  * add webmock gem
@@ -12,7 +21,7 @@
12
21
  * add `:host_name`, `:api_key`, and `:options` attr_reader
13
22
  * update version to [0.1.8](https://rubygems.org/gems/short_io/versions/0.1.8)
14
23
 
15
- 0.1.7 (2021-01-25)
24
+ 0.1.7 (2022-01-25)
16
25
  ------------------
17
26
 
18
27
  * add test
@@ -20,42 +29,42 @@
20
29
  * add check_variables method to raise error when `nil` or `empty` on host name or api_key
21
30
  * update version to [0.1.7](https://rubygems.org/gems/short_io/versions/0.1.7)
22
31
 
23
- 0.1.6 (2021-01-25)
32
+ 0.1.6 (2022-01-25)
24
33
  ------------------
25
34
 
26
35
  * fix version on CHANGELOG.md
27
36
  * update version to [0.1.6](https://rubygems.org/gems/short_io/versions/0.1.6)
28
37
 
29
- 0.1.5 (2021-01-25)
38
+ 0.1.5 (2022-01-25)
30
39
  ------------------
31
40
 
32
41
  * fix CHANGELOG.md path
33
42
  * update version to [0.1.5](https://rubygems.org/gems/short_io/versions/0.1.5)
34
43
 
35
- 0.1.4 (2021-01-25)
44
+ 0.1.4 (2022-01-25)
36
45
  ------------------
37
46
 
38
47
  * add CHANGELOG.md
39
48
  * update version to [0.1.4](https://rubygems.org/gems/short_io/versions/0.1.4)
40
49
 
41
- 0.1.3 (2021-01-25)
50
+ 0.1.3 (2022-01-25)
42
51
  ------------------
43
52
 
44
53
  * add Gemfile.lock
45
54
  * update version to [0.1.3](https://rubygems.org/gems/short_io/versions/0.1.3)
46
55
 
47
- 0.1.2 (2021-01-25)
56
+ 0.1.2 (2022-01-25)
48
57
  ------------------
49
58
 
50
59
  * fix sample usage on README.md
51
60
  * update version to [0.1.2](https://rubygems.org/gems/short_io/versions/0.1.2)
52
61
 
53
- 0.1.1 (2021-01-25)
62
+ 0.1.1 (2022-01-25)
54
63
  ------------------
55
64
 
56
65
  * update version to [0.1.1](https://rubygems.org/gems/short_io/versions/0.1.1) (no changes)
57
66
 
58
- 0.1.0 (2021-01-25)
67
+ 0.1.0 (2022-01-25)
59
68
  ------------------
60
69
 
61
70
  * [YANKED](https://rubygems.org/gems/short_io/versions/0.1.0) Start create `short_io` gem
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- short_io (0.1.9)
4
+ short_io (0.1.10)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  A Ruby gem to use with [short.io](https://short.io)
6
6
 
7
- [Short IO documentation](https://developers.short.io/docs/deleting-a-domain)
7
+ [ShortIo gem documentation](https://rubydoc.info/gems/short_io)
8
8
 
9
9
  ## Installation
10
10
 
@@ -7,18 +7,21 @@ require 'json'
7
7
  module ShortIo
8
8
  # Add domain and list domains registerd to Short.io
9
9
  class ShortUrl
10
- REQUEST_TYPE = 'application/json'
11
- 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'
12
13
 
13
14
  attr_reader :host_name, :api_key, :options
14
15
 
15
- def initialize(host_name, api_key, options={})
16
+ def initialize(host_name, api_key, short_io_base_url=SHORT_IO_BASE_URL, options={})
16
17
  @host_name ||= host_name
17
18
  @api_key ||= api_key
18
- @short_io_base_url ||= SHORT_IO_BASE_URL
19
+ @short_io_base_url ||= short_io_base_url
19
20
  @options ||= options
20
- options_default_value
21
- check_variables
21
+ unless options.key?(:domain_id)
22
+ options_default_value
23
+ check_variables
24
+ end
22
25
  end
23
26
 
24
27
  # Options Default Value
@@ -45,8 +48,8 @@ module ShortIo
45
48
 
46
49
  # Prepare request
47
50
 
48
- def setup
49
- @url = URI(SHORT_IO_BASE_URL)
51
+ def setup(action=nil, base_url=SHORT_IO_BASE_URL)
52
+ @url = action.nil? ? URI(base_url) : URI(base_url + action)
50
53
  @http = Net::HTTP.new(@url.host, @url.port)
51
54
  @http.use_ssl = true
52
55
  @http.verify_mode = OpenSSL::SSL::VERIFY_NONE
@@ -95,17 +98,97 @@ module ShortIo
95
98
  return response.read_body
96
99
  end
97
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
+
98
150
  # Domain List
99
151
  #
100
152
  # @return [JSON] return domain list in JSON format.
101
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
+ #
102
186
  # @see https://developers.short.io/docs/getting-a-list-of-domains
103
187
 
104
188
  def domain_list
105
- setup
189
+ setup(nil, SHORT_IO_API_BASE_URL)
106
190
  request = Net::HTTP::Get.new(@url)
107
191
  request["accept"] = REQUEST_TYPE
108
- request["content-type"] = REQUEST_TYPE
109
192
  request["authorization"] = @api_key
110
193
 
111
194
  response = @http.request(request)
@@ -1,3 +1,3 @@
1
1
  module ShortIo
2
- VERSION = "0.1.9"
2
+ VERSION = "0.1.10"
3
3
  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.9
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-02-02 00:00:00.000000000 Z
11
+ date: 2022-02-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: