Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
# Two spaces for indenting
[*]
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
max_line_length = 120
12 changes: 10 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
sudo: false
language: ruby
cache: bundler

rvm:
- 2.3.3
before_install: gem install bundler -v 1.13.7
- 2.0.0
- 2.1
- 2.2
- 2.3.0
- 2.4.0

before_install:
- gem install bundler
30 changes: 30 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,33 @@ source 'https://rubygems.org'

# Specify your gem's dependencies in ipinfo_io.gemspec
gemspec


group :development do
# Rack 2.0+ requires Ruby >= 2.2.2 which is problematic for the test suite on
# older Ruby versions. Check Ruby the version here and put a maximum
# constraint on Rack if necessary.

if RUBY_VERSION >= "2.2.2"
gem "rack", ">= 1.5"
else
gem "rack", ">= 1.5", "< 2.0"
end

gem "bundler"
gem "rake"
gem "minitest"
gem 'minitest-vcr'
gem 'minitest-reporters'
gem 'webmock'

platforms :mri do
# to avoid problems, bring Byebug in on just versions of Ruby under which
# it's known to work well
if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new("2.0.0")
gem "byebug"
gem "pry"
gem "pry-byebug"
end
end
end
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ Or install it yourself as:
$ gem install ipinfo_io

## Usage
Not yeat published on rubygems.org

...
### Requirements
- Ruby 2.0+

## Development

Expand All @@ -32,5 +34,14 @@ To install this gem onto your local machine, run `bundle exec rake install`. To

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ipinfo_io.
Setting up project:
- Be sure to have **rvm** or **rbenv**
- Be sure to have **bundler gem** installed.
- `bundle install`
- Check that your IDE/editor can handle [.editorconfig](http://editorconfig.org) file

Running tests is easy:
- `bundle exec rake`

Bug reports and pull requests are welcome on GitHub at https://github.com/ipinfoio/ruby/.

7 changes: 3 additions & 4 deletions ipinfo_io.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require 'ipinfo_io/version'
Gem::Specification.new do |spec|
spec.name = "ipinfo_io"
spec.version = IpinfoIo::VERSION
spec.required_ruby_version = ">= 2.0.0"
spec.authors = ["Stanislav K"]
spec.email = ["sk@skylup.com"]

Expand All @@ -22,14 +23,12 @@ Gem::Specification.new do |spec|
"public gem pushes."
end

spec.add_dependency 'faraday'

spec.files = `git ls-files -z`.split("\x0").reject do |f|
f.match(%r{^(test|spec|features)/})
end
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

spec.add_development_dependency "bundler", "~> 1.13"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "minitest", "~> 5.0"
end
10 changes: 9 additions & 1 deletion lib/ipinfo_io.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
require "ipinfo_io/version"
require 'faraday'
require 'json'

module IpinfoIo
# Your code goes here...
def self.call
response = Faraday.get('https://ipinfo.io') do |req|
req.headers['User-Agent'] = 'curl/7.30.0'
end

JSON.parse(response.body)
end
end
52 changes: 52 additions & 0 deletions test/cassettes/current_machine_search.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions test/ipinfo_io_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,19 @@ class IpinfoIoTest < Minitest::Test
def test_that_it_has_a_version_number
refute_nil ::IpinfoIo::VERSION
end

def test_machine_location
response = {
"ip" => "49.229.162.85",
"city" => "",
"region" => "",
"country" => "TH",
"loc" => "13.7500,100.4667",
"org" => "AS131445 ADVANCED WIRELESS NETWORK COMPANY LIMITED"
}

VCR.use_cassette('current machine search') do
assert_equal response, IpinfoIo.call
end
end
end
16 changes: 16 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,19 @@
require 'ipinfo_io'

require 'minitest/autorun'
require 'minitest/reporters'
require 'minitest-vcr'
require 'webmock'

Minitest::Reporters.use!(
Minitest::Reporters::SpecReporter.new
)


VCR.configure do |c|
c.cassette_library_dir = 'test/cassettes'
c.hook_into :webmock
c.allow_http_connections_when_no_cassette = true
end

MinitestVcr::Spec.configure!