Class: Services::Twitter

Inherits:
Service
  • Object
show all
Defined in:
app/models/services/twitter.rb

Constant Summary

MAX_CHARACTERS =
140
SHORTENED_URL_LENGTH =
21

Instance Method Summary (collapse)

Instance Method Details

- (Object) post(post, url = '')



11
12
13
14
15
16
# File 'app/models/services/twitter.rb', line 11

def post(post, url='')
  Rails.logger.debug("event=post_to_service type=twitter sender_id=#{self.user_id}")
  message = public_message(post, url)

  client.update(message)
end

- (Object) profile_photo_url



29
30
31
# File 'app/models/services/twitter.rb', line 29

def profile_photo_url
  client.user(nickname).profile_image_url_https("original")
end

- (Object) provider



7
8
9
# File 'app/models/services/twitter.rb', line 7

def provider
  "twitter"
end

- (Object) public_message(post, url)



19
20
21
22
23
24
25
26
27
# File 'app/models/services/twitter.rb', line 19

def public_message(post, url)
  buffer_amt = 0
  URI.extract( post.text(:plain_text => true), ['http','https'] ) do |a_url|
    buffer_amt += (a_url.length - SHORTENED_URL_LENGTH)
  end

  #if photos, always include url, otherwise not for short posts
  super(post, MAX_CHARACTERS + buffer_amt,  url, post.photos.any?)
end