Skip to content
Browse files

Remove resource_meta, used for discovering valid api endpoints

This was incompatible with OAuth, and has been replaced by the
class heirarchy
  • Loading branch information...
1 parent ef113d1 commit 4f34519b2e29dc1cd59c1c14af0862f99eb5a4f7 @tgsergeant tgsergeant committed Feb 10, 2014
Showing with 7 additions and 48 deletions.
  1. +1 −1 bigcommerce/api.py
  2. +1 −25 bigcommerce/connection.py
  3. +0 −2 examples/ex_time.py
  4. +5 −20 tests/test_api.py
View
2 bigcommerce/api.py
@@ -1,6 +1,6 @@
import sys
from bigcommerce import connection
-from bigcommerce.resources import *
+from bigcommerce.resources import * # Needed for ApiResourceWrapper dynamic loading
class BigcommerceApi(object):
View
26 bigcommerce/connection.py
@@ -14,13 +14,12 @@
import json # only used for urlencode querystr
import logging
import streql
-from pprint import pformat # only used once for logging, in __load_urls
import requests
from bigcommerce.exception import *
-log = logging.getLogger("bigcommerce.api.connection")
+log = logging.getLogger("bigcommerce.connection")
class Connection(object):
@@ -47,29 +46,8 @@ def __init__(self, host, auth, api_path='/api/v2/{}'):
self._session.auth = auth
self._session.headers = {"Accept": "application/json"}
- self.__resource_meta = self.get() # retrieve metadata about urls and resources
- log.debug(pformat(self.__resource_meta))
-
self._last_response = None # for debugging
- def meta_data(self):
- """
- Return a JSON string representation of resource-to-url mappings
- """
- return json.dumps(self.__resource_meta)
-
- def get_url(self, resource_name):
- """
- Lookup the "url" for the resource name from the internally stored resource mappings
- """
- return self.__resource_meta.get(resource_name, {}).get("url", None)
-
- def get_resource_url(self, resource_name):
- """
- Lookup the "resource" for the resource name from the internally stored resource mappings
- """
- return self.__resource_meta.get(resource_name, {}).get("resource", None)
-
def full_path(self, url):
return "https://" + self.host + self.api_path.format(url)
@@ -216,8 +194,6 @@ def __init__(self, client_id, store_hash, access_token=None,
if access_token and store_hash:
self._session.headers.update(self._oauth_headers(client_id, access_token))
- # TODO find meta info new path (/store gives a "your scope does not include this resource")
- self.__resource_meta = {} # self.get() # retrieve metadata about urls and resources
self._last_response = None # for debugging
def full_path(self, url):
View
2 examples/ex_time.py
@@ -1,8 +1,6 @@
from __future__ import print_function
import bigcommerce.api
-__author__ = 'tim'
-
api = bigcommerce.api.BigcommerceApi(client_id='id', store_hash='hash', access_token='token')
print(repr(api.Time.all()))
View
25 tests/test_api.py
@@ -5,32 +5,17 @@
from bigcommerce.resources import ApiResource
from mock import MagicMock, patch, Mock
-__author__ = 'tim'
-
-
class TestBigcommerceApi(unittest.TestCase):
""" Test API client creation and helpers"""
def test_create_basic(self):
- with patch('requests.Session') as mock:
- instance = mock.return_value
- mock_result = Mock()
- mock_result.status_code = 200
- mock_result.json.return_value = {}
- instance.request.return_value = mock_result
- api = bigcommerce.api.BigcommerceApi(store_endpoint='https://store.mybigcommerce.com', basic_auth=('admin', 'abcdef'))
- self.assertIsInstance(api.connection, Connection)
- self.assertNotIsInstance(api.connection, OAuthConnection)
+ api = bigcommerce.api.BigcommerceApi(store_endpoint='https://store.mybigcommerce.com', basic_auth=('admin', 'abcdef'))
+ self.assertIsInstance(api.connection, Connection)
+ self.assertNotIsInstance(api.connection, OAuthConnection)
def test_create_oauth(self):
- with patch('requests.Session') as mock:
- instance = mock.return_value
- mock_result = Mock()
- mock_result.status_code = 200
- mock_result.json.return_value = {}
- instance.request.return_value = mock_result
- api = bigcommerce.api.BigcommerceApi(client_id='123456', store_hash='abcdef', access_token='123abc')
- self.assertIsInstance(api.connection, OAuthConnection)
+ api = bigcommerce.api.BigcommerceApi(client_id='123456', store_hash='abcdef', access_token='123abc')
+ self.assertIsInstance(api.connection, OAuthConnection)
def test_create_incorrect_args(self):
self.assertRaises(Exception, lambda: bigcommerce.api.BigcommerceApi(client_id='123', basic_auth=('admin', 'token')))

0 comments on commit 4f34519

Please sign in to comment.
Something went wrong with that request. Please try again.