Class: Brutalismbot::Client
- Inherits:
-
Object
- Object
- Brutalismbot::Client
- Defined in:
- lib/brutalismbot/stub.rb,
lib/brutalismbot/client.rb
Instance Attribute Summary collapse
-
#posts ⇒ Object
readonly
Returns the value of attribute posts.
-
#reddit ⇒ Object
readonly
Returns the value of attribute reddit.
-
#slack ⇒ Object
readonly
Returns the value of attribute slack.
-
#twitter ⇒ Object
readonly
Returns the value of attribute twitter.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(posts: nil, reddit: nil, slack: nil, twitter: nil) ⇒ Client
constructor
A new instance of Client.
- #pull(limit: nil, min_time: nil, max_time: nil, min_age: nil, dryrun: nil) ⇒ Object
- #push(post, dryrun: nil) ⇒ Object
- #stub!(posts: nil, slack: nil) ⇒ Object
Constructor Details
#initialize(posts: nil, reddit: nil, slack: nil, twitter: nil) ⇒ Client
Returns a new instance of Client.
10 11 12 13 14 15 |
# File 'lib/brutalismbot/client.rb', line 10 def initialize(posts:nil, reddit:nil, slack:nil, twitter:nil) @posts = posts || Posts::Client.new @reddit = reddit || Reddit::Client.new @slack = slack || Slack::Client.new @twitter = twitter || Twitter::Client.new end |
Instance Attribute Details
#posts ⇒ Object (readonly)
Returns the value of attribute posts.
8 9 10 |
# File 'lib/brutalismbot/client.rb', line 8 def posts @posts end |
#reddit ⇒ Object (readonly)
Returns the value of attribute reddit.
8 9 10 |
# File 'lib/brutalismbot/client.rb', line 8 def reddit @reddit end |
#slack ⇒ Object (readonly)
Returns the value of attribute slack.
8 9 10 |
# File 'lib/brutalismbot/client.rb', line 8 def slack @slack end |
#twitter ⇒ Object (readonly)
Returns the value of attribute twitter.
8 9 10 |
# File 'lib/brutalismbot/client.rb', line 8 def twitter @twitter end |
Class Method Details
.stub(posts: nil, slack: nil) ⇒ Object
19 20 21 |
# File 'lib/brutalismbot/stub.rb', line 19 def stub(posts:nil, slack:nil) new.stub!(posts: posts, slack: slack) end |
Instance Method Details
#pull(limit: nil, min_time: nil, max_time: nil, min_age: nil, dryrun: nil) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/brutalismbot/client.rb', line 17 def pull(limit:nil, min_time:nil, max_time:nil, min_age:nil, dryrun:nil) # Get time window for new posts min_age ||= 9000 min_time ||= @posts.max_time max_time ||= Time.now.utc.to_i - min_age.to_i # Get posts opts = {q:"self:no AND nsfw:no", restrict_sr: true, sort: "new"} posts = @reddit.list(:search, **opts).all # Filter, sort, and limit posts = posts.select{|post| post.created_between?(min_time, max_time) } posts = posts.sort{|a,b| a.created_utc <=> b.created_utc } posts = posts.slice(0, limit) unless limit.nil? # Persist posts posts.map{|post| @posts.push(post, dryrun: dryrun) } end |
#push(post, dryrun: nil) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/brutalismbot/client.rb', line 36 def push(post, dryrun:nil) # Push to Twitter @twitter.push(post, dryrun: dryrun) # Push to Slack @slack.push(post, dryrun: dryrun) nil end |