timezone_detection 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -6,7 +6,7 @@ This gem used for setting client's timezone based on his/her IP.
6
6
 
7
7
  Write it in your Gemfile
8
8
 
9
- gem "timezone_detection"
9
+ gem "timezone_detection", '~> 0.0.3'
10
10
 
11
11
  Next, execute following sequences of commands:
12
12
 
@@ -17,6 +17,7 @@ module TimezoneDetection
17
17
 
18
18
  def get_timezone_offset(ip)
19
19
  begin
20
+ raise if ip == "127.0.0.1"
20
21
  response = Net::HTTP.get(URI("http://api.ipinfodb.com/v3/ip-city/?key=#{api_key}&ip=#{ip}&format=json"))
21
22
  json = ActiveSupport::JSON.decode(response)
22
23
  if json["statusCode"] == STATUS_CODES::SUCCESS
@@ -28,7 +29,7 @@ module TimezoneDetection
28
29
  #TODO make output to Rails logger
29
30
  puts e.message
30
31
  "Request to http://www.ipinfodb.com/ failed. Please try later!"
31
- 0
32
+ Time.new.utc_offset / 60 / 60
32
33
  end
33
34
  end
34
35
 
@@ -1,3 +1,3 @@
1
1
  module TimezoneDetection
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -764,3 +764,176 @@ Connecting to database specified by database.yml
764
764
   (0.1ms) rollback transaction
765
765
   (0.1ms) begin transaction
766
766
   (0.0ms) rollback transaction
