FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
shipengine-python/shipengine/shipengine_config.py at main · ShipEngine/shipengine-python · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
ShipEngine
/
shipengine-python
Public
Notifications
You must be signed in to change notification settings
Fork
8
Star
13
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
shipengine-python
/
shipengine
/
shipengine_config.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
99 lines (78 loc) · 3.11 KB
Breadcrumbs
shipengine-python
/
shipengine
/
shipengine_config.py
Copy path
File metadata and controls
99 lines (78 loc) · 3.11 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
"""The global configuration object for the ShipEngine SDK."""
import
json
from
typing
import
Any
,
Dict
,
Optional
from
.
enums
import
BaseURL
from
.
util
import
is_api_key_valid
,
is_retries_valid
,
is_timeout_valid
class
ShipEngineConfig
:
DEFAULT_BASE_URI
:
str
=
BaseURL
.
SHIPENGINE_RPC_URL
.
value
"""A ShipEngine API Key, sandbox API Keys start with `TEST_`."""
DEFAULT_PAGE_SIZE
:
int
=
50
"""Default page size for responses from ShipEngine API."""
DEFAULT_RETRIES
:
int
=
1
"""Default number of retries the ShipEngineClient should make before returning an exception."""
DEFAULT_TIMEOUT
:
int
=
60
"""Default timeout for the ShipEngineClient in seconds."""
def
__init__
(
self
,
config
:
Dict
[
str
,
Any
])
->
None
:
"""
This is the configuration object for the ShipEngine object and it"s properties are
used throughout this SDK.
"""
is_api_key_valid
(
config
)
self
.
api_key
:
str
=
config
[
"api_key"
]
is_timeout_valid
(
config
)
if
"timeout"
in
config
:
self
.
timeout
:
int
=
config
[
"timeout"
]
else
:
self
.
timeout
:
int
=
self
.
DEFAULT_TIMEOUT
if
"base_uri"
in
config
:
self
.
base_uri
:
str
=
config
[
"base_uri"
]
else
:
self
.
base_uri
:
str
=
self
.
DEFAULT_BASE_URI
if
"page_size"
in
config
:
self
.
page_size
:
int
=
config
[
"page_size"
]
else
:
self
.
page_size
:
int
=
self
.
DEFAULT_PAGE_SIZE
is_retries_valid
(
config
)
if
"retries"
in
config
:
self
.
retries
:
int
=
config
[
"retries"
]
else
:
self
.
retries
:
int
=
self
.
DEFAULT_RETRIES
def
merge
(
self
,
new_config
:
Optional
[
Dict
[
str
,
Any
]]
=
None
):
"""
The method allows the merging of a method-level configuration
adjustment into the current configuration.
"""
if
new_config
is
None
:
return
self
else
:
config
=
dict
()
(
config
.
update
({
"api_key"
:
new_config
[
"api_key"
]})
if
"api_key"
in
new_config
else
config
.
update
({
"api_key"
:
self
.
api_key
})
)
(
config
.
update
({
"base_uri"
:
new_config
[
"base_uri"
]})
if
"base_uri"
in
new_config
else
config
.
update
({
"base_uri"
:
self
.
base_uri
})
)
(
config
.
update
({
"page_size"
:
new_config
[
"page_size"
]})
if
"page_size"
in
new_config
else
config
.
update
({
"page_size"
:
self
.
page_size
})
)
(
config
.
update
({
"retries"
:
new_config
[
"retries"
]})
if
"retries"
in
new_config
else
config
.
update
({
"retries"
:
self
.
retries
})
)
(
config
.
update
({
"timeout"
:
new_config
[
"timeout"
]})
if
"timeout"
in
new_config
else
config
.
update
({
"timeout"
:
self
.
timeout
})
)
return
ShipEngineConfig
(
config
)
def
to_dict
(
self
):
return
(
lambda
o
:
o
.
__dict__
)(
self
)
def
to_json
(
self
):
return
json
.
dumps
(
self
,
default
=
lambda
o
:
o
.
__dict__
,
indent
=
2
)
Back
|
FazBrowse Home
|
New Git URL