{"action":"created","issue":{"url":"https://api.github.com/repos/Bluefieldscom/intl-tel-input/issues/174","labels_url":"https://api.github.com/repos/Bluefieldscom/intl-tel-input/issues/174/labels{/name}","comments_url":"https://api.github.com/repos/Bluefieldscom/intl-tel-input/issues/174/comments","events_url":"https://api.github.com/repos/Bluefieldscom/intl-tel-input/issues/174/events","html_url":"https://github.com/Bluefieldscom/intl-tel-input/issues/174","id":59995519,"number":174,"title":"Improve when defaultCountry is auto","user":{"login":"lucaspfsd","id":3768559,"avatar_url":"https://avatars.githubusercontent.com/u/3768559?v=3","gravatar_id":"","url":"https://api.github.com/users/lucaspfsd","html_url":"https://github.com/lucaspfsd","followers_url":"https://api.github.com/users/lucaspfsd/followers","following_url":"https://api.github.com/users/lucaspfsd/following{/other_user}","gists_url":"https://api.github.com/users/lucaspfsd/gists{/gist_id}","starred_url":"https://api.github.com/users/lucaspfsd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lucaspfsd/subscriptions","organizations_url":"https://api.github.com/users/lucaspfsd/orgs","repos_url":"https://api.github.com/users/lucaspfsd/repos","events_url":"https://api.github.com/users/lucaspfsd/events{/privacy}","received_events_url":"https://api.github.com/users/lucaspfsd/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Bluefieldscom/intl-tel-input/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":11,"created_at":"2015-03-05T18:38:48Z","updated_at":"2015-03-14T02:31:11Z","closed_at":"2015-03-14T02:31:11Z","body":"Hi I suggest a improve in check ipinfo, using cookies to dosen't make many request of same user: for example, this is the code that I need implement in your framework:\r\n```javascript\r\ninit: function() {\r\n            var that = this;\r\n            // if defaultCountry is set to \"auto\", we must do a lookup first\r\n            if (this.options.defaultCountry == \"auto\") {\r\n                var cookieDefaultCountry = $.cookie(\"defaultCountry\");\r\n\r\n                if (cookieDefaultCountry != null) {\r\n                    var jsonDefaultCountry = JSON.parse(cookieDefaultCountry);\r\n                    this.options.defaultCountry = jsonDefaultCountry.country.toLowerCase();\r\n\r\n                    this._ready();\r\n                }\r\n                else {\r\n                    // reset this in case lookup fails\r\n                    this.options.defaultCountry = \"\";\r\n                    var ipinfoURL = \"http://ipinfo.io\";\r\n                    if (this.options.ipinfoToken) {\r\n                        ipinfoURL += \"?token=\" + this.options.ipinfoToken;\r\n                    }\r\n                    $.get(ipinfoURL, function (response) {\r\n                        if (response && response.country) {\r\n                            that.options.defaultCountry = response.country.toLowerCase();\r\n                            $.cookie(\"defaultCountry\", JSON.stringify(response), { path: '/', expires: 30 });\r\n                        }\r\n                    }, \"jsonp\").always(function () {\r\n                        that._ready();\r\n                    });\r\n                }\r\n            } else {\r\n                this._ready();\r\n            }\r\n        },\r\n```\r\nNote that I'm checking if cookie is empty, to request the ipinfo API.\r\n\r\nAnd the freegeoip api is more powerfull than ipinfo, so is better to check ips, because, ipinfo the max request is 1,000 per day and freegeoip is 10,000 per hour. ;)\r\n\r\nThat is it, thanks."},"comment":{"url":"https://api.github.com/repos/Bluefieldscom/intl-tel-input/issues/comments/79721977","html_url":"https://github.com/Bluefieldscom/intl-tel-input/issues/174#issuecomment-79721977","issue_url":"https://api.github.com/repos/Bluefieldscom/intl-tel-input/issues/174","id":79721977,"user":{"login":"jackocnr","id":1186883,"avatar_url":"https://avatars.githubusercontent.com/u/1186883?v=3","gravatar_id":"","url":"https://api.github.com/users/jackocnr","html_url":"https://github.com/jackocnr","followers_url":"https://api.github.com/users/jackocnr/followers","following_url":"https://api.github.com/users/jackocnr/following{/other_user}","gists_url":"https://api.github.com/users/jackocnr/gists{/gist_id}","starred_url":"https://api.github.com/users/jackocnr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jackocnr/subscriptions","organizations_url":"https://api.github.com/users/jackocnr/orgs","repos_url":"https://api.github.com/users/jackocnr/repos","events_url":"https://api.github.com/users/jackocnr/events{/privacy}","received_events_url":"https://api.github.com/users/jackocnr/received_events","type":"User","site_admin":false},"created_at":"2015-03-14T02:31:11Z","updated_at":"2015-03-14T02:31:11Z","body":"Ok I added this in v5.8.0 - let me know what you think"}}