1module SharingHelper
  • Complexity 1 » saikuro
2  def share_via_facebook(petition, options = {})
 
3    link_to(share_button(:facebook), share_via_facebook_url(petition), options)
 
4  end
 
5
  • Complexity 1 » saikuro
6  def share_via_facebook_url(petition)
 
7    "https://www.facebook.com/sharer/sharer.php?#{share_via_facebook_params(petition)}"
 
8  end
 
 9
  • Complexity 1 » saikuro
10  def share_via_email(petition, options = {})
 
11    link_to(share_button(:email), share_via_email_url(petition), options)
 
12  end
 
  • Complexity 1 » saikuro
14  def share_via_email_url(petition)
 
15    "mailto:?#{share_via_email_params(petition)}"
 
16  end
 
  • Complexity 1 » saikuro
18  def share_via_twitter(petition, options = {})
 
19    link_to(share_button(:twitter), share_via_twitter_url(petition), options)
 
20  end
 
  • Complexity 1 » saikuro
22  def share_via_twitter_url(petition)
 
23    "https://twitter.com/intent/tweet?#{share_via_twitter_params(petition)}"
 
24  end
 
  • Complexity 1 » saikuro
26  def share_via_whatsapp(petition, options = {})
 
27    link_to(share_button(:whatsapp), share_via_whatsapp_url(petition), options)
 
28  end
 
  • Complexity 1 » saikuro
30  def share_via_whatsapp_url(petition)
 
31    "whatsapp://send?#{share_via_whatsapp_params(petition)}"
 
32  end
 
 
34  private
 
  • Complexity 1 » saikuro
36  def share_via_facebook_params(petition)
 
37    share_params(u: petition_url(petition), ref: "responsive")
 
38  end
 
  • Complexity 1 » saikuro
40  def share_via_email_params(petition)
 
41    share_params(subject: share_title(petition), body: petition_url(petition))
 
42  end
 
  • Complexity 1 » saikuro
44  def share_via_twitter_params(petition)
 
45    share_params(text: share_title(petition), url: petition_url(petition))
 
46  end
 
  • Complexity 1 » saikuro
48  def share_via_whatsapp_params(petition)
 
49    share_params(text: "#{share_title(petition)}\n#{petition_url(petition)}")
 
50  end
 
  • Complexity 1 » saikuro
52  def share_title(petition)
 
53    t(:share_title, scope: :petitions, petition: petition.action)
 
54  end
 
  • UtilityFunction - doesn't depend on instance state (maybe move it to another class?) » reek
  • Complexity 1 » saikuro
56  def share_params(hash)
 
57    hash.to_query.gsub('+', '%20')
 
58  end
 
  • Complexity 1 » saikuro
60  def share_button(service)
 
61    t(:"#{service}.html", scope: :"petitions.sharing")
 
62  end
 
63end