Module: InfomemeClient::Functions::UserMeme
- Included in:
- InfomemeClient::Functions
- Defined in:
- lib/infomeme_client/functions/user_meme.rb
Instance Method Summary collapse
- #activate_meme(meme_id) ⇒ Object
- #can_publish? ⇒ Boolean
- #comment(meme_id, comment) ⇒ Object
- #confirm_meme(meme_id) ⇒ Object
- #deactivate_meme(meme_id) ⇒ Object
- #delete_meme(meme_id) ⇒ Object
- #image_upload_for_memes ⇒ Object
- #inactive(options = {}) ⇒ Object
- #incomplete(options = {}) ⇒ Object
- #library(options = {}) ⇒ Object
- #publish(meme_type, options = {}) ⇒ Object
- #published(options = {}) ⇒ Object
- #published_meme(meme_id) ⇒ Object
- #rate(meme_id, rating) ⇒ Object
- #report(meme_id, reason, refund) ⇒ Object
- #review(meme_id, rating, comment) ⇒ Object
- #update_meme(meme_id, options = {}) ⇒ Object
- #upload(meme_id, file) ⇒ Object
- #upload_for_meme(meme_id, raw = false) ⇒ Object
- #upload_image(file) ⇒ Object
Instance Method Details
#activate_meme(meme_id) ⇒ Object
53 54 55 |
# File 'lib/infomeme_client/functions/user_meme.rb', line 53 def activate_meme(meme_id) meme_function meme_id, :put, "activate" end |
#can_publish? ⇒ Boolean
18 19 20 |
# File 'lib/infomeme_client/functions/user_meme.rb', line 18 def can_publish? && settings && settings.can_publish end |
#comment(meme_id, comment) ⇒ Object
107 108 109 110 |
# File 'lib/infomeme_client/functions/user_meme.rb', line 107 def comment(meme_id, comment) return false unless handle_response :post, "/users/#{verified_user}/memes/#{meme_id}/comments", {:comment => comment} end |
#confirm_meme(meme_id) ⇒ Object
49 50 51 |
# File 'lib/infomeme_client/functions/user_meme.rb', line 49 def confirm_meme(meme_id) meme_function meme_id, :put, "confirm" end |
#deactivate_meme(meme_id) ⇒ Object
57 58 59 |
# File 'lib/infomeme_client/functions/user_meme.rb', line 57 def deactivate_meme(meme_id) meme_function meme_id, :put, "deactivate" end |
#delete_meme(meme_id) ⇒ Object
45 46 47 |
# File 'lib/infomeme_client/functions/user_meme.rb', line 45 def delete_meme(meme_id) meme_function meme_id, :delete end |
#image_upload_for_memes ⇒ Object
68 69 70 71 72 73 |
# File 'lib/infomeme_client/functions/user_meme.rb', line 68 def image_upload_for_memes return false unless handle_response :get, "/users/#{verified_user}/memes/image_upload_parameters" do |resp| resp.image_upload_parameters unless resp.error? end end |
#inactive(options = {}) ⇒ Object
10 11 12 |
# File 'lib/infomeme_client/functions/user_meme.rb', line 10 def inactive( = {}) get_own_memes , "inactive" end |
#incomplete(options = {}) ⇒ Object
14 15 16 |
# File 'lib/infomeme_client/functions/user_meme.rb', line 14 def incomplete( = {}) get_own_memes , "incomplete" end |
#library(options = {}) ⇒ Object
2 3 4 |
# File 'lib/infomeme_client/functions/user_meme.rb', line 2 def library( = {}) get_own_memes end |
#publish(meme_type, options = {}) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/infomeme_client/functions/user_meme.rb', line 22 def publish(meme_type, = {}) return false unless can_publish? skip_upload = .key?(:skip_upload) && [:skip_upload] [:image] = upload_image([:image]) if ! skip_upload && .key?(:image) && ! [:image].nil? && [:image] != "" meme_type = meme_type.id if meme_type.is_a?(InfomemeClient::EntityHash::MemeType) meme_id = handle_response :post, "/users/#{verified_user}/memes", .reject {|k,v| k == :file}.merge({:type => meme_type}) do |resp| resp.meme_id unless resp.error? end upload(meme_id, [:file]) if .key?(:file) meme_id end |
#published(options = {}) ⇒ Object
6 7 8 |
# File 'lib/infomeme_client/functions/user_meme.rb', line 6 def published( = {}) get_own_memes , "published" end |
#published_meme(meme_id) ⇒ Object
34 35 36 37 |
# File 'lib/infomeme_client/functions/user_meme.rb', line 34 def published_meme(meme_id) return false unless extract_from_response :meme, :get, "/users/#{verified_user}/memes/#{meme_id}" end |
#rate(meme_id, rating) ⇒ Object
102 103 104 105 |
# File 'lib/infomeme_client/functions/user_meme.rb', line 102 def rate(meme_id, ) return false unless handle_response :post, "/users/#{verified_user}/memes/#{meme_id}/rates", {:rating => } end |
#report(meme_id, reason, refund) ⇒ Object
87 88 89 90 |
# File 'lib/infomeme_client/functions/user_meme.rb', line 87 def report(meme_id, reason, refund) return false unless handle_response :post, "/users/#{verified_user}/memes/#{meme_id}/reports", {:reason => reason, :refund => refund} end |
#review(meme_id, rating, comment) ⇒ Object
92 93 94 95 |
# File 'lib/infomeme_client/functions/user_meme.rb', line 92 def review(meme_id, review) return false unless handle_response :post, "/users/#{verified_user}/memes/#{meme_id}/reviews", {:review => review} end |
#update_meme(meme_id, options = {}) ⇒ Object
39 40 41 42 43 |
# File 'lib/infomeme_client/functions/user_meme.rb', line 39 def update_meme(meme_id, = {}) skip_upload = .delete(:skip_upload) [:image] = upload_image([:image]) if .key?(:image) and not skip_upload meme_function meme_id, :put, nil, end |
#upload(meme_id, file) ⇒ Object
75 76 77 78 79 |
# File 'lib/infomeme_client/functions/user_meme.rb', line 75 def upload(meme_id, file) file = File.new(file) if file.is_a?(String) upload_url = upload_for_meme(meme_id, true) http_multipart(upload_url, generate_signature.merge({:meme_id => meme_id, :file => uploadio(file)})) if upload_url end |
#upload_for_meme(meme_id, raw = false) ⇒ Object
61 62 63 64 65 66 |
# File 'lib/infomeme_client/functions/user_meme.rb', line 61 def upload_for_meme(meme_id, raw = false) return false unless handle_response :get, "/users/#{verified_user}/memes/#{meme_id}/upload_url" do |resp| (raw ? resp.upload_url : finalize_get_url(resp.upload_url, generate_signature.merge(:meme_id => meme_id))) unless resp.error? end end |
#upload_image(file) ⇒ Object
81 82 83 84 85 |
# File 'lib/infomeme_client/functions/user_meme.rb', line 81 def upload_image(file) file = File.new(file) if file.is_a?(String) upload_params = image_upload_for_memes File.basename(file.path) if upload_params && http_multipart("https://#{upload_params.bucket}.s3.amazonaws.com/", upload_params.to_hash.reject {|k,v| k == :bucket}.merge(:success_action_status => 200).to_a.push([:file, uploadio(file)])) #ensure file comes last (amazon requires the order) end |