Timezone from geolocation - ruby-on-rails

I have a geolocation pair latitude/longitude, is there any way/tool to get the corresponding time zone?

A website called EarthTools has a web service for that.
http://www.earthtools.org/webservices.htm#timezone
You can pass in latitude and longitude like so:
h ttp://www.earthtools.org/timezone/40.71417/-74.00639
And it spits out the time zone and a bunch of other info:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<timezone xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.earthtools.org/timezone.xsd">
<version>1.1</version>
<location>
<latitude>40.71417</latitude>
<longitude>-74.00639</longitude>
</location>
<offset>-5</offset>
<suffix>R</suffix>
<localtime>4 Dec 2005 12:06:56</localtime>
<isotime>2005-12-04 12:06:56 -0500</isotime>
<utctime>2005-12-04 17:06:56</utctime>
<dst>False</dst>
</timezone>

If an external dependancy is not ideal (obviously this brilliant for client side geo location).
Then I recommend reading the answer to this question
Easiest Way to Convert lat lng/zip/city/state to Timezone in Ruby

Related

Bing Ads API Reporting Service returns error code 2015 "No Dimension Selected"

I'm trying to pull some data from the Bing Ads API but I keep getting error code 2015. I'm using Savon with Ruby on Rails. Here is the request:
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="https://bingads.microsoft.com/Reporting/v13" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns="https://bingads.microsoft.com/Reporting/v13">
<env:Header>
<AuthenticationToken>blahblahblah</AuthenticationToken>
<CustomerAccountId>blahblahblah</CustomerAccountId>
<CustomerId>blahblahblah</CustomerId>
<DeveloperToken>blahblahblah</DeveloperToken>
</env:Header>
<env:Body>
<tns:SubmitGenerateReportRequest>
<ReportRequest xsi:nil="false" xsi:type="AccountPerformanceReportRequest">
<ExcludeColumnHeaders>true</ExcludeColumnHeaders>
<ExcludeReportFooter>true</ExcludeReportFooter>
<ExcludeReportHeader>true</ExcludeReportHeader>
<Format>Csv</Format>
<Language>English</Language>
<ReportName>AccountPerformanceReportRequest</ReportName>
<ReturnOnlyCompleteData>false</ReturnOnlyCompleteData>
<Aggregation>Summary</Aggregation>
<Columns>
<AccountPerformanceReportColumn>Spend</AccountPerformanceReportColumn>
<AccountPerformanceReportColumn>Clicks</AccountPerformanceReportColumn>
<AccountPerformanceReportColumn>Conversions</AccountPerformanceReportColumn>
<AccountPerformanceReportColumn>Revenue</AccountPerformanceReportColumn>
</Columns>
<Filter xsi:nil="true"/>
<Scope>
<AccountIds xmlns:a1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<a1:long>blahblahblah</a1:long>
</AccountIds>
</Scope>
<Time>
<CustomDateRangeEnd>
<Day>02</Day>
<Month>04</Month>
<Year>2019</Year>
</CustomDateRangeEnd>
<CustomDateRangeStart>
<Day>01</Day>
<Month>04</Month>
<Year>2019</Year>
</CustomDateRangeStart>
<PredefinedTime xsi:nil="true"/>
<ReportTimeZone>EasternTimeUSCanada</ReportTimeZone>
</Time>
</ReportRequest>
</tns:SubmitGenerateReportRequest>
</env:Body>
</env:Envelope>
As you can see, I'm pulling the report with 'Summary' as the aggregation type. If I use 'Monthly' as the aggregation type and include a 'TimePeriod' column, it works perfectly, but if I do that then the data returned is for the whole month of April as opposed to the date range I've selected 04-01-2019..04-02-2019.
Here is the response:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<s:Fault>
<faultcode>s:Server</faultcode>
<faultstring xml:lang="en-US">Invalid client data. Check the SOAP fault details for more information</faultstring> <detail>
<ApiFaultDetail xmlns="https://bingads.microsoft.com/Reporting/v13" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<TrackingId xmlns="https://adapi.microsoft.com">52665fe5-3eb8-42e0-ad8e-942e848297ce</TrackingId>
<BatchErrors/>
<OperationErrors>
<OperationError>
<Code>2015</Code>
<Details>No Dimension selected.</Details>
<ErrorCode>RequiredColumnsNotSelected</ErrorCode>
<Message>The specified report request does not specify all the required columns for this report type. Please submit a report request with the required columns for this report type, and optionally additional columns that are to be included in the report.</Message>
</OperationError>
</OperationErrors>
</ApiFaultDetail>
</detail>
</s:Fault>
</s:Body>
</s:Envelope>
The error code returned would lead me to believe that a TimePeriod column is required even for Summary, but that contradicts what is documented here.
All other aggregation types work with this setup. Any help would be greatly appreciated.
Good catch. We will update documentation to clarify that at least one attribute (non performance stat) e.g., AccountId must be included. Most of the other reports have specific attributes that must be included, whereas the account report does not. I hope this helps!

