dancroak-twitter-search 0.4

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.markdown ADDED
@@ -0,0 +1,145 @@
1
+ <<<<<<< HEAD:README.markdown
2
+ # A simple Summize client for Ruby.
3
+ =======
4
+ # A Twitter Search client for Ruby.
5
+ >>>>>>> ef8ef7aaafceb04d69cdfb3963f229ec1ab666db:README.markdown
6
+
7
+ <<<<<<< HEAD:README.markdown
8
+ Access the Summize API from your Ruby code.
9
+ =======
10
+ Access the Twitter Search API from your Ruby code.
11
+ >>>>>>> ef8ef7aaafceb04d69cdfb3963f229ec1ab666db:README.markdown
12
+
13
+ ## Usage
14
+
15
+ <<<<<<< HEAD:README.markdown
16
+ =======
17
+ Install the gem.
18
+
19
+ sudo gem install dancroak-twitter-search -s http://gems.github.com
20
+
21
+ >>>>>>> ef8ef7aaafceb04d69cdfb3963f229ec1ab666db:README.markdown
22
+ Require the gem.
23
+
24
+ <<<<<<< HEAD:README.markdown
25
+ require 'summize'
26
+ =======
27
+ require 'twitter-search'
28
+ >>>>>>> ef8ef7aaafceb04d69cdfb3963f229ec1ab666db:README.markdown
29
+
30
+ <<<<<<< HEAD:README.markdown
31
+ Set up a Summize::Client. Name your client (a.k.a. 'user agent') to something meaningful, such as your app's name. This helps Summize answer any questions about your use of the API.
32
+ =======
33
+ Set up a TwitterSearch::Client. Name your client (a.k.a. 'user agent') to something meaningful, such as your app's name. This helps Twitter Search answer any questions about your use of the API.
34
+ >>>>>>> ef8ef7aaafceb04d69cdfb3963f229ec1ab666db:README.markdown
35
+
36
+ <<<<<<< HEAD:README.markdown
37
+ @client = Summize::Client.new 'politweets'
38
+ =======
39
+ @client = TwitterSearch::Client.new 'politweets'
40
+ >>>>>>> ef8ef7aaafceb04d69cdfb3963f229ec1ab666db:README.markdown
41
+
42
+ Request tweets by calling the query method of your client. It takes either a String or a Hash of arguments.
43
+
44
+ @tweets = @client.query 'twitter search'
45
+
46
+ <<<<<<< HEAD:README.markdown
47
+ The String form uses the default Summize behavior, which in this example finds tweets containing both "twitter" and "search". It is identical to the more verbose, explicit version:
48
+ =======
49
+ The String form uses the default Twitter Search behavior, which in this example finds tweets containing both "twitter" and "search". It is identical to the more verbose, explicit version:
50
+ >>>>>>> ef8ef7aaafceb04d69cdfb3963f229ec1ab666db:README.markdown
51
+
52
+ @tweets = @client.query :q => 'twitter search'
53
+
54
+ <<<<<<< HEAD:README.markdown
55
+ Use Summize's query operators with the :q key to access the following behavior:
56
+
57
+ <table>
58
+ <tr><th>Operator</th><th>Finds tweets...</th></tr>
59
+
60
+ <tr><td><a href="http://summize.com/search?q=twitter+search">:q => 'twitter search'</a></td><td>containing both "twitter" and "search". This is the default operator.</td></tr>
61
+ <tr><td><a href="http://summize.com/search?q=%22happy+hour%22">:q => '<b>"</b>happy hour<b>"</b>'</a></td><td>containing the exact phrase "happy hour".</td></tr>
62
+ <tr><td><a href="http://summize.com/search?q=obama+OR+hillary">:q => 'obama <b>OR</b> hillary'</a></td><td>containing either "obama" or "hillary" (or both).</td></tr>
63
+
64
+ <tr><td><a href="http://summize.com/search?q=beer+-root">:q => 'beer <b>-</b>root'</a></td><td>containing "beer" but not "root".</td></tr>
65
+ <tr><td><a href="http://summize.com/search?q=%23haiku">:q => '<b>#</b>haiku</a>'</td><td>containing the hashtag "haiku".</td></tr>
66
+ <tr><td><a href="http://summize.com/search?q=from%3Aalexiskold">:q => '<b>from:</b>alexiskold'</a></td><td>sent from person "alexiskold".</td></tr>
67
+ <tr><td><a href="http://summize.com/search?q=to%3Atechcrunch">:q => '<b>to:</b>techcrunch</a>'</td><td>sent to person "techcrunch".</td></tr>
68
+ <tr><td><a href="http://summize.com/search?q=%40mashable">:q => '<b>@</b>mashable</a>'</td><td>referencing person "mashable".</td></tr>
69
+
70
+ <tr><td><a href="http://summize.com/search?q=superhero+since%3A2008-05-01">:q => 'superhero <b>since:</b>2008-05-01'</a></td><td>containing "superhero" and sent since date "2008-05-01" (year-month-day).</td></tr>
71
+
72
+ <tr><td><a href="http://summize.com/search?q=ftw+until%3A2008-05-03">:q => 'ftw <b>until:</b>2008-05-03'</a></td><td>containing "ftw" and sent up to date "2008-05-03".</td></tr>
73
+ <tr><td><a href="http://summize.com/search?q=movie+-scary+%3A%29">:q => 'movie -scary <b>:)</b>'</a></td><td>containing "movie", but not "scary", and with a positive attitude.</td></tr>
74
+ <tr><td><a href="http://summize.com/search?q=flight+%3A%28">:q => 'flight <b>:(</b>'</a></td><td>containing "flight" and with a negative attitude.</td></tr>
75
+ <tr><td><a href="http://summize.com/search?q=traffic+%3F">:q => 'traffic <b>?</b>'</a></td><td>containing "traffic" and asking a question.</td></tr>
76
+
77
+ <tr><td><a href="http://summize.com/search?q=hilarious+filter%3Alinks">:q => 'hilarious <b>filter:links</b>'</a></td><td>containing "hilarious" and linking to URLs.</td></tr>
78
+ </table>
79
+ =======
80
+ Use the Twitter Search API's query operators with the :q key to access a variety of behavior.
81
+
82
+ ## Search Operators
83
+
84
+ The following operator examples find tweets...
85
+
86
+ * <a href="http://search.twitter.com/search?q=twitter+search">:q => 'twitter search'</a> - containing both "twitter" and "search". This is the default operator.
87
+ * <a href="http://search.twitter.com/search?q=%22happy+hour%22">:q => '<b>"</b>happy hour<b>"</b>'</a> - containing the exact phrase "happy hour".
88
+ * <a href="http://search.twitter.com/search?q=obama+OR+hillary">:q => 'obama <b>OR</b> hillary'</a> - containing either "obama" or "hillary" (or both).
89
+ * <a href="http://search.twitter.com/search?q=beer+-root">:q => 'beer <b>-</b>root'</a> - containing "beer" but not "root".
90
+ * <a href="http://search.twitter.com/search?q=%23haiku">:q => '<b>#</b>haiku</a>' - containing the hashtag "haiku".
91
+ * <a href="http://search.twitter.com/search?q=from%3Aalexiskold">:q => '<b>from:</b>alexiskold'</a> - sent from person "alexiskold".
92
+ * <a href="http://search.twitter.com/search?q=to%3Atechcrunch">:q => '<b>to:</b>techcrunch</a>' - sent to person "techcrunch".
93
+ * <a href="http://search.twitter.com/search?q=%40mashable">:q => '<b>@</b>mashable</a>' - referencing person "mashable".
94
+ * <a href="http://search.twitter.com/search?q=superhero+since%3A2008-05-01">:q => 'superhero <b>since:</b>2008-05-01'</a> - containing "superhero" and sent since date "2008-05-01" (year-month-day).
95
+ * <a href="http://search.twitter.com/search?q=ftw+until%3A2008-05-03">:q => 'ftw <b>until:</b>2008-05-03'</a> - containing "ftw" and sent up to date "2008-05-03".
96
+ * <a href="http://search.twitter.com/search?q=movie+-scary+%3A%29">:q => 'movie -scary <b>:)</b>'</a> - containing "movie", but not "scary", and with a positive attitude.
97
+ * <a href="http://search.twitter.com/search?q=flight+%3A%28">:q => 'flight <b>:(</b>'</a> - containing "flight" and with a negative attitude.
98
+ * <a href="http://search.twitter.com/search?q=traffic+%3F">:q => 'traffic <b>?</b>'</a> - containing "traffic" and asking a question.
99
+ * <a href="http://search.twitter.com/search?q=hilarious+filter%3Alinks">:q => 'hilarious <b>filter:links</b>'</a> - containing "hilarious" and linking to URLs.
100
+ >>>>>>> ef8ef7aaafceb04d69cdfb3963f229ec1ab666db:README.markdown
101
+
102
+ ### Foreign Languages
103
+
104
+ <<<<<<< HEAD:README.markdown
105
+ The Summize API supports foreign languages, accessible via the :lang key. Use the [ISO 639-1](http://en.wikipedia.org/wiki/ISO_639-1) codes as the value:
106
+ =======
107
+ The Twitter Search API supports foreign languages, accessible via the :lang key. Use the [ISO 639-1](http://en.wikipedia.org/wiki/ISO_639-1) codes as the value:
108
+ >>>>>>> ef8ef7aaafceb04d69cdfb3963f229ec1ab666db:README.markdown
109
+
110
+ @tweets = @client.query :q => 'programmé', :lang => 'fr'
111
+
112
+ <<<<<<< HEAD:README.markdown
113
+ =======
114
+ ### Pagination
115
+
116
+ Alter the number of Tweets returned per page with the :rpp key. Stick with 10, 15, 20, 25, 30, or 50.
117
+
118
+ @tweets = @client.query :q => 'Boston Celtics', :rpp => '30'
119
+
120
+ >>>>>>> ef8ef7aaafceb04d69cdfb3963f229ec1ab666db:README.markdown
121
+ ## Gotchas
122
+
123
+ * Searches are case-insenstive.
124
+ <<<<<<< HEAD:README.markdown
125
+ * The "near" operator available in the Summize web interface is not available via the API. You must geocode before making your Summize API call.
126
+ =======
127
+ * The "near" operator available in the Twitter Search web interface is not available via the API. You must geocode before making your Twitter Search API call.
128
+ >>>>>>> ef8ef7aaafceb04d69cdfb3963f229ec1ab666db:README.markdown
129
+ * Searching for a positive attitude :) returns tweets containing the text :), =), :D, and :-)
130
+
131
+ ## Authors
132
+
133
+ Written by Dustin Sallings (dustin@spy.net), forked by Dan Croak (dcroak@thoughtbot.com).
134
+
135
+ ## Resources
136
+
137
+ <<<<<<< HEAD:README.markdown
138
+ * [Official Summize API](http://summize.com/api)
139
+ =======
140
+ * [Official Twitter Search API](http://search.twitter.com/api)
141
+ >>>>>>> ef8ef7aaafceb04d69cdfb3963f229ec1ab666db:README.markdown
142
+
143
+ ## License
144
+
145
+ MIT License, same terms as Ruby.
@@ -0,0 +1,65 @@
1
+ require 'rubygems'
2
+ require 'net/http'
3
+ require 'json'
4
+ require 'cgi'
5
+
6
+ module TwitterSearch
7
+
8
+ class Tweet
9
+ VARS = [:text, :from_user, :created_at, :id]
10
+ attr_reader *VARS
11
+ attr_reader :language
12
+
13
+ def initialize(h)
14
+ @language = h['iso_language_code']
15
+ VARS.each { |v| instance_variable_set "@#{v}", h[v.to_s] }
16
+ end
17
+ end
18
+
19
+ class Tweets
20
+ VARS = [:since_id, :max_id, :results_per_page, :page, :query, :next_page]
21
+ attr_reader *VARS
22
+
23
+ include Enumerable
24
+
25
+ def initialize(h)
26
+ @results = h['results'].map { |tweet| Tweet.new tweet }
27
+ VARS.each { |v| instance_variable_set "@#{v}", h[v.to_s] }
28
+ end
29
+
30
+ def each(&block)
31
+ @results.each(&block)
32
+ end
33
+
34
+ def size
35
+ @results.size
36
+ end
37
+ end
38
+
39
+ class Client
40
+ def initialize(agent = 'twitter-search')
41
+ @agent = agent
42
+ end
43
+
44
+ def query(opts = {})
45
+ url = URI.parse 'http://search.twitter.com/search.json'
46
+ url.query = sanitize_query opts
47
+ Tweets.new JSON.parse(Net::HTTP.get(url))
48
+ end
49
+
50
+ private
51
+
52
+ def sanitize_query(opts)
53
+ if opts.is_a? String
54
+ "q=#{CGI.escape(opts)}"
55
+ elsif opts.is_a? Hash
56
+ "#{sanitize_query_hash(opts)}"
57
+ end
58
+ end
59
+
60
+ def sanitize_query_hash(query_hash)
61
+ query_hash.map{ |k,v| "#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}" }.join('&')
62
+ end
63
+ end
64
+
65
+ end
@@ -0,0 +1,15 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "twitter-search"
3
+ s.version = "0.4"
4
+ s.date = "2008-07-15"
5
+ s.summary = "Ruby client for Twitter Search."
6
+ s.email = "dcroak@thoughtbot.com"
7
+ s.homepage = "http://github.com/dancroak/twitter-search"
8
+ s.description = "A Ruby client for the conversational search engine."
9
+ s.has_rdoc = true
10
+ s.authors = ["Dustin Sallings", "Dan Croak"]
11
+ s.files = ["README.markdown", "twitter-search.gemspec", "lib/twitter_search.rb"]
12
+ s.rdoc_options = ["--main", "README.markdown"]
13
+ s.extra_rdoc_files = ["README.markdown"]
14
+ s.add_dependency('json', '>= 1.1.2')
15
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dancroak-twitter-search
3
+ version: !ruby/object:Gem::Version
4
+ version: "0.4"
5
+ platform: ruby
6
+ authors:
7
+ - Dustin Sallings
8
+ - Dan Croak
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2008-07-15 00:00:00 -07:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: json
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.1.2
24
+ version:
25
+ description: A Ruby client for the conversational search engine.
26
+ email: dcroak@thoughtbot.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - README.markdown
33
+ files:
34
+ - README.markdown
35
+ - twitter-search.gemspec
36
+ - lib/twitter_search.rb
37
+ has_rdoc: true
38
+ homepage: http://github.com/dancroak/twitter-search
39
+ post_install_message:
40
+ rdoc_options:
41
+ - --main
42
+ - README.markdown
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: "0"
50
+ version:
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ requirements: []
58
+
59
+ rubyforge_project:
60
+ rubygems_version: 1.2.0
61
+ signing_key:
62
+ specification_version: 2
63
+ summary: Ruby client for Twitter Search.
64
+ test_files: []
65
+