Git Product home page Git Product logo

google_timezone's Introduction

GoogleTimezone

Small gem to get timezone info by known coordinates using google timezone api.

Installation

Add this line to your application's Gemfile:

gem 'google_timezone'

And then execute:

$ bundle

Or install it yourself as:

$ gem install google_timezone

Usage

You can pass latitude and longitude to gem in several ways: with array or separated values.

GoogleTimezone.fetch([latitude, longitude]) 
GoogleTimezone.fetch(latitude, longitude) 

Any other options which are described in google's documentation you can pass via options hash

GoogleTimezone.fetch(latitude, longitude, language: 'en', signature: 'key')

It uses latitude and longitude to retrieve timezone info.

result = GoogleTimezone.fetch(50.1196004, 8.679918299999999)
result.time_zone_name => 'Europe/Berlin'

It will get GoogleTimezone::Result object which maps major google api responce items named in snake case. More information here Also there is GoogleTimezone::Result#success? method. It returns true if responce was successful.

The bang version fetch! raises an GoogleTimezone::Error exception with error message if response from Google wasn't success.

Usage in tests/specs

During tests, you probably don't want to make remote calls. To achieve this, you should set a default stub in your test/spec helper file, e.g.:

# spec/support/google_timezone.rb
GoogleTimezone.set_default_stub(
  'dstOffset' => 3600,
  'rawOffset' => -10800,
  'status' => 'OK',
  'timeZoneId' => 'America/Sao_Paulo',
  'timeZoneName' => 'Brasilia Summer Time'
)

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

google_timezone's People

Contributors

exviva avatar ledermann avatar rringler avatar salmanasiddiqui avatar sck-v avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

google_timezone's Issues

Gem file not updated

Can you update the gem file to the latest version? I'm linking to the github master right now so I can access the set_default_stub method but I'm not sure if that means it's unstable.

Thanks

getting SSL error

$ rails c
Loading development environment (Rails 4.0.0)
irb(main):001:0> GoogleTimezone.fetch(50.1196004, 8.679918299999999)
OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed
from c:/Ruby200/lib/ruby/2.0.0/net/http.rb:918:in `connect'

Undefined method 'raise_error'

When the result from Google is not a success the gem attempts to call raise_error in base.rb. I don't see this method defined in the gem at all so not sure where it was expecting that to come from.

NoMethodError: undefined method `raise_error' for #<GoogleTimezone::Base:0x...>

How about a little bit of documentation?

Hello, I do appreciate your providing this for us to use, but.. how about a little better description than GoogleTimezone(50, 6.7) ?
For example, how do you extract the timezone from that?
Why is there virtually no wiki?
Which of those numbers are expected to be lat, and which is long (I realize we can tell from the values you used in your example, but it could be a bit more explicit).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.