gopollgo 0.1.6
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.
- data/LICENSE +20 -0
- data/README.markdown +28 -0
- data/lib/gopollgo.rb +51 -0
- metadata +142 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Go Poll Go, Inc.
|
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.markdown
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# GoPollGo API Wrapper
|
2
|
+
|
3
|
+
This is a simple Ruby wrapper to the GoPollGo API to make creating a poll super simple.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
Using the wrapper and creating a poll with your app takes only a few seconds.
|
8
|
+
|
9
|
+
require 'rubygems'
|
10
|
+
require 'gopollgo'
|
11
|
+
|
12
|
+
# Start a new client.
|
13
|
+
client = GoPollGo::Client.new(YOUR_API_KEY)
|
14
|
+
|
15
|
+
# Create a poll. The returned value is a Hash
|
16
|
+
# {
|
17
|
+
# "id" : "what-is-your-favorite-color",
|
18
|
+
# "embed_code" : "<a href=\"http://gopollgo.com/what-is-your-favorite-color-3\" id=\"what-is-your-favorite-color-3-placeholder\">View poll on GoPollGo</a><script>var GPG = window.GPG = window.GPG || {};GPG.slug=\"what-is-your-favorite-color-3\";GPG.path=\"http://localhost:3000\";(function() {var gs = document.createElement(\"script\");gs.type = \"text/javascript\";gs.src = \"http://c221023.r23.cf1.rackcdn.com/gpg_widget-89ae8ef8d8f611b350471738c71c81ca.js\";gs.defer = true;var s = document.getElementsByTagName('script')[0];s.parentNode.insertBefore(gs, s);})();</script>"
|
19
|
+
# }
|
20
|
+
poll = client.create_poll({
|
21
|
+
:question => "What is your favorite color?",
|
22
|
+
:options => ["Blue", "White", "Orange", "Green"]
|
23
|
+
})
|
24
|
+
|
25
|
+
|
26
|
+
## Copyright
|
27
|
+
|
28
|
+
Copyright (c) 2012 Go Poll Go, Inc.
|
data/lib/gopollgo.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module GoPollGo
|
5
|
+
class GoPollGoError < StandardError; end
|
6
|
+
class Unauthorized < StandardError; end
|
7
|
+
class BadArguments < StandardError; end
|
8
|
+
class UnknownResponseCode < StandardError; end
|
9
|
+
|
10
|
+
class Client
|
11
|
+
include HTTParty
|
12
|
+
|
13
|
+
base_uri 'http://gopollgo/api'
|
14
|
+
|
15
|
+
format :json
|
16
|
+
|
17
|
+
# In order to use the write portions of the API, you'll need an API key.
|
18
|
+
# If this is left blank, you'll still be able to use read-only portions
|
19
|
+
# of the API.
|
20
|
+
def initialize(key=nil)
|
21
|
+
@key = key
|
22
|
+
end
|
23
|
+
|
24
|
+
# Create a poll on GoPollGo
|
25
|
+
def create_poll(poll)
|
26
|
+
response = self.class.post('/polls',
|
27
|
+
:query => { :key => @key },
|
28
|
+
:body => {
|
29
|
+
:question => poll[:question],
|
30
|
+
:options => poll[:options]
|
31
|
+
}
|
32
|
+
)
|
33
|
+
|
34
|
+
case response.code
|
35
|
+
when 200
|
36
|
+
return JSON.parse(response.body)
|
37
|
+
when 400
|
38
|
+
raise BadArguments, "Bad Arguments. Please check your poll parameters."
|
39
|
+
when 401
|
40
|
+
raise Unauthorized, "Access denied. Check your API key."
|
41
|
+
when 500
|
42
|
+
raise GoPollGoError, "GoPollGo Internal Error. Please try again in a second. If this persists, please contact dev@gopollgo.com"
|
43
|
+
else
|
44
|
+
raise UnknownResponseCode, "Unexpected Status: #{response.code}"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
end
|
metadata
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gopollgo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 6
|
10
|
+
version: 0.1.6
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Ben Schaechter
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-07-18 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
requirement: *id001
|
33
|
+
name: jeweler
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - "="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
hash: 49
|
43
|
+
segments:
|
44
|
+
- 0
|
45
|
+
- 8
|
46
|
+
- 7
|
47
|
+
version: 0.8.7
|
48
|
+
requirement: *id002
|
49
|
+
name: rake
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
type: :runtime
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
hash: 3
|
59
|
+
segments:
|
60
|
+
- 0
|
61
|
+
version: "0"
|
62
|
+
requirement: *id003
|
63
|
+
name: rcov
|
64
|
+
- !ruby/object:Gem::Dependency
|
65
|
+
type: :runtime
|
66
|
+
prerelease: false
|
67
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ~>
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
hash: 19
|
73
|
+
segments:
|
74
|
+
- 0
|
75
|
+
- 7
|
76
|
+
- 8
|
77
|
+
version: 0.7.8
|
78
|
+
requirement: *id004
|
79
|
+
name: httparty
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
type: :development
|
82
|
+
prerelease: false
|
83
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ~>
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
hash: 3
|
89
|
+
segments:
|
90
|
+
- 2
|
91
|
+
- 0
|
92
|
+
version: "2.0"
|
93
|
+
requirement: *id005
|
94
|
+
name: rspec
|
95
|
+
description: A Ruby wrapper to the GoPollGo API for creating polls.
|
96
|
+
email: dev@gopollgo.com
|
97
|
+
executables: []
|
98
|
+
|
99
|
+
extensions: []
|
100
|
+
|
101
|
+
extra_rdoc_files:
|
102
|
+
- LICENSE
|
103
|
+
- README.markdown
|
104
|
+
files:
|
105
|
+
- lib/gopollgo.rb
|
106
|
+
- LICENSE
|
107
|
+
- README.markdown
|
108
|
+
homepage: http://github.com/gopollgo/gopollgo
|
109
|
+
licenses:
|
110
|
+
- MIT
|
111
|
+
post_install_message:
|
112
|
+
rdoc_options: []
|
113
|
+
|
114
|
+
require_paths:
|
115
|
+
- lib
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
+
none: false
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
hash: 3
|
122
|
+
segments:
|
123
|
+
- 0
|
124
|
+
version: "0"
|
125
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
|
+
none: false
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
hash: 3
|
131
|
+
segments:
|
132
|
+
- 0
|
133
|
+
version: "0"
|
134
|
+
requirements: []
|
135
|
+
|
136
|
+
rubyforge_project:
|
137
|
+
rubygems_version: 1.8.15
|
138
|
+
signing_key:
|
139
|
+
specification_version: 3
|
140
|
+
summary: A Ruby wrapper to the GoPollGo API.
|
141
|
+
test_files: []
|
142
|
+
|