Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

merge

  • Loading branch information...
commit 5c5500db441b037da3d4cf62348bbaac082ef63b 2 parents 230c2d3 + 5da1fee
@mmangino mmangino authored
View
51 lib/facebooker/parser.rb
@@ -109,34 +109,35 @@ def self.hashinate(response_element)
end #do |hash, child|
end
- def self.hash_by_key_or_value_for(element)
+ def self.hash_by_key_or_value_for(element, convert_1_to_true=false)
if element.children.size == 0
{ element['key'] => nil }
elsif element.children.size == 1 && element.children.first.text?
- { element['key'] => element.content.strip }
+ { element['key'] => (convert_1_to_true ? element.content.strip == '1' : element.content.strip) }
else
- hashinate_by_key(element)
+ hashinate_by_key(element, convert_1_to_true)
end
end
# A modification to hashinate. The new dashboard API returns XML in a different format than
# the other calls. What used to be the element name has become an attribute called "key".
- def self.hashinate_by_key(response_element)
+ def self.hashinate_by_key(response_element, convert_1_to_true=false)
response_element.children.reject{|c| c.text? }.inject({}) do |hash, child|
+
# If the node hasn't any child, and is not a list, we want empty strings, not empty hashes,
# except if attributes['nil'] == true
hash[child['key']] =
if (child['nil'] == 'true')
nil
elsif (child.children.size == 1 && child.children.first.text?) || (child.children.size == 0 && child['list'] != 'true')
- anonymous_field_from(child, hash) || child.content.strip
- elsif child['list'] == 'true' && child.children.all? { |subchild| subchild['key'].nil? }
- child.children.reject{|c| c.text? }.map { |subchild| hash_by_key_or_value_for(subchild)}
+ anonymous_field_from(child, hash) || (convert_1_to_true ? child.content.strip == '1' : child.content.strip)
+ elsif child['list'] == 'true' && child.children.reject {|subchild| subchild.text?}.all? { |subchild| !subchild.text? && subchild['key'].nil? }
+ child.children.reject{|c| c.text? }.map { |subchild| hash_by_key_or_value_for(subchild, convert_1_to_true)}
elsif child['list'] == 'true'
- hash_by_key_or_value_for(child)
+ hash_by_key_or_value_for(child, convert_1_to_true)
else
child.children.reject{|c| c.text? }.inject({}) do |subhash, subchild|
- subhash[subchild['key']] = hash_by_key_or_value_for(subchild)
+ subhash[subchild['key']] = hash_by_key_or_value_for(subchild, convert_1_to_true)
subhash
end
end
@@ -717,40 +718,22 @@ def self.process(data)
class DashboardMultiSetCount < Parser
def self.process(data)
- hashinate_by_key(element('dashboard_multiSetCount_response', data))
+ hashinate_by_key(element('dashboard_multiSetCount_response', data), true)
end
end
class DashboardMultiIncrementCount < Parser
def self.process(data)
- hashinate_by_key(element('dashboard_multiIncrementCount_response', data))
+ hashinate_by_key(element('dashboard_multiIncrementCount_response', data), true)
end
end
class DashboardMultiDecrementCount < Parser
def self.process(data)
- hashinate_by_key(element('dashboard_multiDecrementCount_response', data))
+ hashinate_by_key(element('dashboard_multiDecrementCount_response', data), true)
end
end
- class DashboardMultiSetCount < Parser
- def self.process(data)
- hashinate_by_key(element('dashboard_multiSetCount_response', data))
- end
- end
-
- class DashboardMultiIncrementCount < Parser
- def self.process(data)
- hashinate_by_key(element('dashboard_multiIncrementCount_response', data))
- end
- end
-
- class DashboardMultiDecrementCount < Parser
- def self.process(data)
- hashinate_by_key(element('dashboard_multiDecrementCount_response', data))
- end
- end
-
class DashboardAddGlobalNews < Parser
def self.process(data)
element('dashboard_addGlobalNews_response', data).content.strip
@@ -766,7 +749,7 @@ def self.process(data)
class DashboardClearGlobalNews < Parser
def self.process(data)
- hashinate_by_key(element('dashboard_clearGlobalNews_response', data))
+ hashinate_by_key(element('dashboard_clearGlobalNews_response', data), true)
end
end
@@ -784,7 +767,7 @@ def self.process(data)
class DashboardClearNews < Parser
def self.process(data)
- hashinate_by_key(element('dashboard_clearNews_response', data))
+ hashinate_by_key(element('dashboard_clearNews_response', data), true)
end
end
@@ -796,7 +779,7 @@ def self.process(data)
class DashboardMultiClearNews < Parser
def self.process(data)
- hashinate_by_key(element('dashboard_multiClearNews_response', data))
+ hashinate_by_key(element('dashboard_multiClearNews_response', data), true)
end
end
@@ -814,7 +797,7 @@ def self.process(data)
class DashboardRemoveActivity < Parser
def self.process(data)
- hashinate_by_key(element('dashboard_removeActivity_response', data))
+ hashinate_by_key(element('dashboard_removeActivity_response', data), true)
end
end
View
2  test/facebooker/application_test.rb
@@ -41,7 +41,7 @@ def test_can_clear_global_news
def test_can_parse_global_news
expect_http_posts_with_responses(clear_global_news_xml)
- assert_equal({"342345290762"=>"1"}, @session.application.clear_global_news('342345290762'))
+ assert_equal({"342345290762"=>true}, @session.application.clear_global_news('342345290762'))
end
private
View
13 test/facebooker/models/user_test.rb
@@ -356,7 +356,6 @@ def test_can_increment_dashboard_count
def test_parse_increment_dashboard_count
expect_http_posts_with_responses(dashboard_increment_count_xml)
- debugger
assert_equal true, @user.dashboard_increment_count
end
@@ -426,7 +425,7 @@ def test_can_dashboard_multi_set_count
def test_parse_dashboard_multi_set_count
expect_http_posts_with_responses(dashboard_multi_set_count_xml)
- assert_equal({ '1234' => '1', '4321' => '1' }, Facebooker::User.dashboard_multi_set_count({ '1234' => '11', '5678' => '22' }))
+ assert_equal({ '1234' => true, '4321' => true }, Facebooker::User.dashboard_multi_set_count({ '1234' => '11', '5678' => '22' }))
end
def test_can_dashboard_multi_get_count
@@ -456,7 +455,7 @@ def test_can_dashboard_multi_increment_count_with_array_of_uids
def test_parse_dashboard_multi_increment_count
expect_http_posts_with_responses(dashboard_multi_increment_count_xml)
- assert_equal({ '1234' => '1', '4321' => '1' }, Facebooker::User.dashboard_multi_increment_count(['1234', '4321']))
+ assert_equal({ '1234' => true, '4321' => true }, Facebooker::User.dashboard_multi_increment_count(['1234', '4321']))
end
def test_can_dashboard_multi_decrement_count_with_single_uid
@@ -471,7 +470,7 @@ def test_can_dashboard_multi_decrement_count_with_multiple_uids
def test_parse_dashboard_multi_decrement_count_with_array_of_uids
expect_http_posts_with_responses(dashboard_multi_decrement_count_xml)
- assert_equal({ '1234' => '1', '4321' => '1' }, Facebooker::User.dashboard_multi_decrement_count(['1234', '4321']))
+ assert_equal({ '1234' => true, '4321' => true }, Facebooker::User.dashboard_multi_decrement_count(['1234', '4321']))
end
# Dashboard
@@ -507,7 +506,7 @@ def test_can_clear_news
def test_parse_clear_news
expect_http_posts_with_responses(clear_news_xml)
- assert_equal({"362466171040"=>"1"}, @user.clear_news('362466171040'))
+ assert_equal({"362466171040"=>true}, @user.clear_news('362466171040'))
end
def test_can_multi_add_news
@@ -537,7 +536,7 @@ def test_can_multi_clear_news
def test_parse_multi_clear_news
expect_http_posts_with_responses(multi_clear_news_xml)
- assert_equal({"1234"=>{"319103117527"=>"1"}, "4321"=>{"313954287803"=>"1"}}, Facebooker::User.multi_clear_news({"1234"=>["319103117527"], "4321"=>["313954287803"]}))
+ assert_equal({"1234"=>{"319103117527"=>true}, "4321"=>{"313954287803"=>true}}, Facebooker::User.multi_clear_news({"1234"=>["319103117527"], "4321"=>["313954287803"]}))
end
def test_can_publish_activity
@@ -567,7 +566,7 @@ def test_can_remove_activity
def test_parse_remove_activity
expect_http_posts_with_responses(remove_activity_xml)
- assert_equal({"342454152268"=>"1"}, @user.remove_activity('123'))
+ assert_equal({"342454152268"=>true}, @user.remove_activity('123'))
end
Please sign in to comment.
Something went wrong with that request. Please try again.