Skip to content

Commit

Permalink
Remove config folder and refactoring it as a Python module (#13)
Browse files Browse the repository at this point in the history
* Update changes

* bump version

* Updating file name

* Manifest Update

* Test non-wheel upload

* Convert config JSON to Python module

* Remove configparser dependency

Co-authored-by: James Li <[email protected]>
  • Loading branch information
jamesliupenn and James Li authored Aug 19, 2020
1 parent 08ff655 commit b820df9
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 141 deletions.
3 changes: 1 addition & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
include README*
include *.txt
include config.json
include *.txt
125 changes: 0 additions & 125 deletions config/config.json

This file was deleted.

1 change: 1 addition & 0 deletions onfleet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
from onfleet.endpoint import Endpoint
from onfleet.request import Request
from onfleet.error import ValidationError, PermissionError, HttpError, RateLimitError, ServiceError
from onfleet.config import Config

__all__ = ["Onfleet"]
15 changes: 7 additions & 8 deletions onfleet/onfleet.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,20 @@
from requests.auth import HTTPBasicAuth
from onfleet.endpoint import Endpoint
from onfleet.error import ValidationError
from pathlib import Path

from onfleet.config import Config

class Onfleet(object):
config_data_folder = Path("config/")
config_file = config_data_folder / "config.json"
with open(config_file) as json_data_file:
data = json.load(json_data_file)
# Loading config data
data = Config.data
# Look up local authentication JSON if no api_key was passed
if (os.path.isfile(".auth.json")):
with open(".auth.json") as json_secret_file:
secret = json.load(json_secret_file)

def __init__(self, api_key=None):
self._session = requests.Session()
self._session.auth = (api_key if api_key else self.secret["API_KEY"], "") # auth takes api_key and api_secret
# auth takes api_key and api_secret
self._session.auth = (api_key if api_key else self.secret["API_KEY"], "")
self._initialize_resources(self._session)

def auth_test(self):
Expand All @@ -29,6 +28,6 @@ def auth_test(self):

def _initialize_resources(self, session):
resources = self.data["RESOURCES"]
# Go through the config.json file to create endpoints
# Go through the config module to create endpoints
for endpoint, http_methods in resources.items():
setattr(self, endpoint, Endpoint(http_methods, session))
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
requests
configparser
ratelimit
backoff
10 changes: 5 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@

setuptools.setup(
name="pyonfleet",
version= "1.0.2",
version= "1.1.0",
author="James Li",
author_email="[email protected]",
description="Onfleet's Python API Wrapper Package",
long_description=README,
long_description_content_type="text/markdown",
url="http://docs.onfleet.com",
packages=setuptools.find_packages(),
data_files=[
("config", ["config/config.json"])
],
include_package_data=True,
package_data={
"": ["*.json"]
},
install_requires=[
"requests", "configparser", "ratelimit", "backoff"
"requests", "ratelimit", "backoff"
],
classifiers=[
"Programming Language :: Python :: 3.7",
Expand Down

0 comments on commit b820df9

Please sign in to comment.