Skip to content

Added a httpbin & requestbin testing pages and modules #299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Create RequestbinSheet.cls
  • Loading branch information
powdermnky007 authored Jun 21, 2017
commit 979be1d7903a8a9a668d376705f20dccb4d86a2e
59 changes: 59 additions & 0 deletions examples/requestbin/RequestbinSheet.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
Option Explicit

Private Const RequestbinResultsFirstRow As Integer = 2 'Row 2
Private Const RequestbinResultsCol As Integer = 2 'Column B
Private Const RequestbinResultsCount As Integer = 1

Public Sub SearchRequestbin()
Dim Response As WebResponse
Dim Tempurl As String, Post_data As String 'declared variables for readability
Tempurl = Range("E5")
Post_data = Range("B1")

ClearResults 'calls ClearResults()
WebHelpers.EnableLogging = True 'extended debug info

If IsEmpty(Tempurl) = True Then 'user must enter their personal requestbin url
MsgBox ("Please enter your request bin url")
Exit Sub
End If

If IsEmpty(Post_data) = False Then 'don't submit a blank post data
Set Response = RequestbinLookup(Tempurl, Post_data) 'this line goes out and does everything
Else 'when the program comes back to here it is already finished running
MsgBox ("Input is empty")
Exit Sub
End If

ProcessResults Response 'calls ProcessResults() below with Response, the webresponse we received
End Sub

Public Sub ProcessResults(Results As WebResponse)
If Results.StatusCode < 400 Then
OutputResults Results 'calls OutputResults()
Else
OutputError Results.StatusCode, Results.Content 'calls OutputError()
End If
End Sub

Private Sub OutputResults(Results As WebResponse)
'requestbin just lets you post data, it only returns a server response 'ok'
Me.Cells(RequestbinResultsFirstRow, RequestbinResultsCol) = Results.Content
End Sub

Private Sub OutputError(Code As Integer, Message As String)
Me.Cells(RequestbinResultsFirstRow, RequestbinResultsCol) = "Error " & Code & ": " & Message
End Sub

Private Sub ClearResults()
Dim PrevUpdating As Boolean
PrevUpdating = Application.ScreenUpdating
Application.ScreenUpdating = False

Dim LastRow As Integer
LastRow = RequestbinResultsFirstRow + RequestbinResultsCount - 1
'Me.Rows(RequestbinResultsFirstRow & ":" & LastRow).ClearContents 'clear entire row
Me.Range(Me.Cells(RequestbinResultsFirstRow, RequestbinResultsCol), Me.Cells(LastRow, RequestbinResultsCol)).ClearContents 'clear selected part of column

Application.ScreenUpdating = PrevUpdating
End Sub