-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CON-1037] fix(Outreach): ReadResult.Raw
- Loading branch information
Showing
7 changed files
with
293 additions
and
2,085 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,14 @@ | ||
package outreach | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/amp-labs/connectors/internal/jsonquery" | ||
"github.com/spyzhov/ajson" | ||
) | ||
|
||
// getNextRecords returns the "next" url for the next page of results, | ||
// If available, else returns an empty string. | ||
func getNextRecordsURL(node *ajson.Node) (string, error) { | ||
nextPageURL, err := jsonquery.New(node, "links").StringOptional("next") | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
if nextPageURL == nil { | ||
return "", nil | ||
} | ||
|
||
return *nextPageURL, nil | ||
func getRecords(node *ajson.Node) ([]*ajson.Node, error) { | ||
return jsonquery.New(node).ArrayOptional(dataKey) | ||
} | ||
|
||
// getRecords returns the records from the response. | ||
func getRecords(node *ajson.Node) ([]map[string]any, error) { | ||
var d Data | ||
|
||
b := node.Source() | ||
if err := json.Unmarshal(b, &d); err != nil { | ||
return nil, err | ||
} | ||
|
||
records := constructRecords(d) | ||
|
||
return records, nil | ||
} | ||
|
||
func constructRecords(d Data) []map[string]any { | ||
records := make([]map[string]any, len(d.Data)) | ||
|
||
for idx, record := range d.Data { | ||
recordItems := make(map[string]any) | ||
recordItems[idKey] = record.ID | ||
|
||
// Attributes are flattened into the recordItems map. | ||
for k, v := range record.Attributes { | ||
recordItems[k] = v | ||
} | ||
|
||
recordItems[relationshipsKey] = record.Relationships | ||
|
||
records[idx] = recordItems | ||
} | ||
|
||
return records | ||
func getNextRecordsURL(node *ajson.Node) (string, error) { | ||
return jsonquery.New(node, "links").StrWithDefault("next", "") | ||
} |
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 |
---|---|---|
|
@@ -71,7 +71,7 @@ func TestRead(t *testing.T) { // nolint:funlen,gocognit,cyclop | |
Name: "Successfully Read Mailings", | ||
Input: common.ReadParams{ | ||
ObjectName: "mailings", | ||
Fields: connectors.Fields("bodyHtml", "errorReason", "id"), | ||
Fields: connectors.Fields("bodyHtml", "errorReason", "id", "type"), | ||
}, | ||
Server: mockserver.Fixed{ | ||
Setup: mockserver.ContentJSON(), | ||
|
@@ -82,31 +82,36 @@ func TestRead(t *testing.T) { // nolint:funlen,gocognit,cyclop | |
Rows: 1, | ||
Data: []common.ReadResultRow{{ | ||
Fields: map[string]any{ | ||
// Some values come from the nested "attributes". | ||
"bodyhtml": "\u003chtml\u003e\u003cbody\u003e\u003cp\u003eHere Goes your HTML email\u003c/p\u003e\u003c/body\u003e\u003e\u003c/html\u003e", //nolint:lll | ||
"errorreason": nil, | ||
"id": 1, | ||
"id": float64(1), | ||
"type": "mailing", | ||
}, | ||
Raw: map[string]any{ | ||
"bodyHtml": "\u003chtml\u003e\u003cbody\u003e\u003cp\u003eHere Goes your HTML email\u003c/p\u003e\u003c/body\u003e\u003e\u003c/html\u003e", //nolint:lll | ||
"bodyText": "Here Goes your HTML email\u003e", | ||
"clickCount": float64(0), | ||
"errorreason": nil, | ||
"createdAt": "2024-07-26T06:27:17.000Z", | ||
"followUpTaskType": "string", | ||
"mailboxAddress": "[email protected]", | ||
"mailingType": "sequence", | ||
"id": 1, | ||
"openCount": float64(0), | ||
"overrideSafetySettings": false, | ||
"references": []any{}, | ||
"retryCount": float64(0), | ||
"scheduledAt": "2019-08-24T14:15:22.000Z", | ||
"state": "drafted", | ||
"stateChangedAt": "2024-07-26T06:27:17.000Z", | ||
"subject": "My Email Subject", | ||
"trackLinks": true, | ||
"trackOpens": true, | ||
"updatedAt": "2024-08-02T22:28:21.000Z", | ||
"id": float64(1), | ||
"type": "mailing", | ||
"attributes": map[string]any{ | ||
"bodyHtml": "\u003chtml\u003e\u003cbody\u003e\u003cp\u003eHere Goes your HTML email\u003c/p\u003e\u003c/body\u003e\u003e\u003c/html\u003e", //nolint:lll | ||
"bodyText": "Here Goes your HTML email\u003e", | ||
"clickCount": float64(0), | ||
"errorreason": nil, | ||
"createdAt": "2024-07-26T06:27:17.000Z", | ||
"followUpTaskType": "string", | ||
"mailboxAddress": "[email protected]", | ||
"mailingType": "sequence", | ||
"openCount": float64(0), | ||
"overrideSafetySettings": false, | ||
"references": []any{}, | ||
"retryCount": float64(0), | ||
"scheduledAt": "2019-08-24T14:15:22.000Z", | ||
"state": "drafted", | ||
"stateChangedAt": "2024-07-26T06:27:17.000Z", | ||
"subject": "My Email Subject", | ||
"trackLinks": true, | ||
"trackOpens": true, | ||
"updatedAt": "2024-08-02T22:28:21.000Z", | ||
}, | ||
}, | ||
}}, | ||
NextPage: "", | ||
|
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,143 @@ | ||
{ | ||
"rows": 1, | ||
"data": [ | ||
{ | ||
"fields": { | ||
"bodyhtml": "\u003chtml\u003e\u003cbody\u003e\u003cp\u003eHere Goes your HTML email\u003c/p\u003e\u003c/body\u003e\u003e\u003c/html\u003e", | ||
"errorreason": null, | ||
"id": 33 | ||
}, | ||
"raw": { | ||
"attributes": { | ||
"attributableSequenceId": null, | ||
"attributableSequenceName": null, | ||
"bodyHtml": "\u003chtml\u003e\u003cbody\u003e\u003cp\u003eHere Goes your HTML email\u003c/p\u003e\u003c/body\u003e\u003e\u003c/html\u003e", | ||
"bodyText": "Here Goes your HTML email\u003e", | ||
"bouncedAt": null, | ||
"clickCount": 0, | ||
"clickedAt": null, | ||
"createdAt": "2025-01-13T11:36:42.000Z", | ||
"deliveredAt": null, | ||
"desiredAt": null, | ||
"errorBacktrace": null, | ||
"errorReason": null, | ||
"followUpSequenceId": null, | ||
"followUpSequenceName": null, | ||
"followUpSequenceStartingDate": null, | ||
"followUpTaskScheduledAt": null, | ||
"followUpTaskType": null, | ||
"mailboxAddress": "[email protected]", | ||
"mailingType": "sequence", | ||
"markedAsSpamAt": null, | ||
"meetingDescription": null, | ||
"meetingDuration": null, | ||
"meetingLocation": null, | ||
"meetingTitle": null, | ||
"messageId": null, | ||
"notifyThreadCondition": null, | ||
"notifyThreadScheduledAt": null, | ||
"notifyThreadStatus": null, | ||
"openCount": 0, | ||
"openedAt": null, | ||
"optimizedScheduledAt": null, | ||
"overrideSafetySettings": false, | ||
"references": [], | ||
"repliedAt": null, | ||
"replySentiment": null, | ||
"retryAt": null, | ||
"retryCount": 0, | ||
"retryInterval": null, | ||
"scheduleId": null, | ||
"scheduledAt": null, | ||
"state": "drafted", | ||
"stateChangedAt": "2025-01-13T11:36:42.000Z", | ||
"subject": "string", | ||
"trackLinks": null, | ||
"trackOpens": null, | ||
"unsubscribedAt": null, | ||
"updatedAt": "2025-01-13T11:36:42.000Z" | ||
}, | ||
"id": 33, | ||
"links": { | ||
"self": "https://api.outreach.io/api/v2/mailings/33" | ||
}, | ||
"relationships": { | ||
"attachments": { | ||
"data": [], | ||
"links": { | ||
"related": "https://api.outreach.io/api/v2/attachments?filter%5Bmailing%5D%5Bid%5D=33" | ||
}, | ||
"meta": { | ||
"count": 0 | ||
} | ||
}, | ||
"calendar": { | ||
"data": null | ||
}, | ||
"followUpSequence": { | ||
"data": null | ||
}, | ||
"mailbox": { | ||
"data": { | ||
"id": 1, | ||
"type": "mailbox" | ||
} | ||
}, | ||
"opportunity": { | ||
"data": null | ||
}, | ||
"prospect": { | ||
"data": { | ||
"id": 1, | ||
"type": "prospect" | ||
} | ||
}, | ||
"recipients": { | ||
"data": [], | ||
"links": { | ||
"related": "https://api.outreach.io/api/v2/recipients?filter%5Bmailing%5D%5Bid%5D=33" | ||
}, | ||
"meta": { | ||
"count": 0 | ||
} | ||
}, | ||
"schedule": { | ||
"data": null | ||
}, | ||
"sequence": { | ||
"data": null | ||
}, | ||
"sequenceState": { | ||
"data": null | ||
}, | ||
"sequenceStep": { | ||
"data": null | ||
}, | ||
"task": { | ||
"data": null | ||
}, | ||
"tasks": { | ||
"data": [], | ||
"links": { | ||
"related": "https://api.outreach.io/api/v2/tasks?filter%5Bmailing%5D%5Bid%5D=33" | ||
}, | ||
"meta": { | ||
"count": 0 | ||
} | ||
}, | ||
"template": { | ||
"data": null | ||
}, | ||
"user": { | ||
"data": { | ||
"id": 1, | ||
"type": "user" | ||
} | ||
} | ||
}, | ||
"type": "mailing" | ||
} | ||
} | ||
], | ||
"done": true | ||
} |
Oops, something went wrong.