twittercounter 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.watchr ADDED
@@ -0,0 +1,18 @@
1
+ def run_spec(file)
2
+ unless File.exist?(file)
3
+ puts "#{file} does not exist"
4
+ return
5
+ end
6
+
7
+ puts "Running #{file}"
8
+ system "bundle exec rspec #{file}"
9
+ puts
10
+ end
11
+
12
+ watch("spec/.*/*_spec\.rb") do |match|
13
+ run_spec match[0]
14
+ end
15
+
16
+ watch("lib/(.*)\.rb") do |match|
17
+ run_spec %{spec/#{match[1]}_spec.rb}
18
+ end
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "httparty"
4
+
5
+ group :development do
6
+ gem "rspec", "~> 2.3.0"
7
+ gem "bundler", "~> 1.0.0"
8
+ gem "jeweler", "~> 1.6.4"
9
+ gem "rcov", ">= 0"
10
+ gem "vcr"
11
+ gem "fakeweb"
12
+ gem "watchr"
13
+ end
@@ -0,0 +1,38 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ crack (0.1.8)
5
+ diff-lcs (1.1.2)
6
+ fakeweb (1.3.0)
7
+ git (1.2.5)
8
+ httparty (0.7.4)
9
+ crack (= 0.1.8)
10
+ jeweler (1.6.4)
11
+ bundler (~> 1.0)
12
+ git (>= 1.2.5)
13
+ rake
14
+ rake (0.9.2)
15
+ rcov (0.9.9)
16
+ rspec (2.3.0)
17
+ rspec-core (~> 2.3.0)
18
+ rspec-expectations (~> 2.3.0)
19
+ rspec-mocks (~> 2.3.0)
20
+ rspec-core (2.3.1)
21
+ rspec-expectations (2.3.0)
22
+ diff-lcs (~> 1.1.2)
23
+ rspec-mocks (2.3.0)
24
+ vcr (1.10.0)
25
+ watchr (0.7)
26
+
27
+ PLATFORMS
28
+ ruby
29
+
30
+ DEPENDENCIES
31
+ bundler (~> 1.0.0)
32
+ fakeweb
33
+ httparty
34
+ jeweler (~> 1.6.4)
35
+ rcov
36
+ rspec (~> 2.3.0)
37
+ vcr
38
+ watchr
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Jesus Lopes
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,60 @@
1
+ = twittercounter
2
+
3
+ Simple library to access Twitter Counter API.
4
+
5
+ == Basic Usage
6
+
7
+ You'll need the API key for Twitter Counter. See the Twitter Counter API[http://twittercounter.com/pages/api] for request an API key.
8
+
9
+ Twittercounter::Client.new(:apikey => "12345", :twitter_id => "18770991")
10
+
11
+ Returns object with methods:
12
+
13
+ version : the current API version
14
+ username : Twitter username of the requested user
15
+ url : URL of the request user
16
+ avatar : avatar URL of the requested user
17
+ followers_current : current followers count of the requested user
18
+ date_updated : the latest statistics update for the requested user
19
+ follow_days : the number of days Twitter Counter has been tracking the requested user
20
+ started_followers : the number of followers when we started tracking the requested user
21
+ growth_since : the number of followers gained since we started tracking the requested user
22
+ average_growth : the average growth per day of the requested user
23
+ tomorrow : our followers prediction for tomorrow for the requested user
24
+ next_month : our followers prediction for the next month for the requested user
25
+ followers_yesterday : the number of followers for the previous day for the requested user
26
+ rank : the requested user's rank as calculated by Twitter Counter
27
+ followersperdate : a list of dates and the followers count on that date. The list is formatted like this: date{yyyy-mm-dd} : {followers_count}
28
+ last_update : a UNIX timestamp of when this record was last updated
29
+
30
+ Other methods are:
31
+
32
+ followers_2w_ago, growth_since_2w, average_growth_2w, tomorrow_2w and next_month_2w
33
+
34
+ You can specify twitter username instead of twitter id, see:
35
+
36
+ info = Twittercounter::Client.new(:apikey => "12345", :twitter_username => "zigotto")
37
+
38
+ info.twitter_id
39
+ => 18770991
40
+
41
+ ...
42
+
43
+ == More details
44
+
45
+ Please, see Twitter Counter API[http://twittercounter.com/pages/api].
46
+
47
+ == Contributing to twittercounter
48
+
49
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
50
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
51
+ * Fork the project
52
+ * Start a feature/bugfix branch
53
+ * Commit and push until you are happy with your contribution
54
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
55
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
56
+
57
+ == Copyright
58
+
59
+ Copyright (c) 2011 Zigotto. See LICENSE.txt for
60
+ further details.
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "twittercounter"
18
+ gem.homepage = "http://github.com/zigotto/twittercounter"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Library to access Twitter Counter API}
21
+ gem.description = %Q{Simple library to access Twitter Counter API}
22
+ gem.email = "jlopes@zigotto.com.br"
23
+ gem.authors = ["Jesus Lopes"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'rake/rdoctask'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "twittercounter #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,60 @@
1
+ require "httparty"
2
+
3
+ module Twittercounter
4
+
5
+ class Request
6
+ include HTTParty
7
+ end
8
+
9
+ class Client
10
+
11
+ attr_accessor :apikey, :twitter_id
12
+ attr_accessor :version, :username, :url, :avatar, :followers_current, :date_updated, :follow_days,
13
+ :started_followers, :growth_since, :average_growth, :tomorrow, :next_month, :followers_yesterday,
14
+ :rank, :followers_2w_ago, :growth_since_2w, :average_growth_2w, :tomorrow_2w, :next_month_2w, :followersperdate, :last_update
15
+
16
+ def initialize(options={})
17
+ options = {:output => "json", :count => "14"}.merge!(options)
18
+ raise "apikey is required" if options[:apikey].blank?
19
+ raise "twitter_id or twitter_username is required" if options[:twitter_id].blank? && options[:twitter_username].blank?
20
+
21
+ if options.has_key?(:twitter_username)
22
+ twitter_id = Request.get("http://api.twitter.com/users/show.json", :query => {:screen_name => options.delete(:twitter_username)})["id"]
23
+ options.merge!(:twitter_id => twitter_id)
24
+ end
25
+
26
+ self.apikey = options[:apikey]
27
+ self.twitter_id = options[:twitter_id]
28
+
29
+ response = Request.get("http://api.twittercounter.com", :query => options)
30
+ if response.code == 200
31
+ self.version = response["version"]
32
+ self.username = response["username"]
33
+ self.url = response["url"]
34
+ self.avatar = response["avatar"]
35
+ self.followers_current = response["followers_current"]
36
+ self.date_updated = response["date_updated"]
37
+ self.follow_days = response["follow_days"]
38
+ self.started_followers = response["started_followers"]
39
+ self.growth_since = response["growth_since"]
40
+ self.average_growth = response["average_growth"]
41
+ self.tomorrow = response["tomorrow"]
42
+ self.next_month = response["next_month"]
43
+ self.followers_yesterday = response["followers_yesterday"]
44
+ self.rank = response["rank"]
45
+ self.followers_2w_ago = response["followers_2w_ago"]
46
+ self.growth_since_2w = response["growth_since_2w"]
47
+ self.average_growth_2w = response["average_growth_2w"]
48
+ self.tomorrow_2w = response["tomorrow_2w"]
49
+ self.next_month_2w = response["next_month_2w"]
50
+ self.followersperdate = response["followersperdate"]
51
+ self.last_update = response["last_update"]
52
+ else
53
+ raise "#{response.code} #{response.message}"
54
+ end
55
+
56
+ end
57
+
58
+ end
59
+
60
+ end
@@ -0,0 +1,28 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: http://api.twittercounter.com:80/?output=json&count=14&apikey=invalid_api&twitter_id=1123invalid
6
+ body:
7
+ headers:
8
+ response: !ruby/struct:VCR::Response
9
+ status: !ruby/struct:VCR::ResponseStatus
10
+ code: 401
11
+ message: Unauthorized
12
+ headers:
13
+ date:
14
+ - Tue, 26 Jul 2011 05:01:33 GMT
15
+ server:
16
+ - Apache/2.2.17 (Fedora)
17
+ x-powered-by:
18
+ - PHP/5.3.3
19
+ cache-control:
20
+ - no-cache, must-revalidate
21
+ expires:
22
+ - Mon, 26 Jul 1997 05:00:00 GMT
23
+ content-length:
24
+ - "57"
25
+ content-type:
26
+ - application/json
27
+ body: "{\"version\":\"1.1\",\"error\":\"API credentials are incorrect\"}"
28
+ http_version: "1.1"
@@ -0,0 +1,28 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: http://api.twittercounter.com:80/?output=json&count=14&apikey=e9335031a759f251ee9b4e2e6634e1c5&twitter_id=123invalid456ID
6
+ body:
7
+ headers:
8
+ response: !ruby/struct:VCR::Response
9
+ status: !ruby/struct:VCR::ResponseStatus
10
+ code: 404
11
+ message: Not Found
12
+ headers:
13
+ date:
14
+ - Tue, 26 Jul 2011 03:37:53 GMT
15
+ server:
16
+ - Apache/2.2.17 (Fedora)
17
+ x-powered-by:
18
+ - PHP/5.3.3
19
+ cache-control:
20
+ - no-cache, must-revalidate
21
+ expires:
22
+ - Mon, 26 Jul 1997 05:00:00 GMT
23
+ content-length:
24
+ - "67"
25
+ content-type:
26
+ - application/json
27
+ body: "{\"version\":\"1.1\",\"error\":\"Could not load statistics for this user\"}"
28
+ http_version: "1.1"
@@ -0,0 +1,82 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: http://api.twitter.com:80/users/show.json?screen_name=123invalid456ID
6
+ body:
7
+ headers:
8
+ response: !ruby/struct:VCR::Response
9
+ status: !ruby/struct:VCR::ResponseStatus
10
+ code: 404
11
+ message: Not Found
12
+ headers:
13
+ date:
14
+ - Tue, 26 Jul 2011 04:35:38 GMT
15
+ server:
16
+ - hi
17
+ status:
18
+ - 404 Not Found
19
+ x-transaction:
20
+ - 1311654938-43980-14664
21
+ x-ratelimit-limit:
22
+ - "150"
23
+ x-frame-options:
24
+ - SAMEORIGIN
25
+ last-modified:
26
+ - Tue, 26 Jul 2011 04:35:38 GMT
27
+ x-ratelimit-remaining:
28
+ - "109"
29
+ content-type:
30
+ - application/json; charset=utf-8
31
+ content-length:
32
+ - "80"
33
+ pragma:
34
+ - no-cache
35
+ x-ratelimit-class:
36
+ - api
37
+ x-revision:
38
+ - DEV
39
+ expires:
40
+ - Tue, 31 Mar 1981 05:00:00 GMT
41
+ cache-control:
42
+ - no-cache, no-store, must-revalidate, pre-check=0, post-check=0
43
+ x-mid:
44
+ - 071266308458f6c6b96c2cc6b218ca95e3979a05
45
+ x-ratelimit-reset:
46
+ - "1311655885"
47
+ set-cookie:
48
+ - k=201.23.177.72.1311654938689734; path=/; expires=Tue, 02-Aug-11 04:35:38 GMT; domain=.twitter.com
49
+ - guest_id=v1%3A13116549386953595; domain=.twitter.com; path=/; expires=Thu, 25 Jul 2013 16:35:38 GMT
50
+ - _twitter_sess=BAh7CDoPY3JlYXRlZF9hdGwrCEgIumQxAToHaWQiJWMxNWI0MzA3OTY3ZGVh%250AYmRkYzg4NDFkMWY4OTYyN2YwIgpmbGFzaElDOidBY3Rpb25Db250cm9sbGVy%250AOjpGbGFzaDo6Rmxhc2hIYXNoewAGOgpAdXNlZHsA--5cab84a84a8327447e4631d3810db95b5861fd47; domain=.twitter.com; path=/; HttpOnly
51
+ vary:
52
+ - Accept-Encoding
53
+ body: "{\"error\":\"Not found\",\"request\":\"\\/users\\/show.json?screen_name=123invalid456ID\"}"
54
+ http_version: "1.1"
55
+
56
+ - !ruby/struct:VCR::HTTPInteraction
57
+ request: !ruby/struct:VCR::Request
58
+ method: :get
59
+ uri: http://api.twittercounter.com:80/?output=json&count=14&apikey=e9335031a759f251ee9b4e2e6634e1c5&twitter_id=
60
+ body:
61
+ headers:
62
+ response: !ruby/struct:VCR::Response
63
+ status: !ruby/struct:VCR::ResponseStatus
64
+ code: 404
65
+ message: Not Found
66
+ headers:
67
+ date:
68
+ - Tue, 26 Jul 2011 04:42:23 GMT
69
+ server:
70
+ - Apache/2.2.17 (Fedora)
71
+ x-powered-by:
72
+ - PHP/5.3.3
73
+ cache-control:
74
+ - no-cache, must-revalidate
75
+ expires:
76
+ - Mon, 26 Jul 1997 05:00:00 GMT
77
+ content-length:
78
+ - "58"
79
+ content-type:
80
+ - application/json
81
+ body: "{\"version\":\"1.1\",\"error\":\"Invalid username or twitter_id\"}"
82
+ http_version: "1.1"
@@ -0,0 +1,28 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: http://api.twittercounter.com:80/?output=json&count=14&apikey=e9335031a759f251ee9b4e2e6634e1c5&twitter_id=15160529
6
+ body:
7
+ headers:
8
+ response: !ruby/struct:VCR::Response
9
+ status: !ruby/struct:VCR::ResponseStatus
10
+ code: 200
11
+ message: OK
12
+ headers:
13
+ date:
14
+ - Tue, 26 Jul 2011 03:28:09 GMT
15
+ server:
16
+ - Apache/2.2.17 (Fedora)
17
+ x-powered-by:
18
+ - PHP/5.3.3
19
+ cache-control:
20
+ - max-age=1800, must-revalidate
21
+ expires:
22
+ - Tue, 26 Jul 2011 03:58:10 GMT
23
+ content-length:
24
+ - "872"
25
+ content-type:
26
+ - application/json
27
+ body: "{\"version\":\"1.1\",\"username\":\"TheCounter\",\"url\":\"http:\\/\\/twittercounter.com\\/\",\"avatar\":\"http:\\/\\/a1.twimg.com\\/profile_images\\/481277925\\/twc_logo_normal.png\",\"followers_current\":10305,\"date_updated\":\"2011-07-25\",\"follow_days\":\"663\",\"started_followers\":\"3617\",\"growth_since\":6688,\"average_growth\":\"10\",\"tomorrow\":\"10315\",\"next_month\":\"10605\",\"followers_yesterday\":10299,\"rank\":\"38148\",\"followers_2w_ago\":10139,\"growth_since_2w\":166,\"average_growth_2w\":\"12\",\"tomorrow_2w\":\"10317\",\"next_month_2w\":\"10665\",\"followersperdate\":{\"date2011-07-25\":10305,\"date2011-07-24\":10299,\"date2011-07-23\":10308,\"date2011-07-22\":10300,\"date2011-07-21\":10284,\"date2011-07-20\":10268,\"date2011-07-19\":10252,\"date2011-07-18\":10236,\"date2011-07-17\":10220,\"date2011-07-16\":10216,\"date2011-07-15\":10199,\"date2011-07-14\":10175,\"date2011-07-13\":10160,\"date2011-07-12\":10154},\"last_update\":1311650890}"
28
+ http_version: "1.1"
@@ -0,0 +1,88 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: http://api.twitter.com:80/users/show.json?screen_name=zigotto
6
+ body:
7
+ headers:
8
+ response: !ruby/struct:VCR::Response
9
+ status: !ruby/struct:VCR::ResponseStatus
10
+ code: 200
11
+ message: OK
12
+ headers:
13
+ date:
14
+ - Tue, 26 Jul 2011 04:16:02 GMT
15
+ server:
16
+ - hi
17
+ status:
18
+ - 200 OK
19
+ x-transaction:
20
+ - 1311653762-27604-12924
21
+ x-ratelimit-limit:
22
+ - "150"
23
+ etag:
24
+ - "\"20f09e76f4e18e5a84c5a1776ceb6088\""
25
+ x-frame-options:
26
+ - SAMEORIGIN
27
+ last-modified:
28
+ - Tue, 26 Jul 2011 04:16:02 GMT
29
+ x-ratelimit-remaining:
30
+ - "119"
31
+ x-runtime:
32
+ - "0.02314"
33
+ x-transaction-mask:
34
+ - a6183ffa5f8ca943ff1b53b5644ef114b15be17f
35
+ content-type:
36
+ - application/json; charset=utf-8
37
+ content-length:
38
+ - "1987"
39
+ pragma:
40
+ - no-cache
41
+ x-ratelimit-class:
42
+ - api
43
+ x-revision:
44
+ - DEV
45
+ expires:
46
+ - Tue, 31 Mar 1981 05:00:00 GMT
47
+ cache-control:
48
+ - no-cache, no-store, must-revalidate, pre-check=0, post-check=0
49
+ x-mid:
50
+ - 35391f55fcd3c1ef007504e90dcf0d4283e95e8f
51
+ x-ratelimit-reset:
52
+ - "1311655885"
53
+ set-cookie:
54
+ - k=201.23.177.72.1311653762806791; path=/; expires=Tue, 02-Aug-11 04:16:02 GMT; domain=.twitter.com
55
+ - guest_id=v1%3A131165376295821549; domain=.twitter.com; path=/; expires=Thu, 25 Jul 2013 16:16:02 GMT
56
+ - _twitter_sess=BAh7CDoPY3JlYXRlZF9hdGwrCJEXqGQxAToHaWQiJWFlMTQxOGJkMThlN2Ni%250AZDRhZmY2MmI5NjI1Njk0ZDY1IgpmbGFzaElDOidBY3Rpb25Db250cm9sbGVy%250AOjpGbGFzaDo6Rmxhc2hIYXNoewAGOgpAdXNlZHsA--e542ca3175dcd4bb1b76c29853d5df29cb266cbc; domain=.twitter.com; path=/; HttpOnly
57
+ vary:
58
+ - Accept-Encoding
59
+ body: "{\"default_profile_image\":false,\"default_profile\":false,\"statuses_count\":264,\"profile_sidebar_border_color\":\"eeeeee\",\"protected\":false,\"contributors_enabled\":false,\"following\":false,\"time_zone\":\"Greenland\",\"favourites_count\":0,\"url\":\"http:\\/\\/www.zigotto.com.br\",\"name\":\"Zigotto\",\"is_translator\":false,\"verified\":false,\"notifications\":false,\"profile_use_background_image\":true,\"follow_request_sent\":false,\"utc_offset\":-10800,\"created_at\":\"Thu Jan 08 17:30:09 +0000 2009\",\"friends_count\":15,\"profile_background_color\":\"f7f7f7\",\"profile_background_image_url\":\"http:\\/\\/a0.twimg.com\\/profile_background_images\\/172928449\\/bg_site.jpg\",\"status\":{\"in_reply_to_status_id_str\":null,\"coordinates\":null,\"in_reply_to_screen_name\":null,\"in_reply_to_status_id\":null,\"in_reply_to_user_id_str\":null,\"contributors\":null,\"retweeted\":false,\"created_at\":\"Tue Jun 28 21:11:29 +0000 2011\",\"text\":\"Aten\\u00e7\\u00e3o desenvolvedores do Vale do Para\\u00edba, n\\u00e3o percam www.agilevale.com.br #AgileVale\",\"in_reply_to_user_id\":null,\"place\":null,\"geo\":null,\"retweet_count\":1,\"source\":\"\\u003Ca href=\\\"http:\\/\\/itunes.apple.com\\/us\\/app\\/twitter\\/id409789998?mt=12\\\" rel=\\\"nofollow\\\"\\u003ETwitter for Mac\\u003C\\/a\\u003E\",\"truncated\":false,\"id\":85817618442895360,\"id_str\":\"85817618442895360\",\"favorited\":false},\"profile_text_color\":\"333333\",\"description\":\"Desenvolvimento Web.\",\"listed_count\":15,\"lang\":\"en\",\"profile_sidebar_fill_color\":\"e0e0e0\",\"profile_image_url\":\"http:\\/\\/a3.twimg.com\\/profile_images\\/1267147803\\/zigotto-twitter_normal.jpg\",\"show_all_inline_media\":false,\"geo_enabled\":true,\"profile_background_tile\":true,\"followers_count\":224,\"profile_background_image_url_https\":\"https:\\/\\/si0.twimg.com\\/profile_background_images\\/172928449\\/bg_site.jpg\",\"screen_name\":\"zigotto\",\"id\":18770991,\"id_str\":\"18770991\",\"profile_link_color\":\"941896\",\"profile_image_url_https\":\"https:\\/\\/si0.twimg.com\\/profile_images\\/1267147803\\/zigotto-twitter_normal.jpg\",\"location\":\"S\\u00e3o Jos\\u00e9 dos Campos, SP, Brazi\"}"
60
+ http_version: "1.1"
61
+
62
+ - !ruby/struct:VCR::HTTPInteraction
63
+ request: !ruby/struct:VCR::Request
64
+ method: :get
65
+ uri: http://api.twittercounter.com:80/?output=json&count=14&apikey=e9335031a759f251ee9b4e2e6634e1c5&twitter_id=18770991
66
+ body:
67
+ headers:
68
+ response: !ruby/struct:VCR::Response
69
+ status: !ruby/struct:VCR::ResponseStatus
70
+ code: 200
71
+ message: OK
72
+ headers:
73
+ date:
74
+ - Tue, 26 Jul 2011 04:22:54 GMT
75
+ server:
76
+ - Apache/2.2.17 (Fedora)
77
+ x-powered-by:
78
+ - PHP/5.3.3
79
+ cache-control:
80
+ - max-age=1800, must-revalidate
81
+ expires:
82
+ - Tue, 26 Jul 2011 04:52:58 GMT
83
+ content-length:
84
+ - "448"
85
+ content-type:
86
+ - application/json
87
+ body: "{\"version\":\"1.1\",\"username\":\"zigotto\",\"url\":\"http:\\/\\/www.zigotto.com.br\",\"avatar\":\"http:\\/\\/a3.twimg.com\\/profile_images\\/1267147803\\/zigotto-twitter_normal.jpg\",\"followers_current\":224,\"date_updated\":\"2011-07-25\",\"follow_days\":\"15181\",\"started_followers\":null,\"growth_since\":224,\"average_growth\":\"0\",\"tomorrow\":\"224\",\"next_month\":\"224\",\"followers_yesterday\":null,\"rank\":\"340176\",\"followersperdate\":{\"date2011-07-25\":224},\"last_update\":1311653970}"
88
+ http_version: "1.1"
@@ -0,0 +1,20 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'vcr'
5
+ require 'twittercounter'
6
+
7
+ # Requires supporting files with custom matchers and macros, etc,
8
+ # in ./support/ and its subdirectories.
9
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
10
+
11
+ RSpec.configure do |config|
12
+ config.extend VCR::RSpec::Macros
13
+ end
14
+
15
+ VCR.config do |c|
16
+ c.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
17
+ c.stub_with :fakeweb
18
+ c.default_cassette_options = { :record => :once }
19
+ c.allow_http_connections_when_no_cassette = false
20
+ end
@@ -0,0 +1,104 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Twittercounter do
4
+
5
+ context "when use a invalid credentials" do
6
+ use_vcr_cassette "invalid_credentials"
7
+ it { expect { Twittercounter::Client.new(:apikey => "invalid_api", :twitter_id => "1123invalid")}.to raise_error(/401 Unauthorized/) }
8
+ end
9
+
10
+ context "when use a invalid twitter id" do
11
+ use_vcr_cassette "invalid_twitter_id"
12
+ it { expect { Twittercounter::Client.new(:apikey => "e9335031a759f251ee9b4e2e6634e1c5", :twitter_id => "123invalid456ID")}.to raise_error(/404 Not Found/) }
13
+ end
14
+
15
+ context "when use a invalid twitter username" do
16
+ use_vcr_cassette "invalid_twitter_username"
17
+ it { expect { Twittercounter::Client.new(:apikey => "e9335031a759f251ee9b4e2e6634e1c5", :twitter_username => "123invalid456ID")}.to raise_error(/404 Not Found/) }
18
+ end
19
+
20
+ context "when invalid required parameters" do
21
+ it "should raise exception when apikey is blank" do
22
+ expect { Twittercounter::Client.new(:apikey => nil, :twitter_id => "15160529")}.to raise_error(/apikey is required/)
23
+ expect { Twittercounter::Client.new(:twitter_id => "15160529")}.to raise_error(/apikey is required/)
24
+ end
25
+ it "should raise exception when twitter_id is blank" do
26
+ expect { Twittercounter::Client.new(:apikey => "adfas123", :twitter_id => nil)}.to raise_error(/twitter_id or twitter_username is required/)
27
+ end
28
+ it "should raise exception when twitter_username is blank" do
29
+ expect { Twittercounter::Client.new(:apikey => "adfas123", :twitter_username => nil)}.to raise_error(/twitter_id or twitter_username is required/)
30
+ end
31
+ end
32
+
33
+ context "provides information about a twitter username" do
34
+
35
+ use_vcr_cassette "twitter_username_zigotto"
36
+
37
+ let(:info) do
38
+ Twittercounter::Client.new(
39
+ :apikey => "e9335031a759f251ee9b4e2e6634e1c5",
40
+ :twitter_username => "zigotto"
41
+ )
42
+ end
43
+
44
+ it { info.twitter_id.should == 18770991 }
45
+ it { info.username.should == "zigotto" }
46
+ it { info.followers_current.should == 224 }
47
+
48
+ end
49
+
50
+ context "provides information about a twitter id" do
51
+
52
+ use_vcr_cassette "twitter_id_15160529"
53
+
54
+ let(:info) do
55
+ Twittercounter::Client.new(
56
+ :apikey => "e9335031a759f251ee9b4e2e6634e1c5",
57
+ :twitter_id => "15160529"
58
+ )
59
+ end
60
+
61
+ it { info.apikey.should == "e9335031a759f251ee9b4e2e6634e1c5" }
62
+ it { info.twitter_id.should == "15160529" }
63
+
64
+ it { info.version.should == "1.1" }
65
+ it { info.username.should == "TheCounter" }
66
+ it { info.url.should == "http://twittercounter.com/" }
67
+ it { info.avatar.should == "http://a1.twimg.com/profile_images/481277925/twc_logo_normal.png" }
68
+ it { info.followers_current.should == 10305 }
69
+ it { info.date_updated.should == Date.new(2011, 07, 25) }
70
+ it { info.follow_days.should == "663" }
71
+ it { info.started_followers.should == "3617" }
72
+ it { info.growth_since.should == 6688 }
73
+ it { info.average_growth.should == "10" }
74
+ it { info.tomorrow.should == "10315" }
75
+ it { info.next_month.should == "10605" }
76
+ it { info.followers_yesterday.should == 10299 }
77
+ it { info.rank.should == "38148" }
78
+ it { info.followers_2w_ago.should == 10139 }
79
+ it { info.growth_since_2w.should == 166 }
80
+ it { info.average_growth_2w.should == "12" }
81
+ it { info.tomorrow_2w.should == "10317" }
82
+ it { info.next_month_2w.should == "10665" }
83
+ it { info.followersperdate.should == {
84
+ "date2011-07-25"=>10305,
85
+ "date2011-07-24"=>10299,
86
+ "date2011-07-23"=>10308,
87
+ "date2011-07-22"=>10300,
88
+ "date2011-07-21"=>10284,
89
+ "date2011-07-20"=>10268,
90
+ "date2011-07-19"=>10252,
91
+ "date2011-07-18"=>10236,
92
+ "date2011-07-17"=>10220,
93
+ "date2011-07-16"=>10216,
94
+ "date2011-07-15"=>10199,
95
+ "date2011-07-14"=>10175,
96
+ "date2011-07-13"=>10160,
97
+ "date2011-07-12"=>10154
98
+ }
99
+ }
100
+ it { info.last_update.should == 1311650890 }
101
+
102
+ end
103
+
104
+ end
@@ -0,0 +1,78 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{twittercounter}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Jesus Lopes"]
12
+ s.date = %q{2011-07-26}
13
+ s.description = %q{Simple library to access Twitter Counter API}
14
+ s.email = %q{jlopes@zigotto.com.br}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ ".watchr",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "LICENSE.txt",
26
+ "README.rdoc",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "lib/twittercounter.rb",
30
+ "spec/fixtures/vcr_cassettes/invalid_credentials.yml",
31
+ "spec/fixtures/vcr_cassettes/invalid_twitter_id.yml",
32
+ "spec/fixtures/vcr_cassettes/invalid_twitter_username.yml",
33
+ "spec/fixtures/vcr_cassettes/twitter_id_15160529.yml",
34
+ "spec/fixtures/vcr_cassettes/twitter_username_zigotto.yml",
35
+ "spec/spec_helper.rb",
36
+ "spec/twittercounter_spec.rb",
37
+ "twittercounter.gemspec"
38
+ ]
39
+ s.homepage = %q{http://github.com/zigotto/twittercounter}
40
+ s.licenses = ["MIT"]
41
+ s.require_paths = ["lib"]
42
+ s.rubygems_version = %q{1.7.2}
43
+ s.summary = %q{Library to access Twitter Counter API}
44
+
45
+ if s.respond_to? :specification_version then
46
+ s.specification_version = 3
47
+
48
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
49
+ s.add_runtime_dependency(%q<httparty>, [">= 0"])
50
+ s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
51
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
52
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
53
+ s.add_development_dependency(%q<rcov>, [">= 0"])
54
+ s.add_development_dependency(%q<vcr>, [">= 0"])
55
+ s.add_development_dependency(%q<fakeweb>, [">= 0"])
56
+ s.add_development_dependency(%q<watchr>, [">= 0"])
57
+ else
58
+ s.add_dependency(%q<httparty>, [">= 0"])
59
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
60
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
61
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
62
+ s.add_dependency(%q<rcov>, [">= 0"])
63
+ s.add_dependency(%q<vcr>, [">= 0"])
64
+ s.add_dependency(%q<fakeweb>, [">= 0"])
65
+ s.add_dependency(%q<watchr>, [">= 0"])
66
+ end
67
+ else
68
+ s.add_dependency(%q<httparty>, [">= 0"])
69
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
70
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
71
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
72
+ s.add_dependency(%q<rcov>, [">= 0"])
73
+ s.add_dependency(%q<vcr>, [">= 0"])
74
+ s.add_dependency(%q<fakeweb>, [">= 0"])
75
+ s.add_dependency(%q<watchr>, [">= 0"])
76
+ end
77
+ end
78
+
metadata ADDED
@@ -0,0 +1,162 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: twittercounter
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.0
6
+ platform: ruby
7
+ authors:
8
+ - Jesus Lopes
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-07-26 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: httparty
17
+ requirement: &id001 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "0"
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: rspec
28
+ requirement: &id002 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 2.3.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
38
+ name: bundler
39
+ requirement: &id003 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ version: 1.0.0
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *id003
48
+ - !ruby/object:Gem::Dependency
49
+ name: jeweler
50
+ requirement: &id004 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: 1.6.4
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: *id004
59
+ - !ruby/object:Gem::Dependency
60
+ name: rcov
61
+ requirement: &id005 !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
67
+ type: :development
68
+ prerelease: false
69
+ version_requirements: *id005
70
+ - !ruby/object:Gem::Dependency
71
+ name: vcr
72
+ requirement: &id006 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: "0"
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: *id006
81
+ - !ruby/object:Gem::Dependency
82
+ name: fakeweb
83
+ requirement: &id007 !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: "0"
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: *id007
92
+ - !ruby/object:Gem::Dependency
93
+ name: watchr
94
+ requirement: &id008 !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: "0"
100
+ type: :development
101
+ prerelease: false
102
+ version_requirements: *id008
103
+ description: Simple library to access Twitter Counter API
104
+ email: jlopes@zigotto.com.br
105
+ executables: []
106
+
107
+ extensions: []
108
+
109
+ extra_rdoc_files:
110
+ - LICENSE.txt
111
+ - README.rdoc
112
+ files:
113
+ - .document
114
+ - .rspec
115
+ - .watchr
116
+ - Gemfile
117
+ - Gemfile.lock
118
+ - LICENSE.txt
119
+ - README.rdoc
120
+ - Rakefile
121
+ - VERSION
122
+ - lib/twittercounter.rb
123
+ - spec/fixtures/vcr_cassettes/invalid_credentials.yml
124
+ - spec/fixtures/vcr_cassettes/invalid_twitter_id.yml
125
+ - spec/fixtures/vcr_cassettes/invalid_twitter_username.yml
126
+ - spec/fixtures/vcr_cassettes/twitter_id_15160529.yml
127
+ - spec/fixtures/vcr_cassettes/twitter_username_zigotto.yml
128
+ - spec/spec_helper.rb
129
+ - spec/twittercounter_spec.rb
130
+ - twittercounter.gemspec
131
+ homepage: http://github.com/zigotto/twittercounter
132
+ licenses:
133
+ - MIT
134
+ post_install_message:
135
+ rdoc_options: []
136
+
137
+ require_paths:
138
+ - lib
139
+ required_ruby_version: !ruby/object:Gem::Requirement
140
+ none: false
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ hash: -3982709042434259989
145
+ segments:
146
+ - 0
147
+ version: "0"
148
+ required_rubygems_version: !ruby/object:Gem::Requirement
149
+ none: false
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ version: "0"
154
+ requirements: []
155
+
156
+ rubyforge_project:
157
+ rubygems_version: 1.7.2
158
+ signing_key:
159
+ specification_version: 3
160
+ summary: Library to access Twitter Counter API
161
+ test_files: []
162
+