Skip to content

Commit 658fccf

Browse files
author
Yakov Gnusin
committed
Added ActivityCategories support.
1 parent 0772426 commit 658fccf

File tree

12 files changed

+193
-76
lines changed

12 files changed

+193
-76
lines changed

fr8/data.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,39 @@ def from_fr8_json(json_data):
9494
return dto
9595

9696

97+
class ActivityCategoryDTO(object):
98+
def __init__(self, **kwargs):
99+
self.name = kwargs.get('name')
100+
self.icon_path = kwargs.get('icon_path')
101+
102+
def to_fr8_json(self):
103+
return {
104+
'name': self.name,
105+
'iconPath': self.icon_path
106+
}
107+
108+
@staticmethod
109+
def from_fr8_json(json_data):
110+
if not json_data:
111+
return None
112+
113+
ac = ActivityCategoryDTO(
114+
name=json_data.get('name'),
115+
icon_path=json_data.get('iconPath')
116+
)
117+
118+
return ac
119+
120+
121+
ActivityCategories = utility.enum(
122+
MONITORS=ActivityCategoryDTO(name="Monitor", icon_path="/Content/icons/monitor-icon-64x64.png"),
123+
RECEIVERS=ActivityCategoryDTO(name="Get", icon_path="/Content/icons/get-icon-64x64.png"),
124+
PROCESSORS=ActivityCategoryDTO(name="Process", icon_path="/Content/icons/process-icon-64x64.png"),
125+
FORWARDERS=ActivityCategoryDTO(name="Forward", icon_path="/Content/icons/forward-icon-64x64.png"),
126+
SOLUTION=ActivityCategoryDTO(name="Solution")
127+
)
128+
129+
97130
class ActivityTemplateDTO(object):
98131
def __init__(self, **kwargs):
99132
self.id = kwargs.get('id')
@@ -102,6 +135,7 @@ def __init__(self, **kwargs):
102135
self.terminal = kwargs.get('terminal')
103136
self.web_service = kwargs.get('web_service')
104137
self.activity_category = kwargs.get('activity_category')
138+
self.categories = kwargs.get('categories')
105139
self.needs_authentication = kwargs.get('needs_authentication', False)
106140
self.label = kwargs.get('label', '')
107141
self.activity_type = kwargs.get('activity_type', ActivityType.STANDARD)
@@ -113,7 +147,8 @@ def to_fr8_json(self):
113147
'name': self.name,
114148
'version': self.version,
115149
'terminal': self.terminal.to_fr8_json(),
116-
'webService': self.web_service.to_fr8_json() if self.web_service is not None else None,
150+
'webService': self.web_service.to_fr8_json() if self.web_service else None,
151+
'categories': [x.to_fr8_json() for x in self.categories] if self.categories else None,
117152
'category': self.activity_category,
118153
'needsAuthentication': self.needs_authentication,
119154
'label': self.label,
@@ -131,6 +166,8 @@ def from_fr8_json(json_data):
131166
web_service=WebServiceDTO.from_fr8_json(json_data.get('webService')) if json_data.get('webService') else None,
132167
terminal=TerminalDTO.from_fr8_json(json_data.get('terminal')) if json_data.get('terminal') else None,
133168
activity_category=json_data.get('category'),
169+
categories=[ActivityCategoryDTO.from_fr8_json(x) for x in json_data.get('categories')]\
170+
if json_data.get('categories') else [],
134171
activity_type=json_data.get('type'),
135172
min_pane_width=json_data.get('minPaneWidth'),
136173
needs_authentication=json_data.get('needsAuthentication')

fr8/terminal.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ def discover(self):
2828
discover_data = manifests.StandardFr8TerminalCM(terminal=self.terminal, activities=activity_templates)
2929
return discover_data.to_fr8_json()
3030

31-
def auth_request_url(self):
31+
def auth_request_url(self, request):
3232
if not self.authentication_handler:
3333
raise 'No authentication handler registered for TerminalHandler'
3434

