@@ 74-91 (lines=18) @@ | ||
71 | * |
|
72 | * @return mixed |
|
73 | */ |
|
74 | public function createRegistration(RegistrationInterface $registration) |
|
75 | { |
|
76 | if ($registration->getRegistrationId() || $registration->getETag()) { |
|
77 | throw new \RuntimeException('Registration ID and ETag must be empty.'); |
|
78 | } |
|
79 | ||
80 | $uri = $registration->buildUri($this->endpoint, $this->hubPath).self::API_VERSION; |
|
81 | ||
82 | $token = $this->generateSasToken($uri); |
|
83 | $headers = array_merge(['Authorization: '.$token], $registration->getHeaders()); |
|
84 | ||
85 | $response = $this->request(self::METHOD_POST, $uri, $headers, $registration->getPayload()); |
|
86 | ||
87 | return $registration->scrapeResponse($response); |
|
88 | } |
|
89 | ||
90 | /** |
|
91 | * Create or Update Registration. |
|
92 | * |
|
93 | * @param RegistrationInterface $registration |
|
94 | * |
|
@@ 99-113 (lines=15) @@ | ||
96 | * |
|
97 | * @return mixed |
|
98 | */ |
|
99 | public function updateRegistration(RegistrationInterface $registration) |
|
100 | { |
|
101 | if (!$registration->getRegistrationId()) { |
|
102 | throw new \RuntimeException('Registration ID is mandatory.'); |
|
103 | } |
|
104 | ||
105 | $uri = $registration->buildUri($this->endpoint, $this->hubPath).self::API_VERSION; |
|
106 | ||
107 | $token = $this->generateSasToken($uri); |
|
108 | $headers = array_merge(['Authorization: '.$token], $registration->getHeaders()); |
|
109 | ||
110 | $response = $this->request(self::METHOD_PUT, $uri, $headers, $registration->getPayload()); |
|
111 | ||
112 | return $registration->scrapeResponse($response); |
|
113 | } |
|
114 | ||
115 | /** |
|
116 | * Delete Registration. |