wschenk-ws_api 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. data/.document +5 -0
  2. data/.gitignore +7 -0
  3. data/LICENSE +20 -0
  4. data/README.rdoc +16 -0
  5. data/Rakefile +53 -0
  6. data/VERSION +1 -0
  7. data/example/Rakefile +10 -0
  8. data/example/app/controllers/application.rb +15 -0
  9. data/example/app/controllers/user_controller.rb +12 -0
  10. data/example/app/controllers/workstreamer_controller.rb +154 -0
  11. data/example/app/helpers/application_helper.rb +3 -0
  12. data/example/app/helpers/user_helper.rb +2 -0
  13. data/example/app/helpers/workstreamer_helper.rb +2 -0
  14. data/example/app/models/user.rb +2 -0
  15. data/example/app/views/layouts/application.rhtml +158 -0
  16. data/example/app/views/workstreamer/index.html.erb +1 -0
  17. data/example/app/views/workstreamer/info.html.erb +25 -0
  18. data/example/app/views/workstreamer/stream.html.erb +24 -0
  19. data/example/config/boot.rb +109 -0
  20. data/example/config/database.yml +22 -0
  21. data/example/config/environment.rb +77 -0
  22. data/example/config/environments/development.rb +17 -0
  23. data/example/config/environments/production.rb +24 -0
  24. data/example/config/environments/test.rb +22 -0
  25. data/example/config/initializers/inflections.rb +10 -0
  26. data/example/config/initializers/mime_types.rb +5 -0
  27. data/example/config/initializers/new_rails_defaults.rb +17 -0
  28. data/example/config/locales/en.yml +5 -0
  29. data/example/config/routes.rb +43 -0
  30. data/example/db/migrate/20090611183940_create_users.rb +15 -0
  31. data/example/db/schema.rb +23 -0
  32. data/example/doc/README_FOR_APP +5 -0
  33. data/example/public/404.html +30 -0
  34. data/example/public/422.html +30 -0
  35. data/example/public/500.html +33 -0
  36. data/example/public/dispatch.cgi +10 -0
  37. data/example/public/dispatch.fcgi +24 -0
  38. data/example/public/dispatch.rb +10 -0
  39. data/example/public/favicon.ico +0 -0
  40. data/example/public/images/rails.png +0 -0
  41. data/example/public/javascripts/application.js +2 -0
  42. data/example/public/javascripts/controls.js +963 -0
  43. data/example/public/javascripts/dragdrop.js +973 -0
  44. data/example/public/javascripts/effects.js +1128 -0
  45. data/example/public/javascripts/prototype.js +4320 -0
  46. data/example/public/robots.txt +5 -0
  47. data/example/script/about +4 -0
  48. data/example/script/console +3 -0
  49. data/example/script/dbconsole +3 -0
  50. data/example/script/destroy +3 -0
  51. data/example/script/generate +3 -0
  52. data/example/script/performance/benchmarker +3 -0
  53. data/example/script/performance/profiler +3 -0
  54. data/example/script/performance/request +3 -0
  55. data/example/script/plugin +3 -0
  56. data/example/script/process/inspector +3 -0
  57. data/example/script/process/reaper +3 -0
  58. data/example/script/process/spawner +3 -0
  59. data/example/script/runner +3 -0
  60. data/example/script/server +3 -0
  61. data/example/test/fixtures/users.yml +7 -0
  62. data/example/test/functional/user_controller_test.rb +8 -0
  63. data/example/test/functional/workstreamer_controller_test.rb +8 -0
  64. data/example/test/performance/browsing_test.rb +9 -0
  65. data/example/test/test_helper.rb +38 -0
  66. data/example/test/unit/user_test.rb +8 -0
  67. data/spec/spec_helper.rb +9 -0
  68. data/spec/ws_api_spec.rb +7 -0
  69. metadata +131 -0
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ pkg
5
+ example/tmp
6
+ example/log/*
7
+ example/db/*.sqlite3
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Workstreamer, LLC
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,16 @@
1
+ = ws_api
2
+
3
+ This gem provides a ruby wrapper to interface with workstreamer.com. It
4
+ depends on the "nokogiri" and "oauth" gems. Also included is an example
5
+ rails application which has an example of how to use the gem.
6
+
7
+ Documentation on how to use the API can be found http://workstreamer.pbworks.com/
8
+
9
+ To use the rails application, you need to first get a ClientApplication key from
10
+ workstreamer as documented here: http://workstreamer.pbworks.com/Authentication
11
+
12
+ Then edit example/config/app_config.yml
13
+
14
+ == Copyright
15
+
16
+ Copyright (c) 2009 Workstreamer, LLC. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "ws_api"
8
+ gem.summary = %Q{TODO}
9
+ gem.email = "wschenk@gmail.com"
10
+ gem.homepage = "http://github.com/wschenk/ws_api"
11
+ gem.authors = ["Will Schenk"]
12
+ gem.rubyforge_project = "ws_api"
13
+ gem.add_dependency 'oauth'
14
+ gem.add_dependency 'nokogiri'
15
+ # gem.add_dependency 'httparty'
16
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
+ end
18
+
19
+ Jeweler::RubyforgeTasks.new
20
+ rescue LoadError
21
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
22
+ end
23
+
24
+ require 'spec/rake/spectask'
25
+ Spec::Rake::SpecTask.new(:spec) do |spec|
26
+ spec.libs << 'lib' << 'spec'
27
+ spec.spec_files = FileList['spec/**/*_spec.rb']
28
+ end
29
+
30
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
31
+ spec.libs << 'lib' << 'spec'
32
+ spec.pattern = 'spec/**/*_spec.rb'
33
+ spec.rcov = true
34
+ end
35
+
36
+
37
+ task :default => :spec
38
+
39
+ require 'rake/rdoctask'
40
+ Rake::RDocTask.new do |rdoc|
41
+ if File.exist?('VERSION.yml')
42
+ config = YAML.load(File.read('VERSION.yml'))
43
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
44
+ else
45
+ version = ""
46
+ end
47
+
48
+ rdoc.rdoc_dir = 'rdoc'
49
+ rdoc.title = "ws_api #{version}"
50
+ rdoc.rdoc_files.include('README*')
51
+ rdoc.rdoc_files.include('lib/**/*.rb')
52
+ end
53
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
data/example/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require(File.join(File.dirname(__FILE__), 'config', 'boot'))
5
+
6
+ require 'rake'
7
+ require 'rake/testtask'
8
+ require 'rake/rdoctask'
9
+
10
+ require 'tasks/rails'
@@ -0,0 +1,15 @@
1
+ # Filters added to this controller apply to all controllers in the application.
2
+ # Likewise, all the methods added will be available for all controllers.
3
+
4
+ class ApplicationController < ActionController::Base
5
+ helper :all # include all helpers, all the time
6
+
7
+ # See ActionController::RequestForgeryProtection for details
8
+ # Uncomment the :secret if you're not using the cookie session store
9
+ protect_from_forgery # :secret => 'ccc9497e74859d264d4fc9a3aaa1b817'
10
+
11
+ # See ActionController::Base for details
12
+ # Uncomment this to filter the contents of submitted sensitive data parameters
13
+ # from your application log (in this case, all fields with names like "password").
14
+ # filter_parameter_logging :password
15
+ end
@@ -0,0 +1,12 @@
1
+ class UserController < ApplicationController
2
+ def create
3
+ u = User.create
4
+ session[:user_id] = u.id
5
+ redirect_to root_url
6
+ end
7
+
8
+ def switch
9
+ session[:user_id] = params[:id].to_i
10
+ redirect_to root_url
11
+ end
12
+ end
@@ -0,0 +1,154 @@
1
+ class WorkstreamerController < ApplicationController
2
+ before_filter :load_user, :except => :index
3
+ before_filter :require_token, :except => [:index, :callback]
4
+
5
+ rescue_from WsApi::Unauthorized, :with => :incorrect_token
6
+ rescue_from WsApi::Forbidden, :with => :incorrect_token
7
+
8
+ def info
9
+ @info = workstreamer.user_info
10
+
11
+ if @info && @info['login']
12
+ @user.update_attribute( "login", @info['login'])
13
+ end
14
+ end
15
+
16
+ def status_update
17
+ create_content "Status update", workstreamer.post_status_update( params[:content] )
18
+ end
19
+
20
+ def direct_message
21
+ create_content "Direct message", workstreamer.post_direct_message( params[:user_name], params[:message] )
22
+ end
23
+
24
+ def get_content
25
+ result = workstreamer.get_content( params[:id] )
26
+
27
+ master_content = result['hash']['master-content']
28
+
29
+ @stream = [master_content]
30
+
31
+ render :action => "stream"
32
+ end
33
+
34
+ def feed_item
35
+ create_content "Feed Item", workstreamer.post_feed_item( params )
36
+ end
37
+
38
+ def message
39
+ create_content "Message", workstreamer.post_message( params[:title], params[:content], { :recipients => params[:recipients], :project => params[:project]} )
40
+ end
41
+
42
+ def comment
43
+ create_content "Comment", workstreamer.create_comment( params[:comment], params[:parent_id] )
44
+ end
45
+
46
+ def create_task
47
+ create_content "Task", workstreamer.create_task( params[:title], params[:assigned_to], params[:content] )
48
+ end
49
+
50
+ def lookup_users
51
+ @info = workstreamer.lookup_users( params[:usernames] )
52
+ render :action => "info"
53
+ end
54
+
55
+ def lookup_project
56
+ @info = workstreamer.lookup_project( params[:project] )
57
+ render :action => "info"
58
+ end
59
+
60
+ def stream
61
+ @stream = workstreamer.stream
62
+ end
63
+
64
+ def callback
65
+ request_token = OAuth::RequestToken.new(workstreamer.consumer,
66
+ session[:request_token],
67
+ session[:request_token_secret])
68
+
69
+ # Exchange the request token for an access token.
70
+ access_token = request_token.get_access_token
71
+
72
+ @user.update_attributes( :token => access_token.token, :secret => access_token.secret )
73
+
74
+ flash[:notice] = "You have been authorized!"
75
+
76
+ redirect_to :action => "info"
77
+ end
78
+
79
+ protected
80
+ def load_user
81
+ begin
82
+ @user = User.find session[:user_id] if session[:user_id]
83
+ rescue
84
+ @user = nil
85
+ end
86
+
87
+ if @user.nil?
88
+ flash[:notice] = "You need to have a user first!"
89
+ redirect_to root_url
90
+ return false
91
+ end
92
+
93
+ @user
94
+ end
95
+
96
+ def require_token
97
+ # If the user doesn't have a token, then redirect them
98
+ if @user.token.nil?
99
+ return incorrect_token
100
+ end
101
+
102
+ @user
103
+ end
104
+
105
+ def incorrect_token
106
+ logger.info( "Called incorrect token" )
107
+ if @user
108
+ @user.update_attributes( :token => nil, :secret => nil )
109
+ @user = nil
110
+ end
111
+
112
+ @workstreamer = nil
113
+
114
+ request_token = workstreamer.request_token
115
+
116
+ session[:request_token] = request_token.token
117
+ session[:request_token_secret] = request_token.secret
118
+
119
+ redirect_to request_token.authorize_url
120
+ return false
121
+ end
122
+
123
+ def workstreamer
124
+ @workstreamer ||= WorkstreamerController.create_ws_api( @user )
125
+ end
126
+
127
+ ##
128
+ # This method was pulled out just so we can call it from script/console
129
+ def WorkstreamerController.create_ws_api( user = nil )
130
+ user_token = nil
131
+ user_secret = nil
132
+
133
+ if user
134
+ user_token = user.token
135
+ user_secret = user.secret
136
+ end
137
+
138
+ WsApi::Workstreamer.new( APP_CONFIG[:consumer_key],
139
+ APP_CONFIG[:consumer_secret],
140
+ APP_CONFIG[:site],
141
+ user_token,
142
+ user_secret )
143
+ end
144
+
145
+ def create_content( type, result )
146
+ if result
147
+ flash[:notice] = "#{type} was created successfully"
148
+ else
149
+ flash[:notice] = "#{type} was NOT created!"
150
+ end
151
+
152
+ redirect_to "/workstreamer/stream"
153
+ end
154
+ end
@@ -0,0 +1,3 @@
1
+ # Methods added to this helper will be available to all templates in the application.
2
+ module ApplicationHelper
3
+ end
@@ -0,0 +1,2 @@
1
+ module UserHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module WorkstreamerHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ class User < ActiveRecord::Base
2
+ end
@@ -0,0 +1,158 @@
1
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2
+ "http://www.w3.org/TR/html4/strict.dtd">
3
+ <html>
4
+ <head>
5
+ <title>Workstreamer API example application</title>
6
+ </head>
7
+
8
+ <body>
9
+ <% if flash[:notice] %>
10
+ <h1><%= flash[:notice] %></h1>
11
+ <% end %>
12
+ <ul>
13
+ <% User.find( :all ).each do |user| %>
14
+ <li><%= link_to "Become user ##{user.id}", :controller => "user", :action => "switch", :id => user.id %>
15
+ <%= user.login %>
16
+ <%= user.token %>
17
+ <% if user.id == session[:user_id] %>
18
+ Active user
19
+ <% end %>
20
+ </li>
21
+ <% end %>
22
+ <li><%= link_to "Create a new user", :controller => "user", :action => "create" %>
23
+ </ul>
24
+ <table border="1">
25
+ <tr>
26
+ <td>
27
+ <%= link_to "User Info", :controller => "workstreamer", :action => "info" %>
28
+ </td>
29
+ </tr>
30
+
31
+ <tr>
32
+ <td>
33
+ <%= link_to "Get user's stream", :controller => "workstreamer", :action => "stream" %>
34
+ </td>
35
+ </tr>
36
+
37
+ <tr>
38
+ <form action="/workstreamer/lookup_users">
39
+ <td>
40
+ <input type="text" name="usernames">
41
+ </td>
42
+ <td>
43
+ <input type="submit" value="Lookup Users">
44
+ </td>
45
+ </form>
46
+ </tr>
47
+
48
+
49
+ <tr>
50
+ <form action="/workstreamer/lookup_project">
51
+ <td>
52
+ <input type="text" name="project">
53
+ </td>
54
+ <td>
55
+ <input type="submit" value="Lookup Project Info">
56
+ </td>
57
+ </form>
58
+ </tr>
59
+
60
+ <tr>
61
+ <form action="/workstreamer/get_content">
62
+ <td>
63
+ <input type="text" name="id">
64
+ </td>
65
+ <td>
66
+ <input type="submit" value="Get content from id">
67
+ </td>
68
+ </form>
69
+ </tr>
70
+
71
+ <hr>
72
+
73
+ <tr>
74
+ <form action="/workstreamer/status_update">
75
+ <td>
76
+ <input type="text" name="content">
77
+ </td>
78
+ <td>
79
+ <input type="submit" value="Post status update">
80
+ </td>
81
+ </form>
82
+ </tr>
83
+
84
+ <tr>
85
+ <form action="/workstreamer/direct_message">
86
+ <td>
87
+ To user<br/>
88
+ <input type="text" name="user_name"><br/>
89
+ One liner<br/>
90
+ <input type="text" name="message">
91
+ </td>
92
+ <td>
93
+ <input type="submit" value="Post direct message">
94
+ </td>
95
+ </form>
96
+ </tr>
97
+
98
+
99
+ <tr>
100
+ <form action="/workstreamer/message">
101
+ <td>
102
+ Subject (*)<br/>
103
+ <input type="text" name="title"><br/>
104
+ Recipient List<br/>
105
+ <input type="text" name="recipients"><br/>
106
+ Project<br/>
107
+ <input type="text" name="project"><br/>
108
+
109
+ </td>
110
+ <td>
111
+ Message body (*)<br/>
112
+ <textarea name="content" rows="8"></textarea>
113
+ <input type="submit" value="Post message">
114
+ </td>
115
+ </form>
116
+ </tr>
117
+
118
+ <tr>
119
+ <form action="/workstreamer/feed_item">
120
+ <td>
121
+ Title (*)<br/>
122
+ <input type="text" name="title"><br/>
123
+ URL<br/>
124
+ <input type="text" name="url"><br/>
125
+ Created At/Published<br/>
126
+ <input type="text" name="created_at"><br/>
127
+ remote_id<br/>
128
+ <input type="text" name="remote_id"><br/>
129
+ </td>
130
+ <td>
131
+ Extended<br/>
132
+ <textarea name="content" rows="8"></textarea>
133
+ <input type="submit" value="Post Feed Item">
134
+ </td>
135
+ </form>
136
+ </tr>
137
+
138
+ <tr>
139
+ <form action="/workstreamer/create_task">
140
+ <td>
141
+ Task Assignee (*)<br/>
142
+ <input type="text" name="assigned_to"><br/>
143
+ Task title (*)<br/>
144
+ <input type="text" name="title"><br/>
145
+ </td>
146
+ <td>
147
+ Extended<br/>
148
+ <textarea name="content" rows="8"></textarea>
149
+ <input type="submit" value="Create a task">
150
+ </td>
151
+ </form>
152
+ </tr>
153
+
154
+ </table>
155
+ <hr/>
156
+ <%= yield %>
157
+ </body>
158
+ </html>