예제 #1
0
func (r *RRActionMap) Put(rrActionObject *RRActionObject) error {

	method := rrActionObject.Request.Method
	url := rrActionObject.Request.Url

	_, found0 := r.store[url]

	if !found0 {
		r.store[url] = make(map[string][]*RRActionObject)
	}

	rrActionObjects, found := r.store[url][method]

	if !found {
		r.store[url][method] = append(r.store[url][method], rrActionObject)
	} else {

		for _, rrActionObjectItem := range rrActionObjects {

			jsonBody1 := "{}"
			jsonBody2 := "{}"

			if len(rrActionObjectItem.Request.Body) > 0 {
				jsonBody1 = rrActionObjectItem.Request.Body[0].EqualToJson
			}

			if len(rrActionObject.Request.Body) > 0 {
				jsonBody2 = rrActionObject.Request.Body[0].EqualToJson
			}

			equal, err := invdutil.JsonEqual(jsonBody1, jsonBody2)

			if err != nil {
				return err
			}

			if equal {
				return nil
			}

		}

		r.store[url][method] = append(r.store[url][method], rrActionObject)

	}

	return nil

}
예제 #2
0
func (r *RRActionMap) Get(method, url, body string) (*RRActionObject, bool, error) {

	if len(body) == 0 {
		body = "{}"
	}

	_, found0 := r.store[url]

	if !found0 {
		return nil, false, nil
	}

	rrActionObjects, found := r.store[url][method]

	if !found {
		return nil, false, nil
	}

	for _, rrActionObject := range rrActionObjects {
		jsonBody1 := "{}"
		if len(rrActionObject.Request.Body) > 0 {
			jsonBody1 = rrActionObject.Request.Body[0].EqualToJson
		}

		jsonBody2 := body

		equal, err := invdutil.JsonEqual(jsonBody1, jsonBody2)

		if err != nil {
			return nil, false, err
		}

		if equal {
			return rrActionObject, true, nil
		}

	}

	return nil, false, nil

}
예제 #3
0
func TestUnMarshalEventObject(t *testing.T) {
	s := `{
    "id": 1228003,
    "type": "transaction.created",
    "data": {
        "object": {
            "amount": 55,
            "created_at": 1451500772,
            "currency": "usd",
            "customer": 15455,
            "date": 1451500771,
            "fee": 0,
            "gateway": null,
            "gateway_id": null,
            "id": 212047,
            "invoice": 196539,
            "metadata": [],
            "method": "other",
            "notes": null,
            "parent_transaction": null,
            "status": "succeeded",
            "theme": null,
            "type": "payment",
            "pdf_url": "https:\/\/dundermifflin.invoiced.com\/payments\/59FHO96idoXFeiBDu1y5Zggg\/pdf",
            "metadata": {}
        }
    }
}`

	so := new(Event)

	err := json.Unmarshal([]byte(s), so)

	if err != nil {
		t.Fatal(err)
	}

	if so.Id != 1228003 {
		t.Fatal("Event id is incorrect")
	}

	if so.Type != "transaction.created" {
		t.Fatal("Event type is incorrect")
	}

	object := `{
	       "object": {
	           "amount": 55,
	           "created_at": 1451500772,
	           "currency": "usd",
	           "customer": 15455,
	           "date": 1451500771,
	           "fee": 0,
	           "gateway": null,
	           "gateway_id": null,
	           "id": 212047,
	           "invoice": 196539,
	           "metadata": [],
	           "method": "other",
	           "notes": null,
	           "parent_transaction": null,
	           "status": "succeeded",
	           "theme": null,
	           "type": "payment",
	           "pdf_url": "https:\/\/dundermifflin.invoiced.com\/payments\/59FHO96idoXFeiBDu1y5Zggg\/pdf",
	           "metadata": {}
	       }
	   }`

	equal, err := invdutil.JsonEqual(object, string(so.Data))

	if err != nil {
		t.Fatal(err)
	}

	if !equal {
		t.Fatal("Event object is incorrect")
	}

}