-
Notifications
You must be signed in to change notification settings - Fork 2
/
email.go
37 lines (32 loc) · 1.01 KB
/
email.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package golinkedin
import (
"encoding/json"
"net/http"
)
// EndpointEmailAddress is the endpoint for email address api.
const EndpointEmailAddress = "https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))"
// EmailAddress is the response from email address api.
type EmailAddress struct {
ErrorResponse
Elements []struct {
Handle string `json:"handle"`
HandleTilde struct {
EmailAddress string `json:"emailAddress"`
} `json:"handle~"`
} `json:"elements"`
}
// EmailAddressRequest calls emailAddress api.
// Please note that email address is only available with the scope r_emailaddress.
func (c *client) EmailAddressRequest() (resp *http.Response, err error) {
return c.Get(EndpointEmailAddress)
}
// Same as EmailAddressRequest but parses the response.
func (c *client) GetEmailAddress() (r EmailAddress, err error) {
resp, err := c.EmailAddressRequest()
if err != nil {
return r, err
}
defer resp.Body.Close()
err = json.NewDecoder(resp.Body).Decode(&r)
return r, err
}