tbot 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.
- checksums.yaml +7 -0
- data/.DS_Store +0 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +68 -0
- data/Rakefile +11 -0
- data/lib/orig.rb +109 -0
- data/lib/tbot.rb +12 -0
- data/lib/tbot/bot.rb +29 -0
- data/lib/tbot/config.rb +21 -0
- data/lib/tbot/follow.rb +7 -0
- data/lib/tbot/reply.rb +19 -0
- data/lib/tbot/search.rb +46 -0
- data/lib/tbot/version.rb +3 -0
- data/tbot.gemspec +28 -0
- data/test/.DS_Store +0 -0
- data/test/fixtures/tweet.json +77 -0
- data/test/fixtures/tweet.yaml +74 -0
- data/test/tbot_test.rb +60 -0
- data/test/test_helper.rb +19 -0
- metadata +139 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 025adafe195e7421b14356d2f923f55a6833de1f
|
4
|
+
data.tar.gz: c4da9ad0ad4cf2cca4ef4c4e06fd75a34f5edbe4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 890e3ac5a1c33600543636fe4ca0ad5c0ca14ee21a9fe49831fa59fa26aab7142374c01e737894ab39ca8aee09465d5947f6941bcd75bb1a4fb31580ece9c355
|
7
|
+
data.tar.gz: 396d306353811fe89155cfc3f0d5e63281a07fc1b7acfc700c1f626763b3ee66329cecbb20f76edf65ce36458c188800aaeb038d31cb23208355edc21be7d1d8
|
data/.DS_Store
ADDED
Binary file
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Lee Kiernan
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
# Tbot
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
|
7
|
+
gem 'tbot'
|
8
|
+
|
9
|
+
And then execute:
|
10
|
+
|
11
|
+
$ bundle
|
12
|
+
|
13
|
+
Or install it yourself as:
|
14
|
+
|
15
|
+
$ gem install tbot
|
16
|
+
|
17
|
+
|
18
|
+
## === TODO ===
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Fairly thin layer for adding search and recursive search functionality to Twitter's API.
|
22
|
+
|
23
|
+
require 'tbot'
|
24
|
+
API_CREDENTIALS = {
|
25
|
+
:consumer_key => "RfcKdksf0n09MxvG0VdEA",
|
26
|
+
:consumer_secret => "HtNwBorPBkLSOmpUvKv3rLxJzhHjRXLl3Eac0va548",
|
27
|
+
:oauth_token => "70001362-fM513VTyTR4yt6wHzc72e5LzzEdEucExsFgCmFuIo",
|
28
|
+
:oauth_token_secret => "TumMI6gwKTkFiTUoWXUfYar3KnU1yzZLUb727uU"
|
29
|
+
}
|
30
|
+
|
31
|
+
Tbot::Bot.client = API_CREDENTIALS
|
32
|
+
|
33
|
+
a = Tbot::Bot.new
|
34
|
+
b = Tbot::Bot.new
|
35
|
+
c = Tbot::Bot.new
|
36
|
+
|
37
|
+
a.recurring_search "bieber", { :delay => 20 } do |results|
|
38
|
+
results.statuses.each do |tw|
|
39
|
+
p "A::: #{tw.text}"
|
40
|
+
if rand(500) % 4 > 2
|
41
|
+
puts "HIT::: #{Test.get_stuff}"
|
42
|
+
end
|
43
|
+
sleep rand(5)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
b.recurring_search "love", { :delay => 20 } do |results|
|
48
|
+
results.statuses.each do |tw|
|
49
|
+
p "B::: #{tw.text}"
|
50
|
+
sleep rand(5)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
c.recurring_search "swindon", { :delay => 20 } do |results|
|
55
|
+
results.statuses.each do |tw|
|
56
|
+
p "C::: #{tw.text}"
|
57
|
+
sleep rand(5)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
## Contributing
|
63
|
+
|
64
|
+
1. Fork it
|
65
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
66
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
67
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
68
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/orig.rb
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
=begin
|
2
|
+
require 'twitter'
|
3
|
+
|
4
|
+
module Tbot
|
5
|
+
TWITTER_BASE = ""
|
6
|
+
API_CREDENTIALS = {
|
7
|
+
:consumer_key => "RfcKdksf0n09MxvG0VdEA",
|
8
|
+
:consumer_secret => "HtNwBorPBkLSOmpUvKv3rLxJzhHjRXLl3Eac0va548",
|
9
|
+
:oauth_token => "70001362-fM513VTyTR4yt6wHzc72e5LzzEdEucExsFgCmFuIo",
|
10
|
+
:oauth_token_secret => "TumMI6gwKTkFiTUoWXUfYar3KnU1yzZLUb727uU"
|
11
|
+
}
|
12
|
+
|
13
|
+
@@Last_id = nil
|
14
|
+
|
15
|
+
class << self
|
16
|
+
@client = nil
|
17
|
+
|
18
|
+
def client(args)
|
19
|
+
@client ||= Twitter::Client.new (!!args) ? args : API_CREDENTIALS
|
20
|
+
end
|
21
|
+
|
22
|
+
def config
|
23
|
+
end
|
24
|
+
|
25
|
+
def load_config( param )
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
module Search
|
31
|
+
# Parse search params
|
32
|
+
def load_searches
|
33
|
+
end
|
34
|
+
|
35
|
+
def find_search
|
36
|
+
end
|
37
|
+
|
38
|
+
def sleep_loop(delay)
|
39
|
+
delay = 50
|
40
|
+
|
41
|
+
client.saved_searches.each do |search|
|
42
|
+
t = Thread.new do
|
43
|
+
since_id = nil
|
44
|
+
|
45
|
+
while true do
|
46
|
+
# EACH SEARCH?
|
47
|
+
|
48
|
+
res = client.search search.query, {}
|
49
|
+
|
50
|
+
since_id = res.refresh_url[:since_id]
|
51
|
+
|
52
|
+
sleep delay
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
def recurring_search(delay, &block)
|
60
|
+
t = Thread.new do
|
61
|
+
while true do
|
62
|
+
# perform_search()
|
63
|
+
sleep delay
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def search(arg)
|
69
|
+
findings = @client.search arg, since_id: @@last_id
|
70
|
+
|
71
|
+
case findings
|
72
|
+
when ""
|
73
|
+
when ""
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
module Reply
|
80
|
+
def load_replies
|
81
|
+
end
|
82
|
+
|
83
|
+
def reply_to_find
|
84
|
+
replies = reply_for_find
|
85
|
+
reply replies.sample
|
86
|
+
end
|
87
|
+
|
88
|
+
def reply_for_find
|
89
|
+
end
|
90
|
+
|
91
|
+
def reply
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
module Follow
|
96
|
+
end
|
97
|
+
|
98
|
+
module Process
|
99
|
+
# How do i do this?
|
100
|
+
|
101
|
+
# if tweet contains location OR tweeter has location THEN
|
102
|
+
# model.find_by_location -> get id, convert to URL -> shorten -> reply.
|
103
|
+
# http://url.to/results_by_area/yours
|
104
|
+
end
|
105
|
+
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
=end
|
data/lib/tbot.rb
ADDED
data/lib/tbot/bot.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
module Tbot
|
2
|
+
class Bot
|
3
|
+
@@client = nil
|
4
|
+
|
5
|
+
# DRY: Ensure correct data is passed to search, set instance variables as required.
|
6
|
+
def format_opts(opts)
|
7
|
+
if opts[:delay]
|
8
|
+
@delay = opts.delete(:delay)
|
9
|
+
# Minimum 60 seconds.
|
10
|
+
@delay = (@delay < 60) ? 60 : @delay
|
11
|
+
end
|
12
|
+
|
13
|
+
if !!opts[:location]
|
14
|
+
geo = Geocoder.search(opts.delete(:location)).first.geometry['location'].values.join(',')
|
15
|
+
radius = opts.delete(:radius) || 15
|
16
|
+
opts[:geocode] = "#{geo},#{radius}mi"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Instance methods.
|
21
|
+
def initialize
|
22
|
+
raise NoClientError unless @@client
|
23
|
+
@last_id = nil
|
24
|
+
|
25
|
+
@@client
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
data/lib/tbot/config.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module Tbot
|
2
|
+
# module Config
|
3
|
+
class Bot
|
4
|
+
API_CREDENTIALS = {
|
5
|
+
:consumer_key => "",
|
6
|
+
:consumer_secret => "",
|
7
|
+
:oauth_token => "",
|
8
|
+
:oauth_token_secret => ""
|
9
|
+
}
|
10
|
+
|
11
|
+
def self.client=(client)
|
12
|
+
@@client = Twitter::Client.new (!!client ? client : API_CREDENTIALS)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.client
|
16
|
+
@@client
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
# end
|
21
|
+
end
|
data/lib/tbot/follow.rb
ADDED
data/lib/tbot/reply.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Tbot
|
2
|
+
# module Reply
|
3
|
+
class Bot
|
4
|
+
def reply(tweet, response = "")
|
5
|
+
screen_name = tweet.user.screen_name
|
6
|
+
|
7
|
+
if block_given?
|
8
|
+
# pass user to block. tweet already present to call reply.
|
9
|
+
# force string response.
|
10
|
+
# logic will be handled within this block.
|
11
|
+
@@client.update "@#{screen_name} #{yield(tweet.user).to_s}", { :in_reply_to_status_id => tweet.id }
|
12
|
+
else
|
13
|
+
@@client.update "@#{screen_name} #{response}", { :in_reply_to_status_id => tweet.id }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
# end
|
19
|
+
end
|
data/lib/tbot/search.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
module Tbot
|
2
|
+
# module Search
|
3
|
+
class Bot
|
4
|
+
# Clean up options, pass to Twitter search function and yield results for block handling.
|
5
|
+
def search(q, opts = {})
|
6
|
+
format_opts opts
|
7
|
+
|
8
|
+
results = @@client.search q, opts
|
9
|
+
|
10
|
+
yield results if block_given?
|
11
|
+
|
12
|
+
results
|
13
|
+
end
|
14
|
+
|
15
|
+
# Works as search but sets up a thread and calls itself infinitely. Minimum delay between searches 60 seconds.
|
16
|
+
def recurring_search(q, opts = {})
|
17
|
+
format_opts opts
|
18
|
+
|
19
|
+
# Returns current recurring search, or creates a new one.
|
20
|
+
# This should force a single recurring search per instance.
|
21
|
+
# Client held in class method so new instance created per loop...
|
22
|
+
@thread ||= Thread.new do
|
23
|
+
@last_id = nil
|
24
|
+
|
25
|
+
while true do
|
26
|
+
results = self.search q, opts.merge({ :since_id => @last_id })
|
27
|
+
|
28
|
+
@last_id = results.max_id
|
29
|
+
|
30
|
+
yield results if block_given?
|
31
|
+
|
32
|
+
sleep @delay
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# => kill thread loop if it exists.
|
38
|
+
def stop_search!
|
39
|
+
false unless !!@thread
|
40
|
+
|
41
|
+
@thread.exit
|
42
|
+
@thread = nil
|
43
|
+
end
|
44
|
+
end
|
45
|
+
# end
|
46
|
+
end
|
data/lib/tbot/version.rb
ADDED
data/tbot.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'tbot/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "tbot"
|
8
|
+
spec.version = Tbot::VERSION
|
9
|
+
spec.authors = ["Lee Kiernan"]
|
10
|
+
spec.email = ["lee.kiernan@gmail.com"]
|
11
|
+
spec.description = %q{This is a description}
|
12
|
+
spec.summary = %q{Summar}
|
13
|
+
spec.homepage = "http://www.leekiernan.co.uk/"
|
14
|
+
spec.license = "Whatever."
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency(%q<twitter>, [">=4.8.1"])
|
22
|
+
spec.add_runtime_dependency(%q<oj>, ["~>2.1.4"])
|
23
|
+
spec.add_runtime_dependency(%q<geocoder>, ["~>1.1.8"])
|
24
|
+
|
25
|
+
# spec.add_development_dependency "bundler", "~> 1.3"
|
26
|
+
spec.add_development_dependency "rake"
|
27
|
+
spec.add_development_dependency "minitest", "~> 4.7.3"
|
28
|
+
end
|
data/test/.DS_Store
ADDED
Binary file
|
@@ -0,0 +1,77 @@
|
|
1
|
+
{
|
2
|
+
"metadata": {
|
3
|
+
"result_type": "recent",
|
4
|
+
"iso_language_code": "en"
|
5
|
+
},
|
6
|
+
"created_at": "Sat Aug 24 23:35:16 +0000 2013",
|
7
|
+
"id": 371415440582803460,
|
8
|
+
"id_str": "371415440582803456",
|
9
|
+
"text": "Swindon is on Street Crime UK HAHAHA",
|
10
|
+
"source": "<a href=\"http://twitter.com/download/android\" rel=\"nofollow\">Twitter for Android</a>",
|
11
|
+
"truncated": false,
|
12
|
+
"in_reply_to_status_id": null,
|
13
|
+
"in_reply_to_status_id_str": null,
|
14
|
+
"in_reply_to_user_id": null,
|
15
|
+
"in_reply_to_user_id_str": null,
|
16
|
+
"in_reply_to_screen_name": null,
|
17
|
+
"user": {
|
18
|
+
"id": 372492901,
|
19
|
+
"id_str": "372492901",
|
20
|
+
"name": "♡misguided ghost♡",
|
21
|
+
"screen_name": "shanahillxo",
|
22
|
+
"location": "Swindon",
|
23
|
+
"description": "i'll follow back if you tweet decent shit✌",
|
24
|
+
"url": null,
|
25
|
+
"entities": {
|
26
|
+
"description": {
|
27
|
+
"urls": []
|
28
|
+
}
|
29
|
+
},
|
30
|
+
"protected": false,
|
31
|
+
"followers_count": 639,
|
32
|
+
"friends_count": 483,
|
33
|
+
"listed_count": 3,
|
34
|
+
"created_at": "Mon Sep 12 21:40:27 +0000 2011",
|
35
|
+
"favourites_count": 1193,
|
36
|
+
"utc_offset": null,
|
37
|
+
"time_zone": null,
|
38
|
+
"geo_enabled": true,
|
39
|
+
"verified": false,
|
40
|
+
"statuses_count": 25345,
|
41
|
+
"lang": "en",
|
42
|
+
"contributors_enabled": false,
|
43
|
+
"is_translator": false,
|
44
|
+
"profile_background_color": "C0DEED",
|
45
|
+
"profile_background_image_url": "http://a0.twimg.com/profile_background_images/366124521/tumblr_ltonmvYaWJ1qf3lleo1_500.jpg",
|
46
|
+
"profile_background_image_url_https": "https://si0.twimg.com/profile_background_images/366124521/tumblr_ltonmvYaWJ1qf3lleo1_500.jpg",
|
47
|
+
"profile_background_tile": true,
|
48
|
+
"profile_image_url": "http://a0.twimg.com/profile_images/378800000284249362/aff63beea3a4cc8b6ee826669d2a3e49_normal.jpeg",
|
49
|
+
"profile_image_url_https": "https://si0.twimg.com/profile_images/378800000284249362/aff63beea3a4cc8b6ee826669d2a3e49_normal.jpeg",
|
50
|
+
"profile_banner_url": "https://pbs.twimg.com/profile_banners/372492901/1376644611",
|
51
|
+
"profile_link_color": "0084B4",
|
52
|
+
"profile_sidebar_border_color": "C0DEED",
|
53
|
+
"profile_sidebar_fill_color": "DDEEF6",
|
54
|
+
"profile_text_color": "333333",
|
55
|
+
"profile_use_background_image": true,
|
56
|
+
"default_profile": false,
|
57
|
+
"default_profile_image": false,
|
58
|
+
"following": false,
|
59
|
+
"follow_request_sent": false,
|
60
|
+
"notifications": false
|
61
|
+
},
|
62
|
+
"geo": null,
|
63
|
+
"coordinates": null,
|
64
|
+
"place": null,
|
65
|
+
"contributors": null,
|
66
|
+
"retweet_count": 0,
|
67
|
+
"favorite_count": 0,
|
68
|
+
"entities": {
|
69
|
+
"hashtags": [],
|
70
|
+
"symbols": [],
|
71
|
+
"urls": [],
|
72
|
+
"user_mentions": []
|
73
|
+
},
|
74
|
+
"favorited": false,
|
75
|
+
"retweeted": false,
|
76
|
+
"lang": "en"
|
77
|
+
}
|
@@ -0,0 +1,74 @@
|
|
1
|
+
---
|
2
|
+
|
3
|
+
statuses:
|
4
|
+
-
|
5
|
+
metadata:
|
6
|
+
result_type: recent
|
7
|
+
iso_language_code: en
|
8
|
+
created_at: 'SatAug2423: 35: 16+00002013'
|
9
|
+
id: 371415440582803456.000000
|
10
|
+
id_str: "371415440582803456"
|
11
|
+
text: Swindon is on Street Crime UK HAHAHA
|
12
|
+
source: '<ahref="http: //twitter.com/download/android"rel="nofollow">TwitterforAndroid</a>'
|
13
|
+
truncated: false
|
14
|
+
in_reply_to_status_id: ~
|
15
|
+
in_reply_to_status_id_str: ~
|
16
|
+
in_reply_to_user_id: ~
|
17
|
+
in_reply_to_user_id_str: ~
|
18
|
+
in_reply_to_screen_name: ~
|
19
|
+
user:
|
20
|
+
id: 372492901
|
21
|
+
id_str: "372492901"
|
22
|
+
name: ♡misguidedghost♡
|
23
|
+
screen_name: shanahillxo
|
24
|
+
location: Swindon
|
25
|
+
description: i'llfollowbackifyoutweetdecentshit✌
|
26
|
+
url: ~
|
27
|
+
entities:
|
28
|
+
description:
|
29
|
+
urls: []
|
30
|
+
protected: false
|
31
|
+
followers_count: 639
|
32
|
+
friends_count: 483
|
33
|
+
listed_count: 3
|
34
|
+
created_at: 'MonSep1221: 40: 27+00002011'
|
35
|
+
favourites_count: 1193
|
36
|
+
utc_offset: ~
|
37
|
+
time_zone: ~
|
38
|
+
geo_enabled: true
|
39
|
+
verified: false
|
40
|
+
statuses_count: 25345
|
41
|
+
lang: en
|
42
|
+
contributors_enabled: false
|
43
|
+
is_translator: false
|
44
|
+
profile_background_color: C0DEED
|
45
|
+
profile_background_image_url: 'http: //a0.twimg.com/profile_background_images/366124521/tumblr_ltonmvYaWJ1qf3lleo1_500.jpg'
|
46
|
+
profile_background_image_url_https: 'https: //si0.twimg.com/profile_background_images/366124521/tumblr_ltonmvYaWJ1qf3lleo1_500.jpg'
|
47
|
+
profile_background_tile: true
|
48
|
+
profile_image_url: 'http: //a0.twimg.com/profile_images/378800000284249362/aff63beea3a4cc8b6ee826669d2a3e49_normal.jpeg'
|
49
|
+
profile_image_url_https: 'https: //si0.twimg.com/profile_images/378800000284249362/aff63beea3a4cc8b6ee826669d2a3e49_normal.jpeg'
|
50
|
+
profile_banner_url: 'https: //pbs.twimg.com/profile_banners/372492901/1376644611'
|
51
|
+
profile_link_color: 0084B4
|
52
|
+
profile_sidebar_border_color: C0DEED
|
53
|
+
profile_sidebar_fill_color: DDEEF6
|
54
|
+
profile_text_color: "333333"
|
55
|
+
profile_use_background_image: true
|
56
|
+
default_profile: false
|
57
|
+
default_profile_image: false
|
58
|
+
following: false
|
59
|
+
follow_request_sent: false
|
60
|
+
notifications: false
|
61
|
+
geo: ~
|
62
|
+
coordinates: ~
|
63
|
+
place: ~
|
64
|
+
contributors: ~
|
65
|
+
retweet_count: 0
|
66
|
+
favorite_count: 0
|
67
|
+
entities:
|
68
|
+
hashtags: []
|
69
|
+
symbols: []
|
70
|
+
urls: []
|
71
|
+
user_mentions: []
|
72
|
+
favorited: false
|
73
|
+
retweeted: false
|
74
|
+
lang: en
|
data/test/tbot_test.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class PostTest < MiniTest::Unit::TestCase
|
4
|
+
# 1: Client
|
5
|
+
# - default nil
|
6
|
+
# - set
|
7
|
+
# - call
|
8
|
+
# -
|
9
|
+
# 2: Search
|
10
|
+
# 3: Reply
|
11
|
+
# 4: Follow
|
12
|
+
end
|
13
|
+
|
14
|
+
describe Tbot, "Tbot" do
|
15
|
+
client = MiniTest::Mock.new
|
16
|
+
|
17
|
+
describe "Configuration" do
|
18
|
+
it "should default to nil" do
|
19
|
+
Tbot::Bot.client.must_equal nil
|
20
|
+
end
|
21
|
+
it "should be settable" do
|
22
|
+
Tbot::Bot.client = {}
|
23
|
+
assert_kind_of Twitter::Client, Tbot::Bot.client
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "Searching" do
|
29
|
+
# client.expect(:search, YAML::load( File.read('./test/fixtures/tweet.yaml') ), ['term', {}] )
|
30
|
+
|
31
|
+
it "should return results" do
|
32
|
+
client.expect(:search, YAML::load( File.read('./test/fixtures/tweet.yaml') ), ['term'] )
|
33
|
+
client.search("term")['statuses'].must_be_kind_of Array
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should each contain text for each" do
|
37
|
+
client.expect(:search, YAML::load( File.read('./test/fixtures/tweet.yaml') ), ['term'] )
|
38
|
+
assert_equal client.search("term")['statuses'].first['text'], "Swindon is on Street Crime UK HAHAHA"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "Replying" do
|
43
|
+
it "sends tweet to a user" do
|
44
|
+
tw = YAML::load( File.read('./test/fixtures/tweet.yaml') ).statuses.first
|
45
|
+
|
46
|
+
client.expect(:reply, "@#{tw.user.screen_name}", [tw] )
|
47
|
+
client.reply(tw).must_match /^@shanahillxo.*/
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "Following" do
|
52
|
+
it "follows a user" do
|
53
|
+
tw = YAML::load( File.read('./test/fixtures/tweet.yaml') ).statuses.first
|
54
|
+
|
55
|
+
# Docs as so unclear.
|
56
|
+
client.expect(:follow, Twitter::User, [tw] )
|
57
|
+
client.follow(tw).must_respond_to :identity_map
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
require 'tbot'
|
4
|
+
require 'minitest/unit'
|
5
|
+
require 'minitest/mock'
|
6
|
+
require 'minitest/autorun'
|
7
|
+
require 'minitest/pride'
|
8
|
+
|
9
|
+
class Hash
|
10
|
+
def method_missing(method, *opts)
|
11
|
+
m = method.to_s
|
12
|
+
if self.has_key?(m)
|
13
|
+
return self[m]
|
14
|
+
elsif self.has_key?(m.to_sym)
|
15
|
+
return self[m.to_sym]
|
16
|
+
end
|
17
|
+
super
|
18
|
+
end
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tbot
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Lee Kiernan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-08-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: twitter
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.8.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.8.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: oj
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.1.4
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.1.4
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: geocoder
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.1.8
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.1.8
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 4.7.3
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 4.7.3
|
83
|
+
description: This is a description
|
84
|
+
email:
|
85
|
+
- lee.kiernan@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- .DS_Store
|
91
|
+
- .gitignore
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- lib/orig.rb
|
97
|
+
- lib/tbot.rb
|
98
|
+
- lib/tbot/bot.rb
|
99
|
+
- lib/tbot/config.rb
|
100
|
+
- lib/tbot/follow.rb
|
101
|
+
- lib/tbot/reply.rb
|
102
|
+
- lib/tbot/search.rb
|
103
|
+
- lib/tbot/version.rb
|
104
|
+
- tbot.gemspec
|
105
|
+
- test/.DS_Store
|
106
|
+
- test/fixtures/tweet.json
|
107
|
+
- test/fixtures/tweet.yaml
|
108
|
+
- test/tbot_test.rb
|
109
|
+
- test/test_helper.rb
|
110
|
+
homepage: http://www.leekiernan.co.uk/
|
111
|
+
licenses:
|
112
|
+
- Whatever.
|
113
|
+
metadata: {}
|
114
|
+
post_install_message:
|
115
|
+
rdoc_options: []
|
116
|
+
require_paths:
|
117
|
+
- lib
|
118
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - '>='
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - '>='
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
requirements: []
|
129
|
+
rubyforge_project:
|
130
|
+
rubygems_version: 2.0.7
|
131
|
+
signing_key:
|
132
|
+
specification_version: 4
|
133
|
+
summary: Summar
|
134
|
+
test_files:
|
135
|
+
- test/.DS_Store
|
136
|
+
- test/fixtures/tweet.json
|
137
|
+
- test/fixtures/tweet.yaml
|
138
|
+
- test/tbot_test.rb
|
139
|
+
- test/test_helper.rb
|