which_time 1.0.0 → 1.0.3

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: 3979b846b87f8685c2affed89b036eae71f061fa
4
- data.tar.gz: 13674a268709d7cf271ceb272eca3210365a3f50
3
+ metadata.gz: de72fc7c56627b1802acd30fa6a4d1e620dcb935
4
+ data.tar.gz: d597da3ac66b21e718162187e4070891b285fd85
5
5
  SHA512:
6
- metadata.gz: ad43a30259e1a5170156fff38a0a954deb53769685a3c790dd1777d79fe1439ad6f73078b373e8d852bee29de35dd4ada6c7af31d6ab77af63bdf6cd7ad1362a
7
- data.tar.gz: 1c241ec910dcfa1d239598662845f6470fbcc93d72036a5b74d6ed7a19eff26f1a238a9ab3e18e8b277a274afe5df5416eac7899a8e31a856b69408bc209e1b5
6
+ metadata.gz: f97a9da5ee792211612d03dee71ddf4fccc9f882999ca8865d6004514719269cf7ab1b1fce25422115af1c9cffb2b4289f612e6c3dd127b7b8212fcbbdb58c28
7
+ data.tar.gz: 3866111b56ff14587440c90087368369139352d2c239afae9d48f7d4896f1d4be387710c149900e63cd5a30af38e385e89c3d64c0b4982226f18deae6514fc40
data/.codeclimate.yml ADDED
@@ -0,0 +1,2 @@
1
+ languages:
2
+ Ruby: true
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in which_time.gemspec
4
4
  gemspec
5
+
6
+ gem "codeclimate-test-reporter", group: :test, require: nil
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
- Gem which gives you a simple way to find local time (timezone) of some place/address/city/region/country.
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
 
@@ -1,3 +1,3 @@
1
1
  class WhichTime
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.3"
3
3
  end
data/lib/which_time.rb CHANGED
@@ -1,9 +1,12 @@
1
- %W( which_time/version net/http uri net/http json tzinfo active_support/time).each{ |lib| require lib }
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=Time.now
6
- @address, @api_key, @timestamp = address.gsub(' ','+'), api_key, time.to_i
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=Time.new
26
- new(address, api_key, time).time
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
- Net::HTTP.get URI.parse("https://maps.googleapis.com/maps/api/#{type}/json?#{URI.encode_www_form(params)}")
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
- response 'timezone', timestamp: @timestamp, location: coordinates, key: @api_key
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
@@ -1,6 +1,9 @@
1
1
  require 'bundler/setup'
2
2
  Bundler.setup
3
3
 
4
+ require "codeclimate-test-reporter"
5
+ CodeClimate::TestReporter.start
6
+
4
7
  require 'which_time' # and any other gems you need
5
8
 
6
9
  RSpec.configure do |config|
@@ -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) { "AIzaSyCqfXRRJ1d8mCS_I0Kcs4XnaZ9KYRUrJVE" }
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( "Kyiv,+str.+Khmelnitskogo+3,+pub+'Naturlih'" )
13
- expect( whichtime.instance_variable_get("@api_key") ).to eq( "AIzaSyCqfXRRJ1d8mCS_I0Kcs4XnaZ9KYRUrJVE" )
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.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-06 00:00:00.000000000 Z
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.2.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