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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/strawpoll_api.rb +11 -11
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 56d45aa7d8a86856567597d6b0e43e702f8ec6a3
4
- data.tar.gz: ce4ec8b5249455bc6a98697ecfb424ff0efd37bf
3
+ metadata.gz: 2a20d89451f336a6e692488620b58a9e791b80ae
4
+ data.tar.gz: ad9295988f8b2a647f065561dd1164175533a27e
5
5
  SHA512:
6
- metadata.gz: e2611f1a8c14c42a5176208e329cc4a38a00a9c6ed50aa2bcce9fcc9c8c1dcbe52fd39850aec4cf123ef35472b54867ba1a105aea476556ac02c8cee518368af
7
- data.tar.gz: be4d40ecd002b08d3a9f29cf55b7412d89b3822b891ca477f0ee0e209110df16ab588cc0d00dca2fe2c0e1300f2cb9e00ca18138bf83ce1eb3cc10d077577006
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 && @mulit.is_a?(Boolean) && @perm.is_a?(Boolean)
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 'http://strawpoll.me/api/v2/polls'
30
+ url = URI @api
30
31
  resp = Net::HTTP.post_form(url, params)
31
- @id = JSON.parse(resp.body)['id'].to_s
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? Integer
39
- url = URI "http://strawpoll.me/api/v2/#{id}"
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? Integer
46
- url = URI "http://strawpoll.me/api/v2/#{id}"
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: strawpoll_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alessandro Minali