strawpoll_api 1.0.1 → 1.0.2
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.
- checksums.yaml +4 -4
- data/lib/strawpoll_api.rb +47 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d52add7f7588481f81fa44ccd052d5aff858fe5
|
4
|
+
data.tar.gz: 619eb7429505c42420dcc257d24231ead2e0e38f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d69cce4b994376dc8612d3da097406beab4ad00973dd4a73180a0bbe6efeb87a2a6e653d436f062be0f89bab426722b7b107e7e3eae5d421d33e2b44aac40ed
|
7
|
+
data.tar.gz: 189ea76eab268ea9f9e180193f0eedd6a61c0e02e452de3009321a76e207e3f8d97b07695a3660778c685bc8adfcaa87bca65974eeab6e87b5e697ce9d794341
|
data/lib/strawpoll_api.rb
CHANGED
@@ -1,10 +1,33 @@
|
|
1
1
|
require 'json'
|
2
2
|
require 'net/http'
|
3
3
|
|
4
|
+
##
|
5
|
+
# This class stores a poll instance that can interact with www.strawpoll.me
|
6
|
+
# Creates a poll object which you can customize and then
|
7
|
+
# publish online.
|
8
|
+
#
|
9
|
+
# An ArgumentError is raised if you have less than two
|
10
|
+
# options in your poll
|
4
11
|
class StrawPoll
|
12
|
+
##
|
13
|
+
# These attributes can be changed in the same manner
|
14
|
+
# that can be done on the strawpoll.me website
|
15
|
+
|
5
16
|
attr_accessor :title, :multi, :perm, :options
|
17
|
+
|
18
|
+
##
|
19
|
+
# These attributes are internally use to track state
|
20
|
+
# and provide some quickyl accesible features from online polls
|
21
|
+
|
6
22
|
attr_reader :api, :id, :leader, :votes, :link, :results
|
7
23
|
|
24
|
+
##
|
25
|
+
# Creates a new poll instance
|
26
|
+
#
|
27
|
+
# Returns StrawPoll Object
|
28
|
+
#
|
29
|
+
# An ArgumentError is raised if passed less than two options
|
30
|
+
|
8
31
|
def initialize title, *options
|
9
32
|
raise ArgumentError unless options.length >= 2
|
10
33
|
@title = title
|
@@ -19,6 +42,14 @@ class StrawPoll
|
|
19
42
|
@results = nil
|
20
43
|
end
|
21
44
|
|
45
|
+
##
|
46
|
+
# Publishes poll online and setups links for distribution
|
47
|
+
#
|
48
|
+
# Returns raw HTTP body
|
49
|
+
#
|
50
|
+
# An ArgumentError is raised if title is remove or options are
|
51
|
+
# reduced below 2
|
52
|
+
|
22
53
|
def create!
|
23
54
|
raise ArgumentError unless !@title.empty? && @options.length >= 2
|
24
55
|
params = {
|
@@ -35,12 +66,28 @@ class StrawPoll
|
|
35
66
|
resp.body
|
36
67
|
end
|
37
68
|
|
69
|
+
##
|
70
|
+
# Retrieves generic poll info. Defaults to poll instance but
|
71
|
+
# can be pointed at any poll by using it's ID number
|
72
|
+
#
|
73
|
+
# Returns raw HTTP body
|
74
|
+
#
|
75
|
+
# An ArgumentError is raised if ID is not valid type
|
76
|
+
|
38
77
|
def view id=@id
|
39
78
|
raise ArgumentError unless id.is_a? Fixnum
|
40
79
|
url = URI "#{@api}#{id}"
|
41
80
|
resp = Net::HTTP.get(url)
|
42
81
|
end
|
43
82
|
|
83
|
+
##
|
84
|
+
# Retrieves options with most votes. Defaults to poll instance but
|
85
|
+
# can be pointed at any poll by using it's ID number
|
86
|
+
#
|
87
|
+
# Returns String of winning option, setups up internal states for instance
|
88
|
+
#
|
89
|
+
# An ArgumentError is raised if ID is not valid type
|
90
|
+
|
44
91
|
def winner id=@id
|
45
92
|
raise ArgumentError unless id.is_a? Fixnum
|
46
93
|
url = URI "#{@api}#{id}"
|