767
+ Connecting to database specified by database.yml
768
+ Connecting to database specified by database.yml
769
+  (1.5ms) begin transaction
770
+  (0.1ms) rollback transaction
771
+  (0.1ms) begin transaction
772
+  (0.1ms) rollback transaction
773
+  (0.1ms) begin transaction
774
+ TimezoneDetection::IpTimezone Load (0.1ms) SELECT "timezone_detection_ip_timezones".* FROM "timezone_detection_ip_timezones"
775
+  (0.1ms) SAVEPOINT active_record_1
776
+ TimezoneDetection::IpTimezone Exists (0.2ms) SELECT 1 AS one FROM "timezone_detection_ip_timezones" WHERE "timezone_detection_ip_timezones"."ip_in_longint" = 1245284686 LIMIT 1
777
+ SQL (5.6ms) INSERT INTO "timezone_detection_ip_timezones" ("ip_in_longint", "utc_offset") VALUES (?, ?) [["ip_in_longint", 1245284686], ["utc_offset", 3]]
778
+  (0.1ms) RELEASE SAVEPOINT active_record_1
779
+  (0.1ms) SELECT COUNT(*) FROM "timezone_detection_ip_timezones" 
780
+  (0.2ms) rollback transaction
781
+  (0.1ms) begin transaction
782
+  (0.0ms) SAVEPOINT active_record_1
783
+ TimezoneDetection::IpTimezone Exists (0.2ms) SELECT 1 AS one FROM "timezone_detection_ip_timezones" WHERE "timezone_detection_ip_timezones"."ip_in_longint" = 1245284686 LIMIT 1
784
+ SQL (0.2ms) INSERT INTO "timezone_detection_ip_timezones" ("ip_in_longint", "utc_offset") VALUES (?, ?) [["ip_in_longint", 1245284686], ["utc_offset", 3]]
785
+  (0.1ms) RELEASE SAVEPOINT active_record_1
786
+  (0.0ms) SAVEPOINT active_record_1
787
+ TimezoneDetection::IpTimezone Exists (0.2ms) SELECT 1 AS one FROM "timezone_detection_ip_timezones" WHERE "timezone_detection_ip_timezones"."ip_in_longint" = 1245284686 LIMIT 1
788
+  (0.1ms) ROLLBACK TO SAVEPOINT active_record_1
789
+  (0.1ms) SELECT COUNT(*) FROM "timezone_detection_ip_timezones" 
790
+  (0.3ms) rollback transaction
791
+  (0.1ms) begin transaction
792
+  (0.1ms) rollback transaction
793
+  (0.1ms) begin transaction
794
+  (0.1ms) rollback transaction
795
+ Connecting to database specified by database.yml
796
+  (0.6ms) begin transaction
797
+  (0.1ms) rollback transaction
798
+  (0.1ms) begin transaction
799
+  (0.1ms) rollback transaction
800
+  (0.0ms) begin transaction
801
+ TimezoneDetection::IpTimezone Load (0.1ms) SELECT "timezone_detection_ip_timezones".* FROM "timezone_detection_ip_timezones"
802
+  (0.1ms) SAVEPOINT active_record_1
803
+ TimezoneDetection::IpTimezone Exists (0.2ms) SELECT 1 AS one FROM "timezone_detection_ip_timezones" WHERE "timezone_detection_ip_timezones"."ip_in_longint" = 1245284686 LIMIT 1
804
+ SQL (5.6ms) INSERT INTO "timezone_detection_ip_timezones" ("ip_in_longint", "utc_offset") VALUES (?, ?) [["ip_in_longint", 1245284686], ["utc_offset", 3]]
805
+  (0.1ms) RELEASE SAVEPOINT active_record_1
806
+  (0.1ms) SELECT COUNT(*) FROM "timezone_detection_ip_timezones" 
807
+  (0.2ms) rollback transaction
808
+  (0.1ms) begin transaction
809
+  (0.0ms) SAVEPOINT active_record_1
810
+ TimezoneDetection::IpTimezone Exists (0.2ms) SELECT 1 AS one FROM "timezone_detection_ip_timezones" WHERE "timezone_detection_ip_timezones"."ip_in_longint" = 1245284686 LIMIT 1
811
+ SQL (0.2ms) INSERT INTO "timezone_detection_ip_timezones" ("ip_in_longint", "utc_offset") VALUES (?, ?) [["ip_in_longint", 1245284686], ["utc_offset", 3]]
812
+  (0.1ms) RELEASE SAVEPOINT active_record_1
813
+  (0.0ms) SAVEPOINT active_record_1
814
+ TimezoneDetection::IpTimezone Exists (0.2ms) SELECT 1 AS one FROM "timezone_detection_ip_timezones" WHERE "timezone_detection_ip_timezones"."ip_in_longint" = 1245284686 LIMIT 1
815
+  (0.1ms) ROLLBACK TO SAVEPOINT active_record_1
816
+  (0.1ms) SELECT COUNT(*) FROM "timezone_detection_ip_timezones" 
817
+  (0.2ms) rollback transaction
818
+  (0.1ms) begin transaction
819
+  (0.1ms) rollback transaction
820
+  (0.1ms) begin transaction
821
+  (0.1ms) rollback transaction
822
+  (0.1ms) begin transaction
823
+  (0.0ms) rollback transaction
824
+ Connecting to database specified by database.yml
825
+  (0.6ms) begin transaction
826
+  (0.1ms) rollback transaction
827
+  (0.1ms) begin transaction
828
+  (0.1ms) rollback transaction
829
+  (0.1ms) begin transaction
830
+ TimezoneDetection::IpTimezone Load (0.1ms) SELECT "timezone_detection_ip_timezones".* FROM "timezone_detection_ip_timezones"
831
+  (0.1ms) SAVEPOINT active_record_1
832
+ TimezoneDetection::IpTimezone Exists (0.2ms) SELECT 1 AS one FROM "timezone_detection_ip_timezones" WHERE "timezone_detection_ip_timezones"."ip_in_longint" = 1245284686 LIMIT 1
833
+ SQL (6.1ms) INSERT INTO "timezone_detection_ip_timezones" ("ip_in_longint", "utc_offset") VALUES (?, ?) [["ip_in_longint", 1245284686], ["utc_offset", 3]]
834
+  (0.1ms) RELEASE SAVEPOINT active_record_1
835
+  (0.1ms) SELECT COUNT(*) FROM "timezone_detection_ip_timezones" 
836
+  (0.2ms) rollback transaction
837
+  (0.1ms) begin transaction
838
+  (0.1ms) SAVEPOINT active_record_1
839
+ TimezoneDetection::IpTimezone Exists (0.2ms) SELECT 1 AS one FROM "timezone_detection_ip_timezones" WHERE "timezone_detection_ip_timezones"."ip_in_longint" = 1245284686 LIMIT 1
840
+ SQL (0.2ms) INSERT INTO "timezone_detection_ip_timezones" ("ip_in_longint", "utc_offset") VALUES (?, ?) [["ip_in_longint", 1245284686], ["utc_offset", 3]]
841
+  (0.1ms) RELEASE SAVEPOINT active_record_1
842
+  (0.0ms) SAVEPOINT active_record_1
843
+ TimezoneDetection::IpTimezone Exists (0.1ms) SELECT 1 AS one FROM "timezone_detection_ip_timezones" WHERE "timezone_detection_ip_timezones"."ip_in_longint" = 1245284686 LIMIT 1
844
+  (0.1ms) ROLLBACK TO SAVEPOINT active_record_1
845
+  (0.1ms) SELECT COUNT(*) FROM "timezone_detection_ip_timezones" 
846
+  (0.2ms) rollback transaction
847
+  (0.1ms) begin transaction
848
+  (0.1ms) rollback transaction
849
+  (0.1ms) begin transaction
850
+  (0.1ms) rollback transaction
851
+  (0.1ms) begin transaction
852
+  (0.0ms) rollback transaction
853
+ Connecting to database specified by database.yml
854
+  (0.6ms) begin transaction
855
+  (0.1ms) rollback transaction
856
+  (0.1ms) begin transaction
857
+  (0.2ms) rollback transaction
858
+  (0.1ms) begin transaction
859
+ TimezoneDetection::IpTimezone Load (0.1ms) SELECT "timezone_detection_ip_timezones".* FROM "timezone_detection_ip_timezones"
860
+  (0.1ms) SAVEPOINT active_record_1
861
+ TimezoneDetection::IpTimezone Exists (0.2ms) SELECT 1 AS one FROM "timezone_detection_ip_timezones" WHERE "timezone_detection_ip_timezones"."ip_in_longint" = 1245284686 LIMIT 1
862
+ SQL (5.7ms) INSERT INTO "timezone_detection_ip_timezones" ("ip_in_longint", "utc_offset") VALUES (?, ?) [["ip_in_longint", 1245284686], ["utc_offset", 3]]
863
+  (0.1ms) RELEASE SAVEPOINT active_record_1
864
+  (0.1ms) SELECT COUNT(*) FROM "timezone_detection_ip_timezones" 
865
+  (0.2ms) rollback transaction
866
+  (0.1ms) begin transaction
867
+  (0.1ms) SAVEPOINT active_record_1
868
+ TimezoneDetection::IpTimezone Exists (0.2ms) SELECT 1 AS one FROM "timezone_detection_ip_timezones" WHERE "timezone_detection_ip_timezones"."ip_in_longint" = 1245284686 LIMIT 1
869
+ SQL (0.2ms) INSERT INTO "timezone_detection_ip_timezones" ("ip_in_longint", "utc_offset") VALUES (?, ?) [["ip_in_longint", 1245284686], ["utc_offset", 3]]
870
+  (0.1ms) RELEASE SAVEPOINT active_record_1
871
+  (0.0ms) SAVEPOINT active_record_1
872
+ TimezoneDetection::IpTimezone Exists (0.1ms) SELECT 1 AS one FROM "timezone_detection_ip_timezones" WHERE "timezone_detection_ip_timezones"."ip_in_longint" = 1245284686 LIMIT 1
873
+  (0.1ms) ROLLBACK TO SAVEPOINT active_record_1
874
+  (0.1ms) SELECT COUNT(*) FROM "timezone_detection_ip_timezones" 
875
+  (0.2ms) rollback transaction
876
+  (0.1ms) begin transaction
877
+  (0.2ms) rollback transaction
878
+  (0.1ms) begin transaction
879
+  (0.1ms) rollback transaction
880
+  (0.1ms) begin transaction
881
+  (0.1ms) rollback transaction
882
+ Connecting to database specified by database.yml
883
+  (0.6ms) begin transaction
884
+  (0.1ms) rollback transaction
885
+  (0.1ms) begin transaction
886
+  (0.1ms) rollback transaction
887
+  (0.1ms) begin transaction
888
+ TimezoneDetection::IpTimezone Load (0.1ms) SELECT "timezone_detection_ip_timezones".* FROM "timezone_detection_ip_timezones"
889
+  (0.1ms) SAVEPOINT active_record_1
890
+ TimezoneDetection::IpTimezone Exists (0.2ms) SELECT 1 AS one FROM "timezone_detection_ip_timezones" WHERE "timezone_detection_ip_timezones"."ip_in_longint" = 1245284686 LIMIT 1
891
+ SQL (5.6ms) INSERT INTO "timezone_detection_ip_timezones" ("ip_in_longint", "utc_offset") VALUES (?, ?) [["ip_in_longint", 1245284686], ["utc_offset", 3]]
892
+  (0.1ms) RELEASE SAVEPOINT active_record_1
893
+  (0.1ms) SELECT COUNT(*) FROM "timezone_detection_ip_timezones" 
894
+  (0.2ms) rollback transaction
895
+  (0.1ms) begin transaction
896
+  (0.1ms) SAVEPOINT active_record_1
897
+ TimezoneDetection::IpTimezone Exists (0.2ms) SELECT 1 AS one FROM "timezone_detection_ip_timezones" WHERE "timezone_detection_ip_timezones"."ip_in_longint" = 1245284686 LIMIT 1
898
+ SQL (0.2ms) INSERT INTO "timezone_detection_ip_timezones" ("ip_in_longint", "utc_offset") VALUES (?, ?) [["ip_in_longint", 1245284686], ["utc_offset", 3]]
899
+  (0.1ms) RELEASE SAVEPOINT active_record_1
900
+  (0.1ms) SAVEPOINT active_record_1
901
+ TimezoneDetection::IpTimezone Exists (0.1ms) SELECT 1 AS one FROM "timezone_detection_ip_timezones" WHERE "timezone_detection_ip_timezones"."ip_in_longint" = 1245284686 LIMIT 1
902
+  (0.1ms) ROLLBACK TO SAVEPOINT active_record_1
903
+  (0.1ms) SELECT COUNT(*) FROM "timezone_detection_ip_timezones" 
904
+  (0.2ms) rollback transaction
905
+  (0.1ms) begin transaction
906
+  (0.1ms) rollback transaction
907
+  (0.1ms) begin transaction
908
+  (0.1ms) rollback transaction
909
+  (0.1ms) begin transaction
910
+  (0.1ms) rollback transaction
911
+ Connecting to database specified by database.yml
912
+  (0.6ms) begin transaction
913
+  (0.1ms) rollback transaction
914
+  (0.1ms) begin transaction
915
+  (0.1ms) rollback transaction
916
+  (0.1ms) begin transaction
917
+ TimezoneDetection::IpTimezone Load (0.1ms) SELECT "timezone_detection_ip_timezones".* FROM "timezone_detection_ip_timezones"
918
+  (0.1ms) SAVEPOINT active_record_1
919
+ TimezoneDetection::IpTimezone Exists (0.2ms) SELECT 1 AS one FROM "timezone_detection_ip_timezones" WHERE "timezone_detection_ip_timezones"."ip_in_longint" = 1245284686 LIMIT 1
920
+ SQL (5.5ms) INSERT INTO "timezone_detection_ip_timezones" ("ip_in_longint", "utc_offset") VALUES (?, ?) [["ip_in_longint", 1245284686], ["utc_offset", 3]]
921
+  (0.1ms) RELEASE SAVEPOINT active_record_1
922
+  (0.1ms) SELECT COUNT(*) FROM "timezone_detection_ip_timezones" 
923
+  (0.2ms) rollback transaction
924
+  (0.1ms) begin transaction
925
+  (0.0ms) SAVEPOINT active_record_1
926
+ TimezoneDetection::IpTimezone Exists (0.2ms) SELECT 1 AS one FROM "timezone_detection_ip_timezones" WHERE "timezone_detection_ip_timezones"."ip_in_longint" = 1245284686 LIMIT 1
927
+ SQL (0.2ms) INSERT INTO "timezone_detection_ip_timezones" ("ip_in_longint", "utc_offset") VALUES (?, ?) [["ip_in_longint", 1245284686], ["utc_offset", 3]]
928
+  (0.1ms) RELEASE SAVEPOINT active_record_1
929
+  (0.0ms) SAVEPOINT active_record_1
930
+ TimezoneDetection::IpTimezone Exists (0.1ms) SELECT 1 AS one FROM "timezone_detection_ip_timezones" WHERE "timezone_detection_ip_timezones"."ip_in_longint" = 1245284686 LIMIT 1
931
+  (0.1ms) ROLLBACK TO SAVEPOINT active_record_1
932
+  (0.1ms) SELECT COUNT(*) FROM "timezone_detection_ip_timezones" 
933
+  (0.2ms) rollback transaction
934
+  (0.1ms) begin transaction
935
+  (0.1ms) rollback transaction
936
+  (0.1ms) begin transaction
937
+  (0.1ms) rollback transaction
938
+  (0.1ms) begin transaction
939
+  (0.0ms) rollback transaction
@@ -23,6 +23,12 @@ class TimezoneDetectionTest < ActiveSupport::TestCase
23
23
  assert_equal 3, ip_info.get_timezone_offset(ip)
24
24
  end
25
25
 
26
+ test "timezone lookup by local IP" do
27
+ ip = "127.0.0.1"
28
+ ip_info = TimezoneDetection::IpInfoDB.new
29
+ assert_equal Time.new.utc_offset / 60 / 60, ip_info.get_timezone_offset(ip)
30
+ end
31
+
26
32
  test "ip_timezone record creation" do
27
33
  ip = "78.137.57.74"
28
34
  TimezoneDetection::IpTimezone.destroy_all
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timezone_detection
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,39 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
  date: 2012-08-09 00:00:00.000000000 Z
13
- dependencies: []
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - '='
20
+ - !ruby/object:Gem::Version
21
+ version: 3.2.7
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - '='
28
+ - !ruby/object:Gem::Version
29
+ version: 3.2.7
30
+ - !ruby/object:Gem::Dependency
31
+ name: sqlite3
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
14
46
  description: Visit https://github.com/Bor1s/timezone-detection for more information.
15
47
  email:
16
48
  - boris.bbk@gmail.com