PHP library for Office365 EWS with GetRooms

Whole last week i struggled with Php libraries for EWS. I tried Package365Ews and Php-ews but both of them are missing core feature for me, or it's not documented - GetRooms. Do anyone know how to handle it, or know another library implementing this?
I personally would suggest my own library, garethp/php-ews.
It's got simple usage, but not everything is covered under simpler API's. EWS is a large thing, and documenting everything would be intense. That being said, I can certainly help you translate existing documentation by Microsoft to using this code. And, if you find yourself with more issues after this post, I check my Github daily, so logging an issue against my repository will get more help in a better place for a back and forth.
But first, let me outlay how to perform functions that aren't directly documented. Like GetRooms. My API wraps around EWS, it doesn't block your access to it. So even though I've made no obvious way to do a GetRooms, it's still there. Like this
<?php
use garethp\ews\API;
use garethp\ews\API\Type;
$api = API::fromUsernameAndPassword($server, $username, $password);
//Build Request
$result = $api->getClient()->GetRooms($request);
var_dump($result);
So, the question becomes, how do we build the request? Well, thankfully EWS is very well documented in XML. First, find the article that describes what you're trying to do, then look for the XML. I'm not 100% what you want to do, but I'll use this article as a base. The XML that we're going to try to replicate is
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<t:RequestServerVersion Version="Exchange2010" />
</soap:Header>
<soap:Body>
<m:GetRooms>
<m:RoomList>
<t:EmailAddress>bldg3rooms#contoso.com</t:EmailAddress>
</m:RoomList>
</m:GetRooms>
</soap:Body>
</soap:Envelope>
You can skip the header, and the <m:GetRooms> part, those are built for you. What we're focused on is the payload you want to send, which is
<m:RoomList>
<t:EmailAddress>bldg3rooms#contoso.com</t:EmailAddress>
</m:RoomList>
We want to make our request look like that. So, in our code, our request will look like:
$request = array (
'RoomsList' => array (
'EmailAddress' => 'bldg3rooms#contoso.com'
)
);
$request = Type::buildFromArray($request);
And this will be translated to XML for you for the SOAP call. Using this method, for any functions that aren't documented or outright supported, you can easily still use them and just refer to the official Microsoft documentation for any request you need to make

How to Get global contacts from EWS?

I'm working on microsoft EWS Webservice i found the solutions for fectching current users data . Now i need to fetch global contacts from EWS. is there any help?thanks in Advance.
currently im using below string for getting user data
<?xml version=\"1.0\" encoding=\"utf-8\"?>\
<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\
xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"\
xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"\
xmlns:t=\"http://schemas.microsoft.com/exchange/services/2006/types\">\
<soap:Body>\
<ResolveNames xmlns=\"http://schemas.microsoft.com/exchange/services/2006/messages\"\
xmlns:t=\"http://schemas.microsoft.com/exchange/services/2006/types\"\
ReturnFullContactData=\"true\">\
<UnresolvedEntry>smtp:%##atea.dk</UnresolvedEntry>\
</ResolveNames>\
</soap:Body>\
</soap:Envelope>
If you want to Search for contacts in the Global Address List you just need to set the SearchScope to ActiveDirectory see http://msdn.microsoft.com/en-us/library/office/aa565329(v=exchg.150).aspx
eg
<soap:Header>
<t:RequestServerVersion Version="Exchange2013_SP1" />
</soap:Header>
<soap:Body>
<m:ResolveNames ReturnFullContactData="true" SearchScope="ActiveDirectory">
<m:UnresolvedEntry>smtp</m:UnresolvedEntry>
</m:ResolveNames>
</soap:Body>
</soap:Envelope>
The thing to keep in mind with this method is that it will only return a max of 100 entries. If you have a really large directory and have Exchange 2013 then use findpeople http://msdn.microsoft.com/en-us/library/office/jj191039(v=exchg.150).aspx instead
Cheers
Glen

