Skip to content

Conversation

ZA1
Copy link
Contributor

@ZA1 ZA1 commented May 14, 2016

Apologies again for springing this on you. I know I should raise an issue first, but I was in a rush to get a project out. You know how it goes 😉

Here is the test harness I used. In order to test you need to create an inbound domain using my previous PR #68.

    static void Main(string[] args)
    {
        var apiKey = "<Api Key>";

        var client = new SparkPost.Client(apiKey);

        var relayWebhook = new RelayWebhook
        {
            Name = "Test",
            AuthToken = "34395f35-3c29-497f-8a5a-57a4db7d28fc",
            Target = "https://webhooks.customer.example/replies",
            Match = new RelayWebhookMatch { Domain = "test.example.com" }
        };

        var create = client.RelayWebhooks.Create(relayWebhook).Result;

        var list = client.RelayWebhooks.List().Result;
        Debug.Assert(list.RelayWebhooks.Count() == 1);
        Debug.Assert(list.RelayWebhooks.First().Name == relayWebhook.Name);
        Debug.Assert(list.RelayWebhooks.First().AuthToken == relayWebhook.AuthToken);
        Debug.Assert(list.RelayWebhooks.First().Target == relayWebhook.Target);
        Debug.Assert(list.RelayWebhooks.First().Match.Protocol == relayWebhook.Match.Protocol);
        Debug.Assert(list.RelayWebhooks.First().Match.Domain == relayWebhook.Match.Domain);

        relayWebhook.Id = list.RelayWebhooks.First().Id;
        relayWebhook.Name = "Updated Test";

        var update = client.RelayWebhooks.Update(relayWebhook).Result;

        var retrieve = client.RelayWebhooks.Retrieve(relayWebhook.Id).Result;
        Debug.Assert(retrieve.RelayWebhook.Name == relayWebhook.Name);
        Debug.Assert(retrieve.RelayWebhook.AuthToken == relayWebhook.AuthToken);
        Debug.Assert(retrieve.RelayWebhook.Target == relayWebhook.Target);
        Debug.Assert(retrieve.RelayWebhook.Match.Protocol == relayWebhook.Match.Protocol);
        Debug.Assert(retrieve.RelayWebhook.Match.Domain == relayWebhook.Match.Domain);

        var delete = client.RelayWebhooks.Delete(relayWebhook.Id).Result;
        Debug.Assert(delete);
    }

{
public RelayWebhook RelayWebhook { get; set; }

public static RetrieveRelayWebhookResponse CreateFromResponse(Response response)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be helpful to have an override for this method that takes a string? The only value from response that is used is response.Content. Taking in a string would be much more testable... you could feed in raw JSON content from SparkPost and verify the result.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forget I said anything... I have my head deep in another project, and I interpreted Response to be something different. I wrote this before 8 am, my brain is still warming up.

@darrencauthon
Copy link
Owner

Haha, are you apologizing for adding more features to the library?

Thank you very much for this... I'll get this reviewed and the other pull requests added asap. I'll not here when they are deployed to nuget.

@darrencauthon
Copy link
Owner

@ZA1 You said:

I know I should raise an issue first, but I was in a rush to get a project out

I totally disagree! 😄 I think dropping the pull request is better, without the issue.

Some OSS prefer the issue-first approach so they can tell the dev ahead-of-time if they won't accept the pull request. Presumably to avoid the dev "wasting their time." But in most cases, programming is not a waste of time -- especially to the programmer. Solving problems tends to always lead to reward, even if it's just new knowledge. 😄

@darrencauthon darrencauthon merged commit 878906d into darrencauthon:master May 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants