curate_tumblr 1.0.3
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/.project +18 -0
- data/README.md +219 -0
- data/Rakefile +0 -0
- data/curate_tumblr.gemspec +12 -0
- data/example/kubricklove/kubricklove_config.yaml +20 -0
- data/example/kubricklove/links/kubricklove_links +4 -0
- data/example/kubricklove_follow.rb +6 -0
- data/example/kubricklove_reblog.rb +6 -0
- data/example/readme +9 -0
- data/lib/curate_tumblr.rb +25 -0
- data/lib/curate_tumblr/curator.rb +200 -0
- data/lib/curate_tumblr/publish/follow.rb +62 -0
- data/lib/curate_tumblr/publish/post.rb +21 -0
- data/lib/curate_tumblr/publish/reblog.rb +86 -0
- data/lib/curate_tumblr/render/render_follow.rb +29 -0
- data/lib/curate_tumblr/render/render_links.rb +132 -0
- data/lib/curate_tumblr/render/render_reblog.rb +36 -0
- data/lib/curate_tumblr/tumblr/client.rb +347 -0
- data/lib/curate_tumblr/tumblr/extract_links.rb +190 -0
- data/lib/curate_tumblr/tumblr/infos.rb +102 -0
- data/lib/curate_tumblr/utilities/monkey.rb +5 -0
- data/lib/curate_tumblr/utilities/utilities.rb +4 -0
- data/lib/curate_tumblr/utilities/utilities_client.rb +103 -0
- data/lib/curate_tumblr/utilities/utilities_file.rb +50 -0
- data/lib/curate_tumblr/utilities/utilities_format.rb +91 -0
- data/lib/curate_tumblr/utilities/utilities_validate.rb +54 -0
- data/lib/curate_tumblr/values.rb +22 -0
- data/spec/curate_tumblr/curator_spec.rb +36 -0
- data/spec/curate_tumblr/publish/follow_spec.rb +183 -0
- data/spec/curate_tumblr/publish/post_spec.rb +45 -0
- data/spec/curate_tumblr/publish/reblog_spec.rb +118 -0
- data/spec/curate_tumblr/render/render_follow_spec.rb +36 -0
- data/spec/curate_tumblr/render/render_reblog_spec.rb +73 -0
- data/spec/curate_tumblr/tumblr/client_spec.rb +69 -0
- data/spec/curate_tumblr/tumblr/extract_links_spec.rb +204 -0
- data/spec/curate_tumblr/utilities/utilities_validate_spec.rb +27 -0
- data/spec/factories.rb +24 -0
- data/spec/shared_examples.rb +2 -0
- data/spec/shared_values.rb +203 -0
- data/spec/spec_helper.rb +95 -0
- metadata +116 -0
@@ -0,0 +1,91 @@
|
|
1
|
+
module CurateTumblr
|
2
|
+
|
3
|
+
def self.get_format_ar_tumblrs_urls( ar_tumblrs_urls )
|
4
|
+
raise "ar_tumblrs_urls is a #{ar_tumblrs_urls.class} instead of Array" if !ar_tumblrs_urls.is_a? Array
|
5
|
+
ar_new_tumblrs_urls = []
|
6
|
+
ar_tumblrs_urls.each do |tumblr|
|
7
|
+
format_tumblr_url!( tumblr )
|
8
|
+
ar_new_tumblrs_urls << tumblr
|
9
|
+
end
|
10
|
+
ar_new_tumblrs_urls
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.get_format_tumblr_urls( tumblr_urls )
|
14
|
+
if tumblr_urls.is_a? Set
|
15
|
+
new_tumblr_urls = Set.new
|
16
|
+
else
|
17
|
+
new_tumblr_urls = []
|
18
|
+
end
|
19
|
+
tumblr_urls.each do |url|
|
20
|
+
new_url = url.dup
|
21
|
+
format_tumblr_url!( new_url )
|
22
|
+
new_tumblr_urls << new_url
|
23
|
+
end
|
24
|
+
new_tumblr_urls
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.get_format_urls( urls )
|
28
|
+
if urls.is_a? Set
|
29
|
+
new_urls = Set.new
|
30
|
+
else
|
31
|
+
new_urls = []
|
32
|
+
end
|
33
|
+
urls.each do |url|
|
34
|
+
new_url = url.dup
|
35
|
+
format_url!( new_url )
|
36
|
+
new_urls << new_url
|
37
|
+
end
|
38
|
+
new_urls
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.format_url!( url )
|
42
|
+
url.gsub!("target=\"_blank\"", "")
|
43
|
+
url.gsub!("href=\"", "")
|
44
|
+
url.gsub!("http://", "")
|
45
|
+
url.gsub!("https://", "")
|
46
|
+
url.gsub!("http%3A%2F%2F", "")
|
47
|
+
url.gsub!("\"", "")
|
48
|
+
url.gsub!('"', "")
|
49
|
+
url.chomp!
|
50
|
+
url.chomp!( " " )
|
51
|
+
url.lstrip!
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.get_format_ar_urls( ar_urls )
|
55
|
+
raise "ar_urls is a #{ar_urls.class} instead of Array" if !ar_urls.is_a? Array
|
56
|
+
ar_new_urls = []
|
57
|
+
ar_urls.each do |url|
|
58
|
+
format_url!( url )
|
59
|
+
ar_new_urls << url
|
60
|
+
end
|
61
|
+
ar_new_urls
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.get_format_ar_tumblr_urls( ar_urls )
|
65
|
+
raise "ar_urls is a #{ar_urls.class} instead of Array" if !ar_urls.is_a? Array
|
66
|
+
ar_new_urls = []
|
67
|
+
ar_urls.each do |url|
|
68
|
+
format_tumblr_url!( url )
|
69
|
+
ar_new_urls << url
|
70
|
+
end
|
71
|
+
ar_new_urls
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.format_tumblr_url!( tumblr_url )
|
75
|
+
format_url!( tumblr_url )
|
76
|
+
tumblr_url.gsub!("tumblr.com/", "tumblr.com")
|
77
|
+
tumblr_url.gsub!("class=\"tumblr_blog\"", "")
|
78
|
+
tumblr_url.gsub!("tumblr_blog href=", "")
|
79
|
+
tumblr_url.gsub!("tumblr_blog", "")
|
80
|
+
tumblr_url.gsub!("post", "")
|
81
|
+
tumblr_url.gsub!("www.", "")
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.format_post_id( post_id )
|
85
|
+
post_id.gsub('/', '').chomp.strip
|
86
|
+
end
|
87
|
+
|
88
|
+
def self.format_post_reblog_key( key )
|
89
|
+
key.gsub('/', '').gsub('?', '').chomp.strip
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module CurateTumblr
|
2
|
+
def self.hash_multiple_posts_valid?( hash_posts )
|
3
|
+
return false if hash_posts.nil?
|
4
|
+
return false if !hash_posts.is_a? Hash
|
5
|
+
return false if !hash_posts.has_key?( 'posts' )
|
6
|
+
return false if !hash_posts['posts'].is_a? Array
|
7
|
+
true
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.hash_post_valid?( hash_post )
|
11
|
+
return false if !hash_post
|
12
|
+
return false if !hash_post.is_a?( Hash )
|
13
|
+
return false if !hash_post.has_key?( 'blog_name' )
|
14
|
+
return false if !hash_post.has_key?( 'id' )
|
15
|
+
true
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.hash_id_valid?( hash_id )
|
19
|
+
return false if !hash_id.is_a? Hash
|
20
|
+
return false if !hash_id.has_key?( 'id' )
|
21
|
+
return false if !post_id_valid?( hash_id['id'] )
|
22
|
+
true
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.hash_url_valid?( hash_url )
|
26
|
+
return false if !hash_url.is_a? Hash
|
27
|
+
return false if !hash_url.has_key?( :tumblr_url )
|
28
|
+
return false if !hash_url.has_key?( :post_id )
|
29
|
+
return false if !post_id_valid?( hash_url[:post_id] )
|
30
|
+
true
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.check_paths_ar_photos( ar_photos )
|
34
|
+
ar_photos.each do |path|
|
35
|
+
raise "path #{path} doesn't exist" if !File.exist?( path )
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.post_id_valid?( post_id )
|
40
|
+
return false if post_id.nil?
|
41
|
+
return false if !post_id
|
42
|
+
return false if post_id.is_a?( String ) && post_id.empty?
|
43
|
+
return false if post_id.is_a?( Integer ) && post_id.to_s.empty?
|
44
|
+
true
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.reblog_key_valid?( reblog_key )
|
48
|
+
return false if reblog_key.nil?
|
49
|
+
return false if !reblog_key
|
50
|
+
return false if !reblog_key.is_a? String
|
51
|
+
return false if reblog_key.empty?
|
52
|
+
true
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module CurateTumblr
|
2
|
+
STATE_PUBLISHED = "published"
|
3
|
+
STATE_DRAFT = "draft"
|
4
|
+
STATE_QUEUE = "queue"
|
5
|
+
STATE_PRIVATE = "private"
|
6
|
+
|
7
|
+
CLIENT_STATUS_OK = 200
|
8
|
+
CLIENT_STATUS_BAD_REQUEST = 400
|
9
|
+
CLIENT_STATUS_NOT_FOUND = 404
|
10
|
+
CLIENT_STATUS_RATE_LIMIT = 429
|
11
|
+
COUNT_ALERT_IF_TOO_MUCH_BAD_REQUESTS = 5
|
12
|
+
|
13
|
+
DISPLAY_SLEEP_BEFORE = "("
|
14
|
+
DISPLAY_SLEEP_AFTER = ")"
|
15
|
+
DISPLAY_TUMBLR_POST = "+"
|
16
|
+
DISPLAY_TUMBLR_REBLOG = ">"
|
17
|
+
DISPLAY_TUMBLR_DELETE = "-"
|
18
|
+
DISPLAY_TUMBLR_FOLLOW = ":"
|
19
|
+
DISPLAY_TUMBLR_GETPOSTS = "?"
|
20
|
+
|
21
|
+
SANDBOX_POST_ID = 1 # for testing without sending to tumblr
|
22
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CurateTumblr::Curator do
|
4
|
+
|
5
|
+
describe "config" do
|
6
|
+
it "get hash" do
|
7
|
+
oauth_consumer_key = RandomWord.nouns.next
|
8
|
+
oauth_consumer_secret = RandomWord.nouns.next
|
9
|
+
oauth_token = RandomWord.nouns.next
|
10
|
+
oauth_token_secret = RandomWord.nouns.next
|
11
|
+
infos_name = RandomWord.nouns.next
|
12
|
+
hash_config = {}
|
13
|
+
hash_config.merge!( CurateTumblr::Tumblr::Client::get_client_config_hash( oauth_consumer_key, oauth_consumer_secret, oauth_token, oauth_token_secret ) )
|
14
|
+
hash_config.merge!( CurateTumblr::Tumblr::Infos::get_infos_config_hash )
|
15
|
+
expect { CurateTumblr::Curator.check_config_hash( hash_config ) }.to_not raise_error
|
16
|
+
end
|
17
|
+
|
18
|
+
it "empty" do
|
19
|
+
expect { CurateTumblr::Curator.check_config_hash( {
|
20
|
+
CurateTumblr::Tumblr::Client::HASH_CONFIG_CLIENT => {},
|
21
|
+
CurateTumblr::Tumblr::Infos::HASH_CONFIG_INFOS => {},
|
22
|
+
} ) }.to raise_error
|
23
|
+
end
|
24
|
+
|
25
|
+
it "get document yaml" do
|
26
|
+
string_yaml = CurateTumblr::Curator.get_string_yaml_from_config( get_random_config_hash )
|
27
|
+
string_yaml.should be_true
|
28
|
+
string_yaml.empty?.should_not be_true
|
29
|
+
documents = YAML::load_documents( string_yaml )
|
30
|
+
documents.is_a?( Array ).should be_true
|
31
|
+
documents.count.should eq( 1 )
|
32
|
+
hash_config = documents.first
|
33
|
+
expect { CurateTumblr::Curator.check_config_hash( hash_config ) }.to_not raise_error
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,183 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CurateTumblr::Publish::Follow do
|
4
|
+
include_context "shared targets"
|
5
|
+
include_context "shared links"
|
6
|
+
include_context "shared tags"
|
7
|
+
include_context "shared caption post"
|
8
|
+
let(:curator) { FactoryGirl.build( :curator ) }
|
9
|
+
|
10
|
+
describe "to follow after" do
|
11
|
+
it "should follow all links in caption when no source" do
|
12
|
+
ar_links = curator.send( :add_tofollow_tumblr_links_from_caption, caption )
|
13
|
+
ar_links.count.should eq( ar_links_caption_tumblrs.count )
|
14
|
+
ar_links_caption_tumblrs.each { |link| ar_links.include?( link ).should be_true }
|
15
|
+
curator.all_tofollow_urls.count.should eq( ar_links_caption_tumblrs.count )
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should follow links in caption but not the source" do
|
19
|
+
ar_links = curator.send( :add_tofollow_tumblr_links_from_caption, caption, source )
|
20
|
+
ar_links_caption_tumblrs.each { |link| ar_links.include?( link ).should be_true }
|
21
|
+
ar_links.count.should eq( ar_links_caption_tumblrs.count )
|
22
|
+
curator.all_tofollow_urls.count.should eq( ar_links_caption_tumblrs.count - 1 )
|
23
|
+
end
|
24
|
+
|
25
|
+
it "direct extract tumblr links in curation" do
|
26
|
+
curator.all_tofollow_urls.count.should eq( 0 )
|
27
|
+
curator.reblog_and_extract( link_follow )
|
28
|
+
|
29
|
+
curator.count_rebloged.should eq( 1 )
|
30
|
+
curator.all_tofollow_urls.count.should eq( count_caption_links_to_follow + 1 )
|
31
|
+
end
|
32
|
+
|
33
|
+
it "check tofollow tumblrs are not post urls" do
|
34
|
+
ar_tofollow = get_random_ar_tumblrs( 4 )
|
35
|
+
ar_tofollow.each do |link|
|
36
|
+
CurateTumblr::Tumblr::ExtractLinks.simple_tumblr_url?( link ).should eq( true )
|
37
|
+
CurateTumblr::Tumblr::ExtractLinks.tumblr_url?( link ).should eq( true )
|
38
|
+
CurateTumblr::Tumblr::ExtractLinks.tumblr_post_url?( link ).should eq( false )
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
it "add tofollow tumblrs" do
|
43
|
+
ar_tofollow = get_random_ar_tumblrs( 4 )
|
44
|
+
ar_tofollow.each do |link|
|
45
|
+
curator.reblog_and_extract( link )
|
46
|
+
end
|
47
|
+
curator.all_tofollow_urls.count.should eq( ar_tofollow.count )
|
48
|
+
ar_tofollow.each { |link| curator.all_tofollow_urls.include?( link ).should be_true }
|
49
|
+
end
|
50
|
+
|
51
|
+
it "add tofollow from post tumblrs" do
|
52
|
+
ar_tofollow = [ "likeafieldmouse.tumblr.com", "mother-natureson.tumblr.com", "fuck-mefood.tumblr.com", "unpopuler.tumblr.com" ]
|
53
|
+
ar_tumblrs_posts = [ "http://likeafieldmouse.tumblr.com/post/56880391419/adrian-velazco", "http://likeafieldmouse.tumblr.com/post/56878573508/nicolai-howalt-boxers-before-and-after-the", "http://mother-natureson.tumblr.com/post/56880589244/unpopuler-my-blog-will-make-you-smile"]
|
54
|
+
ar_tumblrs_posts.each do |post|
|
55
|
+
curator.reblog_and_extract( post )
|
56
|
+
end
|
57
|
+
curator.all_tofollow_urls.count.should eq( ar_tofollow.count )
|
58
|
+
ar_tofollow.each { |link| curator.all_tofollow_urls.include?( link ).should be_true }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "add follow links to file" do
|
63
|
+
it "puts links in file" do
|
64
|
+
File.delete( curator.get_filename_tofollow ) if File.exists?( curator.get_filename_tofollow )
|
65
|
+
|
66
|
+
count_follow = curator.count_followed
|
67
|
+
urls_tofollow = [ "tofollow1.tumblr.com", "tofollow2.tumblr.com", "tofollow3.tumblr.com"]
|
68
|
+
|
69
|
+
urls_tofollow.each { |url| curator.add_tofollow_url( url ) }
|
70
|
+
curator.add_tofollow_tofile
|
71
|
+
|
72
|
+
File.exists?( curator.get_filename_tofollow ).should eq( true )
|
73
|
+
all_tofollow_urls = CurateTumblr.get_ar_from_file( curator.get_filename_tofollow )
|
74
|
+
all_tofollow_urls.count.should eq( urls_tofollow.count )
|
75
|
+
urls_tofollow.each { |link| all_tofollow_urls.include?( link + "\n" ).should be_true }
|
76
|
+
end
|
77
|
+
|
78
|
+
it "keep links already in file" do
|
79
|
+
File.delete( curator.get_filename_tofollow ) if File.exists?( curator.get_filename_tofollow )
|
80
|
+
|
81
|
+
urls_tofollow = [ "tofollow1.tumblr.com", "tofollow2.tumblr.com", "tofollow3.tumblr.com"]
|
82
|
+
urls_infile = [ "already1.tumblr.com", "already2.tumblr.com" ]
|
83
|
+
|
84
|
+
File.open( curator.get_filename_tofollow, "w+" ) { |file| file.puts( urls_infile ) }
|
85
|
+
CurateTumblr.get_ar_from_file( curator.get_filename_tofollow ).count.should eq( urls_infile.count )
|
86
|
+
|
87
|
+
urls_tofollow.each { |url| curator.add_tofollow_url( url ) }
|
88
|
+
curator.add_tofollow_tofile
|
89
|
+
|
90
|
+
ar_tofollow = CurateTumblr.get_ar_from_file( curator.get_filename_tofollow )
|
91
|
+
ar_tofollow.count.should eq( urls_infile.count + urls_tofollow.count )
|
92
|
+
urls_infile.each { |link| ar_tofollow.include?( link + "\n" ).should be_true }
|
93
|
+
urls_tofollow.each { |link| ar_tofollow.include?( link + "\n" ).should be_true }
|
94
|
+
curator.all_tofollow_urls.count.should eq( 0 )
|
95
|
+
end
|
96
|
+
|
97
|
+
it "dont put link in file if already exists" do
|
98
|
+
File.delete( curator.get_filename_tofollow ) if File.exists?( curator.get_filename_tofollow )
|
99
|
+
|
100
|
+
urls_tofollow = [ "tofollow1.tumblr.com", "tofollow2.tumblr.com", "tofollow3.tumblr.com"]
|
101
|
+
url_tonotfollow = "tofollow2.tumblr.com"
|
102
|
+
|
103
|
+
File.open( curator.get_filename_tofollow, "w+" ) { |file| file.puts( url_tonotfollow ) }
|
104
|
+
CurateTumblr.get_ar_from_file( curator.get_filename_tofollow ).count.should eq( 1 )
|
105
|
+
|
106
|
+
urls_tofollow.each { |url| curator.add_tofollow_url( url ) }
|
107
|
+
curator.add_tofollow_tofile
|
108
|
+
|
109
|
+
ar_tofollow = CurateTumblr.get_ar_from_file( curator.get_filename_tofollow )
|
110
|
+
ar_tofollow.count.should eq( urls_tofollow.count )
|
111
|
+
urls_tofollow.each { |link| ar_tofollow.include?( link + "\n" ).should be_true }
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
describe "follow" do
|
116
|
+
it "url" do
|
117
|
+
curator.count_followed.should eq( 0 )
|
118
|
+
curator.follow_url( "photonotdead.tumblr.com" )
|
119
|
+
curator.count_followed.should eq( 1 )
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
describe "from file" do
|
124
|
+
it "put direct tofollow in file" do
|
125
|
+
File.delete( curator.get_filename_tofollow ) if File.exists?( curator.get_filename_tofollow )
|
126
|
+
File.open( curator.get_filename_tofollow, 'w' ) { }
|
127
|
+
|
128
|
+
ar_links = curator.send( :add_tofollow_tumblr_links_from_caption, caption )
|
129
|
+
curator.add_tofollow_tofile
|
130
|
+
ar_links.count.should eq( ar_links_caption_tumblrs.count )
|
131
|
+
|
132
|
+
ar_tofollow = CurateTumblr.get_ar_from_file( curator.get_filename_tofollow )
|
133
|
+
ar_tofollow.count.should eq( ar_links_caption_tumblrs.count )
|
134
|
+
ar_links_caption_tumblrs.each { |link| ar_tofollow.include?( link + "\n" ).should be_true }
|
135
|
+
end
|
136
|
+
|
137
|
+
it "follow from a caption true post1" do
|
138
|
+
File.delete( curator.get_filename_tofollow ) if File.exists?( curator.get_filename_tofollow )
|
139
|
+
File.open( curator.get_filename_tofollow, 'w' ) { }
|
140
|
+
|
141
|
+
ar_links_caption = ["afleshfesten.tumblr.com"]
|
142
|
+
hash_post = curator.get_hash_post( "creve-coeur.tumblr.com", 49454185206 )
|
143
|
+
CurateTumblr.hash_post_valid?( hash_post ).should be_true
|
144
|
+
curator.extract_links_caption_from_post( hash_post ).should be_true
|
145
|
+
curator.add_tofollow_tofile
|
146
|
+
|
147
|
+
ar_tofollow = CurateTumblr.get_ar_from_file( curator.get_filename_tofollow )
|
148
|
+
ar_tofollow.count.should eq( ar_links_caption.count )
|
149
|
+
ar_links_caption.each { |link| ar_tofollow.include?( link + "\n" ).should be_true }
|
150
|
+
end
|
151
|
+
|
152
|
+
it "follow from a caption true post2" do
|
153
|
+
File.delete( curator.get_filename_tofollow ) if File.exists?( curator.get_filename_tofollow )
|
154
|
+
File.open( curator.get_filename_tofollow, 'w' ) { }
|
155
|
+
|
156
|
+
ar_links_caption = [ "photonotdead.tumblr.com", "classy-as-fcuk.tumblr.com", "crystvllized.tumblr.com", "worldofadvice.tumblr.com" ]
|
157
|
+
|
158
|
+
hash_post = curator.get_hash_post( "photonotdead.tumblr.com", 55108093006 )
|
159
|
+
CurateTumblr.hash_post_valid?( hash_post ).should be_true
|
160
|
+
curator.extract_links_caption_from_post( hash_post ).should be_true
|
161
|
+
curator.add_tofollow_tofile
|
162
|
+
|
163
|
+
ar_tofollow = CurateTumblr.get_ar_from_file( curator.get_filename_tofollow )
|
164
|
+
ar_tofollow.count.should eq( ar_links_caption.count )
|
165
|
+
ar_links_caption.each { |link| ar_tofollow.include?( link + "\n" ).should be_true }
|
166
|
+
end
|
167
|
+
|
168
|
+
it "follow from a caption true post3" do
|
169
|
+
File.delete( curator.get_filename_tofollow ) if File.exists?( curator.get_filename_tofollow )
|
170
|
+
File.open( curator.get_filename_tofollow, 'w' ) { }
|
171
|
+
|
172
|
+
ar_links_caption = [ "we-melancholy-dreams.tumblr.com", "palejizz.tumblr.com", "sinnerer.tumblr.com" ]
|
173
|
+
hash_post = curator.get_hash_post( "melancholicbeautyofsadness.tumblr.com", 55115100145 )
|
174
|
+
CurateTumblr.hash_post_valid?( hash_post ).should be_true
|
175
|
+
curator.extract_links_caption_from_post( hash_post ).should be_true
|
176
|
+
curator.add_tofollow_tofile
|
177
|
+
|
178
|
+
ar_tofollow = CurateTumblr.get_ar_from_file( curator.get_filename_tofollow )
|
179
|
+
ar_tofollow.count.should eq( ar_links_caption.count )
|
180
|
+
ar_links_caption.each { |link| ar_tofollow.include?( link + "\n" ).should be_true }
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CurateTumblr::Publish::Post do
|
4
|
+
include_context "shared targets"
|
5
|
+
let(:curator) { FactoryGirl.build( :curator ) }
|
6
|
+
|
7
|
+
describe "get infos post" do
|
8
|
+
it "hash post from tumblr and id post" do
|
9
|
+
hash_post = curator.get_hash_post( target_tumblr, target_post_id )
|
10
|
+
hash_post.should_not be_nil
|
11
|
+
hash_post.should_not be_false
|
12
|
+
hash_post.is_a?( Hash ).should be_true
|
13
|
+
CurateTumblr.hash_post_valid?( hash_post ).should be_true
|
14
|
+
hash_post["blog_name"].should eq( target_name )
|
15
|
+
hash_post["id"].to_s.should eq( target_post_id )
|
16
|
+
end
|
17
|
+
|
18
|
+
it "extract hash url from post url" do
|
19
|
+
hash_url = CurateTumblr.get_hash_url_from_post_url( target_post_url )
|
20
|
+
hash_url.should be_true
|
21
|
+
hash_url[:tumblr_url].should eq( target_tumblr )
|
22
|
+
hash_url[:post_id].should eq( target_post_id )
|
23
|
+
end
|
24
|
+
|
25
|
+
it "no hash url from bad post url" do
|
26
|
+
hash_url = CurateTumblr.get_hash_url_from_post_url( bad_target_post_url )
|
27
|
+
hash_url.should be_false
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "post" do
|
32
|
+
it "text" do
|
33
|
+
curator.post_in_published
|
34
|
+
curator.count_posted.should eq( 0 )
|
35
|
+
curator.all_published_id.count.should eq( curator.count_posted )
|
36
|
+
|
37
|
+
id = curator.post_text( get_post_title, get_post_text )
|
38
|
+
id.should_not be_nil
|
39
|
+
id.should be_true
|
40
|
+
id.is_a?( Integer ).should be_true
|
41
|
+
curator.count_posted.should eq( 1 )
|
42
|
+
curator.all_published_id.count.should eq( curator.count_posted )
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CurateTumblr::Publish::Reblog do
|
4
|
+
include_context "shared targets"
|
5
|
+
include_context "shared links"
|
6
|
+
include_context "shared tags"
|
7
|
+
let(:curator) { FactoryGirl.build( :curator ) }
|
8
|
+
|
9
|
+
describe "reblog link" do
|
10
|
+
let(:tumblr_url) { "youknow-thisistheend.tumblr.com" }
|
11
|
+
let(:post_url) { "http://youknow-thisistheend.tumblr.com/post/54773810226/facebook-auf-we-heart-it" }
|
12
|
+
let(:post_reblog_url) { "http://www.tumblr.com/reblog/54773810226/HXKbdnPG?redirect_to=http%3A%2F%2Fterryrichardson.tumblr.com%2Fpost%2F221532252&source=iframe" }
|
13
|
+
let(:post_id) { "54773810226" }
|
14
|
+
let(:post_reblog_key) { "HXKbdnPG" }
|
15
|
+
|
16
|
+
context "direct reblog url" do
|
17
|
+
it "hash post from reblog url" do
|
18
|
+
post_reblog_id = CurateTumblr::Tumblr::ExtractLinks.get_post_id_from_reblog_url( post_reblog_url )
|
19
|
+
post_reblog_id.should eq( post_id )
|
20
|
+
|
21
|
+
hash_post = curator.get_hash_post( tumblr_url, post_id )
|
22
|
+
CurateTumblr.hash_post_valid?( hash_post ).should be_true
|
23
|
+
hash_post["id"].to_s.should eq( post_reblog_id )
|
24
|
+
|
25
|
+
reblog_key1 = CurateTumblr.get_reblog_key_from_hash_post( hash_post )
|
26
|
+
reblog_key1.should eq( post_reblog_key )
|
27
|
+
|
28
|
+
reblog_key2 = CurateTumblr::Tumblr::ExtractLinks.get_reblog_key_from_reblog_url( post_reblog_url )
|
29
|
+
reblog_key2.should eq( post_reblog_key )
|
30
|
+
|
31
|
+
curator.send( :reblog_post_key, post_reblog_id, reblog_key2 ).should be_true
|
32
|
+
end
|
33
|
+
|
34
|
+
it "get post id 1" do
|
35
|
+
id = CurateTumblr::Tumblr::ExtractLinks.get_post_id_from_reblog_url( target_reblog_url )
|
36
|
+
id.should eq ( target_reblog_id )
|
37
|
+
end
|
38
|
+
|
39
|
+
it "get reblog key 1" do
|
40
|
+
id = CurateTumblr::Tumblr::ExtractLinks.get_reblog_key_from_reblog_url( target_reblog_url )
|
41
|
+
id.should eq ( target_reblog_key )
|
42
|
+
end
|
43
|
+
|
44
|
+
it "reblog 1" do
|
45
|
+
count = curator.count_rebloged
|
46
|
+
id = curator.reblog_and_extract( target_reblog_url )
|
47
|
+
id.should_not be_nil
|
48
|
+
id.should be_true
|
49
|
+
id.is_a?( Integer ).should be_true
|
50
|
+
curator.count_rebloged.should eq( count+1 )
|
51
|
+
curator.all_published_id.count.should eq( curator.count_rebloged )
|
52
|
+
end
|
53
|
+
|
54
|
+
it "get post id 2" do
|
55
|
+
id = CurateTumblr::Tumblr::ExtractLinks.get_post_id_from_reblog_url( target_reblog_url2 )
|
56
|
+
id.should eq ( target_reblog_id2 )
|
57
|
+
end
|
58
|
+
|
59
|
+
it "get reblog key 2" do
|
60
|
+
id = CurateTumblr::Tumblr::ExtractLinks.get_reblog_key_from_reblog_url( target_reblog_url2 )
|
61
|
+
id.should eq ( target_reblog_key2 )
|
62
|
+
end
|
63
|
+
|
64
|
+
it "reblog 2" do
|
65
|
+
count = curator.count_rebloged
|
66
|
+
id = curator.reblog_and_extract( target_reblog_url2 )
|
67
|
+
id.should_not be_nil
|
68
|
+
id.should be_true
|
69
|
+
id.is_a?( Integer ).should be_true
|
70
|
+
curator.count_rebloged.should eq( count+1 )
|
71
|
+
curator.all_published_id.count.should eq( curator.count_rebloged )
|
72
|
+
end
|
73
|
+
|
74
|
+
it "get post id 3" do
|
75
|
+
id = CurateTumblr::Tumblr::ExtractLinks.get_post_id_from_reblog_url( target_reblog_url3 )
|
76
|
+
id.should eq ( target_reblog_id3 )
|
77
|
+
end
|
78
|
+
|
79
|
+
it "get reblog key 3" do
|
80
|
+
id = CurateTumblr::Tumblr::ExtractLinks.get_reblog_key_from_reblog_url( target_reblog_url3 )
|
81
|
+
id.should eq ( target_reblog_key3 )
|
82
|
+
end
|
83
|
+
|
84
|
+
it "reblog 3" do
|
85
|
+
count = curator.count_rebloged
|
86
|
+
id = curator.reblog_and_extract( target_reblog_url3 )
|
87
|
+
id.should_not be_nil
|
88
|
+
id.should be_true
|
89
|
+
id.is_a?( Integer ).should be_true
|
90
|
+
curator.count_rebloged.should eq( count+1 )
|
91
|
+
curator.all_published_id.count.should eq( curator.count_rebloged )
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
context "from url link" do
|
97
|
+
it "get url source from post" do
|
98
|
+
url_tumblr = "marseraki.tumblr.com"
|
99
|
+
id_post = "55357197864"
|
100
|
+
url_source = "http://d-rogue.tumblr.com"
|
101
|
+
hash_post = curator.get_hash_post( url_tumblr, id_post )
|
102
|
+
hash_post.should be_true
|
103
|
+
CurateTumblr.get_source_from_hash_post( hash_post ).should eq( url_source )
|
104
|
+
end
|
105
|
+
|
106
|
+
it "get url link from post" do
|
107
|
+
url_tumblr = "marseraki.tumblr.com"
|
108
|
+
id_post = "55357197864"
|
109
|
+
url_link = "http://cutbeneathourhands.tumblr.com/"
|
110
|
+
hash_post = curator.get_hash_post( url_tumblr, id_post )
|
111
|
+
hash_post.should be_true
|
112
|
+
CurateTumblr.get_link_url_from_hash_post( hash_post ).should eq( url_link )
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
|
117
|
+
end
|
118
|
+
end
|