35-
request_url_data = self.authentication_handler.get_request_url()
35+
hub_url = request.headers.get('FR8HUBCALLBACKURL')
36+
37+
request_url_data = self.authentication_handler.get_request_url(hub_url)
3638
return request_url_data.to_fr8_json()
3739

3840
def auth_token(self, request):

terminalTwitter/runserver.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
"""
44

55
from os import environ
6-
from terminalTwitter import app
6+
from terminalTwitter.main import app
77

88
if __name__ == '__main__':
99
HOST = environ.get('SERVER_HOST', 'localhost')
1010
try:
11-
PORT = int(environ.get('SERVER_PORT', '5555'))
11+
PORT = int(environ.get('SERVER_PORT', '38080'))
1212
except ValueError:
13-
PORT = 5555
13+
PORT = 38080
1414
app.run(HOST, PORT)

terminalTwitter/runtime.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
python-2.7

terminalTwitter/terminalTwitter.pyproj

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
<ProjectHome>.</ProjectHome>
99
<ProjectTypeGuids>{789894c7-04a9-4a11-a6b5-3f4435165112};{1b580a1a-fdb3-4b32-83e1-6407eb2722e6};{349c5851-65df-11da-9384-00065b846f21};{888888a0-9f3d-457c-b088-3a5042f75d52}</ProjectTypeGuids>
1010
<StartupFile>runserver.py</StartupFile>
11-
<SearchPath>
12-
</SearchPath>
11+
<SearchPath>..\</SearchPath>
1312
<WorkingDirectory>.</WorkingDirectory>
1413
<LaunchProvider>Web launcher</LaunchProvider>
1514
<OutputPath>.</OutputPath>
@@ -20,6 +19,8 @@
2019
<RootNamespace>terminalTwitter</RootNamespace>
2120
<InterpreterId>{c82c5a6b-16b0-4e64-a1ba-5bb344fe8a76}</InterpreterId>
2221
<InterpreterVersion>2.7</InterpreterVersion>
22+
<PythonRunWebServerCommandType>code</PythonRunWebServerCommandType>
23+
<WebBrowserPort>38080</WebBrowserPort>
2324
</PropertyGroup>
2425
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
2526
<DebugSymbols>true</DebugSymbols>
@@ -32,6 +33,9 @@
3233
<ItemGroup>
3334
<Compile Include="runserver.py" />
3435
<Compile Include="terminalTwitter\authentication.py" />
36+
<Compile Include="terminalTwitter\main.py">
37+
<SubType>Code</SubType>
38+
</Compile>
3539
<Compile Include="terminalTwitter\post_to_twitter.py" />
3640
<Compile Include="terminalTwitter\terminal.py" />
3741
<Compile Include="terminalTwitter\__init__.py" />
@@ -41,6 +45,7 @@
4145
</ItemGroup>
4246
<ItemGroup>
4347
<Content Include="requirements.txt" />
48+
<Content Include="runtime.txt" />
4449
</ItemGroup>
4550
<ItemGroup>
4651
<Interpreter Include="venv\">
Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +0,0 @@
1-
from flask import Flask
2-
from flask import jsonify
3-
from flask import request
4-
5-
import fr8.terminal
6-
7-
import authentication
8-
import post_to_twitter
9-
import terminal
10-
11-
# Flask app instance.
12-
app = Flask(__name__)
13-
14-
# Terminal request handler.
15-
handler = fr8.terminal.TerminalHandler(
16-
terminal.terminal,
17-
authentication_handler=authentication.Handler(),
18-
activities=[
19-
(terminal.post_to_twitter, post_to_twitter.Handler)
20-
]
21-
)
22-
23-
24-
# Discover end-point.
25-
@app.route('/discover')
26-
def discover():
27-
return jsonify(handler.discover())
28-
29-
30-
# Authentication Request-Url end-point.
31-
@app.route('/authentication/request_url', methods=['POST'])
32-
def request_url():
33-
return jsonify(handler.auth_request_url())
34-
35-
36-
# Authentication token gathering end-point.
37-
@app.route('/authentication/token', methods=['POST'])
38-
def token():
39-
return jsonify(handler.auth_token(request))
40-
41-
42-
# Configure end-point.
43-
@app.route('/activities/configure', methods=['POST'])
44-
def configure():
45-
return jsonify(handler.configure(request))
46-
47-
48-
# Activate end-point.
49-
@app.route('/activities/activate', methods=['POST'])
50-
def activate():
51-
return jsonify(handler.activate(request))
52-
53-
54-
# Deactivate end-point.
55-
@app.route('/activities/deactivate', methods=['POST'])
56-
def deactivate():
57-
return jsonify(handler.deactivate(request))
58-
59-
60-
# Run end-point.
61-
@app.route('/activities/Run', methods=['POST'])
62-
def run():
63-
return jsonify(handler.run(request))

terminalTwitter/terminalTwitter/authentication.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ class Handler(object):
88
def __init__(self):
99
self.auth_data = {}
1010

11-
def get_request_url(self):
11+
def get_request_url(self, hub_url):
1212
auth = tweepy.OAuthHandler(
1313
terminal.twitter_consumer_key,
1414
terminal.twitter_consumer_secret,
15-
terminal.twitter_callback_url
15+
hub_url + terminal.twitter_callback_url
1616
)
1717

1818
redirect_url = auth.get_authorization_url()
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
from flask import Flask
2+
from flask import jsonify
3+
from flask import request
4+
5+
import fr8.terminal
6+
7+
import authentication
8+
import post_to_twitter
9+
import terminal
10+
11+
# Flask app instance.
12+
app = Flask(__name__)
13+
14+
# Terminal request handler.
15+
handler = fr8.terminal.TerminalHandler(
16+
terminal.terminal,
17+
authentication_handler=authentication.Handler(),
18+
activities=[
19+
(terminal.post_to_twitter, post_to_twitter.Handler)
20+
]
21+
)
22+
23+
24+
# Discover end-point.
25+
@app.route('/discover')
26+
def discover():
27+
return jsonify(handler.discover())
28+
29+
30+
# Authentication Request-Url end-point.
31+
@app.route('/authentication/request_url', methods=['POST'])
32+
def request_url():
33+
return jsonify(handler.auth_request_url(request))
34+
35+
36+
# Authentication token gathering end-point.
37+
@app.route('/authentication/token', methods=['POST'])
38+
def token():
39+
return jsonify(handler.auth_token(request))
40+
41+
42+
# Configure end-point.
43+
@app.route('/activities/configure', methods=['POST'])
44+
def configure():
45+
return jsonify(handler.configure(request))
46+
47+
48+
# Activate end-point.
49+
@app.route('/activities/activate', methods=['POST'])
50+
def activate():
51+
return jsonify(handler.activate(request))
52+
53+
54+
# Deactivate end-point.
55+
@app.route('/activities/deactivate', methods=['POST'])
56+
def deactivate():
57+
return jsonify(handler.deactivate(request))
58+
59+
60+
# Run end-point.
61+
@app.route('/activities/Run', methods=['POST'])
62+
def run():
63+
return jsonify(handler.run(request))

terminalTwitter/terminalTwitter/terminal.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
twitter_consumer_key = 'j0CGin9tvfWEe5UrxsCcjC6fT'
44
twitter_consumer_secret = 'yjSWPAqLOC5ABG8Yz1uAvsGEAWNph5IRThfnwjciAvobXh8Gc2'
5-
twitter_callback_url = 'http://localhost:30643/AuthenticationCallback/ProcessSuccessfulOAuthResponse?terminalName=terminalTwitter&terminalVersion=1'
5+
twitter_callback_url = '/AuthenticationCallback/ProcessSuccessfulOAuthResponse?terminalName=terminalTwitter&terminalVersion=1'
66

77
web_service = fr8.data.WebServiceDTO(name='Twitter', icon_path='/Content/icons/web_services/twitter-icon-64x64.png')
88

@@ -27,6 +27,10 @@
2727
terminal = terminal,
2828
web_service = web_service,
2929
activity_category = fr8.data.ActivityCategory.FORWARDERS,
30+
categories = [
31+
fr8.data.ActivityCategories.FORWARDERS,
32+
fr8.data.ActivityCategoryDTO(name=web_service.name, icon_path=web_service.icon_path)
33+
],
3034
needs_authentication = True,
3135
label = 'Post To Twitter'
3236
)

terminalTwitter/web.2.7.config

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?xml version="1.0"?>
2+
<configuration>
3+
<!--
4+
See PTVS documentation at http://pytools.codeplex.com/documentation
5+
for additional instructions on how to use remote debugging.
6+
-->
7+
<system.diagnostics>
8+
<trace>
9+
<listeners>
10+
<add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics">
11+
<filter type="" />
12+
</add>
13+
</listeners>
14+
</trace>
15+
</system.diagnostics>
16+
<appSettings>
17+
<add key="WSGI_ALT_VIRTUALENV_HANDLER" value="terminalTwitter.app" />
18+
<add key="WSGI_ALT_VIRTUALENV_ACTIVATE_THIS" value="D:\home\site\wwwroot\env\Scripts\activate_this.py" />
19+
<add key="WSGI_HANDLER" value="ptvs_virtualenv_proxy.get_virtualenv_handler()" />
20+
<add key="PYTHONPATH" value="D:\home\site\wwwroot" />
21+
<!--
22+
Uncomment the following key/value to enable remote debugging.
23+
The following setting is meant to protect the debugging endpoint against
24+
inadvertent access, and should be treated as a password.
25+
Set a password in the value attribute. Valid characters are:
26+
ALPHA / DIGIT / "-" / "." / "_" / "~" / "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
27+
-->
28+
<!--
29+
<add key="WSGI_PTVSD_SECRET" value="" />
30+
-->
31+
</appSettings>
32+
<system.web>
33+
<compilation debug="true" targetFramework="4.0" />
34+
<!-- Required for websockets. -->
35+
<httpRuntime targetFramework="4.5"/>
36+
</system.web>
37+
<system.webServer>
38+
<modules runAllManagedModulesForAllRequests="true" />
39+
<handlers>
40+
<remove name="Python273_via_FastCGI" />
41+
<add name="Python FastCGI" path="handler.fcgi" verb="*" modules="FastCgiModule" scriptProcessor="D:\Python27\python.exe|D:\Python27\Scripts\wfastcgi.py" resourceType="Unspecified" requireAccess="Script" />
42+
<!-- Uncomment the following handler to enable remote debugging. -->
43+
<!--
44+
<add name="ptvsd" path="ptvsd" verb="*" resourceType="Unspecified" type="Microsoft.PythonTools.Debugger.WebSocketProxy, Microsoft.PythonTools.WebRole"/>
45+
-->
46+
</handlers>
47+
<rewrite>
48+
<rules>
49+
<!-- Uncomment the following rule to enable remote debugging. -->
50+
<!--
51+
<rule name="ptvsd" enabled="true" stopProcessing="true">
52+
<match url="^ptvsd(/.*)?$"/>
53+
</rule>
54+
-->
55+
<rule name="Static Files" stopProcessing="true">
56+
<match url="^/static/.*" ignoreCase="true" />
57+
<action type="Rewrite" url="^/terminalTwitter/static/.*" appendQueryString="true" />
58+
</rule>
59+
<rule name="Configure Python" stopProcessing="true">
60+
<match url="(.*)" ignoreCase="false" />
61+
<conditions>
62+
</conditions>
63+
<action type="Rewrite" url="handler.fcgi/{R:1}" appendQueryString="true" />
64+
</rule>
65+
</rules>
66+
</rewrite>
67+
</system.webServer>
68+
</configuration>

0 commit comments

Comments
 (0)