which_time 1.0.0 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +2 -0
- data/Gemfile +2 -0
- data/README.md +2 -2
- data/lib/which_time/version.rb +1 -1
- data/lib/which_time.rb +38 -8
- data/spec/spec_helper.rb +3 -0
- data/spec/which_time_spec.rb +5 -5
- data/which_time.gemspec +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de72fc7c56627b1802acd30fa6a4d1e620dcb935
|
4
|
+
data.tar.gz: d597da3ac66b21e718162187e4070891b285fd85
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f97a9da5ee792211612d03dee71ddf4fccc9f882999ca8865d6004514719269cf7ab1b1fce25422115af1c9cffb2b4289f612e6c3dd127b7b8212fcbbdb58c28
|
7
|
+
data.tar.gz: 3866111b56ff14587440c90087368369139352d2c239afae9d48f7d4896f1d4be387710c149900e63cd5a30af38e385e89c3d64c0b4982226f18deae6514fc40
|
data/.codeclimate.yml
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
# WhichTime
|
1
|
+
# WhichTime [![Gem Version](https://badge.fury.io/rb/which_time.svg)](http://badge.fury.io/rb/which_time) [![Code Climate](https://codeclimate.com/github/bmalets/which_time/badges/gpa.svg)](https://codeclimate.com/github/bmalets/which_time) [![Test Coverage](https://codeclimate.com/github/bmalets/which_time/badges/coverage.svg)](https://codeclimate.com/github/bmalets/which_time/coverage)
|
2
2
|
|
3
|
-
|
3
|
+
>Gem which gives you a simple way to find local time (timezone) of some place, address, city, region country or any other location which you want.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
data/lib/which_time/version.rb
CHANGED
data/lib/which_time.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
|
-
%W( which_time/version
|
1
|
+
%W( which_time/version uri net/http json tzinfo active_support/time).each{ |lib| require lib }
|
2
2
|
|
3
3
|
class WhichTime
|
4
4
|
|
5
|
-
def initialize address, api_key, time
|
6
|
-
@address
|
5
|
+
def initialize address, params={api_key: nil, time: Time.now, http_proxy: nil}
|
6
|
+
@address = address
|
7
|
+
@api_key = params[:api_key]
|
8
|
+
@timestamp = params[:time].to_i
|
9
|
+
@proxy = params[:http_proxy]
|
7
10
|
end
|
8
11
|
|
9
12
|
def location
|
@@ -22,14 +25,37 @@ class WhichTime
|
|
22
25
|
Time.at(@timestamp).in_time_zone timezone
|
23
26
|
end
|
24
27
|
|
25
|
-
def self.in address, api_key, time
|
26
|
-
new(address,
|
28
|
+
def self.in address, params={api_key: nil, time: Time.now, http_proxy: nil}
|
29
|
+
new(address, params).time
|
30
|
+
end
|
31
|
+
|
32
|
+
def proxy_host
|
33
|
+
URI.parse(@proxy).host if @proxy
|
34
|
+
end
|
35
|
+
|
36
|
+
def proxy_port
|
37
|
+
URI.parse(@proxy).port if @proxy
|
27
38
|
end
|
28
39
|
|
29
40
|
private
|
30
41
|
|
42
|
+
def with_proxy uri_path
|
43
|
+
http = Net::HTTP.new('maps.googleapis.com', 443, proxy_host, proxy_port)
|
44
|
+
http.use_ssl = true
|
45
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
46
|
+
http.get( uri_path.request_uri ).body
|
47
|
+
end
|
48
|
+
|
49
|
+
def without_proxy uri_path
|
50
|
+
Net::HTTP.get uri_path
|
51
|
+
end
|
52
|
+
|
53
|
+
def request_uri type, params
|
54
|
+
URI.parse("https://maps.googleapis.com/maps/api/#{type}/json?#{URI.encode_www_form(params)}")
|
55
|
+
end
|
56
|
+
|
31
57
|
def request type, params
|
32
|
-
|
58
|
+
send (@proxy ? 'with_proxy' : 'without_proxy'), request_uri(type, params)
|
33
59
|
end
|
34
60
|
|
35
61
|
def response type, params
|
@@ -37,11 +63,15 @@ class WhichTime
|
|
37
63
|
end
|
38
64
|
|
39
65
|
def get_location
|
40
|
-
response 'geocode', address: @address, key: @api_key
|
66
|
+
response 'geocode', address: @address.gsub(' ','+'), key: @api_key
|
41
67
|
end
|
42
68
|
|
43
69
|
def get_timezone
|
44
|
-
|
70
|
+
begin
|
71
|
+
response 'timezone', timestamp: @timestamp, location: coordinates, key: @api_key
|
72
|
+
rescue
|
73
|
+
""
|
74
|
+
end
|
45
75
|
end
|
46
76
|
|
47
77
|
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/which_time_spec.rb
CHANGED
@@ -3,14 +3,14 @@ require 'spec_helper'
|
|
3
3
|
describe WhichTime do
|
4
4
|
|
5
5
|
let(:address) { "Kyiv, str. Khmelnitskogo 3, pub 'Naturlih'" }
|
6
|
-
let(:api_key) { "
|
6
|
+
let(:api_key) { "AIzaSyC9CndnQRSgcI2qT_YCEXwpqwmv8Fml0p0" }
|
7
7
|
let(:sometime) { Time.new(2015, 7, 5, 9, 10) }
|
8
8
|
|
9
|
-
let(:whichtime) { WhichTime.new( address, api_key, sometime ) }
|
9
|
+
let(:whichtime) { WhichTime.new( address, api_key: api_key, time: sometime ) }
|
10
10
|
|
11
11
|
it "should be whichtime object with correct instance variables" do
|
12
|
-
expect( whichtime.instance_variable_get("@address") ).to eq(
|
13
|
-
expect( whichtime.instance_variable_get("@api_key") ).to eq(
|
12
|
+
expect( whichtime.instance_variable_get("@address") ).to eq( address )
|
13
|
+
expect( whichtime.instance_variable_get("@api_key") ).to eq( api_key )
|
14
14
|
expect( whichtime.instance_variable_get("@timestamp") ).to eq( sometime.to_i )
|
15
15
|
end
|
16
16
|
|
@@ -67,7 +67,7 @@ describe WhichTime do
|
|
67
67
|
end
|
68
68
|
|
69
69
|
it "should return correct time by address" do
|
70
|
-
result = WhichTime.in(address, api_key, sometime)
|
70
|
+
result = WhichTime.in(address, api_key: api_key, time: sometime)
|
71
71
|
expect( result.strftime("%Y-%m-%d %H:%M:%S") ).to eq( sometime.strftime("%Y-%m-%d %H:%M:%S") )
|
72
72
|
end
|
73
73
|
|
data/which_time.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["b.malets@gmail.com"]
|
11
11
|
spec.summary = %q{ search local time by your location }
|
12
12
|
spec.description = %q{ this gem provides a possibility to search local time by street/place_name/city/region/country e.g. }
|
13
|
-
spec.homepage = "https://github.com/bmalets/which_time"
|
13
|
+
spec.homepage = "https://github.com/bmalets/which_time/wiki"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: which_time
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- bmalets
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -88,6 +88,7 @@ executables: []
|
|
88
88
|
extensions: []
|
89
89
|
extra_rdoc_files: []
|
90
90
|
files:
|
91
|
+
- ".codeclimate.yml"
|
91
92
|
- ".gitignore"
|
92
93
|
- Gemfile
|
93
94
|
- LICENSE.txt
|
@@ -98,7 +99,7 @@ files:
|
|
98
99
|
- spec/spec_helper.rb
|
99
100
|
- spec/which_time_spec.rb
|
100
101
|
- which_time.gemspec
|
101
|
-
homepage: https://github.com/bmalets/which_time
|
102
|
+
homepage: https://github.com/bmalets/which_time/wiki
|
102
103
|
licenses:
|
103
104
|
- MIT
|
104
105
|
metadata: {}
|
@@ -118,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
119
|
version: '0'
|
119
120
|
requirements: []
|
120
121
|
rubyforge_project:
|
121
|
-
rubygems_version: 2.
|
122
|
+
rubygems_version: 2.4.6
|
122
123
|
signing_key:
|
123
124
|
specification_version: 4
|
124
125
|
summary: search local time by your location
|