EWS always return ErrorTimeZone when you call with timezone UTC

Note: First of all, sorry for my poor level of English.
I'm having trouble with all the requests to EWS (using managed api) in the environment of a client when I use to create the ExchangeService the timezone Utc (new ExchangeService (ExchangeVersion.Exchange2007_SP1, TimeZoneInfo.Utc);)
The returned error is: ResposeCode = ErrorTimeZone (A time zone with the specified ID could not be found.)
Any idea?
Here you have the log traces an EWS request that returns this error:
18 2014-05-19 13:52:33,224 6 TRACE XXXX SCService.exe (null) (null)[EwsResponseHttpHeaders] <Trace Tag="EwsResponseHttpHeaders" Tid="6" Time="2014-05-19 13:52:33Z">
HTTP/1.1 500 Internal Server Error
Content-Length: 1014
Cache-Control: private
Content-Type: text/xml; charset=utf-8
Date: Mon, 19 May 2014 13:52:35 GMT
Server: Microsoft-IIS/6.0
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
</Trace>
(null)
19 2014-05-19 13:52:33,224 6 TRACE XXXX SCService.exe (null) (null)[EwsResponse] <Trace Tag="EwsResponse" Tid="6" Time="2014-05-19 13:52:33Z" Version="15.00.0516.014">
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Header>
<t:ServerVersionInfo MajorVersion="8" MinorVersion="3" MajorBuildNumber="298" MinorBuildNumber="1" Version="Exchange2007_SP1" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" />
</soap:Header>
<soap:Body>
<soap:Fault>
<faultcode>soap:Client</faultcode>
<faultstring>A time zone with the specified ID could not be found.</faultstring>
<detail>
<e:ResponseCode xmlns:e="http://schemas.microsoft.com/exchange/services/2006/errors">ErrorTimeZone</e:ResponseCode>
<e:Message xmlns:e="http://schemas.microsoft.com/exchange/services/2006/errors">A time zone with the specified ID could not be found.</e:Message>
<t:MessageXml xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<t:Value Name="Id">UTC</t:Value>
</t:MessageXml>
</detail>
</soap:Fault>
</soap:Body>
</soap:Envelope>
</Trace>
Thanks for reading :)
The problem was that for some reason none of the exchange CAS in the production environment of the client had the UTC time zone defined in your windows registry.
I was able to access the owa of the client and saw that I couldn't set the UTC time zone in the owa settings. This convinced them to check if the UTC time zone had properly set in one of their CAS. And as it was not, I asked for set manually de utc time zone in the windows registry. Then I configured my application for attack only to this CAS, and all worked well.
Researching the client told me that everything was caused by a patch of exchange they had recently applied and they had already identified and tested in their environment of pre-production another patch that fixed it.
Just following up on this in case someone else stumbles across this. I had a very similar issue after installing Exchange 2016 CU8 (started from CU5). I found that the account with impersonation rights received the 500 error when it made the GetServerTimeZone call. This was due to the account not being mailbox enabled and thus not having a timezone assigned to it. Once I mail enabled the account, the error went away and service was restored.
Microsoft acknowledged that this isn't expected behavior and submitted it for a bugcheck.

Is this normal behavior for Yahoo PlaceFinder API? Seems odd to me

So I have this lat/lng pair, 39.905983/116.459373. Forever, the PlaceFinder API has been returning WOE ID 2151399 for this. Then suddenly it stopped, and started returning null (empty) instead.
I thought maybe the service was remembering that it had already done this for my API key, so I switched to another one. Still, null WOE ID. It makes sense because it is still processing other lat/lng pairs which I have also queried excessively during development.
I changed the values sent to the PlaceFinder query to 39.9059830001/116.4593730001 (just added 0001 to the end of each), and it started returning the WOE ID again.
My question: What gives?
I tried the same query using PlaceFinder via the YQL Console:
select woeid from geo.placefinder where text="39.905983,116.459373" and gflags="R"
...and get the same WOEID result you mentioned:
<?xml version="1.0" encoding="UTF-8"?>
<query xmlns:yahoo="http://www.yahooapis.com/v1/base.rng"
yahoo:count="1" yahoo:created="2012-03-20T16:24:40Z" yahoo:lang="en-US">
<results>
<Result>
<woeid>2151399</woeid>
</Result>
</results>
</query>
I have not seen the behavior you mentioned, so I would consider it not normal. In the case where a null value is returned, do you have the normal HTTP status code? You might be running into a rate limit.

Resources