quickapps_feedback 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0d9c5a129b2bf16cdaa8f2117b5c8875916b5cce
4
+ data.tar.gz: 1b5b3238bfda2188c83cf9c692f5d193a41eb457
5
+ SHA512:
6
+ metadata.gz: a173166b3e4c595d78d1459cc3c923f812b4e4e1eff181c442c64ea169044d1d4cfa676d7fcd3ccf99aa70791f9a0528a70562847b87e04743e2a2cf6e522d48
7
+ data.tar.gz: 3f08741fbf7f507e6512f3fac8dfb1b0a36be752cfb4df785e383cba950eb8869a9ea2803c38c353f8afd7edf12f9481c0c023c71e962b0998ee7ae9725a3fa0
data/.gitignore ADDED
@@ -0,0 +1,23 @@
1
+ .idea
2
+ *.gem
3
+ *.rbc
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
19
+ *.bundle
20
+ *.so
21
+ *.o
22
+ *.a
23
+ mkmf.log
data/.rubocop.yml ADDED
@@ -0,0 +1,5 @@
1
+ Style/Documentation:
2
+ Enabled: false
3
+
4
+ Style/RegexpLiteral:
5
+ MaxSlashes: 0
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.0.0-p247
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in quickapps_feedback.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Grant Speelman
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # QuickappsFeedback
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'quickapps_feedback'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install quickapps_feedback
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/[my-github-username]/quickapps_feedback/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rubocop/rake_task'
3
+
4
+ RuboCop::RakeTask.new
@@ -0,0 +1,33 @@
1
+ require 'excon'
2
+
3
+ module QuickappsFeedback
4
+ class Feedback
5
+ attr_reader :uid, :subject, :message, :support_type
6
+
7
+ def initialize(uid,full_message,support_type)
8
+ @uid = uid
9
+ @subject, @message = full_message.split(':',2)
10
+ @message ||= @subject
11
+ @support_type = support_type
12
+ end
13
+
14
+ def user_account
15
+ return @user_account if @user_account
16
+ connection = Excon.new(ENV['USER_ACCOUNT_API'])
17
+ result = connection.get(path: '/api/user_accounts',
18
+ headers: {'X-API-Token' => ENV['USER_ACCOUNT_API_KEY'] },
19
+ query: {uid: uid,
20
+ provider: 'mxit'},
21
+ :expects => 200)
22
+ @user_account = JSON.parse(result.body).first
23
+ end
24
+
25
+ def user_email
26
+ user_account['email']
27
+ end
28
+
29
+ def user_real_name
30
+ user_account['real_name']
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,56 @@
1
+ require 'uservoice-ruby'
2
+
3
+ module QuickappsFeedback
4
+ class SendFeedbackToUservoice
5
+ def perform(feedback)
6
+ send_options = {:email => feedback.user_email,
7
+ :subject => "[#{ENV['MXIT_APP_NAME']}] #{feedback.subject}",
8
+ :message => feedback.message,
9
+ :name => feedback.user_real_name || CGI::unescape(feedback.user_name.to_s).gsub(/[^a-zA-Z0-9\s]/, '')}
10
+ if feedback.support_type == 'suggestion'
11
+ send_suggestion(send_options)
12
+ else
13
+ send_support(send_options)
14
+ end
15
+ end
16
+
17
+ def send_suggestion(options = {})
18
+ client = UserVoice::Client.new(subdomain_name, api_key, api_secret)
19
+ forum = client.get('/api/v1/forums.json')['forums'].first
20
+ forum_id = forum['id']
21
+ client.login_as(options[:email]) do |access_token|
22
+ access_token.post("/api/v1/forums/#{forum_id}/suggestions.json", {
23
+ :suggestion => {
24
+ :title => options[:subject],
25
+ :text => options[:message],
26
+ :votes => 0
27
+ }
28
+ })
29
+ end
30
+ end
31
+
32
+ def send_support(options = {})
33
+ client = UserVoice::Client.new(subdomain_name, api_key, api_secret)
34
+ client.post('/api/v1/tickets.json', {
35
+ :email => options[:email],
36
+ :name => options[:name],
37
+ :ticket => {
38
+ :subject => options[:subject],
39
+ :message => options[:message]
40
+ }
41
+ })
42
+ end
43
+
44
+ def subdomain_name
45
+ ENV['UV_SUBDOMAIN_NAME']
46
+ end
47
+
48
+ def api_key
49
+ ENV['UV_API_KEY']
50
+ end
51
+
52
+ def api_secret
53
+ ENV['UV_API_SECRET']
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,3 @@
1
+ module QuickappsFeedback
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,24 @@
1
+ require 'quickapps_feedback/version'
2
+ require 'quickapps_feedback/feedback'
3
+ require 'quickapps_feedback/send_feedback_to_uservoice'
4
+ require 'sinatra/base'
5
+
6
+ module QuickappsFeedback
7
+ class App < Sinatra::Base
8
+ get '/feedback' do
9
+ erb :index
10
+ end
11
+
12
+ post '/feedback' do
13
+ feedback = Feedback.new(request.env['HTTP_X_MXIT_USERID_R'] || session[:uid],
14
+ params[:full_message],params[:support_type])
15
+ SendFeedbackToUservoice.new.perform(feedback)
16
+ flash[:notice] = 'thank you for your feedback'
17
+ redirect to('/')
18
+ end
19
+
20
+ get '/feedback/new' do
21
+ erb :new, locals: {support_type: params[:type]}
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,4 @@
1
+ <ul>
2
+ <li><a href="/feedback/new?type=support" id="support">1</a> problems / support</li>
3
+ <li><a href="/feedback/new?type=suggestion" id="suggestion">2</a> ideas / suggestions / other</li>
4
+ </ul>
@@ -0,0 +1,24 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Hangman Extreme</title>
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <link href="/assets/favicon.ico" rel="shortcut icon" />
7
+ <link href="/assets/application.css" media="all" rel="stylesheet" />
8
+ </head>
9
+ <body class="ui-page-active">
10
+ <% if flash[:notice] %>
11
+ <div class="alert alert-info" style="color:#00008b;"><%= flash[:notice] %></div>
12
+ <% elsif flash[:alert] %>
13
+ <div class="alert alert-block" style="color:#8b0000;"><%= flash[:alert] %></div>
14
+ <% end %>
15
+
16
+ <%= yield %>
17
+
18
+ <ul>
19
+ <li>
20
+ <a href="/" id="home">Home</a>
21
+ </li>
22
+ </ul>
23
+ </body>
24
+ </html>
data/lib/views/new.erb ADDED
@@ -0,0 +1,9 @@
1
+ <form accept-charset="UTF-8" action="/feedback" method="post">
2
+ Enter your message or <a href="/">cancel</a>.<br/>
3
+ Type in following format <b>Subject:Message</b>, example : <br/>
4
+ <i>Fun Game:I really enjoy hangman extreme, keep up the good work!</i><br/>
5
+ <label for="feedback_full_message">Textarea:</label>
6
+ <input id="feedback_full_message" name="full_message" type="text" value=":" />
7
+ <input id="feedback_support_type" name="support_type" type="hidden" value="<%= support_type %>" />
8
+ <input name="commit" type="submit" value="send" />
9
+ </form>
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'quickapps_feedback/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'quickapps_feedback'
8
+ spec.version = QuickappsFeedback::VERSION
9
+ spec.authors = ['Grant Speelman']
10
+ spec.email = ['grant.speelman@ubxd.com']
11
+ spec.summary = %q(Simple sinatra rack middleware for quickapps feedback)
12
+ spec.description = %q(Simple sinatra rack middleware for quickapps feedback)
13
+ spec.homepage = ''
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'sinatra', '~> 1.4'
22
+ spec.add_dependency 'uservoice-ruby', '~> 0.0.11'
23
+ spec.add_dependency 'excon', '>= 0.39.0'
24
+
25
+ spec.add_development_dependency 'bundler', '~> 1.6'
26
+ spec.add_development_dependency 'sinatra-flash'
27
+ spec.add_development_dependency 'rake'
28
+ spec.add_development_dependency 'rubocop'
29
+ spec.add_development_dependency 'minitest'
30
+ spec.add_development_dependency 'capybara'
31
+ end
data/test/app_test.rb ADDED
@@ -0,0 +1,36 @@
1
+ require 'minitest/autorun'
2
+ ENV['RACK_ENV'] = 'test'
3
+
4
+ require '../lib/quickapps_feedback'
5
+ require 'sinatra/flash'
6
+ module QuickappsFeedback
7
+ class App < Sinatra::Base
8
+ enable :sessions
9
+ register Sinatra::Flash
10
+ end
11
+ end
12
+ require 'capybara'
13
+ require 'capybara/dsl'
14
+
15
+ describe 'test' do
16
+ include Capybara::DSL
17
+
18
+ def setup
19
+ Capybara.app = QuickappsFeedback::App.new
20
+ end
21
+
22
+ def test_it_works
23
+ add_headers('X_MXIT_USERID_R' => 'm40228998002')
24
+ visit '/feedback'
25
+ click_link('support')
26
+ fill_in 'feedback_full_message', with: 'I have a support issue for you'
27
+ click_button 'send'
28
+ assert page.has_css?('div.alert-info')
29
+ end
30
+
31
+ def add_headers(headers)
32
+ headers.each do |name, value|
33
+ page.driver.browser.header(name, value)
34
+ end
35
+ end
36
+ end
metadata ADDED
@@ -0,0 +1,188 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: quickapps_feedback
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Grant Speelman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sinatra
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: uservoice-ruby
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.0.11
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.0.11
41
+ - !ruby/object:Gem::Dependency
42
+ name: excon
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 0.39.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 0.39.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.6'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.6'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sinatra-flash
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: minitest
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: capybara
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: Simple sinatra rack middleware for quickapps feedback
140
+ email:
141
+ - grant.speelman@ubxd.com
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".gitignore"
147
+ - ".rubocop.yml"
148
+ - ".ruby-version"
149
+ - Gemfile
150
+ - LICENSE.txt
151
+ - README.md
152
+ - Rakefile
153
+ - lib/quickapps_feedback.rb
154
+ - lib/quickapps_feedback/feedback.rb
155
+ - lib/quickapps_feedback/send_feedback_to_uservoice.rb
156
+ - lib/quickapps_feedback/version.rb
157
+ - lib/views/index.erb
158
+ - lib/views/layout.erb
159
+ - lib/views/new.erb
160
+ - quickapps_feedback.gemspec
161
+ - test/app_test.rb
162
+ homepage: ''
163
+ licenses:
164
+ - MIT
165
+ metadata: {}
166
+ post_install_message:
167
+ rdoc_options: []
168
+ require_paths:
169
+ - lib
170
+ required_ruby_version: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - ">="
173
+ - !ruby/object:Gem::Version
174
+ version: '0'
175
+ required_rubygems_version: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - ">="
178
+ - !ruby/object:Gem::Version
179
+ version: '0'
180
+ requirements: []
181
+ rubyforge_project:
182
+ rubygems_version: 2.2.2
183
+ signing_key:
184
+ specification_version: 4
185
+ summary: Simple sinatra rack middleware for quickapps feedback
186
+ test_files:
187
+ - test/app_test.rb
188
+ has_rdoc: