Skip to content

Instantly share code, notes, and snippets.

@takuo
Created December 29, 2012 13:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takuo/4407052 to your computer and use it in GitHub Desktop.
Save takuo/4407052 to your computer and use it in GitHub Desktop.
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