Source

beerfingers / bf / sms / views.py

Full commit
from urllib2 import urlopen, URLError, HTTPError
from django.http import HttpResponse, Http404
import textmarks_v2api_client
from bar.models import Inbox


"""
TextMarks Configuration
TextMark Response: Configured to Dynamic From website
CallBack URL: http://dev.beerfingers.com/sms/?user=\p&req=\0

1st Stage
	(High)
		mybeer love magic hat 100 ipa pine, bitter, lots of alcohol
	(low) 
		mybeer find 1554 (by beer name only)
2nd Stage	
	mybeer last 3
	mybeer fav	
"""

	
	#THIS WORKS
def InviteUser(request):
	# Invite a user to join a TextMark group:
	my_api_key = 'beerfingers_com_ec486999'
	keyword    = 'MYBEER'
	phone      = '6178770872'
	tmapi = textmarks_v2api_client.Client(api_key=my_api_key)
	tmapi.rpc_json('Anybody', 'invite_to_group', {
		'tm': keyword,
		'user': phone
		})

		
	#THIS WORKSSS
def ReceiveSMS(request):
	#MESSAGES COME FROM TEXTMARK TO BF
	#url /sms/?user=\p&req=\0
	try:
		user = request.GET.get('user')
		req = request.GET.get('req')
		slam = Inbox(source=user,message=req)
		slam.save()
	except:
		pass
	
	return HttpResponse(user)
	
	
	
		#THIS WORKS!
def SendSMS(request):
	
	#MESSAGES ARE SEND FROM BF to TEXTMARK
	my_api_key = 'beerfingers_com_ec486999'
	bf_authuser= '6178770872'
	bf_authpass= '6734'
	
	keyword    = 'MYBEER'
	to         = '6178770872' #DYNAMIC
	message    = 'Here is my message' #DYNAMIC
	tmapi = textmarks_v2api_client.Client(api_key=my_api_key)
	tmapi.rpc_json('GroupLeader', 'send_one_message', {
		'auth_user': bf_authuser,
		'auth_pass': bf_authpass,
		'tm': keyword,
		'msg': message,
		'to': phone
		})