command_feedback 0.0.1

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.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in command-feedback.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Christian Schwartz
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.
@@ -0,0 +1,29 @@
1
+ # Command::Feedback
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'command-feedback'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install command-feedback
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
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 new Pull Request
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "command_feedback"
4
+ require "optparse"
5
+
6
+ options = {}
7
+
8
+ optparse = OptionParser.new do |opts|
9
+ opts.banner = "Usage command-feedback [options] title choice1 choice2 ..."
10
+
11
+ options[:description] = ""
12
+ opts.on('-d', '--description DESCRIPTION', 'Add a description to the survey') do |description|
13
+ options[:description] = description
14
+ end
15
+
16
+ opts.on('-h', '--help', 'Display this screen') do
17
+ puts opts
18
+ exit
19
+ end
20
+ end
21
+
22
+
23
+ optparse.parse!
24
+
25
+ if ARGV.length > 2
26
+ title = ARGV.shift
27
+ choices = ARGV
28
+ description = options[:description]
29
+ feedback = CommandFeedback::Service.get_feedback title, choices, description
30
+ if feedback.successfull?
31
+ puts "Successfully created the feedback:"
32
+ puts "\t* Administration Link: #{ feedback.admin_link }"
33
+ puts "\t* Feedback Link: #{ feedback.feedback_link }"
34
+ else
35
+ puts "Failed to create the feedback:"
36
+ puts "\t* #{feedback.errors.join "\n\t* "}"
37
+ end
38
+ else
39
+ puts optparse
40
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'command_feedback/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "command_feedback"
8
+ gem.version = CommandFeedback::VERSION
9
+ gem.authors = ["Christian Schwartz"]
10
+ gem.email = ["christian.schwartz@gmail.com"]
11
+ gem.description = %q{An API and commandline tool for get-feedback.at}
12
+ gem.summary = %q{An API and commandline tool for get-feedback.at}
13
+ gem.homepage = "http://www.get-feedback.at"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency "httparty"
21
+ gem.add_development_dependency "rspec"
22
+ gem.add_development_dependency "webmock"
23
+ gem.add_development_dependency "vcr"
24
+ end
@@ -0,0 +1,6 @@
1
+ require "command_feedback/version"
2
+
3
+ module CommandFeedback
4
+ end
5
+
6
+ require "command_feedback/feedback"
@@ -0,0 +1,77 @@
1
+ require "httparty"
2
+
3
+
4
+ module CommandFeedback
5
+ class Service
6
+ def self.get_feedback title, choices, description = ""
7
+ service = Service.new title, choices, description
8
+ service.process
9
+ end
10
+
11
+ def initialize title, choices, description
12
+ body = {
13
+ "multiplechoice" => {
14
+ "title" => title,
15
+ "description" => description,
16
+ "choices" => Service.build_choices_hash(choices)
17
+ }
18
+ }
19
+ options = { :headers => { 'ContentType' => 'application/json' } }
20
+
21
+ hostname = "get-feedback.at"
22
+ @response = HTTParty.post "http://#{ hostname }/questions.json", :body => body, :options => options
23
+ end
24
+
25
+ def self.build_choices_hash(choices)
26
+ choices_hash = {}
27
+ choices.each_with_index { |choice, index|
28
+ choices_hash["choice_#{index + 1}"] = choice
29
+ }
30
+ choices_hash
31
+ end
32
+
33
+ def process
34
+ if was_successful?
35
+ SuccessfulFeedback.new(@response["question"])
36
+ else
37
+ ErrorFeedback.new(@response["errors"])
38
+ end
39
+ end
40
+
41
+ def was_successful?
42
+ @response.include? "question" and
43
+ @response["question"].include? "admin_link" and
44
+ @response["question"].include? "feedback_link"
45
+ end
46
+
47
+ class ErrorFeedback
48
+ attr_reader :errors
49
+
50
+ def initialize(error_data)
51
+ @errors = []
52
+ error_data.each { |attribute, errors|
53
+ errors.each { |error|
54
+ @errors << "#{attribute} #{error}"
55
+ }
56
+ }
57
+ end
58
+
59
+ def successfull?
60
+ false
61
+ end
62
+ end
63
+
64
+ class SuccessfulFeedback
65
+ attr_reader :admin_link, :feedback_link
66
+
67
+ def initialize(data_json)
68
+ @admin_link = data_json["admin_link"]
69
+ @feedback_link = data_json["feedback_link"]
70
+ end
71
+
72
+ def successfull?
73
+ true
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,3 @@
1
+ module CommandFeedback
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,47 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://get-feedback.at/questions.json
6
+ body:
7
+ encoding: US-ASCII
8
+ string: multiplechoice[title]=A%20title&multiplechoice[description]=A%20Description&multiplechoice[choices][choice_1]=Choice%201&multiplechoice[choices][choice_2]=Choice%202
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 200
13
+ message: OK
14
+ headers:
15
+ Date:
16
+ - Sun, 14 Oct 2012 15:32:14 GMT
17
+ Server:
18
+ - Apache/2.2.14 (Ubuntu)
19
+ X-Powered-By:
20
+ - Phusion Passenger (mod_rails/mod_rack) 3.0.17
21
+ X-Ua-Compatible:
22
+ - IE=Edge,chrome=1
23
+ Etag:
24
+ - ! '"8cef4b17860e39dc513506b0aa385496"'
25
+ Cache-Control:
26
+ - max-age=0, private, must-revalidate
27
+ X-Request-Id:
28
+ - 4cbc6dc59e3ca826f76ddecbe46fb62f
29
+ X-Runtime:
30
+ - '0.447327'
31
+ X-Rack-Cache:
32
+ - invalidate, pass
33
+ Set-Cookie:
34
+ - _get_feedback_session=BAh7B0kiD3Nlc3Npb25faWQGOgZFRkkiJThmZWYxNTMzNzcyNWQxYTFjYWI4NDE2ZTc4OWE4ZWFkBjsAVEkiEF9jc3JmX3Rva2VuBjsARkkiMWNweWhVdjFlM0t0c3JmY0FhcndiT2Q1SnI5VmcwNi9iQmNnbktFYklXcDA9BjsARg%3D%3D--495418c28ab14109964f99648c06450b9bc8939a;
35
+ path=/; HttpOnly
36
+ Status:
37
+ - '200'
38
+ Content-Length:
39
+ - '135'
40
+ Content-Type:
41
+ - application/json; charset=utf-8
42
+ body:
43
+ encoding: US-ASCII
44
+ string: ! '{"question":{"admin_link":"http://get-feedback.at/questions/7-admin-RR12","feedback_link":"http://get-feedback.at/answers/new.7-RR12"}}'
45
+ http_version:
46
+ recorded_at: Sun, 14 Oct 2012 15:32:19 GMT
47
+ recorded_with: VCR 2.2.5
@@ -0,0 +1,48 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://get-feedback.at/questions.json
6
+ body:
7
+ encoding: US-ASCII
8
+ string: multiplechoice[title]=A%20title&multiplechoice[description]=A%20Description&multiplechoice[choices][choice_1]=Choice%201
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 200
13
+ message: OK
14
+ headers:
15
+ Date:
16
+ - Sun, 14 Oct 2012 15:32:20 GMT
17
+ Server:
18
+ - Apache/2.2.14 (Ubuntu)
19
+ X-Powered-By:
20
+ - Phusion Passenger (mod_rails/mod_rack) 3.0.17
21
+ X-Ua-Compatible:
22
+ - IE=Edge,chrome=1
23
+ Etag:
24
+ - ! '"82ab65a739525c5dff9c645e6072c1cc"'
25
+ Cache-Control:
26
+ - max-age=0, private, must-revalidate
27
+ X-Request-Id:
28
+ - be7e7b36bceffd473f83ca43fb6ab30d
29
+ X-Runtime:
30
+ - '0.008238'
31
+ X-Rack-Cache:
32
+ - invalidate, pass
33
+ Set-Cookie:
34
+ - _get_feedback_session=BAh7B0kiD3Nlc3Npb25faWQGOgZFRkkiJThiNzMwZjc1NTBiMjdiYTI0N2Q4NzJjMGVkZTgxNDgwBjsAVEkiEF9jc3JmX3Rva2VuBjsARkkiMXcycGttUDRiUlYvN0R0aDdCM2VOQ2FYZXQyak81NXZDaFIwUW9JTzZlQW89BjsARg%3D%3D--52eeede2ff97c40ca8c88ed33dee0ff1915e3e41;
35
+ path=/; HttpOnly
36
+ Status:
37
+ - '200'
38
+ Content-Length:
39
+ - '159'
40
+ Content-Type:
41
+ - application/json; charset=utf-8
42
+ body:
43
+ encoding: US-ASCII
44
+ string: ! '{"question":{"title":"A title","description":"A Description","choices":[{"description":"Choice
45
+ 1"}]},"errors":{"choices":["must contain at least two items."]}}'
46
+ http_version:
47
+ recorded_at: Sun, 14 Oct 2012 15:32:20 GMT
48
+ recorded_with: VCR 2.2.5
@@ -0,0 +1,49 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://get-feedback.at/questions.json
6
+ body:
7
+ encoding: US-ASCII
8
+ string: multiplechoice[title]=A&multiplechoice[description]=A%20Description&multiplechoice[choices][choice_1]=Choice%201&multiplechoice[choices][choice_2]=Choice%202
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 200
13
+ message: OK
14
+ headers:
15
+ Date:
16
+ - Sun, 14 Oct 2012 15:32:19 GMT
17
+ Server:
18
+ - Apache/2.2.14 (Ubuntu)
19
+ X-Powered-By:
20
+ - Phusion Passenger (mod_rails/mod_rack) 3.0.17
21
+ X-Ua-Compatible:
22
+ - IE=Edge,chrome=1
23
+ Etag:
24
+ - ! '"9a234567d8e380cc47bec7cd146b5fb8"'
25
+ Cache-Control:
26
+ - max-age=0, private, must-revalidate
27
+ X-Request-Id:
28
+ - e6e043692179d80355e74591a300bdd2
29
+ X-Runtime:
30
+ - '0.047420'
31
+ X-Rack-Cache:
32
+ - invalidate, pass
33
+ Set-Cookie:
34
+ - _get_feedback_session=BAh7B0kiD3Nlc3Npb25faWQGOgZFRkkiJTlmMmM2YmYwYzk4NzUzMGQ5Yzc5ZTczYzQwODg2MTI3BjsAVEkiEF9jc3JmX3Rva2VuBjsARkkiMTdLU3kvdVFsOVlGZFBWdncydjZ2bnZtalBUaHJHRU9GY0Vuc24xRW9OSWM9BjsARg%3D%3D--53daa44ceb6c1cd3198b201b4d781d08b0589e57;
35
+ path=/; HttpOnly
36
+ Status:
37
+ - '200'
38
+ Content-Length:
39
+ - '184'
40
+ Content-Type:
41
+ - application/json; charset=utf-8
42
+ body:
43
+ encoding: US-ASCII
44
+ string: ! '{"question":{"title":"A","description":"A Description","choices":[{"description":"Choice
45
+ 1"},{"description":"Choice 2"}]},"errors":{"title":["is too short (minimum
46
+ is 4 characters)"]}}'
47
+ http_version:
48
+ recorded_at: Sun, 14 Oct 2012 15:32:20 GMT
49
+ recorded_with: VCR 2.2.5
@@ -0,0 +1,38 @@
1
+ require "spec_helper"
2
+
3
+ include CommandFeedback
4
+
5
+ describe Service do
6
+ describe "calls out to the REST api" do
7
+ it "successfull" do
8
+ VCR.use_cassette "successfull" do
9
+ feedback = Service.get_feedback "A title", ["Choice 1", "Choice 2"], "A Description"
10
+ expect(feedback.successfull?).to eq(true)
11
+ expect(feedback.admin_link).to eq("http://get-feedback.at/questions/7-admin-RR12")
12
+ expect(feedback.feedback_link).to eq("http://get-feedback.at/answers/new.7-RR12")
13
+ end
14
+ end
15
+
16
+ it "unsuccessfull, too short title" do
17
+ VCR.use_cassette "unsuccessfull-title" do
18
+ feedback = Service.get_feedback "A", ["Choice 1", "Choice 2"], "A Description"
19
+ expect(feedback.successfull?).to eq(false)
20
+ expect(feedback.errors).to include('title is too short (minimum is 4 characters)')
21
+ end
22
+ end
23
+
24
+ it "unsuccessfull, not enough choices" do
25
+ VCR.use_cassette "unsuccessfull-choices" do
26
+ feedback = Service.get_feedback "A title", ["Choice 1"], "A Description"
27
+ expect(feedback.successfull?).to eq(false)
28
+ expect(feedback.errors).to include('choices must contain at least two items.')
29
+ end
30
+ end
31
+
32
+ end
33
+
34
+ it "builds a choices hash" do
35
+ choices = ["a", "b"]
36
+ expect(Service.build_choices_hash(choices)).to eq({"choice_1" => "a", "choice_2" => "b"})
37
+ end
38
+ end
@@ -0,0 +1,27 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+
8
+ require "command_feedback"
9
+
10
+ require "vcr"
11
+
12
+ VCR.configure do |c|
13
+ c.cassette_library_dir = "spec/cassetes"
14
+ c.hook_into :webmock
15
+ end
16
+
17
+ RSpec.configure do |config|
18
+ config.treat_symbols_as_metadata_keys_with_true_values = true
19
+ config.run_all_when_everything_filtered = true
20
+ config.filter_run :focus
21
+
22
+ # Run specs in random order to surface order dependencies. If you find an
23
+ # order dependency and want to debug it, you can fix the order by providing
24
+ # the seed, which is printed after each run.
25
+ # --seed 1234
26
+ config.order = 'random'
27
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: command_feedback
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Christian Schwartz
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-16 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: webmock
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: vcr
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: An API and commandline tool for get-feedback.at
79
+ email:
80
+ - christian.schwartz@gmail.com
81
+ executables:
82
+ - command_feedback
83
+ extensions: []
84
+ extra_rdoc_files: []
85
+ files:
86
+ - .gitignore
87
+ - .rspec
88
+ - Gemfile
89
+ - LICENSE.txt
90
+ - README.md
91
+ - Rakefile
92
+ - bin/command_feedback
93
+ - command_feedback.gemspec
94
+ - lib/command_feedback.rb
95
+ - lib/command_feedback/feedback.rb
96
+ - lib/command_feedback/version.rb
97
+ - spec/cassetes/successfull.yml
98
+ - spec/cassetes/unsuccessfull-choices.yml
99
+ - spec/cassetes/unsuccessfull-title.yml
100
+ - spec/command_feedback_spec.rb
101
+ - spec/spec_helper.rb
102
+ homepage: http://www.get-feedback.at
103
+ licenses: []
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ! '>='
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ! '>='
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 1.8.23
123
+ signing_key:
124
+ specification_version: 3
125
+ summary: An API and commandline tool for get-feedback.at
126
+ test_files:
127
+ - spec/cassetes/successfull.yml
128
+ - spec/cassetes/unsuccessfull-choices.yml
129
+ - spec/cassetes/unsuccessfull-title.yml
130
+ - spec/command_feedback_spec.rb
131
+ - spec/spec_helper.rb