Skip to content

Commit

Permalink
Merge pull request #5 from fullcontact/permission-api
Browse files Browse the repository at this point in the history
Add Permission API
  • Loading branch information
vyasswaroop authored Apr 13, 2021
2 parents 8c07b71 + dc12ea0 commit cb796f8
Show file tree
Hide file tree
Showing 14 changed files with 2,014 additions and 25 deletions.
165 changes: 165 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ your integration.
- `identity.resolve`
- `identity.delete`

- _[Permission](https://platform.fullcontact.com/docs/apis/permission/introduction)_
- `permission.create`
- `permission.delete`
- `permission.find`
- `permission.current`
- `permission.verify`

## Providing Authentication to FullContact Client
FullContact client uses ```CredentialsProvider``` interface for Authentication. Different ways
to provide authentication:
Expand Down Expand Up @@ -165,6 +172,7 @@ such as:
- `PersonId`: _string_
- `LiNonId`: _string_
- `PartnerId`: _string_
- `Placekey`: _string_


```go
Expand Down Expand Up @@ -300,6 +308,7 @@ such as:
- `PersonId`: _string_
- `LiNonId`: _string_
- `PartnerId`: _string_
- `Placekey`: _string_

```go
resolveRequest, err := fc.NewResolveRequest(
Expand Down Expand Up @@ -441,3 +450,159 @@ if resp.IsSuccessful {
}
```

## Permission
[Permission API Reference](https://platform.fullcontact.com/docs/apis/permission/introduction)
- `permission.create`
- `permission.delete`
- `permission.find`
- `permission.current`
- `permission.verify`

#### Permission Request
Permission uses the following type of parameters for it's requests

`PermissionRequest` for
- `permission.create`
- `permission.verify`

and `MultifieldRequest` for
- `permission.delete`
- `permission.find`
- `permission.current`

You can build a Permission Request by using `NewPermissionRequest`
and setting different input parameters that you have.

All Permission Api requires `MultifieldRequest` requests, which can be constructed by using `NewMultifieldRequest` and following are it's parameters.

- `Emails`: _[]string_
- `Phones`: _[]string_
- `Location`: _*Location_
- `AddressLine1`: _string_
- `AddressLine2`: _string_
- `City`: _string_
- `Region`: _string_
- `RegionCode`: _string_
- `PostalCode`: _string_
- `Name`: _*PersonName_
- `Full`: _string_
- `Given`: _string_
- `Family`: _string_
- `Profiles`: _[]*Profile_
- `Service`: _string_
- `Username`: _string_
- `Userid`: _string_
- `Url`: _string_
- `Maids`: _[]string_
- `RecordId`: _string_
- `PersonId`: _string_
- `LiNonId`: _string_
- `PartnerId`: _string_
- `Placekey`: _string_

```go
multifieldRequest, err := fc.NewMultifieldRequest(
fc.WithEmailForMultifieldRequest("bart@fullcontact.com"))
permissionRequest, err := fc.NewPermissionRequest(
fc.WithMultifieldRequestForPermission(multifieldRequest))
```

### Permission Request
All permission methods returns a `channel` of type `APIResponse` from which you can get corresponding response classes.

The following are the corresponding response classes
- `PermissionCreatedResponse` - permission.create
- `PermissionDeleteResponse` - permission.delete
- `PermissionVerifyResponse` - permission.verify
- `PermissionFindResponse` - permission.find
- `PermissionCurrentResponse` - permission.current

`PermissionCreate` and `PermissionVerify` requires a `ResolveRequest` as parameter while the rest requires `MultifieldRequest` as parameter

### Permission Create

#### Parameters:
Supported fields in query:
- `query`: MultifieldRequest - [required]
- `consentPurposes`: List[ConsentPurposes] - [required]
- `locale`: string
- `ipAddress`: string
- `language`: string
- `collectionMethod`: string - [required]
- `collectionLocation`: string - [required]
- `policyUrl`: string - [required]
- `termsService`: string - [required]
- `tcf`: string
- `timestamp`: int

#### Returns:
class: `PermissionCreateResponse`. A basic API response with response code as 202 if successful.

### Permission Verify
#### Parameters:
Supported fields in query:
- `query`: MultifieldRequest - [required]
- `purposeId`: int - [required]
- `channel`: string - [required]

#### Returns:
class: `PermissionVerifyResponse` with following fields.

- `ttl`: string
- `enabled`: bool
- `channel`: string
- `purposeId`: int
- `purposeName`: string
- `timestamp`: int

### Permission Delete
#### Parameters:
Query takes a `MultiFieldReq`

#### Returns:
class: `PermissionDeleteResponse`. A basic API response with response code as 202 if successful.

### Permission Find
#### Parameters:
Query takes a `MultiFieldReq`

#### Returns:
class: `PermissionFindResponse` with list of Permissions.

### Permission Current
#### Parameters:
Query takes a `MultiFieldReq`

#### Returns:
class: `PermissionCurrentResponse` with set of current permissions

```go
resp := <-fcClient.PermissionCreate(permissionRequest)
fmt.Printf("Permission Create API Response: %v", resp)
if resp.IsSuccessful {
fmt.Println("Permission Created Successfully!")
}
resp = <-fcClient.PermissionVerify(permissionRequest)
fmt.Printf("Permission Verify API Response: %v", resp)
if resp.IsSuccessful {
fmt.Printf("Permissions List: %v", resp.PermissionVerifyResponse)
}

resp = <-fcClient.PermissionDelete(multifieldRequest)
fmt.Printf("Permission Delete API Response: %v", resp)
if resp.IsSuccessful {
fmt.Println("Permission Deleted Successfully!")
}

resp = <-fcClient.PermissionFind(multifieldRequest)
fmt.Printf("Permission Find API Response: %v", resp)
if resp.IsSuccessful {
fmt.Printf("Permission Find: %v", resp.PermissionFindResponse)
}

resp = <-fcClient.PermissionCurrent(multifieldRequest)
fmt.Printf("Permission Current API Response: %v", resp)
if resp.IsSuccessful {
fmt.Printf("Permission Current: %v", resp.PermissionCurrentResponse)
}
```
67 changes: 67 additions & 0 deletions example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,71 @@ func main() {
if resp.IsSuccessful {
fmt.Println(resp.EmailVerificationResponse)
}

//Permission
//Permission Create

multifieldRequest, err := fc.NewMultifieldRequest(
fc.WithEmailForMultifieldRequest("bart@fullcontact.com"))

consentPurpose := fc.NewConsentPurpose(
fc.WithConsentPurposeId(1),
fc.WithConsentPurposeChannel("web"),
fc.WithConsentPurposeTtl(365),
fc.WithConsentPurposeEnabled(true))

permissionCreateRequest, err := fc.NewPermissionRequest(
fc.WithMultifieldRequestForPermission(multifieldRequest),
fc.WithConsentPurposeForPermission(consentPurpose),
fc.WithCollectionMethodForPermission("cookiePopUp"),
fc.WithCollectionLocationForPermission("https://kenblahblah.com"),
fc.WithPolicyUrlForPermission("http://foo.baz"),
fc.WithTermsServiceForPermission("http://foo.tos"))
if err != nil {
log.Fatalln(err)
return
}

//Sending Permission Create request
resp = <- fcClient.PermissionCreate(permissionCreateRequest)
fmt.Printf("Permission Create API Response: %v", resp)
if resp.IsSuccessful == true {
fmt.Printf("Permission Create Response: %v", resp)
}

//Permission Find
//Sending Permission Find request which returns a channel of type `APIResponse`
resp = <- fcClient.PermissionFind(multifieldRequest)
fmt.Printf("Permission Find API Response: %v", resp)
if resp.IsSuccessful == true {
fmt.Printf("Permission Find Response: %v", resp.PermissionFindResponse)
}

//Permission Current
//Sending Permission Current request which returns a channel of type `APIResponse`
resp = <- fcClient.PermissionCurrent(multifieldRequest)
fmt.Printf("Permission Current API Response: %v", resp)
if resp.IsSuccessful == true {
fmt.Printf("Permission Current Response: %v", resp.PermissionCurrentResponse)
}

//Permission Verify
permissionVerifyRequest, err := fc.NewPermissionRequest(
fc.WithMultifieldRequestForPermission(multifieldRequest),
fc.WithPurposeIdForPermission(1),
fc.WithChannelForPermission("web"))

//Sending Permission Verify request which returns a channel of type `APIResponse`
resp = <- fcClient.PermissionVerify(permissionVerifyRequest)
fmt.Printf("Permission Verify API Response: %v", resp)
if resp.IsSuccessful == true {
fmt.Printf("Permission Verify Response: %v", resp.PermissionVerifyResponse)
}

//Permission Delete
//Sending Permission Delete request
resp = <- fcClient.PermissionDelete(multifieldRequest)
if resp.IsSuccessful == true {
fmt.Printf("Permission Delete API Response: %v", resp)
}
}
32 changes: 18 additions & 14 deletions fc/api_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,30 @@ import (
)

type APIResponse struct {
RawHttpResponse *http.Response
PersonResponse *PersonResp
CompanyResponse *CompanyResponse
CompanySearchResponse []*CompanySearchResponse
ResolveResponse *ResolveResponse
ResolveResponseWithTags *ResolveResponseWithTags
EmailVerificationResponse *EmailVerificationResponse
TagsResponse *TagsResponse
AudienceResponse *AudienceResponse
StatusCode int
Status string
IsSuccessful bool
Err error
RawHttpResponse *http.Response
PersonResponse *PersonResp
CompanyResponse *CompanyResponse
CompanySearchResponse []*CompanySearchResponse
ResolveResponse *ResolveResponse
ResolveResponseWithTags *ResolveResponseWithTags
EmailVerificationResponse *EmailVerificationResponse
TagsResponse *TagsResponse
AudienceResponse *AudienceResponse
PermissionFindResponse []*PermissionFindResponse
PermissionCurrentResponse map[string]map[string]ConsentPurposeResponse
PermissionVerifyResponse *ConsentPurposeResponse
StatusCode int
Status string
IsSuccessful bool
Err error
}

func (resp *APIResponse) String() string {
return fmt.Sprintf("\nRawHttpResponse: %v,\nPersonResponse: %v,\nCompanyResponse: %v,\nCompanySearchResponse: %v,"+
"\nResolveResponse: %v,\nResolveResponseWithTags: %v,\nTagsResponse: %v,\nAudienceResponse: %v,\nEmailVerificationResponse: %v,"+
"\nStatusCode: %v,\nStatus: %v,\nIsSuccessful: %v,\nErr: %v\n",
"\nPermissionFindResponse: %v,\nPermissionCurrentResponse: %v,\nPermissionVerifyResponse: %v,\nStatusCode: %v,\nStatus: %v,\nIsSuccessful: %v,\nErr: %v\n",
resp.RawHttpResponse, resp.PersonResponse, resp.CompanyResponse, resp.CompanySearchResponse, resp.ResolveResponse,
resp.ResolveResponseWithTags, resp.TagsResponse, resp.AudienceResponse, resp.EmailVerificationResponse,
resp.PermissionFindResponse, resp.PermissionCurrentResponse, resp.PermissionVerifyResponse,
resp.StatusCode, resp.Status, resp.IsSuccessful, resp.Err)
}
7 changes: 6 additions & 1 deletion fc/constants.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package fullcontact

const (
version = "1.1.1"
version = "1.2.0"
userAgent = "FullContact_Go_Client_V" + version
FcApiKey = "FC_API_KEY"
FCGoClientTestType = "FCGoClientTestType"
Expand All @@ -20,4 +20,9 @@ const (
audienceCreateUrl = baseUrl + "audience.create"
audienceDownloadUrl = baseUrl + "audience.download"
emailVerificationUrl = v2BaseUrl + "verification/email"
permissionCreateUrl = baseUrl + "permission.create"
permissionDeleteUrl = baseUrl + "permission.delete"
permissionFindUrl = baseUrl + "permission.find"
permissionCurrentUrl = baseUrl + "permission.current"
permissionVerifyUrl = baseUrl + "permission.verify"
)
Loading

0 comments on commit cb796f8

Please sign in to comment.