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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/strawpoll_api.rb +47 -0
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2a20d89451f336a6e692488620b58a9e791b80ae
4
- data.tar.gz: ad9295988f8b2a647f065561dd1164175533a27e
3
+ metadata.gz: 1d52add7f7588481f81fa44ccd052d5aff858fe5
4
+ data.tar.gz: 619eb7429505c42420dcc257d24231ead2e0e38f
5
5
  SHA512:
6
- metadata.gz: 4d327f9c3ab2314e4732898e550cf5d7f249d6c5f6f0f363affa5f3fa557e325241ee0016259db7b09d8891ba2c474f7fd5183121fb90d7b24dcd11bc7c81bbb
7
- data.tar.gz: b3a6a831d219aac3226db8773f9b9705e6110fbc45c4dc8fcfeb28399883463f27419ce9b99e225ed6fd1cb5bf2f36592fe8b53dc1568e33e08f56520b4fbd92
6
+ metadata.gz: 2d69cce4b994376dc8612d3da097406beab4ad00973dd4a73180a0bbe6efeb87a2a6e653d436f062be0f89bab426722b7b107e7e3eae5d421d33e2b44aac40ed
7
+ data.tar.gz: 189ea76eab268ea9f9e180193f0eedd6a61c0e02e452de3009321a76e207e3f8d97b07695a3660778c685bc8adfcaa87bca65974eeab6e87b5e697ce9d794341
@@ -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}"
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: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alessandro Minali