Skip to content

Instantly share code, notes, and snippets.

@MikeSel
Created November 7, 2013 19:42
Show Gist options
  • Save MikeSel/7360681 to your computer and use it in GitHub Desktop.
Save MikeSel/7360681 to your computer and use it in GitHub Desktop.
'***************************************************************************************************************************************************************************************
'***************************************************************************************************************************************************************************************
'**********
'********** Easy Digital Download Licence Wrap Class
'********** by Mike Hudson - http://www.mikesel.info
'********** Version 1.0
'**********
'***************************************************************************************************************************************************************************************
'***************************************************************************************************************************************************************************************
Imports System.Net
Imports System.IO
Imports System.Linq
Imports Newtonsoft.Json
Imports Newtonsoft.Json.Linq
Public Class EDD_Licence
Dim request As HttpWebRequest
Dim response As HttpWebResponse = Nothing
Dim reader As StreamReader
Public Sub EDDLicense(strRequest As String, streddURL As String, strAppName As String, strLicenceKey As String)
Select Case strRequest
Case "CheckLicense"
request = DirectCast(WebRequest.Create(streddURL & strAppName & strLicenceKey), HttpWebRequest)
response = DirectCast(request.GetResponse(), HttpWebResponse)
reader = New StreamReader(response.GetResponseStream())
Dim rawresp As String
rawresp = reader.ReadToEnd()
Dim jResults As JObject = JObject.Parse(rawresp)
Dim results As List(Of JToken) = jResults.Children().ToList()
For Each item As JProperty In results
item.CreateReader()
Select Case item.Name
Case "license"
Dim strResult = item.Value.ToString
Select Case strResult
Case "expired"
MsgBox("Your license is either invalid or has expired")
Case "valid"
MsgBox("Your license is valid, thank you for your support")
Case "invalid"
MsgBox("The license code you have entered is not valid, please check and try again")
Case "inactive"
MsgBox("The license code you have entered is valid, but is not yet active")
Case "disabled"
MsgBox("The license code you have entered is valid, but has been disabled")
Case Else
MsgBox("Unable to handle " & strResult)
End Select
End Select
Next
Case "ActivateLicense"
request = DirectCast(WebRequest.Create(streddURL & strAppName & strLicenceKey), HttpWebRequest)
EDDLicense("CheckLicense", streddURL, strAppName, strLicenceKey)
End Select
End Sub
End Class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment