Skip to content

Commit 79aa21e

Browse files
authored
Merge pull request #10 from AASHE/client-parameters
Subscription Service
2 parents cb8b041 + 75da463 commit 79aa21e

15 files changed

Lines changed: 155 additions & 11 deletions

.coveragerc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
[run]
2-
source = membersuite-api-client
2+
source = membersuite_api_client
3+
4+
omit =
5+
*/python?.?/*
6+
*/site-packages/*
7+
*/unittest2/*

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ python:
55
- '3.5'
66
install:
77
- pip install -r requirements.txt
8-
script: coverage run membersuite-api-client/tests.py
8+
- pip install -r requirements_test.txt
9+
script: nosetests --with-coverage
910
after_success: coveralls
1011
notifications:
1112
hipchat: 5534a6204d6caa1a45ac2444282aca@WebDevActivity

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
include LICENSE
22
include README.md
33
include setup.py
4-
recursive-include membersuite-api-client *
4+
recursive-include membersuite_api_client *
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,14 @@ def convert_ms_object(self, ms_object):
144144
for item in ms_object:
145145
out_dict[item["Key"]] = item["Value"]
146146
return out_dict
147+
148+
def runSQL(self, query, start_record=0):
149+
concierge_request_header = self.construct_concierge_header(
150+
url="http://membersuite.com/contracts/"
151+
"IConciergeAPIService/ExecuteMSQL")
152+
result = self.client.service.ExecuteMSQL(
153+
_soapheaders=[concierge_request_header],
154+
msqlStatement=query,
155+
startRecord=start_record
156+
)
157+
return result

membersuite_api_client/subscriptions/__init__.py

Whitespace-only changes.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""
2+
Models the Subscription object in MemberSuite
3+
4+
http://api.docs.membersuite.com/#References/Objects/Subscription.htm
5+
"""
6+
7+
8+
class Subscription(object):
9+
10+
def __init__(self, id, org, start, end, extra_data={}):
11+
self.id = id
12+
self.org = org
13+
self.start = start
14+
self.end = end
15+
self.extra_data = extra_data # all other fields, for reference
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
"""
2+
The service for connecting to MemberSuite for SubscriptionService
3+
4+
http://api.docs.membersuite.com/#References/Objects/Subscription.htm
5+
6+
@todo
7+
let's define an Organization object, like this Subscription,
8+
for this interface
9+
@todo
10+
confirm owner field is actually the orgnization
11+
@todo
12+
set up fixtures in MemberSuite for integration testing
13+
@todo
14+
add date modified param for performance
15+
@todo
16+
additional method for getting all subscriptions for syncing purposes
17+
"""
18+
19+
from .models import Subscription
20+
21+
22+
class SubscriptionService(object):
23+
24+
def __init__(self, client):
25+
"""
26+
Accepts a ConciergeClient to connect with MemberSuite
27+
"""
28+
self.client = client
29+
30+
def get_org_subscriptions(self, org_id, publication_id=None):
31+
"""
32+
Get all the subscriptions for a given organization
33+
34+
Returns a list of subscription objects
35+
"""
36+
query = "SELECT Objects() FROM Subscription"
37+
query += " WHERE owner = '%s'" % org_id
38+
39+
if publication_id:
40+
query += "AND publication = '%s'" % publication_id
41+
42+
result = self.client.runSQL(query)
43+
mysql_result = result['body']['ExecuteMSQLResult']
44+
45+
if not mysql_result['Errors']:
46+
obj_result = mysql_result['ResultValue']['ObjectSearchResult']
47+
objects = obj_result['Objects']['MemberSuiteObject']
48+
49+
subscription_list = []
50+
for obj in objects:
51+
sane_obj = self.client.convert_ms_object(
52+
obj['Fields']['KeyValueOfstringanyType'])
53+
subscription = Subscription(
54+
id=sane_obj['ID'],
55+
org=org_id,
56+
start=sane_obj['StartDate'],
57+
end=sane_obj['TerminationDate'],
58+
extra_data=sane_obj)
59+
subscription_list.append(subscription)
60+
61+
return subscription_list
62+
63+
else:
64+
return None

membersuite_api_client/tests/__init__.py

Whitespace-only changes.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import os
2+
import unittest
3+
4+
from ..client import ConciergeClient
5+
6+
7+
class BaseTestCase(unittest.TestCase):
8+
9+
def setUp(self):
10+
self.MS_ACCESS_KEY = os.environ["MS_ACCESS_KEY"]
11+
self.MS_SECRET_KEY = os.environ["MS_SECRET_KEY"]
12+
self.MS_ASSOCIATION_ID = os.environ["MS_ASSOCIATION_ID"]
13+
14+
self.client = ConciergeClient(
15+
access_key=self.MS_ACCESS_KEY,
16+
secret_key=self.MS_SECRET_KEY,
17+
association_id=self.MS_ASSOCIATION_ID)

0 commit comments

Comments
 (0)