Class: Meme
- Inherits:
-
Object
- Object
- Meme
- Defined in:
- lib/twitter_meme/meme.rb
Instance Attribute Summary collapse
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#template_id ⇒ Object
readonly
Returns the value of attribute template_id.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
- #generate_meme(text0, text1) ⇒ Object
-
#initialize(username, password, template_id) ⇒ Meme
constructor
A new instance of Meme.
- #make_api_call(text0, text1) ⇒ Object
Constructor Details
#initialize(username, password, template_id) ⇒ Meme
Returns a new instance of Meme.
6 7 8 9 10 |
# File 'lib/twitter_meme/meme.rb', line 6 def initialize(username, password, template_id) @username = username @password = password @template_id = template_id end |
Instance Attribute Details
#password ⇒ Object (readonly)
Returns the value of attribute password.
4 5 6 |
# File 'lib/twitter_meme/meme.rb', line 4 def password @password end |
#template_id ⇒ Object (readonly)
Returns the value of attribute template_id.
4 5 6 |
# File 'lib/twitter_meme/meme.rb', line 4 def template_id @template_id end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
4 5 6 |
# File 'lib/twitter_meme/meme.rb', line 4 def username @username end |
Instance Method Details
#generate_meme(text0, text1) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/twitter_meme/meme.rb', line 12 def generate_meme(text0, text1) http_resp = make_api_call(text0, text1) return unless http_resp.code == 200 result = JSON.parse(http_resp.body) return unless result['success'] result['data']['url'] end |
#make_api_call(text0, text1) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/twitter_meme/meme.rb', line 22 def make_api_call(text0, text1) RestClient.post( 'http://api.imgflip.com/caption_image', username: username, password: password, template_id: template_id, text0: text0, text1: text1 ) end |