From f539d142f51b6c035a322a8f458c32f22d2cdf6c Mon Sep 17 00:00:00 2001 From: Jens-Christian Fischer Date: Thu, 17 Jan 2013 17:08:30 +0100 Subject: [PATCH 1/3] Add support for the map widget --- lib/geckoboard/push.rb | 10 ++++++++++ test/geckoboard/push_test.rb | 11 ++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/geckoboard/push.rb b/lib/geckoboard/push.rb index d2b5600..c25d374 100644 --- a/lib/geckoboard/push.rb +++ b/lib/geckoboard/push.rb @@ -93,5 +93,15 @@ def funnel(items, reverse = false, hide_percentage = false) opts[:percentage] = "hide" if hide_percentage self.push(opts) end + + # Items should be an array of hashes. These are passed verabit to the Map API + # check http://docs.geckoboard.com/custom-widgets/map.html for possible + # examples + def map(items) + data = items.collect do |item| + {:point => item } + end + self.push(:points => data) + end end end diff --git a/test/geckoboard/push_test.rb b/test/geckoboard/push_test.rb index e68ce56..bba2e80 100644 --- a/test/geckoboard/push_test.rb +++ b/test/geckoboard/push_test.rb @@ -42,12 +42,12 @@ def test_text def test_rag expect_http_request({"api_key" => "12345", "data" => {"item" => [{"value" => 1}, {"value" => 2}, {"value" => 3}]}}.to_json) - assert_equal true, @push.rag(1,2,3) + assert_equal true, @push.rag(1, 2, 3) end def test_line - expect_http_request({"api_key" => "12345", "data" => {"item" => [1,2,3], "settings" => {"axisx" => "x axis", "axisy" => "y axis", "colour" => "ff9900"}}}.to_json) - assert_equal true, @push.line([1,2,3], "ff9900", "x axis", "y axis") + expect_http_request({"api_key" => "12345", "data" => {"item" => [1, 2, 3], "settings" => {"axisx" => "x axis", "axisy" => "y axis", "colour" => "ff9900"}}}.to_json) + assert_equal true, @push.line([1, 2, 3], "ff9900", "x axis", "y axis") end def test_pie @@ -65,6 +65,11 @@ def test_funnel assert_equal true, @push.funnel([{:label => "Test1", :value => 5}, {:label => "Test2", :value => 10}], true, true) end + def test_map + expect_http_request({"api_key" => "12345", "data" => {"points" => [{"point" => { "city" => { "city_name" => "London", "country_code" => "GB"}}}]}}.to_json) + assert_equal true, @push.map(["city" => { "city_name" => "London", "country_code" => "GB" }]) + end + def expect_http_request(json) response = Net::HTTPOK.new("1.1", 200, "OK") response.instance_variable_set(:@body, '{"success":true}') From 8a4d99d0ab24cd5cedc7a1f6744d073307589cac Mon Sep 17 00:00:00 2001 From: Jens-Christian Fischer Date: Thu, 17 Jan 2013 17:09:28 +0100 Subject: [PATCH 2/3] + update readme --- README.rdoc | 1 + 1 file changed, 1 insertion(+) diff --git a/README.rdoc b/README.rdoc index 5b74bef..f0478de 100644 --- a/README.rdoc +++ b/README.rdoc @@ -17,6 +17,7 @@ Exposes a Geckoboard::Push class allowing updates for the following widget types * pie chart * geckometer * funnel chart +* map == SYNOPSIS: From 56012634f87bc06196327df9d59e82f19127e9e5 Mon Sep 17 00:00:00 2001 From: Jens-Christian Fischer Date: Thu, 17 Jan 2013 17:46:50 +0100 Subject: [PATCH 3/3] + fix json for Map widget --- lib/geckoboard/push.rb | 5 +---- test/geckoboard/push_test.rb | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/geckoboard/push.rb b/lib/geckoboard/push.rb index c25d374..ffeed65 100644 --- a/lib/geckoboard/push.rb +++ b/lib/geckoboard/push.rb @@ -98,10 +98,7 @@ def funnel(items, reverse = false, hide_percentage = false) # check http://docs.geckoboard.com/custom-widgets/map.html for possible # examples def map(items) - data = items.collect do |item| - {:point => item } - end - self.push(:points => data) + self.push(:points => { :point => items}) end end end diff --git a/test/geckoboard/push_test.rb b/test/geckoboard/push_test.rb index bba2e80..12032b9 100644 --- a/test/geckoboard/push_test.rb +++ b/test/geckoboard/push_test.rb @@ -66,7 +66,7 @@ def test_funnel end def test_map - expect_http_request({"api_key" => "12345", "data" => {"points" => [{"point" => { "city" => { "city_name" => "London", "country_code" => "GB"}}}]}}.to_json) + expect_http_request({"api_key" => "12345", "data" => {"points" => {"point" => [{ "city" => { "city_name" => "London", "country_code" => "GB"}}]}}}.to_json) assert_equal true, @push.map(["city" => { "city_name" => "London", "country_code" => "GB" }]) end