gfrom 0.1.2 → 0.1.5
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.
- data/gfrom.gemspec +1 -2
- data/lib/gfrom.rb +21 -8
- data/readme.md +4 -2
- metadata +2 -2
data/gfrom.gemspec
CHANGED
@@ -5,14 +5,13 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.platform = Gem::Platform::RUBY
|
7
7
|
spec.name = "gfrom"
|
8
|
-
spec.version = "0.1.
|
8
|
+
spec.version = "0.1.5"
|
9
9
|
spec.authors = ["Marvin Marcelo"]
|
10
10
|
spec.email = ["mrclmrvn@gmail.com"]
|
11
11
|
spec.description = %q{Render unathenticated Google Form in your website. Useful for collecting data from your users without a database. Just create a google form from your google account. If you are using Google Apps, please read form options}
|
12
12
|
spec.summary = %q{From Google Form}
|
13
13
|
spec.homepage = "https://bitbucket.org/mrclmrvn/gfrom/"
|
14
14
|
spec.license = "MIT"
|
15
|
-
spec.date = '2013-05-01'
|
16
15
|
|
17
16
|
spec.files = `git ls-files`.split($/)
|
18
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
data/lib/gfrom.rb
CHANGED
@@ -8,14 +8,14 @@ class Gfrom
|
|
8
8
|
|
9
9
|
attr_accessor :form, :fields
|
10
10
|
|
11
|
-
MATCHERS = '//input[@type="text"] | //input[@type="hidden"] | //textarea | //form'
|
11
|
+
MATCHERS = '//input[@type="text"] | //input[@type="radio"] |//input[@type="checkbox"] | //input[@type="hidden"] | //textarea | //form'
|
12
12
|
|
13
|
-
def initialize(url,
|
13
|
+
def initialize(url, regenerate_cache = false)
|
14
14
|
@form = Hash.new
|
15
15
|
@fields = []
|
16
16
|
|
17
17
|
cache = "#{Dir.tmpdir}/#{Digest::SHA1.hexdigest(url)}"
|
18
|
-
File.delete cache if
|
18
|
+
File.delete cache if regenerate_cache
|
19
19
|
|
20
20
|
unless File.exists?(cache)
|
21
21
|
req = Curl.get(url)
|
@@ -31,13 +31,14 @@ class Gfrom
|
|
31
31
|
case node.name
|
32
32
|
when "form"
|
33
33
|
@form[:action] = node.attributes["action"].value unless @form.has_key?(:action)
|
34
|
+
@form[:title] = doc.search('//title').first.text.strip unless @form.has_key?(:title)
|
34
35
|
else
|
35
36
|
n = hash_it(node)
|
36
37
|
@fields << n
|
37
38
|
keys << n[:name]
|
38
39
|
end
|
39
40
|
end
|
40
|
-
@form[:keys] = keys
|
41
|
+
@form[:keys] = keys
|
41
42
|
|
42
43
|
end
|
43
44
|
|
@@ -46,7 +47,8 @@ class Gfrom
|
|
46
47
|
doc = Nokogiri::XML.parse(response.body_str)
|
47
48
|
errorheader = doc.search('//div[@class="errorheader"]')
|
48
49
|
success = errorheader.empty?
|
49
|
-
|
50
|
+
success_response = doc.search('//div[@class="ss-custom-resp"]').first.text.strip
|
51
|
+
out = { :success => success, :message => success_response || doc.search('//title').first.text.strip }
|
50
52
|
unless success
|
51
53
|
out[:message] = errorheader.children.first.text.strip
|
52
54
|
end
|
@@ -56,14 +58,25 @@ class Gfrom
|
|
56
58
|
private
|
57
59
|
|
58
60
|
def hash_it(node)
|
61
|
+
group = ["checkbox", "radio"]
|
59
62
|
object = Hash.new
|
60
63
|
object[:element] = node.name
|
61
64
|
node.attributes.each do |k,v|
|
62
|
-
|
65
|
+
if (k == "name" and v.value == "checkbox" and node.search("//input[@name=\"#{v.value}\"]").length > 1)
|
66
|
+
# checkbox needs name to be array'ed
|
67
|
+
object[k.to_sym] = "#{v.value}[]"
|
68
|
+
else
|
69
|
+
object[k.to_sym] = v.value
|
70
|
+
end
|
63
71
|
if k == "id"
|
64
72
|
label = node.search("//label[@for=\"#{v.value}\"]").first
|
65
|
-
|
66
|
-
|
73
|
+
if label
|
74
|
+
object[:label] = label.children.first.text.strip
|
75
|
+
object[:required] = true unless label.search("//label[@for=\"#{v.value}\"]/span[contains(@class, \"required\")]").empty?
|
76
|
+
end
|
77
|
+
end
|
78
|
+
if object[:label].nil? and group.include?(object[:type])
|
79
|
+
object[:label] = node.attributes["value"].value
|
67
80
|
end
|
68
81
|
end
|
69
82
|
object
|
data/readme.md
CHANGED
@@ -28,7 +28,8 @@ GOOGLE_FORM_URL = "https://docs.google.com/a/myorganization.com/spreadsheet/embe
|
|
28
28
|
# {:element=>"input", :type=>"text", :name=>"entry.0.single", :value=>"", :class=>"ss-q-short", :id=>"entry_0", :label=>"Name", :required=>true},
|
29
29
|
# {:element=>"input", :type=>"text", :name=>"entry.2.single", :value=>"", :class=>"ss-q-short", :id=>"entry_2", :label=>"Email", :required=>true},
|
30
30
|
# {:element=>"textarea", :name=>"entry.1.single", :rows=>"8", :cols=>"75", :class=>"ss-q-long", :id=>"entry_1", :label=>"Message"},
|
31
|
-
# {:element=>"input", :type=>"hidden", :name=>"pageNumber", :value=>"0"},
|
31
|
+
# {:element=>"input", :type=>"hidden", :name=>"pageNumber", :value=>"0"},
|
32
|
+
# {:element=>"input", :type=>"hidden", :name=>"backupCache", :value=>""}
|
32
33
|
# ]
|
33
34
|
puts @myform.fields
|
34
35
|
# submit the form data to Google will return a hash
|
@@ -40,7 +41,8 @@ result = @myform.submit(params)
|
|
40
41
|
## TODO
|
41
42
|
|
42
43
|
* Support for Authenticated forms (requires login to organization/google apps)
|
43
|
-
*
|
44
|
+
* <del>Ensure radio buttons and checkboxes are grouped (not sure if this works in current version - 0.1.2)</del>
|
45
|
+
* Label for grouped form tags - checkbox and radio
|
44
46
|
* Supply an RDOC
|
45
47
|
* Tests
|
46
48
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gfrom
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: curb
|