Added tag handling
This commit is contained in:
parent
b2b03d2679
commit
3793d36609
1 changed files with 11 additions and 4 deletions
|
|
@ -8,11 +8,14 @@ module Services
|
||||||
"tumblr"
|
"tumblr"
|
||||||
end
|
end
|
||||||
|
|
||||||
def post(post, url="")
|
def post(post, url="") # rubocop:disable Metrics/AbcSize
|
||||||
|
return true if post.nil? # return if post is deleted while waiting in queue
|
||||||
|
|
||||||
body = build_tumblr_post(post, url)
|
body = build_tumblr_post(post, url)
|
||||||
user_info = JSON.parse(client.get("/v2/user/info").body)
|
user_info = JSON.parse(client.get("/v2/user/info").body)
|
||||||
blogs = user_info["response"]["user"]["blogs"]
|
blogs = user_info["response"]["user"]["blogs"]
|
||||||
primaryblog = blogs.find {|blog| blog["primary"] } || blogs[0]
|
primaryblog = blogs.find {|blog| blog["primary"] } || blogs[0]
|
||||||
|
|
||||||
tumblr_ids = {}
|
tumblr_ids = {}
|
||||||
|
|
||||||
blogurl = URI.parse(primaryblog["url"])
|
blogurl = URI.parse(primaryblog["url"])
|
||||||
|
|
@ -35,13 +38,13 @@ module Services
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_tumblr_post(post, url)
|
def build_tumblr_post(post, url)
|
||||||
{type: "text", format: "markdown", body: tumblr_template(post, url)}
|
{type: "text", format: "markdown", body: tumblr_template(post, url), tags: tags(post), native_inline_images: true}
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def client
|
def client
|
||||||
@consumer ||= OAuth::Consumer.new(consumer_key, consumer_secret, site: "http://api.tumblr.com")
|
@consumer ||= OAuth::Consumer.new(consumer_key, consumer_secret, site: "https://api.tumblr.com")
|
||||||
@client ||= OAuth::AccessToken.new(@consumer, access_token, access_secret)
|
@client ||= OAuth::AccessToken.new(@consumer, access_token, access_secret)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -51,13 +54,17 @@ module Services
|
||||||
"#{photo_html}#{post.message.html(mentioned_people: [])}\n\n[original post](#{url})"
|
"#{photo_html}#{post.message.html(mentioned_people: [])}\n\n[original post](#{url})"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def tags(post)
|
||||||
|
post.tags.pluck(:name).join(",").to_s
|
||||||
|
end
|
||||||
|
|
||||||
def delete_from_tumblr(blog_name, service_post_id)
|
def delete_from_tumblr(blog_name, service_post_id)
|
||||||
client.post("/v2/blog/#{blog_name}/post/delete", "id" => service_post_id)
|
client.post("/v2/blog/#{blog_name}/post/delete", "id" => service_post_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def request_to_external_blog(blogurl, body)
|
def request_to_external_blog(blogurl, body)
|
||||||
resp = client.post("/v2/blog/#{blogurl.host}/post", body)
|
resp = client.post("/v2/blog/#{blogurl.host}/post", body)
|
||||||
JSON.parse(resp.body)["response"]["id"] if resp.code == "201"
|
JSON.parse(resp.body)["response"]["id"] if resp.code == 201
|
||||||
end
|
end
|
||||||
|
|
||||||
def consumer_key
|
def consumer_key
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue