Module: InfomemeClient::Functions::UserMeme

Included in:
InfomemeClient::Functions
Defined in:
lib/infomeme_client/functions/user_meme.rb

Instance Method Summary collapse

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

Returns:

  • (Boolean)


18
19
20
# File 'lib/infomeme_client/functions/user_meme.rb', line 18

def can_publish?
  authorized? && 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 authorized?
  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_memesObject



68
69
70
71
72
73
# File 'lib/infomeme_client/functions/user_meme.rb', line 68

def image_upload_for_memes
  return false unless authorized?
  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(options = {})
  get_own_memes options, "inactive"
end

#incomplete(options = {}) ⇒ Object



14
15
16
# File 'lib/infomeme_client/functions/user_meme.rb', line 14

def incomplete(options = {})
  get_own_memes options, "incomplete"
end

#library(options = {}) ⇒ Object



2
3
4
# File 'lib/infomeme_client/functions/user_meme.rb', line 2

def library(options = {})
  get_own_memes options
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, options = {})
  return false unless can_publish?
  skip_upload = options.key?(:skip_upload) && options[:skip_upload]
  options[:image] = upload_image(options[:image]) if ! skip_upload && options.key?(:image) && ! options[:image].nil? && options[:image] != ""
  meme_type = meme_type.id if meme_type.is_a?(InfomemeClient::EntityHash::MemeType)
  meme_id = handle_response :post, "/users/#{verified_user}/memes", options.reject {|k,v| k == :file}.merge({:type => meme_type}) do |resp|
    resp.meme_id unless resp.error?
  end
  upload(meme_id, options[:file]) if options.key?(:file)
  meme_id
end

#published(options = {}) ⇒ Object



6
7
8
# File 'lib/infomeme_client/functions/user_meme.rb', line 6

def published(options = {})
  get_own_memes options, "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 authorized?
  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, rating)
  return false unless authorized?
  handle_response :post, "/users/#{verified_user}/memes/#{meme_id}/rates", {:rating => 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 authorized?
  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 authorized?
  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, options = {})
  skip_upload = options.delete(:skip_upload)
  options[:image] = upload_image(options[:image]) if options.key?(:image) and not skip_upload
  meme_function meme_id, :put, nil, options
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 authorized?
  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