From 1d39ae5faf69e51d2c7ef34250d60aab42f3573c Mon Sep 17 00:00:00 2001
From: Alexander Logunov <unlovedru@gmail.com>
Date: Fri, 10 Nov 2017 00:09:41 +0300
Subject: [PATCH] add yandex bbox support (#1240)

---
 lib/geocoder/lookups/yandex.rb   | 8 ++++++--
 test/unit/lookups/yandex_test.rb | 9 +++++++++
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/lib/geocoder/lookups/yandex.rb b/lib/geocoder/lookups/yandex.rb
index daa150e9..2d9ffd3b 100644
--- a/lib/geocoder/lookups/yandex.rb
+++ b/lib/geocoder/lookups/yandex.rb
@@ -47,12 +47,16 @@ module Geocoder::Lookup
       else
         q = query.sanitized_text
       end
-      {
+      params = {
         :geocode => q,
         :format => "json",
         :plng => "#{query.language || configuration.language}", # supports ru, uk, be
         :key => configuration.api_key
-      }.merge(super)
+      }
+      unless (bounds = query.options[:bounds]).nil?
+        params[:bbox] = bounds.map{ |point| "%f,%f" % point }.join('~')
+      end
+      params.merge(super)
     end
   end
 end
diff --git a/test/unit/lookups/yandex_test.rb b/test/unit/lookups/yandex_test.rb
index 9bf36c80..09be7929 100644
--- a/test/unit/lookups/yandex_test.rb
+++ b/test/unit/lookups/yandex_test.rb
@@ -19,4 +19,13 @@ class YandexTest < GeocoderTestCase
     assert_equal "", result.country_code
     assert_equal "", result.country
   end
+
+  def test_yandex_query_url_contains_bbox
+    lookup = Geocoder::Lookup::Google.new
+    url = lookup.query_url(Geocoder::Query.new(
+      "Some Intersection",
+      :bounds => [[40.0, -120.0], [39.0, -121.0]]
+    ))
+    assert_match(/bbox=40.0+%2C-120.0+%7E39.0+%2C-121.0+/, url)
+  end
 end
-- 
GitLab