rdwu 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 013b2c1e698ff1acd92fce949bb54cdd777f62b515ea913d0e2982d36f9ba428
4
+ data.tar.gz: 47fc53c71342d92f4c06795a54e26f7a54fc77ddea2867e164e1be21e8c00dcf
5
+ SHA512:
6
+ metadata.gz: bdcbc97c172095defe6cf3142c6d7685ba51bd7bc7d55ae9b785dc0410d8709bfd8e13282cf82baf8386946f4b5d7d1595572388f2e46892ec93c4f303a6d5ff
7
+ data.tar.gz: 5ee81f3d5c03adf9cbbecd56bad73251d80d42ddac053688ed3119a9775f0562aace232e10c7f6dc59c3e41b9fa0ae1bca8be400ca73c3dae7532aa30fe16d9d
@@ -0,0 +1,4 @@
1
+ RDWU_ENABLED=true
2
+ RDWU_API_KEY=
3
+ RDWU_HOST=http://localhost:3000
4
+ RDWU_TIMEOUT_SECONDS=3
data/README.md ADDED
@@ -0,0 +1,130 @@
1
+ # Rdwu
2
+
3
+ Client for Redirect Web URL
4
+
5
+ ## Installation
6
+
7
+ Install the gem and add to the application's Gemfile by executing:
8
+
9
+ ```bash
10
+ bundle add rdwu
11
+ ```
12
+
13
+ If bundler is not being used to manage dependencies, install the gem by executing:
14
+
15
+ ```bash
16
+ gem install rdwu
17
+ ```
18
+
19
+ ## Setup
20
+
21
+ In the environment variable set the folowings
22
+
23
+ ```shell
24
+ RDWU_ENABLED=true
25
+ RDWU_API_KEY=
26
+ RDWU_HOST=http://localhost:3004
27
+ RDWU_TIMEOUT_SECONDS=3
28
+ ```
29
+
30
+ ## Usage
31
+
32
+ ### List
33
+
34
+ ```ruby
35
+ rdwu = Rdwu::Api.new
36
+ rdwu.list
37
+ [
38
+ {
39
+ "id" => "0198cf30-f234-708e-afd1-d5a96c270a97",
40
+ "type" => "web_redirect",
41
+ "attributes" => {
42
+ "id" => "0198cf30-f234-708e-afd1-d5a96c270a97",
43
+ "name" => "Test ma",
44
+ "to_url" => "http://adawd.com",
45
+ "is_permanent" => false,
46
+ "is_enabled" => true,
47
+ "expires_on" => nil,
48
+ "external_link" => "http://localhost:3000/0198cf30-f234-708e-afd1-d5a96c270a97"
49
+ }
50
+ }
51
+ ]
52
+ ```
53
+
54
+ ### Find
55
+
56
+ ```ruby
57
+ rdwu = Rdwu::Api.new
58
+ rdwu.find('http://adawd.com')
59
+ {
60
+ "id" => "0198cf30-f234-708e-afd1-d5a96c270a97",
61
+ "type" => "web_redirect",
62
+ "attributes" => {
63
+ "id" => "0198cf30-f234-708e-afd1-d5a96c270a97",
64
+ "name" => "Test ma",
65
+ "to_url" => "http://adawd.com",
66
+ "is_permanent" => false,
67
+ "is_enabled" => true,
68
+ "expires_on" => nil,
69
+ "external_link" => "http://localhost:3000/0198cf30-f234-708e-afd1-d5a96c270a97"
70
+ }
71
+ }
72
+ ```
73
+
74
+ ### Retrieve
75
+
76
+ ```ruby
77
+ rdwu = Rdwu::Api.new
78
+ rdwu.retrieve('0198cf30-f234-708e-afd1-d5a96c270a97')
79
+ {
80
+ "id" => "0198cf30-f234-708e-afd1-d5a96c270a97",
81
+ "type" => "web_redirect",
82
+ "attributes" => {
83
+ "id" => "0198cf30-f234-708e-afd1-d5a96c270a97",
84
+ "name" => "Test ma",
85
+ "to_url" => "http://adawd.com",
86
+ "is_permanent" => false,
87
+ "is_enabled" => true,
88
+ "expires_on" => nil,
89
+ "external_link" => "http://localhost:3000/0198cf30-f234-708e-afd1-d5a96c270a97"
90
+ }
91
+ }
92
+ ```
93
+
94
+ ### Create
95
+
96
+ ```ruby
97
+ rdwu = Rdwu::Api.new
98
+ rdwu.create(
99
+ {
100
+ name: 'Test ma',
101
+ to_url: 'http://adawd.com',
102
+ is_permanent: false,
103
+ is_enabled: true,
104
+ expires_on: nil
105
+ }
106
+ )
107
+ ```
108
+
109
+ ### Update
110
+
111
+ ```ruby
112
+ rdwu = Rdwu::Api.new
113
+ rdwu.update(
114
+ '0198cf30-f234-708e-afd1-d5a96c270a97',
115
+ {
116
+ name: 'Test ma',
117
+ to_url: 'http://adawd.com',
118
+ is_permanent: false,
119
+ is_enabled: true,
120
+ expires_on: nil
121
+ }
122
+ )
123
+ ```
124
+
125
+ ### Delete
126
+
127
+ ```ruby
128
+ rdwu = Rdwu::Api.new
129
+ rdwu.delete('0198cf30-f234-708e-afd1-d5a96c270a97')
130
+ ```
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ task default: %i[]
data/lib/rdwu/read.rb ADDED
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rdwu::Read
4
+ def list
5
+ http = get_request('/api/v1/web_redirects')
6
+ body = JSON.parse(http.body)
7
+ body['data']
8
+ end
9
+
10
+ def find(url)
11
+ http = get_request("/api/v1/web_redirects/find?url=#{url}")
12
+
13
+ if http.status == 200
14
+ body = JSON.parse(http.body)
15
+ return body['data']
16
+ end
17
+
18
+ nil
19
+ end
20
+
21
+ def retrieve(uuid)
22
+ http = get_request("/api/v1/web_redirects/#{uuid}")
23
+
24
+ if http.status == 200
25
+ body = JSON.parse(http.body)
26
+ return body['data']
27
+ end
28
+
29
+ nil
30
+ end
31
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rdwu::Settings
4
+ def enabled?
5
+ %w[true on 1 enabled yes].include?(ENV['RDWU_ENABLED']&.downcase)
6
+ end
7
+
8
+ def token
9
+ ENV['RDWU_API_KEY']
10
+ end
11
+
12
+ def host
13
+ ENV['RDWU_HOST']
14
+ end
15
+
16
+ def timeout_seconds
17
+ (ENV['RDWU_TIMEOUT_SECONDS'] || 3).to_i
18
+ end
19
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rdwu
4
+ VERSION = '0.1.0'
5
+ end
data/lib/rdwu/write.rb ADDED
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rdwu::Write
4
+ def create(payload)
5
+ http = post_request('/api/v1/web_redirects', payload)
6
+
7
+ if http.status == 200 || http.status == 201
8
+ body = JSON.parse(http.body)
9
+ return body['data']
10
+ end
11
+
12
+ return { 'errors': JSON.parse(http.body) } if http.status == 422
13
+
14
+ nil
15
+ end
16
+
17
+ def update(uuid, payload)
18
+ http = post_request("/api/v1/web_redirects/#{uuid}", payload)
19
+
20
+ if http.status == 200
21
+ body = JSON.parse(http.body)
22
+ return body['data']
23
+ end
24
+
25
+ return { 'errors': JSON.parse(http.body) } if http.status == 422
26
+ return { 'errors': { 'message': 'Not found!' } } if http.status == 404
27
+
28
+ nil
29
+ end
30
+
31
+ def delete(uuid)
32
+ http = delete_request("/api/v1/web_redirects/#{uuid}")
33
+
34
+ return true if http.status == 204
35
+ false
36
+ end
37
+ end
data/lib/rdwu.rb ADDED
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'http'
4
+ require 'pry'
5
+
6
+ require_relative 'rdwu/version'
7
+
8
+ module Rdwu
9
+ require_relative 'rdwu/settings'
10
+ require_relative 'rdwu/read'
11
+ require_relative 'rdwu/write'
12
+
13
+ class Error < StandardError; end
14
+
15
+ class Api
16
+ include JSON
17
+ include Settings
18
+ include Read
19
+ include Write
20
+
21
+ def get_request(path)
22
+ return nil unless enabled?
23
+
24
+ path = [host, path].join
25
+
26
+ HTTP
27
+ .timeout(timeout_seconds)
28
+ .headers(token:)
29
+ .get(path)
30
+ end
31
+
32
+ def post_request(path, payload)
33
+ return nil unless enabled?
34
+
35
+ path = [host, path].join
36
+
37
+ HTTP
38
+ .timeout(timeout_seconds)
39
+ .headers(token:)
40
+ .post(path, json: payload)
41
+ end
42
+
43
+ def delete_request(path)
44
+ return nil unless enabled?
45
+
46
+ path = [host, path].join
47
+
48
+ HTTP
49
+ .timeout(timeout_seconds)
50
+ .headers(token:)
51
+ .delete(path)
52
+ end
53
+ end
54
+ end
data/sig/rdwu/api.rbs ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rdwu
4
+ class Api
5
+ def get_request: -> HTTP::Response
6
+ def post_request: -> HTTP::Response
7
+ def delete_request: -> HTTP::Response
8
+ end
9
+ end
data/sig/rdwu/read.rbs ADDED
@@ -0,0 +1,47 @@
1
+ module Rdwu
2
+ module Read
3
+ def list: -> [
4
+ {
5
+ "id" => "uuid",
6
+ "type" => "web_redirect",
7
+ "attributes" => {
8
+ "id" => "uuid",
9
+ "name" => String,
10
+ "to_url" => String,
11
+ "is_permanent" => bool,
12
+ "is_enabled" => bool,
13
+ "expires_on" => "2025-12-28" | nil,
14
+ "external_link" => String
15
+ }
16
+ }
17
+ ]
18
+
19
+ def find: -> {
20
+ "id" => "uuid",
21
+ "type" => "web_redirect",
22
+ "attributes" => {
23
+ "id" => "uuid",
24
+ "name" => String,
25
+ "to_url" => String,
26
+ "is_permanent" => bool,
27
+ "is_enabled" => bool,
28
+ "expires_on" => "2025-12-28" | nil,
29
+ "external_link" => String
30
+ }
31
+ }
32
+
33
+ def retrieve: -> {
34
+ "id" => "uuid",
35
+ "type" => "web_redirect",
36
+ "attributes" => {
37
+ "id" => "uuid",
38
+ "name" => String,
39
+ "to_url" => String,
40
+ "is_permanent" => bool,
41
+ "is_enabled" => bool,
42
+ "expires_on" => "2025-12-28" | nil,
43
+ "external_link" => String
44
+ }
45
+ }
46
+ end
47
+ end
@@ -0,0 +1,10 @@
1
+ module Rdwu
2
+ module Settings
3
+ def enabled?: -> bool
4
+
5
+ def host: -> String
6
+ def token: -> String
7
+
8
+ def timeout_seconds: -> Integer
9
+ end
10
+ end
@@ -0,0 +1,33 @@
1
+ module Rdwu
2
+ module Write
3
+ def create: -> {
4
+ "id" => "uuid",
5
+ "type" => "web_redirect",
6
+ "attributes" => {
7
+ "id" => "uuid",
8
+ "name" => String,
9
+ "to_url" => String,
10
+ "is_permanent" => bool,
11
+ "is_enabled" => bool,
12
+ "expires_on" => "2025-12-28" | nil,
13
+ "external_link" => String
14
+ }
15
+ }
16
+
17
+ def update: -> {
18
+ "id" => "uuid",
19
+ "type" => "web_redirect",
20
+ "attributes" => {
21
+ "id" => "uuid",
22
+ "name" => String,
23
+ "to_url" => String,
24
+ "is_permanent" => bool,
25
+ "is_enabled" => bool,
26
+ "expires_on" => "2025-12-28" | nil,
27
+ "external_link" => String
28
+ }
29
+ }
30
+
31
+ def delete: -> bool
32
+ end
33
+ end
data/sig/rdwu.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Rdwu
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rdwu
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Saimon Lovell
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: http
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '5'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '5'
26
+ - !ruby/object:Gem::Dependency
27
+ name: ipaddr
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '1.2'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.2'
40
+ description: Does an API call to the RDWU to shorten the url and get a shortened URL
41
+ email:
42
+ - staysynchronize@gmail.com
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - ".rbenv-vars.example"
48
+ - README.md
49
+ - Rakefile
50
+ - lib/rdwu.rb
51
+ - lib/rdwu/read.rb
52
+ - lib/rdwu/settings.rb
53
+ - lib/rdwu/version.rb
54
+ - lib/rdwu/write.rb
55
+ - sig/rdwu.rbs
56
+ - sig/rdwu/api.rbs
57
+ - sig/rdwu/read.rbs
58
+ - sig/rdwu/settings.rbs
59
+ - sig/rdwu/write.rbs
60
+ homepage: https://gitlab.com/redirect-web-url/rdwu-gem
61
+ licenses:
62
+ - MIT
63
+ metadata:
64
+ allowed_push_host: https://rubygems.org
65
+ homepage_uri: https://gitlab.com/redirect-web-url/rdwu-gem
66
+ source_code_uri: https://gitlab.com/redirect-web-url/rdwu-gem
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 3.2.0
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubygems_version: 3.7.1
82
+ specification_version: 4
83
+ summary: Shorten the url
84
+ test_files: []