Class: Twoffein::Tweet

Inherits:
Object
  • Object
show all
Defined in:
lib/twoffein-client/tweet.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(drink_key, target_screen_name = nil) ⇒ Tweet

Returns a new instance of Tweet.



10
11
12
13
# File 'lib/twoffein-client/tweet.rb', line 10

def initialize drink_key, target_screen_name=nil
  @drink = drink_key.to_sym
  @target_screen_name = target_screen_name
end

Instance Attribute Details

#drinkObject

Returns the value of attribute drink.



7
8
9
# File 'lib/twoffein-client/tweet.rb', line 7

def drink
  @drink
end

#target_screen_nameObject

Returns the value of attribute target_screen_name.



7
8
9
# File 'lib/twoffein-client/tweet.rb', line 7

def target_screen_name
  @target_screen_name
end

Instance Method Details

#postObject Also known as: publish

Raises:



15
16
17
18
19
20
21
22
# File 'lib/twoffein-client/tweet.rb', line 15

def post
  info = HTTP.post("tweet", {
    :drink => @drink,
    :target_screen_name => @target_screen_name
  })
  raise Server::Error.new(info[:code], info[:error]) if info.has_key? :error
  info
end

#to_sObject



25
26
27
28
29
# File 'lib/twoffein-client/tweet.rb', line 25

def to_s
  s = "Ich trinke gerade #{Drinks[@drink].name}"
  s << " mit #{@target_screen_name}" if @target_screen_name
  s << "."
end