Skip to content
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

Read admin #86

Open
wants to merge 5 commits into
base: v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 10 additions & 4 deletions admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@ import (
"fmt"
)

// AdminAvatar represents an admin's avatar
type AdminAvatar struct {
ImageURL string `json:"image_url"`
}

// Admin represents an Admin in Intercom.
type Admin struct {
ID json.Number `json:"id"`
Type string `json:"type"`
Name string `json:"name"`
Email string `json:"email"`
ID json.Number `json:"id"`
Type string `json:"type"`
Name string `json:"name"`
Email string `json:"email"`
Avatar *AdminAvatar `json:"avatar"`
}

// AdminList represents an object holding list of Admins
Expand Down
10 changes: 10 additions & 0 deletions admin_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,13 @@ func (api AdminAPI) list() (AdminList, error) {
err = json.Unmarshal(data, &adminList)
return adminList, err
}

func (api AdminAPI) read(adminID string) (Admin, error) {
admin := Admin{}
data, err := api.httpClient.Get("/admins/"+adminID, nil)
if err != nil {
return admin, err
}
err = json.Unmarshal(data, &admin)
return admin, err
}
13 changes: 13 additions & 0 deletions admin_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ func TestAdminAPIList(t *testing.T) {
}
}

func TestAdminAPIRead(t *testing.T) {
http := TestAdminHTTPClient{fixtureFilename: "fixtures/admin.json", expectedURI: "/admins/123", t: t}
api := AdminAPI{httpClient: &http}
admin, err := api.read("123")
if err != nil {
t.Errorf("Error reading admin: %v", err)
}

if admin.Avatar.ImageURL != "https://intercom.io/testA.png" {
t.Errorf("Expected: https://intercom.io/testA.png, got %s", admin.Avatar.ImageURL)
}
}

type TestAdminHTTPClient struct {
TestHTTPClient
t *testing.T
Expand Down
10 changes: 10 additions & 0 deletions fixtures/admin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"type": "admin",
"type": "admin",
"email": "[email protected]",
"id": "123",
"name": "Admin A",
"avatar": {
"image_url": "https://intercom.io/testA.png"
}
}
30 changes: 15 additions & 15 deletions fixtures/admins.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"type": "admin.list",
"admins": [
{
"type": "admin",
"email": "[email protected]",
"id": "1",
"name": "Admin A"
},
{
"type": "admin",
"email": "[email protected]",
"id": "2",
"name": "Admin B"
}
]
"type": "admin.list",
"admins": [
{
"type": "admin",
"email": "[email protected]",
"id": "1",
"name": "Admin A"
},
{
"type": "admin",
"email": "[email protected]",
"id": "2",
"name": "Admin B"
}
]
}