From b857dae0d2314935accfbaa85737709cd43f403a Mon Sep 17 00:00:00 2001 From: Alexi Rahman Date: Mon, 15 Dec 2014 20:42:14 +0100 Subject: [PATCH] Added google +1 to social signals --- README.md | 10 ++--- lib/page_rankr/socials.rb | 1 + lib/page_rankr/socials/google.rb | 30 ++++++++++++++ .../vcr_cassettes/failure_socials.yml | 39 +++++++++++++++++++ .../vcr_cassettes/success_socials.yml | 39 +++++++++++++++++++ spec/socials_spec.rb | 5 +++ 6 files changed, 119 insertions(+), 5 deletions(-) create mode 100644 lib/page_rankr/socials/google.rb diff --git a/README.md b/README.md index 450a260..9aae442 100644 --- a/README.md +++ b/README.md @@ -131,18 +131,18 @@ Social signals are a somewhat oversimplified way of telling how popular a site o If you don't specify a social tracker, then all of them are used. ``` ruby - PageRankr.socials('www.google.com', :linked_in, :pinterest, :stumbled_upon, :twitter) - #=> {:linked_in=>1001, :pinterest=>75108, :stumple_upon=>255078, :twitter=>21933764} + PageRankr.socials('www.google.com', :google, :linked_in, :pinterest, :stumbled_upon, :twitter) + #=> {:google=>10000, :linked_in=>1001, :pinterest=>75108, :stumple_upon=>255078, :twitter=>21933764} # this also gives the same result PageRankr.socials('www.google.com') - #=> {:linked_in=>1001, :pinterest=>75108, :stumble_upon=>255078, :twitter=>21933764} + #=> {:google=>10000, :linked_in=>1001, :pinterest=>75108, :stumble_upon=>255078, :twitter=>21933764} ``` -Valid social trackers are: `:linked_in, :pinterest, :stumble_upon, :twitter`. To get this you can do: +Valid social trackers are: `:google, :linked_in, :pinterest, :stumble_upon, :twitter`. To get this you can do: ``` ruby - PageRankr.social_trackers #=> [:linked_in, :pinterest, :stumble_upon, :twitter] + PageRankr.social_trackers #=> [:google, :linked_in, :pinterest, :stumble_upon, :twitter] ``` diff --git a/lib/page_rankr/socials.rb b/lib/page_rankr/socials.rb index c1c7267..bfef98e 100644 --- a/lib/page_rankr/socials.rb +++ b/lib/page_rankr/socials.rb @@ -1,5 +1,6 @@ require File.expand_path("../trackers", __FILE__) require File.expand_path("../socials/facebook", __FILE__) +require File.expand_path("../socials/google", __FILE__) require File.expand_path("../socials/linkedin", __FILE__) require File.expand_path("../socials/pinterest", __FILE__) require File.expand_path("../socials/stumble_upon", __FILE__) diff --git a/lib/page_rankr/socials/google.rb b/lib/page_rankr/socials/google.rb new file mode 100644 index 0000000..4f542c1 --- /dev/null +++ b/lib/page_rankr/socials/google.rb @@ -0,0 +1,30 @@ +require File.expand_path('../../social', __FILE__) + +module PageRankr + class Socials + class Google + include Social + + def url + # Yandex supplies Google +1 counts in a convenient matter + 'http://share.yandex.ru/gpp.xml' + end + + def params + {:url => tracked_url} + end + + def regex + /(\d+)/ + end + + def supported_components + [:subdomain, :path, :scheme] + end + + def name + :socials_google + end + end + end +end diff --git a/spec/fixtures/vcr_cassettes/failure_socials.yml b/spec/fixtures/vcr_cassettes/failure_socials.yml index b386818..9ff5cc5 100644 --- a/spec/fixtures/vcr_cassettes/failure_socials.yml +++ b/spec/fixtures/vcr_cassettes/failure_socials.yml @@ -357,4 +357,43 @@ http_interactions: } http_version: '1.1' recorded_at: Mon, 15 Dec 2014 07:39:10 GMT +- request: + method: get + uri: http://share.yandex.ru/gpp.xml?url=http%3A%2F%2Fplease-dont-register-a-site-that-breaks-this-test.com + body: + encoding: US-ASCII + string: '' + headers: + user-agent: + - Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/534.56.5 (KHTML, + like Gecko) Version/5.1.6 Safari/534.56.5 + response: + status: + code: 200 + message: OK + headers: + server: + - nginx/1.6.2 + date: + - Mon, 15 Dec 2014 19:34:56 GMT + content-type: + - text/javascript; charset=utf-8 + transfer-encoding: + - chunked + connection: + - close + cache-control: + - max-age=0, must-revalidate, proxy-revalidate, no-cache, no-store, private + expires: + - Mon, 15 Dec 2014 19:34:56 GMT + pragma: + - no-cache + set-cookie: + - yandexuid=4575016491418672096; domain=.yandex.ru; path=/; expires=Tue, 19 + Jan 2038 03:14:07 GMT + body: + encoding: UTF-8 + string: services.gplus.cb("0"); + http_version: '1.1' + recorded_at: Mon, 15 Dec 2014 19:34:56 GMT recorded_with: VCR 2.9.3 diff --git a/spec/fixtures/vcr_cassettes/success_socials.yml b/spec/fixtures/vcr_cassettes/success_socials.yml index db120e7..359d847 100644 --- a/spec/fixtures/vcr_cassettes/success_socials.yml +++ b/spec/fixtures/vcr_cassettes/success_socials.yml @@ -416,4 +416,43 @@ http_interactions: } http_version: '1.1' recorded_at: Mon, 15 Dec 2014 07:39:09 GMT +- request: + method: get + uri: http://share.yandex.ru/gpp.xml?url=http%3A%2F%2Fwww.google.com + body: + encoding: US-ASCII + string: '' + headers: + user-agent: + - Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/534.56.5 (KHTML, + like Gecko) Version/5.1.6 Safari/534.56.5 + response: + status: + code: 200 + message: OK + headers: + server: + - nginx/1.6.2 + date: + - Mon, 15 Dec 2014 19:34:55 GMT + content-type: + - text/javascript; charset=utf-8 + transfer-encoding: + - chunked + connection: + - close + cache-control: + - max-age=0, must-revalidate, proxy-revalidate, no-cache, no-store, private + expires: + - Mon, 15 Dec 2014 19:34:55 GMT + pragma: + - no-cache + set-cookie: + - yandexuid=587059891418672095; domain=.yandex.ru; path=/; expires=Tue, 19 Jan + 2038 03:14:07 GMT + body: + encoding: UTF-8 + string: services.gplus.cb("10000"); + http_version: '1.1' + recorded_at: Mon, 15 Dec 2014 19:34:55 GMT recorded_with: VCR 2.9.3 diff --git a/spec/socials_spec.rb b/spec/socials_spec.rb index acf3579..3adef3c 100644 --- a/spec/socials_spec.rb +++ b/spec/socials_spec.rb @@ -5,6 +5,7 @@ subject{ PageRankr.social_trackers } it{ should include(:facebook) } + it{ should include(:google) } it{ should include(:linked_in) } it{ should include(:pinterest) } it{ should include(:stumble_upon) } @@ -20,12 +21,14 @@ end it{ should have_key(:facebook) } + it{ should have_key(:google) } it{ should have_key(:linked_in) } it{ should have_key(:pinterest) } it{ should have_key(:stumble_upon) } it{ should have_key(:twitter) } it{ subject[:facebook].should > 1000000 } + it{ subject[:google].should > 5000 } it{ subject[:linked_in].should > 500 } it{ subject[:pinterest].should > 70000 } it{ subject[:stumble_upon].should > 20000 } @@ -40,12 +43,14 @@ end it{ should have_key(:facebook) } + it{ should have_key(:google) } it{ should have_key(:linked_in) } it{ should have_key(:pinterest) } it{ should have_key(:stumble_upon) } it{ should have_key(:twitter) } it{ subject[:facebook].should be_nil } + it{ subject[:google].should == 0 } it{ subject[:linked_in].should == 0 } it{ subject[:pinterest].should == 0 } it{ subject[:stumble_upon].should be_nil }