contentbofu 1.0
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/lib/contentbofu.rb +129 -0
- metadata +54 -0
data/lib/contentbofu.rb
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
class ContentBofu
|
2
|
+
|
3
|
+
def initialize
|
4
|
+
# Just the defaults that I use.
|
5
|
+
@tbs_method = 'replaceEveryonesFavorites'
|
6
|
+
@tbs_maxsyns = '7'
|
7
|
+
@tbs_quality = '1'
|
8
|
+
end
|
9
|
+
|
10
|
+
def madlib(body)
|
11
|
+
|
12
|
+
# Replaces {}, {|},{|||||||||}, etc
|
13
|
+
body.gsub!(/(\{\}|\{\|*\})/,'')
|
14
|
+
|
15
|
+
while true do
|
16
|
+
vars = body.scan(/\{[^\{\}]+?\}/)
|
17
|
+
|
18
|
+
if vars.count == 0
|
19
|
+
# No more madlib eval's, break out
|
20
|
+
break;
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
# Evaluate the spintax on the run
|
25
|
+
vars.each do |ind|
|
26
|
+
parts = ind.gsub(/(\{|\})/,'').split(/\|/)
|
27
|
+
body.gsub!(ind,parts[rand(parts.size)])
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
return body
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
# TBS User Definition & Setting
|
38
|
+
def tbs_user
|
39
|
+
return @tbs_user
|
40
|
+
end
|
41
|
+
|
42
|
+
def tbs_user=(value)
|
43
|
+
@tbs_user = value
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
# TBS Password Definition & Setting
|
48
|
+
def tbs_pass
|
49
|
+
return @tbs_pass
|
50
|
+
end
|
51
|
+
|
52
|
+
def tbs_pass=(value)
|
53
|
+
@tbs_pass = value
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
# TBS Method Definition & Setting
|
58
|
+
def tbs_method
|
59
|
+
return @tbs_method
|
60
|
+
end
|
61
|
+
def tbs_method=(value)
|
62
|
+
@tbs_method = value
|
63
|
+
end
|
64
|
+
|
65
|
+
# TBS Quality Definition & Setting - Quality only applies for the method replaceEveryonesFavorites
|
66
|
+
def tbs_quality
|
67
|
+
return @tbs_quality
|
68
|
+
end
|
69
|
+
def tbs_quality=(value)
|
70
|
+
@tbs_quality = value
|
71
|
+
end
|
72
|
+
|
73
|
+
# TBS Maxsyns (Max Synonyms) Definition & Setting - Quality only applies for the method replaceEveryonesFavorites
|
74
|
+
def tbs_maxsyns
|
75
|
+
return @tbs_maxsyns
|
76
|
+
end
|
77
|
+
def tbs_maxsyns=(value)
|
78
|
+
@tbs_maxsyns = value
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
# TBS Spin
|
83
|
+
def tbs_spin(body)
|
84
|
+
|
85
|
+
require 'rubygems'
|
86
|
+
require 'mechanize'
|
87
|
+
require 'php_serialize'
|
88
|
+
|
89
|
+
if (@tbs_user == nil) || (@tbs_pass == nil)
|
90
|
+
raise "Your username (tbs_user) or password (tbs_pass) are unset."
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
api_url = "http://thebestspinner.com/api.php"
|
95
|
+
|
96
|
+
# Set basics to establish the session
|
97
|
+
data = Hash.new
|
98
|
+
data['action'] = 'authenticate'
|
99
|
+
data['format'] = 'php'
|
100
|
+
data['username'] = @tbs_user
|
101
|
+
data['password'] = @tbs_pass
|
102
|
+
|
103
|
+
agent = Mechanize.new
|
104
|
+
session_info = PHP.unserialize(agent.post(api_url,data).content)
|
105
|
+
|
106
|
+
# If the "session" is set correctly, continue
|
107
|
+
if session_info['success'] == "true"
|
108
|
+
|
109
|
+
data = Hash.new
|
110
|
+
data['session'] = session_info['session']
|
111
|
+
data['format'] = 'php'
|
112
|
+
data['text'] = body
|
113
|
+
data['action'] = @tbs_method
|
114
|
+
if @tbs_method == 'replaceEveryonesFavorites'
|
115
|
+
data['maxsyns'] = @tbs_maxsyns
|
116
|
+
data['quality'] = @tbs_quality
|
117
|
+
end
|
118
|
+
|
119
|
+
# Post & Get Result
|
120
|
+
spin_return = PHP.unserialize(agent.post(api_url,data).content)
|
121
|
+
|
122
|
+
# Return just the output (still in spintax, NOT evaluated)
|
123
|
+
return spin_return['output']
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
metadata
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: contentbofu
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: "1.0"
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Robert Adler
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-09-11 00:00:00 Z
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Ported over TheBestSpinner API from PHP, integration with nested spinning
|
17
|
+
email: radler@thelinkbuilders.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- lib/contentbofu.rb
|
26
|
+
homepage: http://www.AutomatedTendencies.com
|
27
|
+
licenses: []
|
28
|
+
|
29
|
+
post_install_message:
|
30
|
+
rdoc_options: []
|
31
|
+
|
32
|
+
require_paths:
|
33
|
+
- lib
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: "0"
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
46
|
+
requirements: []
|
47
|
+
|
48
|
+
rubyforge_project:
|
49
|
+
rubygems_version: 1.8.5
|
50
|
+
signing_key:
|
51
|
+
specification_version: 3
|
52
|
+
summary: Bofu's toolset for all things content
|
53
|
+
test_files: []
|
54
|
+
|