yandex_locator 0.2.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fb740623678a1e5908048dee785284f00b007f89
4
- data.tar.gz: 085d0f3801eec015012b6b5c8b55e232e3a363ea
3
+ metadata.gz: 73440fb516a10f0604782286b029d2b74d21da64
4
+ data.tar.gz: f139f95d5a6f0e723ecd42a6b548072df25d2a41
5
5
  SHA512:
6
- metadata.gz: 3d3422fefa90e85ff3598fe51c0a89c02bdb6b0029e1c9cff6fb1da4da51bace878800684f318222436c13231b74fbd332f6821277390b2ad211799d9bc7f322
7
- data.tar.gz: 79f311183c97a959852d3f3ced7c54a14888310565262d8080fc1e358ce35f449518175ec03cb7bca2691717c16e171479457d4865ada58de0865f584a8cacb5
6
+ metadata.gz: 01f6fe05a9959dbe4f98621f6a1b9ae54a757a7e89528b319e419eeb8e4e18f8fe34088ab14c0ccfbe42b824337a9462a5cbcee626988f0a38e1a9991f11a5a6
7
+ data.tar.gz: cf498ce80eee42b79e94ea68973a23694a649e0893cc66f983646c36eb83ff898c43b41b8a9388a773d815da19ce2699096ec8c251ed63ffb79ab3f8f7ca9c07
data/.gitignore CHANGED
@@ -9,3 +9,5 @@
9
9
  /tmp/
10
10
 
11
11
  .ruby-version
