polleverywhere 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,5 +1,6 @@
1
1
  .DS_Store
2
2
  *.gem
3
3
  .bundle
4
+ .sass-cache
4
5
  Gemfile.lock
5
6
  pkg/*
data/Gemfile CHANGED
@@ -11,4 +11,9 @@ group :development, :test do
11
11
  gem 'haml'
12
12
  gem 'rake'
13
13
  gem 'ruby-debug19'
14
+ end
15
+
16
+ group :api_docs do
17
+ gem 'middleman'
18
+ gem 'sourcify'
14
19
  end
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Poll Everywhere API Gem
1
+ # The Official Poll Everywhere API Gem
2
2
 
3
3
  The Poll Everywhere gem is the best way to integrate Poll Everywhere with your applications.
4
4
 
@@ -22,19 +22,20 @@ If you're using bundler, add the following line to your Gemfile:
22
22
  password "my_password"
23
23
  end
24
24
 
25
- # Now start playing!
26
- polls = PollEverywhere::Poll.all
27
- poll = poll.first
28
- poll.close
29
- poll.title = "Hey there, I like changing titles around"
30
- poll.options = %w[uno dos tres]
25
+ # Create a multiple choice poll
26
+ poll = PollEverywhere::MultipleChoicePoll.new
27
+ poll.title = 'Do you love numbers?'
28
+ poll.options = %w[1 2 3]
29
+ poll.save
30
+ # Create a free text poll
31
+ poll = PollEverywhere::FreeTextPoll.new
32
+ poll.title = 'What is your favorite thing about vacation?'
31
33
  poll.save
32
- poll.open
34
+ # Now start playing! Get a list of your polls
35
+ polls = PollEverywhere::Poll.all
33
36
 
34
37
  You can do all sorts of fun stuff with polls!
35
38
 
36
- # TODO
37
-
38
39
  A roadmap for our API:
39
40
 
40
41
  * API models and documentation for more pieces of our application
data/Rakefile CHANGED
@@ -1,14 +1,15 @@
1
1
  require 'bundler'
2
2
  Bundler::GemHelper.install_tasks
3
- require 'haml'
4
3
  require 'polleverywhere'
5
4
 
6
5
  namespace :doc do
7
6
  desc "Generate API documentation"
8
7
  task :api do
9
8
  PollEverywhere.config do
10
- username "test"
11
- password "test"
9
+ username "test"
10
+ password "test"
11
+ url "http://api.polleverywhere.com"
12
+ http_adapter :doc
12
13
  end
13
14
 
14
15
  puts PollEverywhere::API::Documentation.generate
File without changes
data/api/config.rb ADDED
@@ -0,0 +1,64 @@
1
+ # CodeRay syntax highlighting in Haml
2
+ # activate :code_ray
3
+
4
+ # Automatic sitemaps (gem install middleman-slickmap)
5
+ # require "middleman-slickmap"
6
+ # activate :slickmap
7
+
8
+ # Automatic image dimension calculations
9
+ # activate :automatic_image_sizes
10
+
11
+ # Per-page layout changes
12
+ # With no layout
13
+ # page "/path/to/file.html", :layout => false
14
+ # With alternative layout
15
+ # page "/path/to/file.html", :layout => :otherlayout
16
+
17
+ # Helpers
18
+ helpers do
19
+ def examples(model)
20
+ model.http.adapter.request.to_curl
21
+ end
22
+
23
+ def example(&block)
24
+ formats = {}
25
+ block.call
26
+ # formats[:ruby] = block.to_source(:strip_enclosure => true)
27
+ formats[:curl] = PollEverywhere.config.http_adapter.last_requests.map(&:to_curl).join("\n\n")
28
+ puts formats.map{ |format, example| %(<pre class="#{format}">#{example}</pre>) }.join
29
+ end
30
+ end
31
+
32
+ # Change the CSS directory
33
+ # set :css_dir, "alternative_css_directory"
34
+
35
+ # Change the JS directory
36
+ # set :js_dir, "alternative_js_directory"
37
+
38
+ # Change the images directory
39
+ # set :images_dir, "alternative_image_directory"
40
+
41
+ # Build-specific configuration
42
+ configure :build do
43
+ # For example, change the Compass output style for deployment
44
+ # activate :minify_css
45
+
46
+ # Minify Javascript on build
47
+ # activate :minify_javascript
48
+
49
+ # Enable cache buster
50
+ # activate :cache_buster
51
+
52
+ # Use relative URLs
53
+ # activate :relative_assets
54
+
55
+ # Compress PNGs after build (gem install middleman-smusher)
56
+ # require "middleman-smusher"
57
+ # activate :smusher
58
+
59
+ # Generate ugly/obfuscated HTML from Haml
60
+ # activate :ugly_haml
61
+
62
+ # Or use a different image path
63
+ # set :http_path, "/Content/images/"
64
+ end
data/api/config.ru ADDED
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'middleman'
4
+ require 'polleverywhere'
5
+ require 'sourcify'
6
+
7
+ PollEverywhere.config do
8
+ username "test"
9
+ password "test"
10
+ url "http://localhost:3000"
11
+ http_adapter :doc
12
+ end
13
+
14
+ run Middleman::Server
@@ -0,0 +1,112 @@
1
+ !!! html
2
+ %html
3
+ %head
4
+ %title Poll Everywhere API
5
+ %body
6
+ %header
7
+ %h1 Poll Everywhere API Documentation
8
+
9
+ %section
10
+ %p This API assumes that you are familar with the low-level semantics of HTTP, including the use of tools like cURL, and JSON.
11
+
12
+ %h1 Authentication
13
+ %p HTTP Basic authentication is currently used for logging into Poll Everywhere accounts. More information can be found at <a href="http://en.wikipedia.org/HTTP Basic">Wikipedia</a>.
14
+
15
+ %h1 We use JSON
16
+ %p Simple JSON key-value data structures are used throughout the API application to persist and modify data to the web application. Typically resources will include a root key that corresponds with the name of the name of the resource; from example, multiple choice polls all have the root key 'multiple_choice_poll'.
17
+
18
+ %h1 Polls
19
+ %h2 Multiple choice polls
20
+ %p These polls are great for collecting structured information from audiences if you want to define a set of answers that participants may choose from.
21
+
22
+ %h3 Attributes
23
+ %dl.attributes
24
+ %dt=PollEverywhere::MultipleChoicePoll.root_key
25
+ %dd Root key for multiple choice poll data.
26
+ %dd
27
+ %dl
28
+ -PollEverywhere::MultipleChoicePoll.props.each do |_, prop|
29
+ %dt=prop.name
30
+ %dd=prop.description
31
+ -if prop.name == :options
32
+ %dd
33
+ %dl
34
+ -PollEverywhere::MultipleChoicePoll::Option.props.each do |_, prop|
35
+ %dt=prop.name
36
+ %dd=prop.description
37
+ %h3 Creating a multiple choice poll
38
+ :ruby
39
+ example do
40
+ @mcp = PollEverywhere::MultipleChoicePoll.from_hash(:title => 'Hey dude!', :options => %w[red blue green]).save
41
+ end
42
+
43
+ %h3 Changing the title of a multiple choice poll
44
+ :ruby
45
+ example do
46
+ @mcp.title = "I like different titles"
47
+ @mcp.save
48
+ end
49
+
50
+ %h3 Closing and opening multiple choice polls
51
+ %p To close a poll, change the state to "closed"
52
+ :ruby
53
+ example do
54
+ @mcp.stop
55
+ end
56
+
57
+ %p To open it back up (and allow responses to come on through) change the state to "opened"
58
+ :ruby
59
+ example do
60
+ @mcp.start
61
+ end
62
+
63
+ %h3 Delete a multiple choice poll
64
+ %p When you're totally finished with the poll and you want to tidy things up a bit, you can delete polls
65
+ :ruby
66
+ example do
67
+ @mcp.destroy
68
+ end
69
+
70
+ %h2 Free text polls
71
+ %p These polls are used to collect short answers or unstructured responses from participants.
72
+ %h3 Attributes
73
+ %dl.attributes
74
+ %dt=PollEverywhere::FTP.root_key
75
+ %dd Root key for free text poll data.
76
+ %dd
77
+ %dl
78
+ -PollEverywhere::FTP.props.each do |_, prop|
79
+ %dt=prop.name
80
+ %dd=prop.description
81
+
82
+ %h3 Create free text polls
83
+ %p Creating a free text poll is similar to building a multiple choice poll, just without the options attribute.
84
+ :ruby
85
+ example do
86
+ @ftp = PollEverywhere::FreeTextPoll.from_hash(:title => "What is the meaning of life?").save
87
+ end
88
+
89
+ %h3 Modify a free text poll
90
+ %p Change the title attribute to change the poll
91
+ :ruby
92
+ example do
93
+ @ftp.state = "opened"
94
+ @ftp.save
95
+ end
96
+
97
+ %h3 Delete a free text poll
98
+ :ruby
99
+ example do
100
+ @ftp.destroy
101
+ end
102
+
103
+ %footer
104
+ %p
105
+ This documentation was automatically generated by the Poll Everywhere rubygem at
106
+ =succeed '.' do
107
+ %a(href="http://github.com/polleverywhere/polleverywhere") http://github.com/polleverywhere/polleverywhere
108
+ Community support for the API is available on the
109
+ %a(href="http://groups.google.com/group/polleverywhere-dev") Poll Everywhere Developer mailing list
110
+ and paid professional support at
111
+ =succeed '.' do
112
+ %a(href="http://www.polleverywhere.com/professional-support") Poll Everywhere
@@ -0,0 +1,21 @@
1
+ !!! 5
2
+ %html{ :lang => "en" }
3
+ %head
4
+ %meta{ :charset => "utf-8" }
5
+
6
+ / Always force latest IE rendering engine (even in intranet) & Chrome Frame
7
+ %meta{ :content => "IE=edge,chrome=1", "http-equiv" => "X-UA-Compatible" }
8
+
9
+ / Comment in layout
10
+
11
+ = stylesheet_link_tag "site.css"
12
+
13
+ :javascript
14
+ // Comment in javascript
15
+
16
+ = yield_content :head
17
+
18
+ %body{ :class => page_classes }
19
+
20
+ #main{ :role => "main" }
21
+ = yield
@@ -0,0 +1,42 @@
1
+ @import "compass"
2
+
3
+ $base-font-size: 16px
4
+ $code-font-size: 13px
5
+
6
+ body
7
+ font:
8
+ family: Georgia, Palatino, "Palatino Linotype", Times, "Times New Roman", serif
9
+ size: $base-font-size
10
+ width: 40em
11
+ margin: auto auto
12
+
13
+ code
14
+ font-family: monaco, courier
15
+ font-size: $code-font-size
16
+ line-height: $base-font-size
17
+ padding: $base-font-size
18
+ display: block
19
+ padding: 1em
20
+ background: #eee
21
+ margin: 1em 0
22
+
23
+ h1,h2,h3,h4,h5,h6
24
+ font-weight: normal
25
+
26
+ h1
27
+ font-size: 30px
28
+ h2
29
+ font-size: 24px
30
+ h3,h4,h5.h6
31
+ font-size: 20px
32
+
33
+ dl.attributes
34
+ dt
35
+ margin-top: 1em
36
+ font-family: courier
37
+ font-size: $code-font-size
38
+ line-height: $base-font-size
39
+ dl, dd
40
+ margin-left: 0
41
+ dd > dl
42
+ margin-left: 1em
data/docs/api.haml CHANGED
@@ -5,21 +5,22 @@
5
5
  %body
6
6
  %header
7
7
  %h1 Poll Everywhere API Documentation
8
- %em Disclaimer: this documentation is only intended for an internal preview. Hold off on using this stuff until we announce it on our blog.
9
8
 
10
9
  %section
11
10
  %p This API assumes that you are familar with the low-level semantics of HTTP, including the use of tools like cURL, and JSON.
12
11
 
13
12
  %h1 Authentication
14
- %p HTTP Basic authentication is currently used for logging into Poll Everywhere accounts.
13
+ %p HTTP Basic authentication is currently used for logging into Poll Everywhere accounts. More information can be found at <a href="http://en.wikipedia.org/HTTP Basic">Wikipedia</a>.
15
14
 
16
15
  %h1 We use JSON
17
16
  %p Simple JSON key-value data structures are used throughout the API application to persist and modify data to the web application. Typically resources will include a root key that corresponds with the name of the name of the resource; from example, multiple choice polls all have the root key 'multiple_choice_poll'.
18
-
17
+
19
18
  %h1 Polls
20
19
  %h2 Multiple choice polls
21
- %h3 JSON Attributes
22
- %dl
20
+ %p These polls are great for collecting structured information from audiences if you want to define a set of answers that participants may choose from.
21
+
22
+ %h3 Attributes
23
+ %dl.attributes
23
24
  %dt=PollEverywhere::MultipleChoicePoll.root_key
24
25
  %dd Root key for multiple choice poll data.
25
26
  %dd
@@ -33,33 +34,43 @@
33
34
  -PollEverywhere::MultipleChoicePoll::Option.props.each do |_, prop|
34
35
  %dt=prop.name
35
36
  %dd=prop.description
36
-
37
37
  %h3 Creating a multiple choice poll
38
- -@mcp = PollEverywhere::MultipleChoicePoll.from_hash(:title => 'Hey dude!', :options => %w[red blue green]).save
39
- %code=examples @mcp
40
-
41
- %h3 Changing the title of the multiple choice poll
42
- -@mcp.title = "I like different titles"
43
- -@mcp.save
44
- %code=examples @mcp
38
+ :ruby
39
+ example do
40
+ @mcp = PollEverywhere::MultipleChoicePoll.from_hash(:title => 'Hey dude!', :options => %w[red blue green]).save
41
+ end
42
+
43
+ %h3 Changing the title of a multiple choice poll
44
+ :ruby
45
+ example do
46
+ @mcp.title = "I like different titles"
47
+ @mcp.save
48
+ end
45
49
 
46
50
  %h3 Closing and opening multiple choice polls
47
51
  %p To close a poll, change the state to "closed"
48
- -@mcp.stop
49
- %code=examples @mcp
52
+ :ruby
53
+ example do
54
+ @mcp.stop
55
+ end
50
56
 
51
57
  %p To open it back up (and allow responses to come on through) change the state to "opened"
52
- -@mcp.start
53
- %code=examples @mcp
58
+ :ruby
59
+ example do
60
+ @mcp.start
61
+ end
54
62
 
55
63
  %h3 Delete a multiple choice poll
56
64
  %p When you're totally finished with the poll and you want to tidy things up a bit, you can delete polls
57
- -@mcp.destroy
58
- %code=examples @mcp
59
-
65
+ :ruby
66
+ example do
67
+ @mcp.destroy
68
+ end
69
+
60
70
  %h2 Free text polls
61
- %h3 JSON Attributes
62
- %dl
71
+ %p These polls are used to collect short answers or unstructured responses from participants.
72
+ %h3 Attributes
73
+ %dl.attributes
63
74
  %dt=PollEverywhere::FTP.root_key
64
75
  %dd Root key for free text poll data.
65
76
  %dd
@@ -70,18 +81,25 @@
70
81
 
71
82
  %h3 Create free text polls
72
83
  %p Creating a free text poll is similar to building a multiple choice poll, just without the options attribute.
73
- -@ftp = PollEverywhere::FreeTextPoll.from_hash(:title => "What is the meaning of life?").save
74
- %code=examples @ftp
75
-
84
+ :ruby
85
+ example do
86
+ @ftp = PollEverywhere::FreeTextPoll.from_hash(:title => "What is the meaning of life?").save
87
+ end
88
+
76
89
  %h3 Modify a free text poll
77
90
  %p Change the title attribute to change the poll
78
- -@ftp.state = "opened"
79
- -@ftp.save
80
- %code=examples @ftp
81
-
91
+ :ruby
92
+ example do
93
+ @ftp.state = "opened"
94
+ @ftp.save
95
+ end
96
+
82
97
  %h3 Delete a free text poll
83
- -@ftp.destroy
84
- %code=examples @ftp
98
+ :ruby
99
+ example do
100
+ @ftp.destroy
101
+ end
102
+
85
103
  %footer
86
104
  %p
87
105
  This documentation was automatically generated by the Poll Everywhere rubygem at
@@ -1,3 +1,4 @@
1
+ # require 'sourcify'
1
2
  require 'haml'
2
3
 
3
4
  module PollEverywhere
@@ -23,6 +24,14 @@ module PollEverywhere
23
24
  def examples(model)
24
25
  model.http.adapter.request.to_curl
25
26
  end
27
+
28
+ def example(&block)
29
+ formats = {}
30
+ block.call
31
+ # formats[:ruby] = block.to_source(:strip_enclosure => true)
32
+ formats[:curl] = PollEverywhere.config.http_adapter.last_requests.map(&:to_curl).join("\n\n")
33
+ puts formats.map{ |format, example| %(<pre class="#{format}">#{example}</pre>) }.join
34
+ end
26
35
  end
27
36
  end
28
37
  end
@@ -27,7 +27,7 @@ module PollEverywhere
27
27
  # this form of authorization will be replaced with a token authorization
28
28
  # so that a password is not required.
29
29
  def http_basic_credentials
30
- "Basic #{Base64.encode64("#{username}:#{password}")}"
30
+ "Basic #{Base64.encode64("#{username}:#{password}")}".chomp
31
31
  end
32
32
  end
33
33
  end
@@ -33,7 +33,7 @@ module PollEverywhere
33
33
  requests << request
34
34
  super request, &block
35
35
  end
36
-
36
+
37
37
  def requests
38
38
  @requests ||= []
39
39
  end
@@ -11,7 +11,7 @@ module PollEverywhere
11
11
  # Simple HTTP request/response objects for our adapter and DSL
12
12
  class Request < Struct.new(:method, :url, :headers, :body)
13
13
  def to_curl
14
- %(curl -X #{method.to_s.upcase} #{headers.map{|h,v| %(-H "#{h}: #{v}")}.join(" ")} -d "#{body.gsub(/[!"`']/){|m| "\\#{m}" }}" "#{url}")
14
+ %(curl -X #{method.to_s.upcase} #{headers.map{|h,v| %(-H "#{h}: #{v}")}.join(" ")} -d "#{body.gsub(/[!"`'\n]/){|m| "\\#{m}" }}" "#{url}")
15
15
  end
16
16
  end
17
17
 
@@ -1,10 +1,9 @@
1
1
  module PollEverywhere # :nodoc
2
2
  module Models # :nodoc
3
-
4
- # Poll is an abstract base classe for multiple choice and free text polls
3
+ # Poll is an abstract base class for multiple choice and free text polls
5
4
  class Poll
6
5
  include Serializable
7
-
6
+
8
7
  prop :id
9
8
 
10
9
  prop :updated_at do
@@ -19,10 +18,6 @@ module PollEverywhere # :nodoc
19
18
  description %{Data and time that the poll was started.}
20
19
  end
21
20
 
22
- prop :options do
23
- description %{The possible choices that people choose for a poll.}
24
- end
25
-
26
21
  prop :permalink do
27
22
  description %{An obscufated ID that's used as a private link for sharing the poll}
28
23
  end
@@ -39,13 +34,13 @@ module PollEverywhere # :nodoc
39
34
 
40
35
  # Start the poll so that it may receive audience responses
41
36
  def start
42
- state = "opened"
37
+ self.state = "opened"
43
38
  save
44
39
  end
45
40
 
46
41
  # Stop the poll so that it stops receieving responses
47
42
  def stop
48
- state = "closed"
43
+ self.state = "closed"
49
44
  save
50
45
  end
51
46
 
@@ -109,10 +104,16 @@ module PollEverywhere # :nodoc
109
104
 
110
105
  root_key :multiple_choice_poll
111
106
 
107
+ prop :options do
108
+ description %{The possible choices that people choose for a poll.}
109
+ end
110
+
112
111
  class Option
113
112
  include Serializable
114
113
 
115
- prop :id
114
+ prop :id do
115
+ description "Unique identifier for the option. This is primarily used to keep track of what option attributes are changed."
116
+ end
116
117
 
117
118
  prop :value do
118
119
  description "Text that is displayed in the chart that represents what a participant chooses when they response to a poll."
@@ -1,3 +1,3 @@
1
1
  module Polleverywhere
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -7,14 +7,15 @@ Gem::Specification.new do |s|
7
7
  s.version = Polleverywhere::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ["Brad Gessler, Steel Fu"]
10
- s.email = ["geeks@polleverywhere.com"]
11
- s.homepage = "http://www.polleverywhere.com/"
12
- s.summary = %q{Integration Poll Everywhere into your Ruby applications}
10
+ s.email = ["opensource@polleverywhere.com"]
11
+ s.homepage = "http://www.github.com/polleverywhere/polleverywhere"
12
+ s.summary = %q{Integrate Poll Everywhere into your Ruby applications}
13
13
  s.description = %q{An easy way to integrate Poll Everywhere into your Ruby applications.}
14
-
14
+
15
15
  s.rubyforge_project = "polleverywhere"
16
16
  s.add_dependency "json"
17
- s.add_development_dependency "rest-client", "~> 1.6.3"
17
+ # TODO get rid of this dependency by using Ruby Net::HTTP
18
+ s.add_dependency "rest-client", "~> 1.6.3"
18
19
 
19
20
  s.files = `git ls-files`.split("\n")
20
21
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -60,6 +60,16 @@ describe "API" do
60
60
  it "should update title" do
61
61
  @mcp.title.should eql("My pita bread is moldy")
62
62
  end
63
+
64
+ it "should start" do
65
+ @mcp.start
66
+ @mcp.state.should eql("opened")
67
+ end
68
+
69
+ it "should stop" do
70
+ @mcp.stop
71
+ @mcp.state.should eql("closed")
72
+ end
63
73
  end
64
74
 
65
75
  it "should destroy" do
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: polleverywhere
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.2
5
+ version: 0.0.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - Brad Gessler, Steel Fu
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-06-24 00:00:00 -07:00
13
+ date: 2011-06-27 00:00:00 -06:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -33,11 +33,11 @@ dependencies:
33
33
  - - ~>
34
34
  - !ruby/object:Gem::Version
35
35
  version: 1.6.3
36
- type: :development
36
+ type: :runtime
37
37
  version_requirements: *id002
38
38
  description: An easy way to integrate Poll Everywhere into your Ruby applications.
39
39
  email:
40
- - geeks@polleverywhere.com
40
+ - opensource@polleverywhere.com
41
41
  executables: []
42
42
 
43
43
  extensions: []
@@ -51,6 +51,12 @@ files:
51
51
  - Guardfile
52
52
  - README.md
53
53
  - Rakefile
54
+ - api/build/index.html
55
+ - api/config.rb
56
+ - api/config.ru
57
+ - api/views/index.html.haml
58
+ - api/views/layout.haml
59
+ - api/views/stylesheets/site.css.sass
54
60
  - docs/api.haml
55
61
  - lib/polleverywhere.rb
56
62
  - lib/polleverywhere/api.rb
@@ -68,7 +74,7 @@ files:
68
74
  - spec/lib/polleverywhere_spec.rb
69
75
  - spec/spec_helper.rb
70
76
  has_rdoc: true
71
- homepage: http://www.polleverywhere.com/
77
+ homepage: http://www.github.com/polleverywhere/polleverywhere
72
78
  licenses: []
73
79
 
74
80
  post_install_message:
@@ -94,7 +100,7 @@ rubyforge_project: polleverywhere
94
100
  rubygems_version: 1.5.2
95
101
  signing_key:
96
102
  specification_version: 3
97
- summary: Integration Poll Everywhere into your Ruby applications
103
+ summary: Integrate Poll Everywhere into your Ruby applications
98
104
  test_files:
99
105
  - spec/integration/api_spec.rb
100
106
  - spec/lib/polleverywhere_spec.rb