Module: WorldTimeApi

Defined in:
lib/world_time_api.rb,
lib/world_time_api/error.rb,
lib/world_time_api/request.rb,
lib/world_time_api/version.rb,
lib/world_time_api/response.rb

Overview

A Ruby wrapper for the World Time API.

Defined Under Namespace

Modules: Request

Constant Summary collapse

Timezones =

Returns a list of all timezones supported by the World Time API.

Examples:

WorldTimeApi::Timezones.call

Returns:

  • (Hash)

    A hash representing the response body, or an error hash if there was a problem with the request.

-> { Request::Call["/timezone"] }
Time =

Returns the current time for the specified timezone.

Examples:

WorldTimeApi::Time.call('Europe/London')

Returns:

  • (Hash)

    A hash representing the response body, or an error hash if there was a problem with the request.

->(timezone) { Request::Call["/timezone/#{timezone}"] }
ClientIp =

Returns the current time for the client’s IP address, or for the specified IP address if provided.

Examples:

WorldTimeApi::ClientIp.call('127.0.0.1')

Returns:

  • (Hash)

    A hash representing the response body, or an error hash if there was a problem with the request.

->(ip = nil) { Request::Call["/ip#{ip ? "/#{ip}" : ""}"] }
AreaTimezones =

Returns a list of all timezones for a given area.

Examples:

WorldTimeApi::AreaTimezones.call('Europe')

Returns:

  • (Hash)

    Hash with the response body or error hash.

->(area) { Request::Call["/timezone/#{area}"] }
LocationTimezones =

Returns a list of all timezones for a given area and location.

Examples:

WorldTimeApi::LocationTimezones.call('America', 'Sao_Paulo')

Returns:

  • (Hash)

    Hash with the response body or error hash.

->(area, location) { Request::Call["/timezone/#{area}/#{location}"] }
RegionTime =

Returns the current time for a given area, location, and region.

Examples:

WorldTimeApi::RegionTime.call('America', 'Argentina', 'Salta')

Returns:

  • (Hash)

    Hash with the response body or error hash.

->(area, location, region) { Request::Call["/timezone/#{area}/#{location}/#{region}"] }
TimezonesTxt =

Returns a list of all timezones in plain text format.

Examples:

WorldTimeApi::TimezonesTxt.call

Returns:

  • (Hash)

    Hash with the response body as plain text or error hash.

-> { Request::Call["/timezone.txt"] }
AreaTimezonesTxt =

Returns a list of all timezones for a given area in plain text format.

Examples:

WorldTimeApi::AreaTimezonesTxt.call('Europe')

Returns:

  • (Hash)

    Hash with the response body as plain text or error hash.

->(area) { Request::Call["/timezone/#{area}.txt"] }
LocationTimezonesTxt =

Returns a list of all timezones for a given area and location in plain text format.

Examples:

WorldTimeApi::LocationTimezonesTxt.call('America', 'Sao_Paulo')

Returns:

  • (Hash)

    Hash with the response body as plain text or error hash.

->(area, location) { Request::Call["/timezone/#{area}/#{location}.txt"] }
RegionTimeTxt =

Returns the current time for a given area, location, and region in plain text format.

Examples:

WorldTimeApi::RegionTimeTxt.call('America', 'Argentina', 'Salta')

Returns:

  • (Hash)

    Hash with the response body as plain text or error hash.

->(area, location, region) { Request::Call["/timezone/#{area}/#{location}/#{region}.txt"] }
ClientIpTxt =

Returns the current time for the client’s IP address in plain text format, or for the specified IP address if provided.

Examples:

WorldTimeApi::ClientIpTxt.call('127.0.0.1')

Returns:

  • (Hash)

    Hash with the response body as plain text or error hash.

->(ip = nil) { Request::Call["/ip#{ip ? "/#{ip}" : ""}.txt"] }
Error =

Creates an error object with the specified message.

Examples:

WorldTimeApi::Error.call('Invalid timezone')

Returns:

  • (Hash)

    A hash with a single key ‘“error”` containing the error message.

->(message) { { error: message } }
VERSION =

The current version number of the WorldTimeApi gem.

"0.1.8"
Response =

Converts the HTTParty response object into a hash.

Examples:

WorldTimeApi::Response.call(HTTParty.get('http://worldtimeapi.org/api/timezone/Europe/London'))

Returns:

  • (Hash)

    A hash representation of the response body.

->(response) { JSON.parse(response.body) }