strawpoll_api 0.0.0 → 1.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.
- checksums.yaml +4 -4
- data/lib/strawpoll_api.rb +11 -11
- 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: 2a20d89451f336a6e692488620b58a9e791b80ae
|
4
|
+
data.tar.gz: ad9295988f8b2a647f065561dd1164175533a27e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d327f9c3ab2314e4732898e550cf5d7f249d6c5f6f0f363affa5f3fa557e325241ee0016259db7b09d8891ba2c474f7fd5183121fb90d7b24dcd11bc7c81bbb
|
7
|
+
data.tar.gz: b3a6a831d219aac3226db8773f9b9705e6110fbc45c4dc8fcfeb28399883463f27419ce9b99e225ed6fd1cb5bf2f36592fe8b53dc1568e33e08f56520b4fbd92
|
data/lib/strawpoll_api.rb
CHANGED
@@ -3,14 +3,15 @@ require 'net/http'
|
|
3
3
|
|
4
4
|
class StrawPoll
|
5
5
|
attr_accessor :title, :multi, :perm, :options
|
6
|
-
attr_reader :api, :id, :leader, :votes, :link
|
6
|
+
attr_reader :api, :id, :leader, :votes, :link, :results
|
7
7
|
|
8
8
|
def initialize title, *options
|
9
|
+
raise ArgumentError unless options.length >= 2
|
9
10
|
@title = title
|
10
11
|
@multi = false
|
11
12
|
@perm = true
|
12
13
|
@options = options
|
13
|
-
@api = 'http://strawpoll.me/api/v2/'
|
14
|
+
@api = 'http://strawpoll.me/api/v2/polls/'
|
14
15
|
@id = nil
|
15
16
|
@leader = nil
|
16
17
|
@votes = nil
|
@@ -19,31 +20,30 @@ class StrawPoll
|
|
19
20
|
end
|
20
21
|
|
21
22
|
def create!
|
22
|
-
raise ArgumentError unless !@title.empty? && @options.length >= 2
|
23
|
+
raise ArgumentError unless !@title.empty? && @options.length >= 2
|
23
24
|
params = {
|
24
25
|
"title" => @title,
|
25
26
|
"options" => @options,
|
26
27
|
"multi" => @multi,
|
27
28
|
"permissive" => @perm,
|
28
29
|
}
|
29
|
-
url = URI
|
30
|
+
url = URI @api
|
30
31
|
resp = Net::HTTP.post_form(url, params)
|
31
|
-
@id = JSON.parse(resp.body)['id']
|
32
|
+
@id = JSON.parse(resp.body)['id']
|
32
33
|
@link = "http://strawpoll.me/#{@id}"
|
33
34
|
@results = "http://strawpoll.me/#{@id}/r"
|
34
35
|
resp.body
|
35
36
|
end
|
36
37
|
|
37
38
|
def view id=@id
|
38
|
-
raise ArgumentError unless id.is_a?
|
39
|
-
url = URI "
|
39
|
+
raise ArgumentError unless id.is_a? Fixnum
|
40
|
+
url = URI "#{@api}#{id}"
|
40
41
|
resp = Net::HTTP.get(url)
|
41
|
-
resp.body
|
42
42
|
end
|
43
43
|
|
44
44
|
def winner id=@id
|
45
|
-
raise ArgumentError unless id.is_a?
|
46
|
-
url = URI "
|
45
|
+
raise ArgumentError unless id.is_a? Fixnum
|
46
|
+
url = URI "#{@api}#{id}"
|
47
47
|
resp = Net::HTTP.get(url)
|
48
48
|
result = JSON.parse(resp)['votes']
|
49
49
|
winner = JSON.parse(resp)['options'][result.index(result.max)]
|
@@ -53,4 +53,4 @@ class StrawPoll
|
|
53
53
|
end
|
54
54
|
winner
|
55
55
|
end
|
56
|
-
end
|
56
|
+
end
|