-
Notifications
You must be signed in to change notification settings - Fork 24
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
Add factory methods for DocumentClient, ResponseParser and DocumentParser #79
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a wat to do this. Another option might be a DefaultClientFactory
or something that just creates the classes with sane defaults. I mean, why wouldn't you want an different MetaParser to parse Meta information supplied by a specific JSON:API server? By seperating the factory from the classes you perhaps keep options open a little more.
If you go this route you should also change DocumentParserTest::getDocumentParser
to use this?
A lot of popular packages, such as Guzzle, have a static method (instead of a factory class) to create an instance with sensible defaults, so that's why I went that route. I can also add such a factory method to the Although the internal parsers don't have an interface, it is possible to use your own MetaParser by using the constructors. The methods introduced here are for convenience and I do not consider that as sensible defaults so I wouldn't include that in this PR. Updating |
@bbrala I also added a factory method to |
Looking good, but perhaps add a small section to the readme? It should be getting-started, but perhaps a little chapter somewhere is a good idea. If that is covered, it will be approved :) |
@bbrala fair point! I've updated the getting started section in the readme. |
Description
I've added factory methods to
DocumentClient
,ResponseParser
andDocumentParser
. All other parsers are internal and should not be used by consumers, so I didn't add a factory method to those.Motivation and context
As seen in #74 (comment) setting up the
DocumentClient
orResponseParser
without a container is quit cumbersome and the user doesn't have to be bothered with internal implementation details. With these factory methods that example can be reduced to this:How has this been tested?
Added unit tests and example above.
Types of changes
What types of changes does your code introduce? Put an
x
in all the boxes that apply:Checklist:
Go over all the following points, and put an
x
in all the boxes that apply.