ruby_ipify 0.0.0 → 0.0.1
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/lib/ruby_ipify.rb +1 -1
- data/specs/ruby_ipify_spec.rb +117 -0
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75c83f4719c3bad055d76c1de15df254057ac95c66c03205326ef02860198fd1
|
4
|
+
data.tar.gz: 7adffb03551f9d2959d314d0e053c34fe3e9c716a091120fab5164984abed920
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f8c1be749bbcb9b87c1e16673cb45f920abb86bb29adcdb0fd3f54790508bebaca2d6262935b52b7dbf7e0b62a73210fa88bf35c65e0d90049a9c61478bcaa4
|
7
|
+
data.tar.gz: 40474765980562ea8d78ebf6d79cbf899667dde3e7a72e947a7053f97d652bf5f124c1677cad474c867126724a4b80002056f354a7f00d0d5bcaefb5ed6dc764
|
data/lib/ruby_ipify.rb
CHANGED
@@ -0,0 +1,117 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'ruby_ipify'
|
3
|
+
require './lib/constant'
|
4
|
+
|
5
|
+
describe RubyIpify do
|
6
|
+
before(:each) {
|
7
|
+
@sample_ipv4 = "1.1.1.1"
|
8
|
+
@sample_ipv6 = "240x:40fx:102x:e36x:749x:cabx:2b8x:cb2x"
|
9
|
+
@response = Net::HTTPSuccess.new("1.0", '200', 'OK')
|
10
|
+
allow(Net::HTTP).to receive(:get_response).and_return(@response)
|
11
|
+
}
|
12
|
+
|
13
|
+
context 'IPv4' do
|
14
|
+
before { allow(@response).to receive(:body).and_return(@sample_ipv4) }
|
15
|
+
it 'triggers api to IPv4 endpoint' do
|
16
|
+
expect(Net::HTTP).to receive(:get_response).with(IPV4_URI)
|
17
|
+
RubyIpify.get_my_public_ip
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'returns IPv4 address' do
|
21
|
+
expect(RubyIpify.get_my_public_ip).to eq(@sample_ipv4)
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'format as json' do
|
25
|
+
it 'trigger api with format' do
|
26
|
+
expect(Net::HTTP).to receive(:get_response) do |request|
|
27
|
+
expect(request.request_uri).to eq("/?format=json")
|
28
|
+
@response
|
29
|
+
end
|
30
|
+
RubyIpify.get_my_public_ip(format: 'json')
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'returns IPv4 address as json format' do
|
34
|
+
expected_response = { 'ip' => @sample_ipv4 }.to_json
|
35
|
+
allow(@response).to receive(:body).and_return(expected_response)
|
36
|
+
res = RubyIpify.get_my_public_ip(format: 'json')
|
37
|
+
expect(res).to eq expected_response
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'format as parsed_json' do
|
42
|
+
it 'trigger api with format' do
|
43
|
+
expect(Net::HTTP).to receive(:get_response) do |request|
|
44
|
+
expect(request.request_uri).to eq("/?format=json")
|
45
|
+
@response
|
46
|
+
end
|
47
|
+
RubyIpify.get_my_public_ip(format: 'json')
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'returns IPv4 address as parsed json format' do
|
51
|
+
expected_response = { 'ip' => @sample_ipv4 }
|
52
|
+
allow(@response).to receive(:body).and_return(expected_response.to_json)
|
53
|
+
res = RubyIpify.get_my_public_ip(format: 'parsed_json')
|
54
|
+
expect(res).to eq expected_response
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'wrong format passed' do
|
59
|
+
it 'raise InvalidParamsError exception' do
|
60
|
+
expect{ RubyIpify.get_my_public_ip(format: 'abc') }.to raise_error (RubyIpifyException::InvalidParamsError)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context 'IPv6' do
|
66
|
+
before { allow(@response).to receive(:body).and_return(@sample_ipv6) }
|
67
|
+
|
68
|
+
it 'triggers api to IPv4 endpoint' do
|
69
|
+
expect(Net::HTTP).to receive(:get_response).with(IPV6_URI)
|
70
|
+
RubyIpify.get_my_public_ip(as_ipv6: true)
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'returns IPv4 address' do
|
74
|
+
expect(RubyIpify.get_my_public_ip(as_ipv6: true)).to eq(@sample_ipv6)
|
75
|
+
end
|
76
|
+
|
77
|
+
context 'format as json' do
|
78
|
+
it 'trigger api with format' do
|
79
|
+
expect(Net::HTTP).to receive(:get_response) do |request|
|
80
|
+
expect(request.request_uri).to eq("/?format=json")
|
81
|
+
@response
|
82
|
+
end
|
83
|
+
RubyIpify.get_my_public_ip(as_ipv6:true, format: 'json')
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'returns IPv4 address as json format' do
|
87
|
+
expected_response = { 'ip' => @sample_ipv6 }.to_json
|
88
|
+
allow(@response).to receive(:body).and_return(expected_response)
|
89
|
+
res = RubyIpify.get_my_public_ip(as_ipv6: true, format: 'json')
|
90
|
+
expect(res).to eq expected_response
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
context 'format as parsed_json' do
|
95
|
+
it 'trigger api with format' do
|
96
|
+
expect(Net::HTTP).to receive(:get_response) do |request|
|
97
|
+
expect(request.request_uri).to eq("/?format=json")
|
98
|
+
@response
|
99
|
+
end
|
100
|
+
RubyIpify.get_my_public_ip(as_ipv6: true, format: 'json')
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'returns IPv4 address as parsed json format' do
|
104
|
+
expected_response = { 'ip' => @sample_ipv6 }
|
105
|
+
allow(@response).to receive(:body).and_return(expected_response.to_json)
|
106
|
+
res = RubyIpify.get_my_public_ip(as_ipv6: true, format: 'parsed_json')
|
107
|
+
expect(res).to eq expected_response
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
context 'wrong format passed' do
|
112
|
+
it 'raise InvalidParamsError exception' do
|
113
|
+
expect{ RubyIpify.get_my_public_ip(format: 'abc') }.to raise_error (RubyIpifyException::InvalidParamsError)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_ipify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gokulakrishnan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-10-
|
12
|
-
dependencies:
|
11
|
+
date: 2023-10-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
description: A Ruby gem to use ipify which is a simple public IP address API.
|
14
28
|
email: gokulakrishnan312@gmail.com
|
15
29
|
executables: []
|
@@ -19,6 +33,7 @@ files:
|
|
19
33
|
- lib/constant.rb
|
20
34
|
- lib/ruby_ipify.rb
|
21
35
|
- lib/ruby_ipify_exception.rb
|
36
|
+
- specs/ruby_ipify_spec.rb
|
22
37
|
homepage: https://rubygems.org/gems/ruby_ipify
|
23
38
|
licenses:
|
24
39
|
- MIT
|