Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
nma http gateway
# -*- coding: utf-8 -*-
require 'oauth'
require 'json'
require 'sinatra/base'
require 'net/http'
class NmaGw < Sinatra::Base
set :logging, true
API_KEY = ''
API_URL = 'https://www.notifymyandroid.com/publicapi/notify'
get '/notify/:ip' do
u = URI::parse( API_URL )
h = Net::HTTP.new( u.host, u.port )
h.use_ssl = true
data = {
'apikey' => API_KEY,
'application' => 'PQI Air card',
'event' => "update IP",
'description' => params[:ip],
'priority' => 0,
}
r = Net::HTTP::Post.new( u.request_uri )
r.content_type = "application/x-www-form-urlencoded"
q = data.map do |key, val| "#{key}=#{val.to_s}" end
res = h.request( r, q.join( '&' ) )
return res.code
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment