tweets 0.0.1.pre2
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.
- data/README.rdoc +36 -0
- data/lib/tweets/version.rb +13 -0
- data/lib/tweets.rb +50 -0
- data/spec/tweets_spec.rb +20 -0
- metadata +48 -0
data/README.rdoc
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
=begin
|
2
|
+
= Tweets
|
3
|
+
|
4
|
+
Tweets provides lists of twitter updates based on the supplied string.
|
5
|
+
|
6
|
+
Build: http://github.com/james-turner/tweets
|
7
|
+
Gem: https://rubygems.org/gems/tweets
|
8
|
+
Wiki: http://github.com/james-turner/tweets/wiki
|
9
|
+
|
10
|
+
== Installation
|
11
|
+
|
12
|
+
The latest release is available on rubygems.
|
13
|
+
gem install tweets
|
14
|
+
|
15
|
+
== Require
|
16
|
+
|
17
|
+
To use tweets:
|
18
|
+
require 'tweets'
|
19
|
+
|
20
|
+
== Usage
|
21
|
+
|
22
|
+
The tweets method is available on all strings
|
23
|
+
and will return you an array of the latest twitter
|
24
|
+
status updates
|
25
|
+
|
26
|
+
It couldn't be simpler
|
27
|
+
"justin bieber".tweets
|
28
|
+
=>
|
29
|
+
["justin bieber is the best",
|
30
|
+
"i love justin bieber",
|
31
|
+
"wow, love the latest justin bieber track"
|
32
|
+
]
|
33
|
+
|
34
|
+
= COPYRIGHT
|
35
|
+
Copyright 2011 J. Turner <copyright@phpninjas.co.uk>.
|
36
|
+
=end
|
data/lib/tweets.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Tweets
|
5
|
+
module Extensions
|
6
|
+
module String
|
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}]"))
|
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
|
data/spec/tweets_spec.rb
ADDED
@@ -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
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tweets
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1.pre2
|
5
|
+
prerelease: 6
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- James Turner
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-10-13 00:00:00.000000000Z
|
13
|
+
dependencies: []
|
14
|
+
description: Tweet finder for strings
|
15
|
+
email:
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/tweets/version.rb
|
21
|
+
- lib/tweets.rb
|
22
|
+
- spec/tweets_spec.rb
|
23
|
+
- README.rdoc
|
24
|
+
homepage: http://github.com/james-turner/tweets
|
25
|
+
licenses: []
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ! '>='
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: 1.9.2
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ! '>'
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 1.3.1
|
42
|
+
requirements: []
|
43
|
+
rubyforge_project: tweets
|
44
|
+
rubygems_version: 1.8.10
|
45
|
+
signing_key:
|
46
|
+
specification_version: 3
|
47
|
+
summary: Tweet finder for strings
|
48
|
+
test_files: []
|