Completed
Push — master ( 7989d4...bccf74 )
by Ryan
02:12
created

EcommerceBridge::sendSyncMessages()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 2
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace SevenShores\Hubspot\Resources;
4
5
class EcommerceBridge extends Resource
6
{
7
    /**
8
     * Installs the ecommerce bridge into a portal.
9
     *
10
     * @return \SevenShores\Hubspot\Http\Response
11
     * @throws \SevenShores\Hubspot\Exceptions\BadRequest
12
     */
13
    function install()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
14
    {
15
        $endpoint = 'https://api.hubapi.com/extensions/ecomm/v1/installs';
16
17
        return $this->client->request('post', $endpoint);
18
    }
19
20
    /**
21
     * Check the status of the ecommerce bridge.
22
     *
23
     * @return \SevenShores\Hubspot\Http\Response
24
     * @throws \SevenShores\Hubspot\Exceptions\BadRequest
25
     */
26
    function checkInstall()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
27
    {
28
        $endpoint = 'https://api.hubapi.com/extensions/ecomm/v1/installs/status';
29
30
        return $this->client->request('get', $endpoint);
31
    }
32
33
    /**
34
     * Uninstall the ecommerce settings from a portal.
35
     *
36
     * @return \SevenShores\Hubspot\Http\Response
37
     * @throws \SevenShores\Hubspot\Exceptions\BadRequest
38
     */
39
    function uninstall()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
40
    {
41
        $endpoint = 'https://api.hubapi.com/extensions/ecomm/v1/installs/uninstall';
42
43
        return $this->client->request('post', $endpoint);
44
    }
45
46
    /**
47
     * Create or update the ecommerce settings.
48
     *
49
     * @param  array $settings
50
     * @return \SevenShores\Hubspot\Http\Response
51
     * @throws \SevenShores\Hubspot\Exceptions\BadRequest
52
     */
53
    function upsertSettings($settings = [])
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
54
    {
55
        $endpoint = 'https://api.hubapi.com/extensions/ecomm/v1/settings';
56
57
        $options['json'] = $settings;
58
59
        return $this->client->request('put', $endpoint, $options);
60
    }
61
62
    /**
63
     * Delete the ecommerce settings for your app or portal.
64
     * Note: This action cannot be undone. If you want to disable sync messages from being applied, it is recommended that you disable the settings rather than deleting them.
65
     *
66
     * @return \SevenShores\Hubspot\Http\Response
67
     * @throws \SevenShores\Hubspot\Exceptions\BadRequest
68
     */
69
    function deleteSettings()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
70
    {
71
        $endpoint = 'https://api.hubapi.com/extensions/ecomm/v1/settings';
72
73
        return $this->client->request('delete', $endpoint);
74
    }
75
76
    /**
77
     * Send a group of sync messages for a specific object type. Sync messages would be notifications of creates, updates, or deletes of ecommerce objects.
78
     *
79
     * @param  string $objectType - The object type that the updates are for. One of CONTACT, DEAL, PRODUCT, or LINE_ITEM.
80
     * @param  array  $messages
81
     * @return \SevenShores\Hubspot\Http\Response
82
     * @throws \SevenShores\Hubspot\Exceptions\BadRequest
83
     */
84
    function sendSyncMessages($objectType, $messages = [])
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
85
    {
86
        $endpoint = "https://api.hubapi.com/extensions/ecomm/v1/sync-messages/{$objectType}";
87
88
        $options['json'] = $messages;
89
90
        return $this->client->request('put', $endpoint, $options);
91
    }
92
93
    /**
94
     * Get errors from previously processed sync messages.
95
     *
96
     * @return \SevenShores\Hubspot\Http\Response
97
     * @throws \SevenShores\Hubspot\Exceptions\BadRequest
98
     */
99
    function getSyncErrors()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
100
    {
101
        $endpoint = 'https://api.hubapi.com/extensions/ecomm/v1/sync-errors';
102
103
        return $this->client->request('get', $endpoint);
104
    }
105
106
    /**
107
     * Set the URI for the import initialization webhook.
108
     *
109
     * @param  string $importTriggerUri - The URI that will be hit with the import webhook.
110
     * @return \SevenShores\Hubspot\Http\Response
111
     * @throws \SevenShores\Hubspot\Exceptions\BadRequest
112
     */
113
    function setImportUri($importTriggerUri)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
114
    {
115
        $endpoint = 'https://api.hubapi.com/extensions/ecomm/v1/import-settings';
116
117
        $options['json'] = [
0 ignored issues
show
Coding Style Comprehensibility introduced by
$options was never initialized. Although not strictly required by PHP, it is generally a good practice to add $options = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
118
            'importTriggerUri' => $importTriggerUri
119
        ];
120
121
        return $this->client->request('put', $endpoint, $options);
122
    }
123
124
    /**
125
     * Retrieve the ecommerce import settings for an app.
126
     *
127
     * @return \SevenShores\Hubspot\Http\Response
128
     * @throws \SevenShores\Hubspot\Exceptions\BadRequest
129
     */
130
    function getImportSettings()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
131
    {
132
        $endpoint = 'https://api.hubapi.com/extensions/ecomm/v1/import-settings';
133
134
        return $this->client->request('get', $endpoint);
135
    }
136
137
    /**
138
     * @param  int    $importStartedAt - Timestamp from the import initialization request
139
     * @param  string $objectType      - The object type this data corresponds to. Must be one of CONTACT, DEAL, LINE_ITEM, or PRODUCT.
140
     * @param  int    $pageNumber      - A numeric page number that identifies this page of data
141
     * @param  array  $messages        - The import messages
142
     * @return \SevenShores\Hubspot\Http\Response
143
     * @throws \SevenShores\Hubspot\Exceptions\BadRequest
144
     */
145
    function importObjects($importStartedAt, $objectType, $pageNumber, $messages)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
146
    {
147
        $endpoint = "https://api.hubapi.com/import-pages/{$importStartedAt}/{$objectType}/{$pageNumber}";
148
149
        $options['json'] = $messages;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$options was never initialized. Although not strictly required by PHP, it is generally a good practice to add $options = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
150
151
        return $this->client->request('put', $endpoint, $options);
152
    }
153
154
    /**
155
     * @param  int    $importStartedAt - Timestamp from the import initialization request
156
     * @param  string $objectType      - The object type this data corresponds to. Must be one of CONTACT, DEAL, LINE_ITEM, or PRODUCT.
157
     * @param  int    $pageCount       - The total number of pages sent via the import pages endpoint.
158
     * @param  int    $itemCount       - The total number of items sent via the import pages endpoint.
159
     * @return \SevenShores\Hubspot\Http\Response
160
     * @throws \SevenShores\Hubspot\Exceptions\BadRequest
161
     */
162
    function signalImportEnd($importStartedAt, $objectType, $pageCount, $itemCount)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
163
    {
164
        $endpoint = "https://api.hubapi.com/import-pages/{$importStartedAt}/{$objectType}/end";
165
166
        $options['json'] = [
0 ignored issues
show
Coding Style Comprehensibility introduced by
$options was never initialized. Although not strictly required by PHP, it is generally a good practice to add $options = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
167
            'pageCount' => $pageCount,
168
            'itemCount' => $itemCount
169
        ];
170
171
        return $this->client->request('put', $endpoint, $options);
172
    }
173
}