forked from square/square-python-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmobile_authorization_api.py
More file actions
73 lines (62 loc) · 2.81 KB
/
mobile_authorization_api.py
File metadata and controls
73 lines (62 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# -*- coding: utf-8 -*-
from square.api_helper import APIHelper
from square.http.api_response import ApiResponse
from square.api.base_api import BaseApi
from apimatic_core.request_builder import RequestBuilder
from apimatic_core.response_handler import ResponseHandler
from apimatic_core.types.parameter import Parameter
from square.http.http_method_enum import HttpMethodEnum
from apimatic_core.authentication.multiple.single_auth import Single
class MobileAuthorizationApi(BaseApi):
"""A Controller to access Endpoints in the square API."""
def __init__(self, config):
super(MobileAuthorizationApi, self).__init__(config)
def create_mobile_authorization_code(self,
body):
"""Does a POST request to /mobile/authorization-code.
Generates code to authorize a mobile application to connect to a
Square card reader.
Authorization codes are one-time-use codes and expire 60 minutes after
being issued.
__Important:__ The `Authorization` header you provide to this endpoint
must have the following format:
```
Authorization: Bearer ACCESS_TOKEN
```
Replace `ACCESS_TOKEN` with a
[valid production authorization
credential](https://developer.squareup.com/docs/build-basics/access-tok
ens).
Args:
body (CreateMobileAuthorizationCodeRequest): An object containing
the fields to POST for the request. See the corresponding
object definition for field details.
Returns:
ApiResponse: An object with the response value as well as other
useful information such as status codes and headers. Success
Raises:
APIException: When an error occurs while fetching the data from
the remote API. This exception includes the HTTP Response
code, an error message, and the HTTP body that was received in
the request.
"""
return super().new_api_call_builder.request(
RequestBuilder().server('default')
.path('/mobile/authorization-code')
.http_method(HttpMethodEnum.POST)
.header_param(Parameter()
.key('Content-Type')
.value('application/json'))
.body_param(Parameter()
.value(body))
.header_param(Parameter()
.key('accept')
.value('application/json'))
.body_serializer(APIHelper.json_serialize)
.auth(Single('global'))
).response(
ResponseHandler()
.deserializer(APIHelper.json_deserialize)
.is_api_response(True)
.convertor(ApiResponse.create)
).execute()