Created
July 14, 2020 11:23
-
-
Save Snarp/05c5120b2ae1614885f911fc545102e4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This isn't the official Ruby Tumblr client, it's a clone that accepts some extra arguments | |
require_relative 'lib/tumblr_client' | |
@credentials = YAML::load(File.read('credentials.env.yml')) | |
@client ||= TumblrClient.new(**@credentials) | |
@info ||= @client.user_info[:user] | |
@uuid ||= @info[:blogs].first[:uuid] | |
@username ||= @info[:name] | |
@other_blog = 'staff' | |
@owned_blog = 'themagnusaaaaaa' | |
@tag = 'cats' | |
@offset = 56 | |
@tag_before ||= Time.now-(24*24*60) | |
# As of 2020-05-09: | |
# => {:offset=>false, :before_id=>false, :after=>false} | |
def test_tag_opts(tag=@tag, offset: @offset, before: @tag_before.to_i, **args) | |
offset = test_tag_offset(tag, offset: offset, **args) | |
before_id = test_tag_before_id(tag, before: before, **args) | |
after = test_tag_after(tag, before: before, set: @control_set, **args) | |
return { offset: offset, before_id: before_id, after: after } | |
end | |
# As of 2020-05-09: | |
# => {:before=>true, :before_id=>true, :after=>false, :since_id=>false} | |
def test_blog_opts(blog=@other_blog, offset: @offset, **args) | |
args[:reblog_info] ||= false | |
set = @client.posts(blog, offset: offset, **args) | |
before = test_blog_before(blog, offset: offset, set: set, **args) | |
before_id = test_blog_before_id(blog, offset: offset, set: set, **args) | |
after = test_blog_after(blog, offset: offset, set: set, **args) | |
since_id = test_blog_since_id(blog, offset: offset, set: set, **args) | |
return {before: before,before_id: before_id,after: after,since_id: since_id} | |
end | |
# As of 2020-05-09: | |
# => {:before=>false, :before_id=>true, :after=>false} | |
def test_dash_opts(offset: @offset, **args) | |
set = @client.dashboard(offset: offset) | |
before = test_dash_before(offset: offset, set: set, **args) | |
before_id = test_dash_before_id(offset: offset, set: set, **args) | |
after = test_dash_after(offset: offset, set: set, **args) | |
return { before: before, before_id: before_id, after: after } | |
end | |
# ---------------- | |
# BLOG PARAMS | |
# ---------------- | |
# Working as of 2020-05-09! | |
def test_blog_before(blog=@other_blog, offset: @offset, set: nil, **args) | |
args[:reblog_info] ||= false | |
@control_set = set || @client.posts(blog, offset: offset, **args) | |
first_timestamp = @control_set[:posts].first[:timestamp] | |
@test_args = args.merge before: (first_timestamp+1) | |
sleep(1.0) | |
@test_set = @client.posts(blog, **@test_args) | |
control_ids = @control_set[:posts].map { |p| p[:id] } | |
test_ids = @test_set[:posts].map { |p| p[:id] } | |
ids_diff = control_ids - test_ids | |
if ids_diff.empty? | |
puts "YES! #blog :before appears to be working!" | |
return true | |
elsif ids_diff.count<=5 # 5 seems like a safe number of identical timestamps | |
puts "YES! KINDA! #blog :before works, but incorrectly includes the post(s) of the given timestamp in the set!" | |
return true | |
else | |
puts "UH-OH! #blog :before DOES NOT appear to be working!" | |
return false | |
end | |
# return { working: working, control: @control_set, test: @test_set } | |
end | |
# Working as of 2020-05-09! | |
def test_blog_before_id(blog=@other_blog, offset: @offset, set: nil, **args) | |
args[:reblog_info] ||= false | |
@control_set = set || @client.posts(blog, offset: offset, **args) | |
first_id = @control_set[:posts].first[:id] | |
@test_args = args.merge before_id: (first_id+1) | |
sleep(1.0) | |
@test_set = @client.posts(blog, **@test_args) | |
control_ids = @control_set[:posts].map { |p| p[:id] } | |
test_ids = @test_set[:posts].map { |p| p[:id] } | |
ids_diff = control_ids - test_ids | |
if ids_diff.empty? | |
puts "YES! #blog :before_id appears to be working!" | |
return true | |
elsif ids_diff.count==1 | |
puts "YES! KINDA! #blog :before_id works, but incorrectly includes the post of the given ID in the set!" | |
return true | |
else | |
puts "UH-OH! #blog :before_id DOES NOT appear to be working!" | |
return false | |
end | |
# return { working: working, control: @control_set, test: @test_set } | |
end | |
# NOT working as of 2020-05-09. | |
def test_blog_after(blog=@other_blog, offset: @offset, set: nil, **args) | |
args[:reblog_info] ||= false | |
@control_set = set || @client.posts(blog, offset: offset, **args) | |
last_timestamp = @control_set[:posts].last[:timestamp] | |
@test_args = args.merge after: (last_timestamp-1) | |
sleep(1.0) | |
@test_set = @client.posts(blog, **@test_args) | |
control_ids = @control_set[:posts].map { |p| p[:id] } | |
test_ids = @test_set[:posts].map { |p| p[:id] } | |
ids_diff = control_ids - test_ids | |
if ids_diff.empty? | |
puts "YES! #blog :after appears to be working!" | |
return true | |
elsif ids_diff.count<=5 # 5 seems like a safe number of identical timestamps | |
puts "YES! KINDA! #blog :after works, but incorrectly includes the post(s) of the given timestamp in the set!" | |
return true | |
else | |
puts "UH-OH! #blog :after DOES NOT appear to be working!" | |
return false | |
end | |
# return { working: working, control: @control_set, test: @test_set } | |
end | |
# NOT working as of 2020-05-09. | |
def test_blog_since_id(blog=@other_blog, offset: @offset, set: nil, **args) | |
args[:reblog_info] ||= false | |
@control_set = set || @client.posts(blog, offset: offset, **args) | |
last_id = @control_set[:posts].last[:id] | |
@test_args = args.merge since_id: (last_id-1) | |
sleep(1.0) | |
@test_set = @client.posts(blog, **@test_args) | |
control_ids = @control_set[:posts].map { |p| p[:id] } | |
test_ids = @test_set[:posts].map { |p| p[:id] } | |
ids_diff = control_ids - test_ids | |
if ids_diff.empty? | |
puts "YES! #blog :since_id appears to be working!" | |
return true | |
elsif ids_diff.count==1 | |
puts "YES! KINDA! #blog :since_id works, but incorrectly includes the post of the given ID in the set!" | |
return true | |
else | |
puts "UH-OH! #blog :since_id DOES NOT appear to be working!" | |
return false | |
end | |
# return { working: working, control: @control_set, test: @test_set } | |
end | |
# --------------------- | |
# BLOG PARAMS - PRIVATE | |
# --------------------- | |
# As of 2020-05-09, 'before_id' and 'since_id' are working. | |
# => {:offset=>false, :before_id=>true, :since_id=>true, :before=>false, :after=>false} | |
def test_blog_drafts | |
test_blog_private('draft') | |
end | |
# As of 2020-05-09, only 'offset' is working. | |
# => {:offset=>true, :after=>false, :since_id=>false, :before_id=>false, :before=>false} | |
def test_blog_q | |
test_blog_private('queue') | |
end | |
# REVIEW: THIS IS VERY UGLY | |
def test_blog_private(method_name='queue', blog=@owned_blog, **args) | |
return nil unless ['queue','draft','submission'].include?(method_name) | |
results = {} | |
path = "v2/blog/#{full_blog_id(blog)}/posts/#{method_name}" | |
# Test (usually-)documented arg 'offset': | |
@control_set = @client.get_body(path, **args) | |
control_ids = @control_set[:posts].map { |p| p[:id] } | |
last_id = @control_set[:posts].last[:id] | |
last_timestamp = @control_set[:posts].last[:timestamp] | |
@test_args = args.merge offset: 20 | |
puts "test_args: #{@test_args}" | |
sleep(1.0) | |
@test_set = @client.get_body(path, **@test_args) | |
test_ids = @test_set[:posts].map { |p| p[:id] } | |
ids_diff = control_ids - test_ids | |
if ids_diff.count > 1 | |
puts "YES! ##{method_name} :offset appears to be working!" | |
results[:offset] = true | |
else | |
puts "UH-OH! ##{method_name} :offset DOES NOT appear to be working!" | |
results[:offset] = false | |
end | |
# 'before_id': | |
@test_args = args.merge before_id: last_id | |
puts "test_args: #{@test_args}" | |
sleep(1.0) | |
@test_set = @client.get_body(path, **@test_args) | |
test_ids = @test_set[:posts].map { |p| p[:id] } | |
ids_diff = test_ids - control_ids | |
if ids_diff.count==test_ids.count | |
puts "YES! ##{method_name} :before_id appears to be working!" | |
results[:before_id] = true | |
elsif ids_diff.count==1 | |
puts "YES! KINDA! ##{method_name} :before_id works, but incorrectly includes the post of the given ID in the set!" | |
results[:before_id] = true | |
else | |
puts "UH-OH! ##{method_name} :before_id DOES NOT appear to be working!" | |
results[:before_id] = false | |
end | |
# 'since_id': | |
since_id = if results[:before_id] || results[:offset] | |
control_ids = @test_set[:posts].map { |p| p[:id] } | |
control_ids.first | |
else | |
1 | |
end | |
@test_args = args.merge since_id: since_id | |
puts "test_args: #{@test_args}" | |
sleep(1.0) | |
@test_set = @client.get_body(path, **@test_args) | |
test_ids = @test_set[:posts].map { |p| p[:id] } | |
ids_diff = test_ids - control_ids | |
if ids_diff.count==test_ids.count | |
puts "YES! ##{method_name} :since_id appears to be working!" | |
results[:since_id] = true | |
elsif ids_diff.count==1 | |
puts "YES! KINDA! ##{method_name} :since_id works, but incorrectly includes the post of the given ID in the set!" | |
results[:since_id] = true | |
else | |
puts "UH-OH! ##{method_name} :since_id DOES NOT appear to be working!" | |
results[:since_id] = false | |
end | |
control_ids = @control_set[:posts].map { |p| p[:id] } # resetting | |
# 'before': | |
@test_args = args.merge before: last_timestamp | |
puts "test_args: #{@test_args}" | |
sleep(1.0) | |
@test_set = @client.get_body(path, **@test_args) | |
test_ids = @test_set[:posts].map { |p| p[:id] } | |
ids_diff = control_ids - test_ids | |
if ids_diff.count > 1 | |
puts "YES! ##{method_name} :before appears to be working!" | |
results[:before] = true | |
else | |
puts "UH-OH! ##{method_name} :before DOES NOT appear to be working!" | |
results[:before] = false | |
end | |
# 'after': | |
after = 0 | |
puts "last_timestamp: #{Time.at(after)} (#{after})" | |
@test_args = args.merge after: after | |
puts "test_args: #{@test_args}" | |
sleep(1.0) | |
@test_set = @client.get_body(path, **@test_args) | |
test_ids = @test_set[:posts].map { |p| p[:id] } | |
ids_diff = test_ids - control_ids | |
if ids_diff.count > 1 | |
puts "YES! ##{method_name} :after appears to be working!" | |
results[:after] = true | |
else | |
puts "UH-OH! ##{method_name} :after DOES NOT appear to be working!" | |
results[:after] = false | |
end | |
return results | |
end | |
# ---------------- | |
# DASHBOARD PARAMS | |
# ---------------- | |
# Working as of 2020-05-09! | |
def test_dash_before_id(offset: @offset, set: nil) | |
@control_set = set || @client.dashboard(offset: offset) | |
first_id = @control_set[:posts].first[:id] | |
@test_args = { before_id: (first_id+1) } | |
sleep(1.0) | |
@test_set = @client.dashboard(**@test_args) | |
control_ids = @control_set[:posts].map { |p| p[:id] } | |
test_ids = @test_set[:posts].map { |p| p[:id] } | |
ids_diff = control_ids - test_ids | |
if ids_diff.empty? | |
puts "YES! #dashboard :before_id appears to be working!" | |
return true | |
elsif ids_diff.count==1 | |
puts "YES! KINDA! #dashboard :before_id works, but incorrectly includes the post of the given ID in the set!" | |
return true | |
else | |
puts "UH-OH! #dashboard :before_id DOES NOT appear to be working!" | |
return false | |
end | |
# return { working: working, control: @control_set, test: @test_set } | |
end | |
# NOT working as of 2020-05-09. | |
def test_dash_before(offset: @offset, set: nil) | |
@control_set = set || @client.dashboard(offset: offset) | |
first_timestamp = @control_set[:posts].first[:timestamp] | |
@test_args = { before: (first_timestamp+1) } | |
sleep(1.0) | |
@test_set = @client.dashboard(**@test_args) | |
control_ids = @control_set[:posts].map { |p| p[:id] } | |
test_ids = @test_set[:posts].map { |p| p[:id] } | |
ids_diff = control_ids - test_ids | |
if ids_diff.empty? | |
puts "YES! #dashboard :before appears to be working!" | |
return true | |
elsif ids_diff.count<=5 # 5 seems like a safe number of identical timestamps | |
puts "YES! KINDA! #dashboard :before works, but incorrectly includes the post(s) of the given timestamp in the set!" | |
return true | |
else | |
puts "UH-OH! #dashboard :before DOES NOT appear to be working!" | |
return false | |
end | |
# return { working: working, control: @control_set, test: @test_set } | |
end | |
# NOT working as of 2020-05-09. | |
def test_dash_after(offset: @offset, set: nil) | |
@control_set = set || @client.dashboard(offset: offset) | |
last_timestamp = @control_set[:posts].last[:timestamp] | |
@test_args = { after: (last_timestamp-1) } | |
sleep(1.0) | |
@test_set = @client.dashboard(**@test_args) | |
control_ids = @control_set[:posts].map { |p| p[:id] } | |
test_ids = @test_set[:posts].map { |p| p[:id] } | |
ids_diff = control_ids - test_ids | |
if ids_diff.empty? | |
puts "YES! #dashboard :after appears to be working!" | |
return true | |
elsif ids_diff.count<=5 # 5 seems like a safe number of identical timestamps | |
puts "YES! KINDA! #dashboard :after works, but incorrectly includes the post(s) of the given timestamp in the set!" | |
return true | |
else | |
puts "UH-OH! #dashboard :after DOES NOT appear to be working!" | |
return false | |
end | |
# return { working: working, control: @control_set, test: @test_set } | |
end | |
# ---------- | |
# TAG PARAMS | |
# ---------- | |
# NOT working as of 2020-05-09. | |
def test_tag_offset(tag=@tag, offset: @offset, set: nil, **args) | |
args[:tag] ||= tag | |
args.delete(:before) | |
@control_set = @client.tagged(**args) | |
@test_args = args.merge offset: offset | |
sleep(1.0) | |
@test_set = @client.tagged(**@test_args) | |
control_ids = @control_set.map { |p| p[:id] } | |
test_ids = @test_set.map { |p| p[:id] } | |
ids_diff = control_ids - test_ids | |
if ids_diff.count==20 | |
puts "YES! #tagged :offset appears to be working!" | |
return true | |
else | |
puts "UH-OH! #tagged :offset DOES NOT appear to be working!" | |
return false | |
end | |
end | |
# NOT working as of 2020-05-09. | |
def test_tag_before_id(tag=@tag, before: @tag_before.to_i, set: nil, **args) | |
args[:tag] ||= tag | |
@control_set = set || @client.tagged(before: before.to_i, **args) | |
first_id = @control_set.first[:id] | |
@test_args = args.merge before_id: (first_id+1) | |
sleep(1.0) | |
@test_set = @client.tagged(**@test_args) | |
control_ids = @control_set.map { |p| p[:id] } | |
test_ids = @test_set.map { |p| p[:id] } | |
ids_diff = control_ids - test_ids | |
if ids_diff.empty? | |
puts "YES! #tagged :before_id appears to be working!" | |
return true | |
elsif ids_diff.count==1 | |
puts "YES! KINDA! #tagged :before_id works, but incorrectly includes the post of the given ID in the set!" | |
return true | |
else | |
puts "UH-OH! #tagged :before_id DOES NOT appear to be working!" | |
return false | |
end | |
end | |
# NOT working as of 2020-05-09. | |
def test_tag_after(tag=@tag, before: @tag_before.to_i, set: nil, **args) | |
args[:tag] ||= tag | |
@control_set = set || @client.tagged(before: before.to_i, **args) | |
last_timestamp = @control_set.last[:timestamp] | |
@test_args = args.merge after: (last_timestamp-1) | |
sleep(1.0) | |
@test_set = @client.tagged(**@test_args) | |
control_ids = @control_set.map { |p| p[:id] } | |
test_ids = @test_set.map { |p| p[:id] } | |
ids_diff = control_ids - test_ids | |
if ids_diff.empty? | |
puts "YES! #tagged :after appears to be working!" | |
return true | |
elsif ids_diff.count<=5 # 5 seems like a safe number of identical timestamps | |
puts "YES! KINDA! #tagged :after works, but incorrectly includes the post(s) of the given timestamp in the set!" | |
return true | |
else | |
puts "UH-OH! #tagged :after DOES NOT appear to be working!" | |
return false | |
end | |
end | |
# HELPERS | |
def full_blog_id(blog_id) | |
if blog_id.include?('.') || blog_id.include?(':') | |
return blog_id | |
else | |
return blog_id+".tumblr.com" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment