Skip to content

Commit 88a07ff

Browse files
committed
simplify tests and do real requests
1 parent f3bd7a8 commit 88a07ff

File tree

11 files changed

+148
-380
lines changed

11 files changed

+148
-380
lines changed

.rubocop.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ Metrics/MethodLength:
1818
Metrics/AbcSize:
1919
Enabled: false
2020

21+
Metrics/ClassLength:
22+
Enabled: false
23+
2124
Lint/DuplicateMethods:
2225
Enabled: false
2326

Gemfile

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,6 @@ group :development do
88
gem 'bundler'
99
gem 'minitest'
1010
gem 'minitest-reporters'
11-
gem 'minitest-vcr'
12-
gem 'rack', '>= 1.5'
1311
gem 'rake'
1412
gem 'rubocop'
15-
gem 'webmock'
16-
17-
platforms :mri do
18-
# to avoid problems, bring Byebug in on just versions of Ruby under
19-
# which it's known to work well
20-
if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.0.0')
21-
gem 'byebug'
22-
gem 'pry'
23-
gem 'pry-byebug'
24-
end
25-
end
2613
end

lib/ipinfo.rb

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,21 @@ def details(ip_address = nil)
6363
protected
6464

6565
def request_details(ip_address = nil)
66-
unless @cache.contains?(ip_address)
67-
response = @httpc.get(escape_path(ip_address))
66+
res = @cache.get(ip_address)
67+
if res != nil
68+
return res
69+
end
6870

69-
if response.status.eql?(429)
70-
raise RateLimitError,
71-
RATE_LIMIT_MESSAGE
72-
end
71+
response = @httpc.get(escape_path(ip_address))
7372

74-
details = JSON.parse(response.body, symbolize_names: true)
75-
@cache.set(ip_address, details)
73+
if response.status.eql?(429)
74+
raise RateLimitError,
75+
RATE_LIMIT_MESSAGE
7676
end
77-
@cache.get(ip_address)
77+
78+
details = JSON.parse(response.body, symbolize_names: true)
79+
@cache.set(ip_address, details)
80+
details
7881
end
7982

8083
def prepare_http_client(httpc = nil)

lib/ipinfo/response.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ def initialize(response)
1111

1212
@all.each do |name, value|
1313
instance_variable_set("@#{name}", value)
14-
self.class.send(:attr_accessor, name)
14+
15+
c = class << self; self end
16+
c.send(:attr_accessor, name)
1517
end
1618
end
1719
end

test/cassettes/current_machine_search.yml

Lines changed: 0 additions & 54 deletions
This file was deleted.

test/cassettes/lookup_with_awkward_token.yml

Lines changed: 0 additions & 54 deletions
This file was deleted.

test/cassettes/lookup_with_token.yml

Lines changed: 0 additions & 54 deletions
This file was deleted.

test/cassettes/search_with_ip6.yml

Lines changed: 0 additions & 52 deletions
This file was deleted.

test/cassettes/search_with_random_ip.yml

Lines changed: 0 additions & 52 deletions
This file was deleted.

0 commit comments

Comments
 (0)