tweetly 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -2,7 +2,9 @@
2
2
 
3
3
  Generate nifty word frequency distributions from your Twitter statuses.
4
4
 
5
- Written and tested in __Ruby 1.9.3__.
5
+ Written and tested in __Ruby 1.9.3__
6
+
7
+ Gem hosted on [RubyGems](https://rubygems.org/gems/tweetly), where you can find more documentation.
6
8
 
7
9
  ## Installation
8
10
 
@@ -35,11 +37,11 @@ user.print_word_freq(tweets: 20, count: 5)
35
37
 
36
38
  which prints:
37
39
 
38
- for (5)
39
- $10 (3)
40
- @julioz2 (3)
41
- my (3)
42
- post: (2)
40
+ for (5)
41
+ $10 (3)
42
+ @julioz2 (3)
43
+ my (3)
44
+ post: (2)
43
45
 
44
46
  By default, Tweetly pulls the last 1000 tweets from the user's timeline and displays the entire list of words.
45
47
 
@@ -49,52 +51,53 @@ user.print_word_freq
49
51
 
50
52
  which prints:
51
53
 
52
- the (262)
53
- to (179)
54
- a (165)
55
- @Sualehh (161)
56
- my (112)
57
- RT (107)
58
- I (105)
59
- of (100)
60
- # and so on...
54
+ the (262)
55
+ to (179)
56
+ a (165)
57
+ @Sualehh (161)
58
+ my (112)
59
+ RT (107)
60
+ I (105)
61
+ of (100)
62
+ # and so on...
61
63
 
62
64
  Well, that's not a very interesting list. Let's ignore retweets as well as a few common words. Additionally, let's constrain our list to words of at least length 5, only word characters (i.e. letters, digits, underscores), and case insensitive:
63
65
 
64
66
  ```ruby
65
- options = {
66
- include_rts: false,
67
- ignore: ['the', 'to', 'a', 'I'],
68
- min_length: 5,
69
- words_only: true,
70
- case_sensitive: false
71
- }
72
- user.print_word_freq(options)
67
+ options = {
68
+ include_rts: false,
69
+ ignore: ['the', 'to', 'a', 'I'],
70
+ min_length: 5,
71
+ words_only: true,
72
+ case_sensitive: false
73
+ }
74
+
75
+ user.print_word_freq(options)
73
76
  ```
74
77
 
75
78
  The above prints out:
76
79
 
77
- sualehh (206)
78
- foursquare (31)
79
- julioz2 (30)
80
- mlacitation (24)
81
- compywiz (24)
82
- right (21)
83
- think (20)
84
- pretty (20)
80
+ sualehh (206)
81
+ foursquare (31)
82
+ julioz2 (30)
83
+ mlacitation (24)
84
+ compywiz (24)
85
+ right (21)
86
+ think (20)
87
+ pretty (20)
85
88
 
86
89
  Awesome! That's a great looking list.
87
90
 
88
91
  If you strictly want the words and not the frequency counts printed, you can pass in the option `print_count: false`. For the above, we would just have
89
92
 
90
- sualehh
91
- foursquare
92
- julioz2
93
- mlacitation
94
- compywiz
95
- right
96
- think
97
- pretty
93
+ sualehh
94
+ foursquare
95
+ julioz2
96
+ mlacitation
97
+ compywiz
98
+ right
99
+ think
100
+ pretty
98
101
 
99
102
  ## Contributing
100
103
 
data/lib/tweetly.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "tweetly/version"
2
2
  require "twitter"
3
3
  require "tweetly/user"
4
+ require "tweetly/error"
4
5
 
5
6
  module Tweetly
6
7
  # Your code goes here...
@@ -0,0 +1,15 @@
1
+ module Tweetly
2
+ class Error < StandardError
3
+
4
+ # Initializes a new Error object
5
+ #
6
+ # @param [String] message the error message
7
+ # @return [Tweetly::Error]
8
+ def initialize(message)
9
+ super(message)
10
+ end
11
+ end
12
+
13
+ class Error::Unauthorized < Tweetly::Error
14
+ end
15
+ end
data/lib/tweetly/user.rb CHANGED
@@ -5,12 +5,14 @@ module Tweetly
5
5
 
6
6
  def initialize(name)
7
7
  user = Twitter.user(name)
8
- unless user.protected?
8
+ if !user.protected?
9
9
  @name = user.name
10
10
  @screen_name = user.screen_name
11
11
  @protected = user.protected?
12
12
  @statuses_count = user.statuses_count
13
13
  @timeline = []
14
+ else
15
+ raise Tweetly::Error::Unauthorized, "User is protected", caller
14
16
  end
15
17
  end
16
18
 
@@ -40,26 +42,19 @@ module Tweetly
40
42
  fetch_timeline(params[:tweets]) if @timeline.count < params[:tweets]
41
43
 
42
44
  freqDist = {}
43
-
44
45
  @timeline.each_with_index do |tweet, i|
45
46
  # :include_rts option
46
47
  next if !params[:include_rts] && tweet.retweeted_status
47
48
 
48
49
  tweet.text.split.each do |word|
49
- # :ignore option
50
+ # Adjust according to options
50
51
  next if params[:ignore].include? word
51
-
52
- # :case_sensitive option
53
52
  word.downcase! if !params[:case_sensitive]
54
-
55
- # :words_only option
56
53
  if params[:words_only]
57
54
  word = word.match(/\w+/)
58
55
  next unless word
59
56
  word = word[0]
60
57
  end
61
-
62
- # :min_length option
63
58
  next if params[:min_length] && word.length < params[:min_length]
64
59
 
65
60
  if freqDist.has_key? word
@@ -1,3 +1,3 @@
1
1
  module Tweetly
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
data/spec/user_spec.rb CHANGED
@@ -11,6 +11,14 @@ describe Tweetly::User do
11
11
  end
12
12
  end
13
13
 
14
+ context "Initializing a protected user" do
15
+ it "should raise an error" do
16
+ lambda {
17
+ @user = Tweetly::User.new('lbpere')
18
+ }.should raise_error(Tweetly::Error::Unauthorized)
19
+ end
20
+ end
21
+
14
22
  context "Fetching a user timeline" do
15
23
  before do
16
24
  @user = Tweetly::User.new('jicooo')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tweetly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-05-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &70128994114340 !ruby/object:Gem::Requirement
16
+ requirement: &70228646582600 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70128994114340
24
+ version_requirements: *70228646582600
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &70128994113540 !ruby/object:Gem::Requirement
27
+ requirement: &70228646582020 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 2.9.0
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70128994113540
35
+ version_requirements: *70228646582020
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: twitter
38
- requirement: &70128994113060 !ruby/object:Gem::Requirement
38
+ requirement: &70228646581420 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70128994113060
46
+ version_requirements: *70228646581420
47
47
  description: Twitter user timeline stats.
48
48
  email:
49
49
  - jico@baligod.com
@@ -58,6 +58,7 @@ files:
58
58
  - README.md
59
59
  - Rakefile
60
60
  - lib/tweetly.rb
61
+ - lib/tweetly/error.rb
61
62
  - lib/tweetly/user.rb
62
63
  - lib/tweetly/version.rb
63
64
  - spec/spec_helper.rb
@@ -77,7 +78,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
77
78
  version: '0'
78
79
  segments:
79
80
  - 0
80
- hash: -4256241259014341675
81
+ hash: 3708206646365248655
81
82
  required_rubygems_version: !ruby/object:Gem::Requirement
82
83
  none: false
83
84
  requirements:
@@ -86,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
87
  version: '0'
87
88
  segments:
88
89
  - 0
89
- hash: -4256241259014341675
90
+ hash: 3708206646365248655
90
91
  requirements: []
91
92
  rubyforge_project:
92
93
  rubygems_version: 1.8.17