* Update Travis.yml * Update README * Update README * Adjust test to not rely on env vars * Update encryption * Refactor * Update env key * Stub AWS calls * Create ApplicationConfig * Fix specs * Fix lint * Update ApplicationConfig * Remove travis env vars * Fix lint * Extend character limit to 100 * Add env to travis * Take out auto-restart after deploy * Immediately discarded test cache * Stub GA in request specs * Stub Pusher * Fix broken specs * Update fixture * Add CodeClimate id * Change CodeClimate key * Remove merge mistakes * WIP * Add Envied gem & Change README * Add missing keys * Add missing key * Update fixture * Fix broken spec * Add Slack Notification for Travis * Fix wording * Fix typo
50 lines
1.2 KiB
Ruby
50 lines
1.2 KiB
Ruby
class Bufferizer
|
|
def initialize(article, text)
|
|
@article = article
|
|
@text = text
|
|
end
|
|
|
|
def twitter_post!
|
|
client = Buffer::Client.new(ApplicationConfig["BUFFER_ACCESS_TOKEN"])
|
|
client.create_update(
|
|
body: {
|
|
text:
|
|
twitter_buffer_text,
|
|
profile_ids: [
|
|
ApplicationConfig["BUFFER_TWITTER_ID"],
|
|
],
|
|
},
|
|
)
|
|
@article.update(last_buffered: Time.now)
|
|
end
|
|
|
|
def facebook_post!
|
|
client = Buffer::Client.new(ApplicationConfig["BUFFER_ACCESS_TOKEN"])
|
|
client.create_update(
|
|
body: {
|
|
text:
|
|
fb_buffer_text,
|
|
profile_ids: [
|
|
ApplicationConfig["BUFFER_FACEBOOK_ID"], # We're sending to LinkedIn and FB with this.
|
|
ApplicationConfig["BUFFER_LINKEDIN_ID"], # That's why there are two profile IDs
|
|
],
|
|
},
|
|
)
|
|
@article.update(facebook_last_buffered: Time.now)
|
|
end
|
|
|
|
private
|
|
|
|
def twitter_buffer_text
|
|
twit_name = @article.user.twitter_username
|
|
if twit_name.present? && @text.size < 245
|
|
"#{@text}\n{ author: @#{twit_name} }\nhttps://dev.to#{@article.path}"
|
|
else
|
|
"#{@text} https://dev.to#{@article.path}"
|
|
end
|
|
end
|
|
|
|
def fb_buffer_text
|
|
"#{@text} https://dev.to#{@article.path}"
|
|
end
|
|
end
|