geolocation 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/geolocation.rb +76 -0
  3. metadata +43 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4c2b7a1dc59d8790c665d14511e86de528ac82f5c2657381d3a07352249e8795
4
+ data.tar.gz: 228f97f4cb78d53fe0f115917f9d7174562fbd211b7dfedb13173ca09d9daf73
5
+ SHA512:
6
+ metadata.gz: aa5cc9f831ed499dca7b82285b195876fa30ee5f1643d9f4407a23abf32847796811e6ba50f0ef0cbb82c035cf183d0dad50ecf375915e21e2ce02bd7a8ecb94
7
+ data.tar.gz: e9c780147a543842059e5e32189220b18c7f6789088aa74537488a0e8a5de68e6166f711e85f4657fde679dd9642ffac991ca8cb9f858fa2bdf4271e4f24a27c
@@ -0,0 +1,76 @@
1
+ require 'net/http'
2
+ require 'json'
3
+
4
+ class Geolocation
5
+
6
+ attr_accessor :report
7
+
8
+ def initialize(token, &report_type)
9
+ @report = report_type
10
+ @token = token
11
+ end
12
+
13
+ def get_location_by_place(place)
14
+ retrieve_data("https://us1.locationiq.com/v1/search.php?key=#{@token}&q=#{place}&format=json")
15
+ end
16
+
17
+ def get_location_by_coordenates(latitude, longitude)
18
+ retrieve_data("https://us1.locationiq.com/v1/reverse.php?key=#{@token}&lat=#{latitude}&lon=#{longitude}&format=json")
19
+ end
20
+
21
+ def get_nerby_countries(latitude, longitude, radius)
22
+ retrieve_data("https://us1.locationiq.com/v1/nearby.php?key=#{@token}&lat=#{latitude}&lon=#{longitude}&tag=countries&radius=#{radius}&format=json")
23
+ end
24
+
25
+ def get_points_of_interest(latitude, longitude, radius, point)
26
+ retrieve_data("https://us1.locationiq.com/v1/nearby.php?key=#{@token}&lat=#{latitude}&lon=#{longitude}&tag=#{point}&radius=#{radius}&format=json")
27
+ end
28
+
29
+ def give_format_to_response(data, position = 0)
30
+ position == 0 ? @report.call(data) : @report.call(data,position)
31
+ end
32
+
33
+ def retrieve_data(url)
34
+ uri = URI(url)
35
+ data = Net::HTTP.get_response(uri)
36
+ parseData(data.body)
37
+ end
38
+
39
+ def save_data_in_file(filename, text)
40
+ file = File.new(filename, "w")
41
+ file.puts text
42
+ file.close
43
+ end
44
+
45
+ def parseData(data)
46
+ JSON.parse(data)
47
+ end
48
+
49
+ private :parseData, :retrieve_data
50
+
51
+ end
52
+
53
+ dataWithKeys = lambda do |data|
54
+ text ="Data report: \n"
55
+ data[0].each do |key, value|
56
+ text += "#{key}: #{value}\n"
57
+ end
58
+ return text
59
+ end
60
+
61
+ points_of_interests = lambda do |data|
62
+ text = "data report\n"
63
+ data.each do |point|
64
+ point.each do |key,value|
65
+ text += "#{key}:#{value}\n"
66
+ end
67
+ text += "-----------\n"
68
+ end
69
+ return text
70
+ end
71
+
72
+
73
+
74
+
75
+
76
+
metadata ADDED
@@ -0,0 +1,43 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: geolocation
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Cesar Magallon
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-02-04 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A gem which retrieves information about the place or coordinates provided
14
+ email: cesar9mv@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/geolocation.rb
20
+ homepage: https://rubygems.org/gems/geolocation
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubygems_version: 3.0.6
40
+ signing_key:
41
+ specification_version: 4
42
+ summary: Geolocation gem
43
+ test_files: []