strawpoll_api 0.0.0

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 +7 -0
  2. data/lib/strawpoll_api.rb +56 -0
  3. metadata +44 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 56d45aa7d8a86856567597d6b0e43e702f8ec6a3
4
+ data.tar.gz: ce4ec8b5249455bc6a98697ecfb424ff0efd37bf
5
+ SHA512:
6
+ metadata.gz: e2611f1a8c14c42a5176208e329cc4a38a00a9c6ed50aa2bcce9fcc9c8c1dcbe52fd39850aec4cf123ef35472b54867ba1a105aea476556ac02c8cee518368af
7
+ data.tar.gz: be4d40ecd002b08d3a9f29cf55b7412d89b3822b891ca477f0ee0e209110df16ab588cc0d00dca2fe2c0e1300f2cb9e00ca18138bf83ce1eb3cc10d077577006
@@ -0,0 +1,56 @@
1
+ require 'json'
2
+ require 'net/http'
3
+
4
+ class StrawPoll
5
+ attr_accessor :title, :multi, :perm, :options
6
+ attr_reader :api, :id, :leader, :votes, :link
7
+
8
+ def initialize title, *options
9
+ @title = title
10
+ @multi = false
11
+ @perm = true
12
+ @options = options
13
+ @api = 'http://strawpoll.me/api/v2/'
14
+ @id = nil
15
+ @leader = nil
16
+ @votes = nil
17
+ @link = nil
18
+ @results = nil
19
+ end
20
+
21
+ def create!
22
+ raise ArgumentError unless !@title.empty? && @options.length >= 2 && @mulit.is_a?(Boolean) && @perm.is_a?(Boolean)
23
+ params = {
24
+ "title" => @title,
25
+ "options" => @options,
26
+ "multi" => @multi,
27
+ "permissive" => @perm,
28
+ }
29
+ url = URI 'http://strawpoll.me/api/v2/polls'
30
+ resp = Net::HTTP.post_form(url, params)
31
+ @id = JSON.parse(resp.body)['id'].to_s
32
+ @link = "http://strawpoll.me/#{@id}"
33
+ @results = "http://strawpoll.me/#{@id}/r"
34
+ resp.body
35
+ end
36
+
37
+ def view id=@id
38
+ raise ArgumentError unless id.is_a? Integer
39
+ url = URI "http://strawpoll.me/api/v2/#{id}"
40
+ resp = Net::HTTP.get(url)
41
+ resp.body
42
+ end
43
+
44
+ def winner id=@id
45
+ raise ArgumentError unless id.is_a? Integer
46
+ url = URI "http://strawpoll.me/api/v2/#{id}"
47
+ resp = Net::HTTP.get(url)
48
+ result = JSON.parse(resp)['votes']
49
+ winner = JSON.parse(resp)['options'][result.index(result.max)]
50
+ if id == @id
51
+ @leader = winner
52
+ @votes = result
53
+ end
54
+ winner
55
+ end
56
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: strawpoll_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Alessandro Minali
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-08 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A Ruby interface to the Strawpoll API. http://strawpoll.me/
14
+ email: alessandro.minali@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/strawpoll_api.rb
20
+ homepage: https://github.com/AlessandroMinali/strawpoll
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.4.6
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: A Ruby interface to the Strawpoll
44
+ test_files: []