-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
145 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package authy | ||
|
||
import ( | ||
"encoding/json" | ||
"io/ioutil" | ||
"net/http" | ||
) | ||
|
||
// PhoneVerificationStart encapsulates the response from the Authy API when requesting a phone verification. | ||
type PhoneVerificationStart struct { | ||
HTTPResponse *http.Response | ||
UUID string `json:"uuid"` | ||
Message string `json:"message"` | ||
Success bool `json:"success"` | ||
Carrier string `json:"carrier"` | ||
} | ||
|
||
// NewPhoneVerificationStart receives a http request, parses the body and return an instance of PhoneVerification | ||
func NewPhoneVerificationStart(response *http.Response) (*PhoneVerificationStart, error) { | ||
phoneVerification := &PhoneVerificationStart{HTTPResponse: response} | ||
body, err := ioutil.ReadAll(response.Body) | ||
|
||
if err != nil { | ||
return phoneVerification, err | ||
} | ||
|
||
err = json.Unmarshal(body, &phoneVerification) | ||
if err != nil { | ||
return phoneVerification, err | ||
} | ||
|
||
return phoneVerification, nil | ||
} | ||
|
||
// PhoneVerificationCheck encapsulates the response from the Authy API when checking a phone verification. | ||
type PhoneVerificationCheck struct { | ||
HTTPResponse *http.Response | ||
Message string `json:"message"` | ||
Success bool `json:"success"` | ||
} | ||
|
||
// NewPhoneVerificationCheck receives a http request, parses the body and return an instance of PhoneVerification | ||
func NewPhoneVerificationCheck(response *http.Response) (*PhoneVerificationCheck, error) { | ||
phoneVerification := &PhoneVerificationCheck{HTTPResponse: response} | ||
body, err := ioutil.ReadAll(response.Body) | ||
|
||
if err != nil { | ||
return phoneVerification, err | ||
} | ||
|
||
err = json.Unmarshal(body, &phoneVerification) | ||
if err != nil { | ||
return phoneVerification, err | ||
} | ||
|
||
return phoneVerification, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package authy | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"net/url" | ||
"testing" | ||
) | ||
|
||
func Test_StartPhoneVerification(t *testing.T) { | ||
api := NewSandboxAuthyAPI("bf12974d70818a08199d17d5e2bae630") | ||
|
||
verification, err := api.StartPhoneVerification(1, "555-555-5555", SMS, url.Values{}) | ||
|
||
assert.Nil(t, err) | ||
assert.NotNil(t, verification) | ||
} | ||
|
||
func Test_CheckPhoneVerification(t *testing.T) { | ||
api := NewSandboxAuthyAPI("bf12974d70818a08199d17d5e2bae630") | ||
|
||
verification, err := api.CheckPhoneVerification(1, "555-555-5555", "000000", url.Values{}) | ||
|
||
assert.Nil(t, err) | ||
assert.NotNil(t, verification) | ||
} |