12
+
13
+ .env
data/Gemfile CHANGED
@@ -1,4 +1,17 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in yandex_locator.gemspec
3
+ gem 'rake', '> 11.0.1', '< 12.0'
4
+
5
+ group :development do
6
+ gem 'pry'
7
+ end
8
+
9
+ group :test do
10
+ gem 'rspec', '~> 3.0.0'
11
+ gem 'vcr', '~> 2.9.2'
12
+ gem 'webmock', '>= 1.9', '< 2.0.0'
13
+ gem 'coveralls', require: false
14
+ gem 'dotenv-rails'
15
+ end
16
+
4
17
  gemspec
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
  [![Build Status](https://travis-ci.org/sergey-chechaev/yandex_locator.svg?branch=master)](https://travis-ci.org/sergey-chechaev/yandex_locator)
3
3
  [![Code Climate](https://codeclimate.com/github/sergey-chechaev/yandex_locator.svg)](https://codeclimate.com/github/sergey-chechaev/yandex_locator)
4
4
  [![Dependency Status](https://www.versioneye.com/user/projects/57bf6ec8968d640033602245/badge.svg?style=flat-square)](https://www.versioneye.com/user/projects/57bf6ec8968d640033602245)
5
- [![Test Coverage](https://codeclimate.com/github/sergey-chechaev/yandex_locator/badges/coverage.svg)](https://codeclimate.com/github/sergey-chechaev/yandex_locator/coverage)
5
+ [![Coverage Status](https://coveralls.io/repos/github/sergey-chechaev/yandex_locator/badge.svg)](https://coveralls.io/github/sergey-chechaev/yandex_locator)
6
6
 
7
7
  # YandexLocator
8
8
 
@@ -30,17 +30,39 @@ Configure gem credentials
30
30
 
31
31
  ```ruby
32
32
  YandexLocator.configure do |config|
33
- config.api_key = ENV['YANDEX_API_KEY']
34
- config.version = "1.0"
33
+ config.api_key = 'api key'
34
+ config.version = '1.0'
35
35
  end
36
36
  ```
37
+ or
37
38
 
39
+ ```ruby
40
+ client = YandexLocator::Client.new(api_key: 'api key', version: '1.0')
41
+ client.lookup(ip: { address_v4: '178.247.233.3' })
42
+ ```
38
43
  Make request
39
44
 
40
45
  ```ruby
41
- conn = YandexLocator::Client.new
42
- result = conn.lookup(ip: "109.252.52.39")
43
- # => {"position"=>{"altitude"=>0.0, "altitude_precision"=>30.0, "latitude"=>55.75395965576172, "longitude"=>37.62039184570312, "precision"=>100000.0, "type"=>"ip"}}
46
+ client = YandexLocator::Client.new(api_key: 'api key', version: '1.0')
47
+ result = client.lookup(ip: { address_v4: '178.247.233.3' })
48
+ result.position
49
+ # => {"altitude"=>0.0, "altitude_precision"=>30.0, "latitude"=>41.00892639160156, "longitude"=>28.96711158752441, "precision"=>100000.0, "type"=>"ip"}
50
+ result = client.lookup(
51
+ wifi_networks: [{
52
+ mac: 'ec:43:f6:d1:a2:1e'
53
+ }],
54
+ gsm_cells: [{
55
+ countrycode: 250,
56
+ operatorid: 99,
57
+ cellid: 12_082,
58
+ lac: 25_254
59
+ }],
60
+ ip: {
61
+ address_v4: '178.247.233.3'
62
+ }
63
+ )
64
+ result.position
65
+ # => {"altitude"=>0.0, "altitude_precision"=>30.0, "latitude"=>56.87141036987305, "longitude"=>60.61107635498047, "precision"=>1066.041137695312, "type"=>"gsm"}
44
66
  ```
45
67
 
46
68
 
@@ -48,7 +70,7 @@ Make request
48
70
 
49
71
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
50
72
 
51
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
73
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org/gems/yandex_locator).
52
74
 
53
75
  ## Contributing
54
76
 
@@ -2,23 +2,47 @@ require "yandex_locator/configuration"
2
2
 
3
3
  module YandexLocator
4
4
  module API
5
+ def post(url, options = {})
6
+ request :post, url, options
7
+ end
5
8
 
6
- class << self
9
+ def call
10
+ connection(url: YandexLocator.configuration.url_prefix)
11
+ end
7
12
 
8
- def call
9
- connection(url: YandexLocator.configuration.url_prefix)
13
+ def connection(url:)
14
+ Faraday.new(url) do |builder|
15
+ builder.request :url_encoded
16
+ builder.response :logger
17
+ builder.adapter Faraday.default_adapter
10
18
  end
19
+ end
11
20
 
12
- def connection(url: )
13
- Faraday.new(url) do |builder|
14
- builder.request :url_encoded
15
- builder.response :logger
16
- builder.adapter Faraday.default_adapter
17
- end
21
+ private
22
+
23
+ def request(method, path, data)
24
+ response = call.send(method) do |req|
25
+ req.url path
26
+ req.headers['Content-Type'] = 'application/json'
27
+ req.params['json'] = request_data(data).to_json
18
28
  end
19
29
 
30
+ pars_response(response.body)
20
31
  end
21
- end
22
- end
23
32
 
33
+ def request_data(data)
34
+ {
35
+ common:
36
+ {
37
+ version: YandexLocator.configuration.version,
38
+ api_key: YandexLocator.configuration.api_key
39
+ }
40
+ }.merge(data)
41
+ end
24
42
 
43
+ def pars_response(body)
44
+ data = JSON.parse(body)
45
+ OpenStruct.new(data)
46
+ end
47
+ end
48
+ end
@@ -1,41 +1,16 @@
1
+ require 'yandex_locator/api'
2
+
1
3
  module YandexLocator
2
4
  class Client
3
- def initialize
4
- @conn = YandexLocator::API.call
5
- end
5
+ include YandexLocator::API
6
6
 
7
- def lookup(ip: nil, mac: nil, cellid: nil, lac: nil, signal_strength: nil)
8
- result = @conn.post do |req|
9
- req.url '/geolocation'
10
- req.headers['Content-Type'] = 'application/json'
11
- req.params['json'] = insert_data(ip: ip, mac: mac, cellid: cellid, lac: lac, signal_strength: signal_strength).to_json
12
- end
13
-
14
- JSON.parse(result.body)
7
+ def initialize(api_key: nil, version: nil)
8
+ YandexLocator.configuration.api_key = api_key if api_key
9
+ YandexLocator.configuration.version = version if version
15
10
  end
16
11
 
17
- def insert_data(ip: , mac: , cellid: , lac: , signal_strength:)
18
- {common:
19
- {version: YandexLocator.configuration.version,
20
- api_key: YandexLocator.configuration.api_key
21
- },
22
- ip: {
23
- address_v4: ip
24
- },
25
- wifi_networks: [
26
- {
27
- mac: mac
28
- },
29
- gsm_cells: [
30
- {
31
- cellid: cellid,
32
- lac: lac,
33
- signal_strength: signal_strength,
34
- }
35
- ]
36
- ]
37
- }
12
+ def lookup(options = {})
13
+ post 'geolocation', options
38
14
  end
39
15
  end
40
16
  end
41
-
@@ -1,14 +1,16 @@
1
1
  module YandexLocator
2
2
  class Configuration
3
- # curl -H "Content-Type: application/json" -X POST -d 'json={"common":{"version":"1.0","api_key":"ABM6WU0BAAAANfFuIQIAV1pUEYIBeogyUNvVbhNaJPWeM-AAAAAAAAAAAACRXgDsaYNpZWpBczn4Lq6QmkwK6g=="},"gsm_cells":[{"countrycode":250,"operatorid":99,"cellid":42332,"lac":36002,"signal_strength":-80,"age":5555}],"wifi_networks":[{"mac":"00-1C-F0-E4-BB-F5","signal_strength":-88,"age":0}],"ip":{"address_v4":"178.247.233.32"}}' http://api.lbs.yandex.net/geolocation
4
3
  attr_accessor :api_key, :version, :url_prefix
5
4
 
5
+ DEFAULT_CONF = {
6
+ version: '1.0',
7
+ url_prefix: 'http://api.lbs.yandex.net'
8
+ }.freeze
9
+
6
10
  def initialize
7
11
  @key = nil
8
- @version = "1.0"
9
- @url_prefix = "http://api.lbs.yandex.net"
12
+ @version = DEFAULT_CONF[:version]
13
+ @url_prefix = DEFAULT_CONF[:url_prefix]
10
14
  end
11
-
12
15
  end
13
16
  end
14
-
@@ -1,3 +1,3 @@
1
1
  module YandexLocator
2
- VERSION = "0.2.0"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -1,10 +1,9 @@
1
1
  require 'faraday'
2
2
  require 'json'
3
-
4
- require "yandex_locator/version"
5
- require "yandex_locator/configuration"
6
- require "yandex_locator/client"
7
- require "yandex_locator/api"
3
+ require 'yandex_locator/version'
4
+ require 'yandex_locator/configuration'
5
+ require 'yandex_locator/client'
6
+ require 'yandex_locator/api'
8
7
 
9
8
  module YandexLocator
10
9
  class << self
@@ -22,5 +21,4 @@ module YandexLocator
22
21
  def self.configure
23
22
  yield(configuration)
24
23
  end
25
-
26
24
  end
@@ -17,15 +17,9 @@ Gem::Specification.new do |spec|
17
17
  spec.bindir = "exe"
18
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
19
  spec.require_paths = ["lib"]
20
- spec.required_ruby_version = '~> 2.3'
21
-
20
+ spec.required_ruby_version = '>= 2.0.0'
22
21
 
23
22
  spec.add_development_dependency "bundler", "~> 1.12"
24
- spec.add_development_dependency "rake", "~> 10.0"
25
- spec.add_development_dependency "rspec", "~> 3.0"
26
- spec.add_development_dependency 'pry-rails'
27
- spec.add_development_dependency 'codeclimate-test-reporter'
28
-
29
23
  spec.add_runtime_dependency 'faraday', '~> 0.9.2'
30
24
 
31
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yandex_locator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Chechaev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-09-25 00:00:00.000000000 Z
11
+ date: 2017-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -24,62 +24,6 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.12'
27
- - !ruby/object:Gem::Dependency
28
- name: rake
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '10.0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '10.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: '3.0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '3.0'
55
- - !ruby/object:Gem::Dependency
56
- name: pry-rails
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: codeclimate-test-reporter
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
27
  - !ruby/object:Gem::Dependency
84
28
  name: faraday
85
29
  requirement: !ruby/object:Gem::Requirement
@@ -124,9 +68,9 @@ require_paths:
124
68
  - lib
125
69
  required_ruby_version: !ruby/object:Gem::Requirement
126
70
  requirements:
127
- - - "~>"
71
+ - - ">="
128
72
  - !ruby/object:Gem::Version
129
- version: '2.3'
73
+ version: 2.0.0
130
74
  required_rubygems_version: !ruby/object:Gem::Requirement
131
75
  requirements:
132
76
  - - ">="