New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optional config parameter for user-agent header, alias for OSMGeocoder #195
Conversation
…r because of class_name = "#{Geokit::Inflector.camelize(provider.to_s)}Geocoder"
@@ -2,7 +2,8 @@ module Geokit | |||
module NetAdapter | |||
class Typhoeus | |||
def self.do_get(url) | |||
::Typhoeus.get(url.to_s) | |||
Geokit::Geocoders.useragent ? headers = {'User-Agent' => Geokit::Geocoders.useragent} : headers = {} | |||
::Typhoeus.get(url.to_s, :headers => headers) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the new Ruby 1.9 hash syntax.
@@ -2,7 +2,8 @@ module Geokit | |||
module NetAdapter | |||
class Typhoeus | |||
def self.do_get(url) | |||
::Typhoeus.get(url.to_s) | |||
Geokit::Geocoders.useragent ? headers = {'User-Agent' => Geokit::Geocoders.useragent} : headers = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the return of the conditional for variable assignment and comparison.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you address this comment, e.g. headers = Geokit::Geocoders.useragent ? {'User-Agent' => Geokit::Geocoders.useragent} : {}
@@ -3,7 +3,8 @@ module NetAdapter | |||
class NetHttp | |||
def self.do_get(url) | |||
uri = URI(url) | |||
req = Net::HTTP::Get.new(uri.request_uri) | |||
Geokit::Geocoders.useragent ? headers = {'User-Agent' => Geokit::Geocoders.useragent} : headers = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the return of the conditional for variable assignment and comparison.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
Trailing whitespace detected.
I mostly like the Pull Request, I think it just needs a test that verifies if Net::HTTP receives the user agent. e.g. mock 'Net::HTTP::Get' class |
Thanks, I will give it a try with webmock next week... |
…aram, reverse_geocode accepts :provider_order param
def test_typhoeus_set_to_default | ||
stub_request(:get, URL).with(:headers => TYPHOEUSDEFAULTHEADERS.merge('User-Agent' => TYPHOEUSDEFAULT)) | ||
|
||
Geokit::Geocoders::useragent = nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not use :: for method calls.
end | ||
|
||
def test_typhoeus_set_to_default | ||
stub_request(:get, URL).with(:headers => TYPHOEUSDEFAULTHEADERS.merge('User-Agent' => TYPHOEUSDEFAULT)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use 2 (not 4) spaces for indentation.
Use the new Ruby 1.9 hash syntax.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
def test_typhoeus_set_to_testagent | ||
stub_request(:get, URL).with(:headers => TYPHOEUSDEFAULTHEADERS.merge('User-Agent' => TESTAGENT)) | ||
|
||
Geokit::Geocoders::useragent = TESTAGENT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not use :: for method calls.
end | ||
|
||
def test_typhoeus_set_to_testagent | ||
stub_request(:get, URL).with(:headers => TYPHOEUSDEFAULTHEADERS.merge('User-Agent' => TESTAGENT)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use 2 (not 4) spaces for indentation.
Use the new Ruby 1.9 hash syntax.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
def test_nethttp_useragent_set_to_default | ||
stub_request(:get, URL).with(:headers => NETHTTPDEFAULTHEADERS.merge('User-Agent' => NETHTTPDEFAULT)) | ||
|
||
Geokit::Geocoders::useragent = nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not use :: for method calls.
end | ||
|
||
def test_nethttp_useragent_set_to_default | ||
stub_request(:get, URL).with(:headers => NETHTTPDEFAULTHEADERS.merge('User-Agent' => NETHTTPDEFAULT)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use 2 (not 4) spaces for indentation.
Use the new Ruby 1.9 hash syntax.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
def test_nethttp_useragent_set_to_testagent | ||
stub_request(:get, URL).with(:headers => NETHTTPDEFAULTHEADERS.merge('User-Agent' => TESTAGENT)) | ||
|
||
Geokit::Geocoders::useragent = TESTAGENT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not use :: for method calls.
URL = 'http://www.example.com' | ||
|
||
def test_nethttp_useragent_set_to_testagent | ||
stub_request(:get, URL).with(:headers => NETHTTPDEFAULTHEADERS.merge('User-Agent' => TESTAGENT)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use 2 (not 4) spaces for indentation.
Use the new Ruby 1.9 hash syntax.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
TYPHOEUSDEFAULT = 'Typhoeus - https://github.com/typhoeus/typhoeus' | ||
TYPHOEUSDEFAULTHEADERS = {'Expect'=>''} | ||
TESTAGENT = 'MyAgent' | ||
URL = 'http://www.example.com' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Freeze mutable objects assigned to constants.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
NETHTTPDEFAULTHEADERS = {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3'} | ||
TYPHOEUSDEFAULT = 'Typhoeus - https://github.com/typhoeus/typhoeus' | ||
TYPHOEUSDEFAULTHEADERS = {'Expect'=>''} | ||
TESTAGENT = 'MyAgent' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Freeze mutable objects assigned to constants.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
NETHTTPDEFAULT = 'Ruby' | ||
NETHTTPDEFAULTHEADERS = {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3'} | ||
TYPHOEUSDEFAULT = 'Typhoeus - https://github.com/typhoeus/typhoeus' | ||
TYPHOEUSDEFAULTHEADERS = {'Expect'=>''} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Freeze mutable objects assigned to constants.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
Surrounding space missing for operator =>.
|
||
NETHTTPDEFAULT = 'Ruby' | ||
NETHTTPDEFAULTHEADERS = {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3'} | ||
TYPHOEUSDEFAULT = 'Typhoeus - https://github.com/typhoeus/typhoeus' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Freeze mutable objects assigned to constants.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
class UserAgentTest < Test::Unit::TestCase | ||
|
||
NETHTTPDEFAULT = 'Ruby' | ||
NETHTTPDEFAULTHEADERS = {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3'} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Freeze mutable objects assigned to constants.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
Surrounding space missing for operator =>.
|
||
class UserAgentTest < Test::Unit::TestCase | ||
|
||
NETHTTPDEFAULT = 'Ruby' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use 2 (not 4) spaces for indentation.
Freeze mutable objects assigned to constants.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
require File.join(File.dirname(__FILE__), '../lib/geokit.rb') | ||
|
||
class UserAgentTest < Test::Unit::TestCase | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra empty line detected at class body beginning.
require 'test/unit' | ||
require 'webmock/test_unit' | ||
|
||
require File.join(File.dirname(__FILE__), '../lib/geokit.rb') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
1 similar comment
Now here is my shot at webmock for testing the netadapters useragent. Hope it's ok this way. Please feel free to modify it. I also fixed a bug with missing options param in bing geocoder, when using MultiGeocoder. |
@@ -110,4 +110,6 @@ def self.set_bounds(result_json, loc) | |||
end | |||
end | |||
end | |||
|
|||
Geokit::Geocoders::OsmGeocoder = Geokit::Geocoders::OSMGeocoder |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you do this. I feel we're just adding another alias when people are already using OSM, if anything the class should reflect the file name (or file name reflect the class, e.g. OpenStreetMapGeocoder
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see my first comment. Multigeocode throws an error in const_get, reason is the wrong class name in
class_name = "#{Geokit::Inflector.camelize(provider.to_s)}Geocoder"
E, [2016-10-27T17:37:51.610364 #9174] ERROR -- : Caught an error during Multi geocoding call: uninitialized constant Geokit::Geocoders::OsmGeocoder
E, [2016-10-27T17:37:51.610421 #9174] ERROR -- : /Users/co/projects/geokit/lib/geokit/multi_geocoder.rb:65:in `const_get'
/Users/co/projects/geokit/lib/geokit/multi_geocoder.rb:65:in `geocoder'
/Users/co/projects/geokit/lib/geokit/multi_geocoder.rb:32:in `block in do_geocode'
/Users/co/projects/geokit/lib/geokit/multi_geocoder.rb:31:in `each'
/Users/co/projects/geokit/lib/geokit/multi_geocoder.rb:31:in `do_geocode'
/Users/co/projects/geokit/lib/geokit/geocoders.rb:90:in `geocode'
1 similar comment
@chriso0710 I've fixed tests in #202 so am closing this. Thanks very much for contributing to the fix. |
My pleasure, thanks for merging :-) |
Made the following changes regarding issue #194 :
Sorry for not providing any tests, but I was having some issues with
and as I am not familiar with vcr and simplecov, I was not very keen to debug the issue :-)
Additionally I created a new alias OsmGeocoder because of the following error in Multigeocoding with OSM: