pointpin 1.0.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 +7 -0
- data/.gitignore +22 -0
- data/.rspec +0 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +43 -0
- data/Rakefile +10 -0
- data/lib/pointpin.rb +40 -0
- data/lib/pointpin/configuration.rb +29 -0
- data/lib/pointpin/version.rb +3 -0
- data/pointpin.gemspec +31 -0
- data/spec/cassettes/location_for_ip.yml +43 -0
- data/spec/pointpin/configuration_spec.rb +12 -0
- data/spec/pointpin/pointpin_spec.rb +49 -0
- data/spec/pointpin/version_spec.rb +7 -0
- data/spec/spec_helper.rb +21 -0
- metadata +176 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b450f35c3da0837208c3181ed16b7a2d81ae53e3
|
4
|
+
data.tar.gz: 94450c6a4ea22c51d1906f739fa7ee65332a1d05
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8f9620b68a98edfda303d2682c2c9fdc45543656d120565ed8a49cc0b2456b11bd7687187461ec040018ddb1f77ef460c0468e316b3f14c39603d5b81b2b15ec
|
7
|
+
data.tar.gz: 168904cb5dcdc3fa56d8032b85d278ca5ed8da61913a99d937e0032f349c1bad9b21f8b221a1c3d032face52e042cdb445662e7adace04a0581a4999bc032446
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/.rspec
ADDED
File without changes
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Brian Flanagan
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# Pointp.in
|
2
|
+
|
3
|
+
[Pointp.in](https://pointp.in) API wrapper in Ruby.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
`gem install pointpin`
|
8
|
+
|
9
|
+
or in your `Gemfile`
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'pointpin'
|
13
|
+
```
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
Make sure you require the library.
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
require 'pointpin'
|
21
|
+
```
|
22
|
+
|
23
|
+
You will need to set your API key before you can make requests to the [Pointp.in](https://pointp.in) API.
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
Pointpin.api_key = 'this-is-your-api-key'
|
27
|
+
```
|
28
|
+
|
29
|
+
You can then make requests to the `Pointpin.locate(ip_address)` method.
|
30
|
+
|
31
|
+
Get location data for an IP address:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
location = Pointpin.locate('55.111.555.555')
|
35
|
+
```
|
36
|
+
|
37
|
+
Please refer to the [pointp.in docs](https://pointp.in/docs/get-started) for more information on the full response properties.
|
38
|
+
|
39
|
+
The gem uses [Faraday](https://github.com/lostisland/faraday) for HTTP requests. It uses `Net::HTTP` by default, but changing the adapter is pretty straightforward.
|
40
|
+
|
41
|
+
## Copyright
|
42
|
+
|
43
|
+
Copyright (c) 2014 Brian Flanagan. See LICENSE.txt for further details.
|
data/Rakefile
ADDED
data/lib/pointpin.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'pointpin/configuration'
|
2
|
+
require 'pointpin/version'
|
3
|
+
|
4
|
+
require 'hashie'
|
5
|
+
require 'multi_json'
|
6
|
+
require 'faraday'
|
7
|
+
|
8
|
+
module Pointpin
|
9
|
+
extend Configuration
|
10
|
+
|
11
|
+
self.default_params = {}
|
12
|
+
|
13
|
+
class << self
|
14
|
+
def locate(ip)
|
15
|
+
pointpin_url = "#{ Pointpin.api_endpoint }/#{ Pointpin.api_key }/json/#{ ip }"
|
16
|
+
|
17
|
+
pointpin_response = get(pointpin_url)
|
18
|
+
|
19
|
+
if pointpin_response.success?
|
20
|
+
return Hashie::Mash.new(MultiJson.load(pointpin_response.body))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def connection
|
25
|
+
@connection ||= Faraday.new
|
26
|
+
end
|
27
|
+
|
28
|
+
def connection=(connection)
|
29
|
+
@connection = connection
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def get(path, params = {})
|
35
|
+
params = Pointpin.default_params.merge(params || {})
|
36
|
+
|
37
|
+
connection.get(path, params)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Pointpin
|
2
|
+
module Configuration
|
3
|
+
# Default API endpoint
|
4
|
+
DEFAULT_API_ENDPOINT = 'http://geo.pointp.in'
|
5
|
+
|
6
|
+
# Pointpin API endpoint
|
7
|
+
attr_writer :api_endpoint
|
8
|
+
|
9
|
+
# API key
|
10
|
+
attr_writer :api_key
|
11
|
+
|
12
|
+
# Default parameters
|
13
|
+
attr_accessor :default_params
|
14
|
+
|
15
|
+
def configure
|
16
|
+
yield self
|
17
|
+
end
|
18
|
+
|
19
|
+
# API endpoint
|
20
|
+
def api_endpoint
|
21
|
+
@api_endpoint ||= DEFAULT_API_ENDPOINT
|
22
|
+
end
|
23
|
+
|
24
|
+
# API key
|
25
|
+
def api_key
|
26
|
+
@api_key
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/pointpin.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'pointpin/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "pointpin"
|
8
|
+
spec.version = Pointpin::VERSION
|
9
|
+
spec.authors = ["Brian Flanagan"]
|
10
|
+
spec.email = ["brian@coralmade.com"]
|
11
|
+
spec.homepage = "https://github.com/coralmade/pointpin-ruby"
|
12
|
+
spec.summary = %q{Pointp.in API wrapper in Ruby}
|
13
|
+
spec.description = %q{Pointp.in API wrapper in Rub}
|
14
|
+
spec.homepage = ""
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0")
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
23
|
+
spec.add_development_dependency('rake')
|
24
|
+
spec.add_development_dependency('rspec')
|
25
|
+
spec.add_development_dependency('vcr')
|
26
|
+
spec.add_development_dependency('typhoeus')
|
27
|
+
|
28
|
+
spec.add_dependency('faraday')
|
29
|
+
spec.add_dependency('multi_json')
|
30
|
+
spec.add_dependency('hashie')
|
31
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://geo.pointp.in/this-is-a-valid-api-key/json/55.111.555.555
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Faraday v0.9.0
|
12
|
+
response:
|
13
|
+
status:
|
14
|
+
code: 200
|
15
|
+
message: OK
|
16
|
+
headers:
|
17
|
+
Content-Type:
|
18
|
+
- application/json
|
19
|
+
Content-Length:
|
20
|
+
- '222'
|
21
|
+
Connection:
|
22
|
+
- keep-alive
|
23
|
+
Status:
|
24
|
+
- 200 OK
|
25
|
+
Last-Modified:
|
26
|
+
- Wed, 16 Jul 2014 08:42:12 GMT
|
27
|
+
X-Content-Type-Options:
|
28
|
+
- nosniff
|
29
|
+
X-Powered-By:
|
30
|
+
- Phusion Passenger 4.0.45
|
31
|
+
Date:
|
32
|
+
- Wed, 16 Jul 2014 08:42:12 GMT
|
33
|
+
Server:
|
34
|
+
- nginx/1.6.0 + Phusion Passenger 4.0.45
|
35
|
+
body:
|
36
|
+
encoding: UTF-8
|
37
|
+
string: '{"ip":"55.111.555.555","continent_code":"EU","country_code":"IE","country_name":"Ireland","region_name":"Dublin
|
38
|
+
City","city_name":"Dublin","postcode":null,"latitude":53.3331,"longitude":-6.2489,"time_zone":"Europe/Dublin"}'
|
39
|
+
http_version: '1.1'
|
40
|
+
adapter_metadata:
|
41
|
+
effective_url: http://geo.pointp.in/this-is-a-valid-api-key/json/55.111.555.555
|
42
|
+
recorded_at: Wed, 16 Jul 2014 08:42:12 GMT
|
43
|
+
recorded_with: VCR 2.9.2
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Pointpin::Configuration do
|
4
|
+
describe '.configure' do
|
5
|
+
it 'should have default attributes' do
|
6
|
+
Pointpin.configure do |configuration|
|
7
|
+
configuration.api_endpoint.should eql(Pointpin::Configuration::DEFAULT_API_ENDPOINT)
|
8
|
+
configuration.api_key.should be_nil
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Pointpin do
|
4
|
+
describe '.default_params' do
|
5
|
+
it "defaults to an empty hash" do
|
6
|
+
Pointpin.default_params.should == {}
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '.locate' do
|
11
|
+
before :each do
|
12
|
+
Pointpin.api_key = 'this-is-a-valid-api-key'
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should return a location for a given IP address' do
|
16
|
+
VCR.use_cassette('location_for_ip', record: :once) do
|
17
|
+
location = Pointpin.locate('55.111.555.555')
|
18
|
+
location.should_not be_nil
|
19
|
+
location.latitude.should == 53.3331
|
20
|
+
location.longitude.should == -6.2489
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'unit tests' do
|
25
|
+
let(:faraday) { double 'Faraday', get: response }
|
26
|
+
let(:response) { double 'Response', success?: true, body: '{}' }
|
27
|
+
|
28
|
+
before :each do
|
29
|
+
stub_const 'Faraday', double(new: faraday)
|
30
|
+
|
31
|
+
Pointpin.stub(api_key: 'api-key', connection: faraday)
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'without default parameters' do
|
35
|
+
before :each do
|
36
|
+
Pointpin.stub(default_params: {})
|
37
|
+
end
|
38
|
+
|
39
|
+
it "sends a standard request" do
|
40
|
+
faraday.should_receive(:get).with(
|
41
|
+
'http://geo.pointp.in/api-key/json/1.2.3.4', {}
|
42
|
+
).and_return(response)
|
43
|
+
|
44
|
+
Pointpin.locate('1.2.3.4')
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'pointpin'
|
3
|
+
|
4
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
5
|
+
|
6
|
+
require 'vcr'
|
7
|
+
require 'typhoeus/adapters/faraday'
|
8
|
+
|
9
|
+
VCR.configure do |c|
|
10
|
+
c.cassette_library_dir = 'spec/cassettes'
|
11
|
+
c.hook_into :typhoeus
|
12
|
+
c.allow_http_connections_when_no_cassette = false
|
13
|
+
end
|
14
|
+
|
15
|
+
Faraday.default_adapter = :typhoeus
|
16
|
+
|
17
|
+
RSpec.configure do |config|
|
18
|
+
config.before(:each) do
|
19
|
+
Pointpin.api_key = nil
|
20
|
+
end
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,176 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pointpin
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brian Flanagan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: vcr
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: typhoeus
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: faraday
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: multi_json
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: hashie
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description: Pointp.in API wrapper in Rub
|
126
|
+
email:
|
127
|
+
- brian@coralmade.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- ".gitignore"
|
133
|
+
- ".rspec"
|
134
|
+
- Gemfile
|
135
|
+
- LICENSE.txt
|
136
|
+
- README.md
|
137
|
+
- Rakefile
|
138
|
+
- lib/pointpin.rb
|
139
|
+
- lib/pointpin/configuration.rb
|
140
|
+
- lib/pointpin/version.rb
|
141
|
+
- pointpin.gemspec
|
142
|
+
- spec/cassettes/location_for_ip.yml
|
143
|
+
- spec/pointpin/configuration_spec.rb
|
144
|
+
- spec/pointpin/pointpin_spec.rb
|
145
|
+
- spec/pointpin/version_spec.rb
|
146
|
+
- spec/spec_helper.rb
|
147
|
+
homepage: ''
|
148
|
+
licenses:
|
149
|
+
- MIT
|
150
|
+
metadata: {}
|
151
|
+
post_install_message:
|
152
|
+
rdoc_options: []
|
153
|
+
require_paths:
|
154
|
+
- lib
|
155
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
161
|
+
requirements:
|
162
|
+
- - ">="
|
163
|
+
- !ruby/object:Gem::Version
|
164
|
+
version: '0'
|
165
|
+
requirements: []
|
166
|
+
rubyforge_project:
|
167
|
+
rubygems_version: 2.3.0
|
168
|
+
signing_key:
|
169
|
+
specification_version: 4
|
170
|
+
summary: Pointp.in API wrapper in Ruby
|
171
|
+
test_files:
|
172
|
+
- spec/cassettes/location_for_ip.yml
|
173
|
+
- spec/pointpin/configuration_spec.rb
|
174
|
+
- spec/pointpin/pointpin_spec.rb
|
175
|
+
- spec/pointpin/version_spec.rb
|
176
|
+
- spec/spec_helper.rb
|