diff --git a/admin.go b/admin.go index 7b3e3ac..b32d6a0 100644 --- a/admin.go +++ b/admin.go @@ -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 diff --git a/admin_api.go b/admin_api.go index 2671348..1c12424 100644 --- a/admin_api.go +++ b/admin_api.go @@ -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 +} diff --git a/admin_api_test.go b/admin_api_test.go index 3a92f89..b445e60 100644 --- a/admin_api_test.go +++ b/admin_api_test.go @@ -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 diff --git a/fixtures/admin.json b/fixtures/admin.json new file mode 100644 index 0000000..d907ec7 --- /dev/null +++ b/fixtures/admin.json @@ -0,0 +1,10 @@ +{ + "type": "admin", + "type": "admin", + "email": "admin_a@example.io", + "id": "123", + "name": "Admin A", + "avatar": { + "image_url": "https://intercom.io/testA.png" + } +} diff --git a/fixtures/admins.json b/fixtures/admins.json index 5a719a5..8689b3a 100644 --- a/fixtures/admins.json +++ b/fixtures/admins.json @@ -1,17 +1,17 @@ { - "type": "admin.list", - "admins": [ - { - "type": "admin", - "email": "admin_a@example.io", - "id": "1", - "name": "Admin A" - }, - { - "type": "admin", - "email": "admin_b@example.io", - "id": "2", - "name": "Admin B" - } - ] + "type": "admin.list", + "admins": [ + { + "type": "admin", + "email": "admin_a@example.io", + "id": "1", + "name": "Admin A" + }, + { + "type": "admin", + "email": "admin_b@example.io", + "id": "2", + "name": "Admin B" + } + ] }