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

Remove File in favor of FileUpload #585

Merged
merged 1 commit into from
Jun 12, 2018
Merged
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
54 changes: 27 additions & 27 deletions dispute.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,33 +118,33 @@ type EvidenceDetails struct {
// Almost all fields are strings since there structures (i.e. address)
// do not typically get parsed by anyone and are thus presented as-received.
type DisputeEvidence struct {
AccessActivityLog string `json:"access_activity_log"`
BillingAddress string `json:"billing_address"`
CancellationPolicy *File `json:"cancellation_policy"`
CancellationPolicyDisclosure string `json:"cancellation_policy_disclosure"`
CancellationRebuttal string `json:"cancellation_rebuttal"`
CustomerCommunication *File `json:"customer_communication"`
CustomerEmailAddress string `json:"customer_email_address"`
CustomerName string `json:"customer_name"`
CustomerPurchaseIP string `json:"customer_purchase_ip"`
CustomerSignature *File `json:"customer_signature"`
DuplicateChargeDocumentation *File `json:"duplicate_charge_documentation"`
DuplicateChargeExplanation string `json:"duplicate_charge_explanation"`
DuplicateChargeID string `json:"duplicate_charge_id"`
ProductDescription string `json:"product_description"`
Receipt *File `json:"receipt"`
RefundPolicy *File `json:"refund_policy"`
RefundPolicyDisclosure string `json:"refund_policy_disclosure"`
RefundRefusalExplanation string `json:"refund_refusal_explanation"`
ServiceDate string `json:"service_date"`
ServiceDocumentation *File `json:"service_documentation"`
ShippingAddress string `json:"shipping_address"`
ShippingCarrier string `json:"shipping_carrier"`
ShippingDate string `json:"shipping_date"`
ShippingDocumentation *File `json:"shipping_documentation"`
ShippingTrackingNumber string `json:"shipping_tracking_number"`
UncategorizedFile *File `json:"uncategorized_file"`
UncategorizedText string `json:"uncategorized_text"`
AccessActivityLog string `json:"access_activity_log"`
BillingAddress string `json:"billing_address"`
CancellationPolicy *FileUpload `json:"cancellation_policy"`
CancellationPolicyDisclosure string `json:"cancellation_policy_disclosure"`
CancellationRebuttal string `json:"cancellation_rebuttal"`
CustomerCommunication *FileUpload `json:"customer_communication"`
CustomerEmailAddress string `json:"customer_email_address"`
CustomerName string `json:"customer_name"`
CustomerPurchaseIP string `json:"customer_purchase_ip"`
CustomerSignature *FileUpload `json:"customer_signature"`
DuplicateChargeDocumentation *FileUpload `json:"duplicate_charge_documentation"`
DuplicateChargeExplanation string `json:"duplicate_charge_explanation"`
DuplicateChargeID string `json:"duplicate_charge_id"`
ProductDescription string `json:"product_description"`
Receipt *FileUpload `json:"receipt"`
RefundPolicy *FileUpload `json:"refund_policy"`
RefundPolicyDisclosure string `json:"refund_policy_disclosure"`
RefundRefusalExplanation string `json:"refund_refusal_explanation"`
ServiceDate string `json:"service_date"`
ServiceDocumentation *FileUpload `json:"service_documentation"`
ShippingAddress string `json:"shipping_address"`
ShippingCarrier string `json:"shipping_carrier"`
ShippingDate string `json:"shipping_date"`
ShippingDocumentation *FileUpload `json:"shipping_documentation"`
ShippingTrackingNumber string `json:"shipping_tracking_number"`
UncategorizedFile *FileUpload `json:"uncategorized_file"`
UncategorizedText string `json:"uncategorized_text"`
}

// UnmarshalJSON handles deserialization of a Dispute.
Expand Down
32 changes: 0 additions & 32 deletions fileupload.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,6 @@ const (
FileUploadPurposeIdentityDocument FileUploadPurpose = "identity_document"
)

// File represents a link to downloadable content.
//
// This is an earlier incarnation of FileUpload, and they'll eventually be
// merged into the same struct.
type File struct {
Created int64 `json:"created"`
ID string `json:"id"`
MIMEType string `json:"mime_type"`
Purpose string `json:"purpose"`
Size int64 `json:"size"`
URL string `json:"url"`
}

// UnmarshalJSON handles deserialization of a File.
// This custom unmarshaling is needed because the resulting
// property may be an id or the full struct if it was expanded.
func (f *File) UnmarshalJSON(data []byte) error {
if id, ok := ParseID(data); ok {
f.ID = id
return nil
}

type file File
var v file
if err := json.Unmarshal(data, &v); err != nil {
return err
}

*f = File(v)
return nil
}

// FileUploadParams is the set of parameters that can be used when creating a
// file upload.
// For more details see https://stripe.com/docs/api#create_file_upload.
Expand Down
21 changes: 0 additions & 21 deletions fileupload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,6 @@ import (
assert "github.com/stretchr/testify/require"
)

func TestFile_UnmarshalJSON(t *testing.T) {
// Unmarshals from a JSON string
{
var v File
err := json.Unmarshal([]byte(`"file_123"`), &v)
assert.NoError(t, err)
assert.Equal(t, "file_123", v.ID)
}

// Unmarshals from a JSON object
{
v := File{ID: "file_123"}
data, err := json.Marshal(&v)
assert.NoError(t, err)

err = json.Unmarshal(data, &v)
assert.NoError(t, err)
assert.Equal(t, "file_123", v.ID)
}
}

func TestFileUpload_UnmarshalJSON(t *testing.T) {
// Unmarshals from a JSON string
{
Expand Down