yandex_locator 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 92d161904fed1aaf07a644c876a53ad1fd06b56d
4
+ data.tar.gz: c125f216f44388473c7dd23fd0b6940382b3a02c
5
+ SHA512:
6
+ metadata.gz: ddf60646cf08c0473c644bb24437792558c03feafeaa1c7efab7d04f740c643fe2a75e2e8f743e1e27ff92245ab0a60df6cf3b571a907662301ed7625f5f8847
7
+ data.tar.gz: 3bfc57ab6efbe5a3f69434bafd34621a7ff56f140a319a2e2d53d7d8143238335c2adc1e4468cb54e6bd21d4c7d9a8ae2c186e9ef0df0636a571706f4cde9bcc
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ .ruby-version
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.0.0
5
+ before_install: gem install bundler -v 1.12.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in yandex_locator.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # YandexLocator
2
+
3
+ Ruby gem for Yandex locator (https://tech.yandex.ru/locator/). Yandex locator servic that find mobile devices in a region delineated by a circle. Service return longitude, latitude and precision.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'yandex_locator'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install yandex_locator
20
+
21
+ ## Usage
22
+
23
+ Configure gem credentials
24
+
25
+ ```ruby
26
+ YandexLocator.configure do |config|
27
+ config.api_key = ENV['YANDEX_API_KEY']
28
+ config.version = "1.0"
29
+ end
30
+ ```
31
+
32
+ Make request
33
+
34
+ ```ruby
35
+ conn = YandexLocator::Client.new
36
+ result = conn.lookup(ip: "109.252.52.39")
37
+ ```
38
+
39
+
40
+ ## Development
41
+
42
+ 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.
43
+
44
+ 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).
45
+
46
+ ## Contributing
47
+
48
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/yandex_locator.
49
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "yandex_locator"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,24 @@
1
+ require "yandex_locator/configuration"
2
+
3
+ module YandexLocator
4
+ module API
5
+
6
+ class << self
7
+
8
+ def call
9
+ connection(url: YandexLocator.configuration.url_prefix)
10
+ end
11
+
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
18
+ end
19
+
20
+ end
21
+ end
22
+ end
23
+
24
+
@@ -0,0 +1,29 @@
1
+ module YandexLocator
2
+ class Client
3
+ def initialize
4
+ @conn = YandexLocator::API.call
5
+ end
6
+
7
+ def lookup(ip: )
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).to_json
12
+ end
13
+
14
+ JSON.parse(result.body)
15
+ end
16
+
17
+ def insert_data(ip: )
18
+ {common:
19
+ {version: YandexLocator.configuration.version,
20
+ api_key: YandexLocator.configuration.api_key
21
+ },
22
+ ip: {
23
+ address_v4: ip
24
+ }
25
+ }
26
+ end
27
+ end
28
+ end
29
+
@@ -0,0 +1,14 @@
1
+ module YandexLocator
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
+ attr_accessor :api_key, :version, :url_prefix
5
+
6
+ def initialize
7
+ @key = nil
8
+ @version = "1.0"
9
+ @url_prefix = "http://api.lbs.yandex.net"
10
+ end
11
+
12
+ end
13
+ end
14
+
@@ -0,0 +1,3 @@
1
+ module YandexLocator
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,26 @@
1
+ require 'faraday'
2
+ require 'json'
3
+
4
+ require "yandex_locator/version"
5
+ require "yandex_locator/configuration"
6
+ require "yandex_locator/client"
7
+ require "yandex_locator/api"
8
+
9
+ module YandexLocator
10
+ class << self
11
+ attr_accessor :configuration
12
+ end
13
+
14
+ def self.configuration
15
+ @configuration ||= Configuration.new
16
+ end
17
+
18
+ def self.reset
19
+ @configuration = Configuration.new
20
+ end
21
+
22
+ def self.configure
23
+ yield(configuration)
24
+ end
25
+
26
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'yandex_locator/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "yandex_locator"
8
+ spec.version = YandexLocator::VERSION
9
+ spec.authors = ["Sergey Chechaev"]
10
+ spec.email = ["kompotdrinker@gmail.com"]
11
+
12
+ spec.summary = %q{ruby gem for yandex locator}
13
+ spec.description = %q{ruby gem for yandex locator}
14
+ spec.homepage = "https://github.com/sergey-chechaev/yandex_locator.git"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+ spec.required_ruby_version = '~> 2.0'
21
+
22
+
23
+ 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
+
28
+ spec.add_runtime_dependency 'faraday', '~> 0.9.2'
29
+
30
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yandex_locator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sergey Chechaev
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-08-25 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.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
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: faraday
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.9.2
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.9.2
83
+ description: ruby gem for yandex locator
84
+ email:
85
+ - kompotdrinker@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - README.md
95
+ - Rakefile
96
+ - bin/console
97
+ - bin/setup
98
+ - lib/yandex_locator.rb
99
+ - lib/yandex_locator/api.rb
100
+ - lib/yandex_locator/client.rb
101
+ - lib/yandex_locator/configuration.rb
102
+ - lib/yandex_locator/version.rb
103
+ - yandex_locator.gemspec
104
+ homepage: https://github.com/sergey-chechaev/yandex_locator.git
105
+ licenses: []
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - "~>"
114
+ - !ruby/object:Gem::Version
115
+ version: '2.0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.2.2
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: ruby gem for yandex locator
127
+ test_files: []