Module: ArolitecSms::HttpInterceptor
- Defined in:
- lib/arolitec_sms/interceptor.rb
Instance Method Summary collapse
Instance Method Details
#api_configured? ⇒ Boolean
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/arolitec_sms/interceptor.rb', line 6 def api_configured? api_base_url = ArolitecSms.configuration.api_base_url send_sms_endpoint = ArolitecSms.configuration.send_sms_endpoint api_user_name = ArolitecSms.configuration.api_user_name api_user_password = ArolitecSms.configuration.api_user_password if api_base_url.present? && send_sms_endpoint.present? && api_user_name.present? && api_user_password.present? return true else return false end end |
#post(endpoint, message) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/arolitec_sms/interceptor.rb', line 22 def post(endpoint, ) if api_configured? # Inialize a new connection. conn = Faraday.new(ArolitecSms.configuration.api_base_url) payload = "?user=#{ArolitecSms.configuration.api_user_name}&password=#{ArolitecSms.configuration.api_user_password}&sender=#{[:sender]}&receiv er=#{[:receiver]}&content=#{[:content]}" response = conn.post do |req| req.url endpoint + payload #req.headers['Content-Type'] = 'application/json' #req.headers['Authorization'] = 'Bearer ' + ArolitecSms.configuration.access_token #req.body = payload.to_json end if response.status == 200 puts "LA REPONSE DE LA REQUETTE EST: #{response.body}" return response elsif response.status == 401 puts "LA REPONSE DE LA REQUETTE EST: #{response.body}" end else render text: "Invalid API Base!" end end |