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

feat(address): add address client #1

Merged
merged 3 commits into from
Jun 5, 2018
Merged

feat(address): add address client #1

merged 3 commits into from
Jun 5, 2018

Conversation

jws
Copy link

@jws jws commented May 25, 2018

What:

  • Add initial directory structure, sln and csproj files for library and test.
  • Add client library functionality to create/delete/get/list addresses.
    • list with parameters deferred until later.

Details:

  • Usage:
            // create address
            var response = await LobClient.Address.CreateAsync(
                description: ADDRESS.Description,
                name: ADDRESS.Name,
                company: ADDRESS.Company,
                email: ADDRESS.Email,
                phone: ADDRESS.Phone,
                addressLine1: ADDRESS.AddressLine1,
                addressCity: ADDRESS.AddressCity,
                addressState: ADDRESS.AddressState,
                addressZip: ADDRESS.AddressZip,
                addressCountry: "US", // so odd we can't put UNITED STATES here
                metadata: ADDRESS.Metadata
            );

            // access results
            var httpStatusCode = response.HttpStatusCode;
            var address = response.Result;

            // get address
            await LobClient.Address.GetAsync(id: address.Id);

            // delete address
            await LobClient.Address.DeleteAsync(id: address.Id);

            // list addresses
            await LobClient.Address.ListAsync();
  • Overview:
    • LobClient is instantiated with the apiKey and is used to access the various API resources e.g. LobClient.Address.CreateAsync(...) or LobClient.Letter.CreateAsync(...) later
    • LobRestClient is a thin layer over HttpClient and does only the following:
      • Query parameter handling (future)
      • Lob header handling (future)
      • Lob's API response handling (deserialization, error handling)
    • Since LobRestClient has limited intelligence, it pushes content serialization and query parameter encoding to the resource client themselves (AddressClient, LetterClient, etc.). Not a big fan, but open to ideas.
        // LobRestClient.cs
        public async Task<LobResponse<TResult>> ExecuteAsync<TResult>(
            HttpMethod method,
            string requestUrl,
            HttpContent content = null,
            IDictionary<string, string> queryParams = null,
            LobRequestOptions requestOptions = null)
  • Notes:
    • This version of the library uses async / await, so we do not support clients without said capability.
    • Since request and response have varying fields (especially for other mail types), the design is to use separate objects. e.g.
public Task<LobResponse<AddressResource>> CreateAsync(CreateAddressRequest options)
  • We won't know if this client structure will work going forward until we get to the more complicated types. e.g. Letters. Address is too simplistic. I can see challenges here:
    • Request/Response fields with multiple possible types. Object is the common denominator, but still need to think if that should be exposed to the end user. Also this will be interesting when it comes to serialization and content types.
    • Nested objects (inline address, fancy list filtering, etc.)

* add exception unit test
Copy link

@virtualdom virtualdom left a comment

Choose a reason for hiding this comment

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

This is a great base to start with and we can iterate on it. Thanks for putting in the initial work, Jin! LGTM

@virtualdom virtualdom removed their assignment May 28, 2018
Copy link

@dckrooney dckrooney left a comment

Choose a reason for hiding this comment

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

LGTM, with some questions/nits


public Task<LobResponse<AddressResource>> GetAsync(string id)
{
Console.WriteLine($"getasync {id}");

Choose a reason for hiding this comment

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

Leftover from debugging?

{
public class AddressResource : DeletableResource
{
public string AddressLine1 { get; set; }

Choose a reason for hiding this comment

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

Do we need these prefixed with Address if they're already part of the AddressResource class?

Copy link
Author

Choose a reason for hiding this comment

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

since it is reflected with the prefix in the API schema, just keeping it 1-1. its also arguably clearer, since we bundle a number of non-address fields into our address object.

@jws jws merged commit 11a6e88 into master Jun 5, 2018
@jws jws deleted the jin/address_client branch June 5, 2018 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants