tweets 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,34 @@
1
+ = Tweets
2
+
3
+ Tweets provides lists of twitter updates based on the supplied string.
4
+
5
+ Build: http://github.com/james-turner/tweets
6
+ Gem: https://rubygems.org/gems/tweets
7
+ Wiki: http://github.com/james-turner/tweets/wiki
8
+
9
+ == Installation
10
+
11
+ The latest release is available on rubygems.
12
+ gem install tweets
13
+
14
+ == Require
15
+
16
+ To use tweets:
17
+ require 'tweets'
18
+
19
+ == Usage
20
+
21
+ The tweets method is available on all strings
22
+ and will return you an array of the latest twitter
23
+ status updates
24
+
25
+ It couldn't be simpler
26
+ "justin bieber".tweets
27
+ =>
28
+ ["justin bieber is the best",
29
+ "i love justin bieber",
30
+ "wow, love the latest justin bieber track"
31
+ ]
32
+
33
+ = COPYRIGHT
34
+ Copyright 2011 J. Turner <copyright@phpninjas.co.uk>.
@@ -1,5 +1,50 @@
1
- require 'tweets/extensions'
2
- require 'tweets/string'
1
+ require 'open-uri'
2
+ require 'json'
3
3
 
4
+ module Tweets
5
+ module Extensions
6
+ module String
4
7
 
8
+ # Retrieve the latest tweets defined by the string version of yourself.
9
+ #
10
+ # Example:
11
+ # >> "justin bieber".tweets
12
+ # => ["the bieb is amazing!", "moar beeb plox", ...]
13
+ #
14
+ # >> "@user".tweets
15
+ # => ["@user you are amazing", ...]
16
+ #
17
+ # >> "#tag"
18
+ # => ["#tag is the most cool twitter tag evah ya!", ...]
19
+ #
20
+ #
21
+ # The string can contain the syntax that is allowed in
22
+ # any of the twitter search
23
+ # @see https://dev.twitter.com/docs/using-search
24
+ #
25
+ # Arguments:
26
+ # language: (String)
27
+ def tweets
28
+ search = URI.escape(self.to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
5
29
 
30
+ begin
31
+ json = JSON.parse open("http://search.twitter.com/search.json?q=#{search}").read.to_s
32
+ json["results"].map { |result| result["text"] } unless json.has_key? "error" || []
33
+ rescue SocketError
34
+ # no socket connection.
35
+ raise SocketError, "Could not connect to the twitter search api. Check your internet connection."
36
+ rescue JSON::ParserError
37
+ # not json?
38
+ raise JSON::ParserError, "The response received from twitter was not JSON. Check your internet connection."
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ # In you go!
46
+ #
47
+ # Includes the tweets string extension
48
+ # inside the String ruby class via mixin
49
+ #
50
+ String.send :include, Tweets::Extensions::String
@@ -0,0 +1,13 @@
1
+ module Tweets
2
+ module Version
3
+ MAJOR = 0
4
+ MINOR = 0
5
+ PATCH = 2
6
+ BUILD = ""
7
+ STRING = [MAJOR, MINOR, PATCH, BUILD].select{|version| version.to_s.length > 0}.join('.')
8
+ end
9
+
10
+ def self.version
11
+ return Version::STRING
12
+ end
13
+ end
@@ -0,0 +1,20 @@
1
+ $:.unshift "#{File.dirname(__FILE__)}/../lib"
2
+ require 'tweets'
3
+ require 'tweets/version'
4
+ require 'rspec'
5
+
6
+ describe "tweets" do
7
+
8
+ it "should give me a list" do
9
+
10
+ "justin bieber".tweets.should be_a_kind_of Array
11
+
12
+ end
13
+
14
+ it "version should be in a major.minor.patch.build format" do
15
+
16
+ Tweets.version.should match /(\d\.){,3}(\w)/
17
+
18
+ end
19
+
20
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tweets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,20 +9,19 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-11 00:00:00.000000000Z
12
+ date: 2011-10-13 00:00:00.000000000Z
13
13
  dependencies: []
14
14
  description: Tweet finder for strings
15
- email: james.turner.phpninja@gmail.com
15
+ email:
16
16
  executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
- - README.rdoc
20
+ - lib/tweets/version.rb
21
21
  - lib/tweets.rb
22
22
  - spec/tweets_spec.rb
23
- - lib/tweets/extensions.rb
24
- - lib/tweets/string.rb
25
- homepage: ''
23
+ - README.rdoc
24
+ homepage: http://github.com/james-turner/tweets
26
25
  licenses: []
27
26
  post_install_message:
28
27
  rdoc_options: []
@@ -33,7 +32,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
33
32
  requirements:
34
33
  - - ! '>='
35
34
  - !ruby/object:Gem::Version
36
- version: '0'
35
+ version: 1.9.2
37
36
  required_rubygems_version: !ruby/object:Gem::Requirement
38
37
  none: false
39
38
  requirements:
@@ -1,21 +0,0 @@
1
- require 'open-uri'
2
- require 'json'
3
-
4
- module Tweets
5
- module Extensions
6
- module String
7
-
8
- # tweets => []
9
- #
10
- #
11
- def tweets
12
- tweets = []
13
- search = URI.escape(self.to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
14
- json = JSON.parse open("http://search.twitter.com/search.json?q=#{search}").read.to_s
15
-
16
- tweets = json["results"].map { |result| result["text"] } unless json.has_key? "error"
17
- tweets
18
- end
19
- end
20
- end
21
- end
@@ -1,9 +0,0 @@
1
- # tweets => ["one","two","three",...]
2
- #
3
- #
4
- # Includes the tweets string extension
5
- # inside the String ruby class via mixin
6
- #
7
- class String
8
- include Tweets::Extensions::String
9
- end