@@ -13,14 +13,21 @@ composer require herald-project/client-php
1313use Herald\Client\Client as HeraldClient;
1414use Herald\Client\Message as HeraldMessage;
1515
16- // get the client
16+ // get the client with explicit parameters
1717$herald = new HeraldClient(
1818 '[herald api username]',
1919 '[herald api password]',
2020 '[herald server uri]',
21- '[herald transport, e.g. smtp]')
21+ '[herald transport, e.g. smtp]'),
22+ '[herald account]',
23+ '[herald library]',
2224);
2325
26+ // get the client by DSN
27+
28+ $herald = HeraldClient::fromDsn('https://username:password@herald.dev/myAccount/myLibrary/myTransport');
29+
30+
2431// check template existance.
2532if ($herald->templateExists('signup')) {
2633 // get the message
@@ -37,43 +44,74 @@ if ($herald->templateExists('signup')) {
3744}
3845```
3946## CLI usage
40- ``` sh
41- #! /bin/sh
4247
43- common_param=" \
44- --username=api_username \
45- --password=api_password \
46- --apiurl=http://localhost:8787/api/v2 \
47- --account=test \
48- --library=test"
48+ You can use the ` bin/herald-client ` CLI application to run commands against your herald server.
49+
50+ The application needs a couple of configuration directives to work:
51+
52+ * username + password: The account you use to connect. Either a user account, or an API key+secret pair
53+ * apiurl: the base url of herald, (i.e. https://herald.dev ) with postfix ` /api/v2 `
54+ * account + library: This is the library identifier you use to create your templates, layouts and transports
55+
56+ You can pass this data in 3 ways:
57+
58+ ### Individual options:
59+
60+ For example:
61+
62+ ./bin/herald-client --username=x --password=y --apiurl=https://herald.dev/api/v2 --account=test --library=test template:exists welcome
63+
64+ ### A single DSN
65+
66+ For example:
67+
68+ ./bin/herald-client --dsn=https://x:y@herald.dev/test/test/mandrill
69+
70+ ### By environment variables
71+
72+ You can define the environment variable ` HERALD_DSN ` with a valid URL, this way you don't
73+ need to pass any options to the CLI application
74+
75+ ### By .env
76+
77+ The Herald CLI application loads ` .env ` before running any commands, allowing you to create a ` .env ` file
78+ like this:
79+
80+ ``` ini
81+ HERALD_DSN =https://x:y@herald.dev/test/test/mandrill
82+ ```
83+
84+ This way you also don't need to pass any options for each command
85+
86+ ### Example commands
4987
50- # get list of all contact lists
51- bin/herald-client list:list ${common_param}
88+ # get list of all contact lists
89+ bin/herald-client list:list
5290
53- # get list of contacts in contact list #1
54- bin/herald-client list:contacts ${common_param} --listId= 1
91+ # get list of contacts in contact list #1
92+ bin/herald-client list:contacts 1
5593
56- # get list of segments for list #1
57- bin/herald-client list:segments ${common_param} --listId= 1
94+ # get list of segments for list #1
95+ bin/herald-client list:segments 1
5896
59- # get available list_fields for list #1
60- bin/herald-client list:fields ${common_param} --listId= 1
97+ # get available list_fields for list #1
98+ bin/herald-client list:fields 1
6199
62- # delete contact #42
63- # bin/herald-client contact:delete ${common_param} --contactId= 42
100+ # delete contact #42
101+ #bin/herald-client contact:delete 42
64102
65- # get properties of contact #6
66- bin/herald-client contact:properties ${common_param} --contactId= 6
103+ # get properties of contact #6
104+ bin/herald-client contact:properties 6
67105
68- # add new contact with address 'new.contact@example.com' to list #1
69- bin/herald-client contact:add ${common_param} --listId=1 --address= new.contact@example.com
106+ # add new contact with address 'new.contact@example.com' to list #1
107+ bin/herald-client contact:add 1 new.contact@example.com
70108
71- # add new property to contact #36
72- bin/herald-client property:add ${common_param} --contactId= 36 --listFieldId=4 --value= " some value"
109+ # add new property to contact #36 for list field id #4
110+ bin/herald-client property:add 36 4 "some value"
73111
74- # send message based on tamplate #1 to all contacts in list #1
75- bin/herald-client list:send ${common_param} --listId=1 --templateId=1
112+ # send message based on template #7 to all contacts in list #1
113+ bin/herald-client list:send 1 7
76114
77- # send message based on tamplate #1 to contacts in list #1 that meet the conditions for segment #6
78- bin/herald-client list:send ${common_param} --listId=1 --templateId=1 --segmentId= 6
115+ # send message based on template #1 to contacts in list #1 that meet the conditions for segment #6
116+ bin/herald-client list:send 1 7 6
79117
0 commit comments