gsmetrics 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +0 -1
- data/Gemfile.lock +5 -2
- data/README.md +26 -4
- data/gsmetrics.gemspec +6 -5
- data/lib/gsmetrics/gsmetrics.rb +27 -20
- metadata +40 -5
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
gsmetrics (0.0.
|
4
|
+
gsmetrics (0.0.4)
|
5
|
+
builder
|
6
|
+
crack
|
7
|
+
httparty
|
5
8
|
|
6
9
|
GEM
|
7
10
|
specs:
|
@@ -13,7 +16,7 @@ GEM
|
|
13
16
|
multi_xml
|
14
17
|
launchy (2.0.5)
|
15
18
|
addressable (~> 2.2.6)
|
16
|
-
multi_json (1.0.
|
19
|
+
multi_json (1.0.4)
|
17
20
|
multi_xml (0.4.1)
|
18
21
|
thor (0.14.6)
|
19
22
|
|
data/README.md
CHANGED
@@ -25,7 +25,28 @@ worksheet.append(5)
|
|
25
25
|
worksheet.save_row
|
26
26
|
```
|
27
27
|
|
28
|
-
|
28
|
+
Every row is added in one batch call, so only one HTTP request is sent for every row.
|
29
|
+
|
30
|
+
You can also set the exact row in the worksheet the data should be saved into. This is very handy if you have a worksheet that you need to update repeatedly.
|
31
|
+
|
32
|
+
The following example saves the worksheet to row nr 1. The rows start with 1 in Googledocs.
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
worksheet.save_row 5
|
36
|
+
```
|
37
|
+
|
38
|
+
The following example sets the number of rows in the worksheet beforehand and then disables the check if there is still a free row. By default gsmetrics checks
|
39
|
+
if there is a free row at the end of the worksheet and if not adds one. If you know beforehand the number of rows you need (e.g. daily updated list of users) you can
|
40
|
+
set the worksheet size and disable the check. This makes the upload process much faster, as the check doesn't have to be made before every new row is added.
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
set_worksheet_size 5
|
44
|
+
worksheet.check_worksheet_size = false
|
45
|
+
worksheet << 1
|
46
|
+
worksheet.save_row
|
47
|
+
```
|
48
|
+
|
49
|
+
After saving a row all appended data is removed and you can start with a new row.
|
29
50
|
Please make sure there are only empty lines at the end of the spreadsheet as the first empty line is used to write the data.
|
30
51
|
|
31
52
|
|
@@ -35,8 +56,9 @@ You can find out what your worksheet_id is by going to
|
|
35
56
|
|
36
57
|
https://spreadsheets.google.com/feeds/worksheets/#{your_document_id}/private/full
|
37
58
|
|
38
|
-
For every worksheet there will be an <entry> element which has an id. The last part of the id (something like od6) is the worksheet_id you have to provide.
|
39
|
-
|
59
|
+
For every worksheet there will be an <entry> element which has an id. The last part of the id (something like od6) is the worksheet_id you have to provide.
|
60
|
+
The executable will give you a list of all worksheets for your document at the end of the setup process.
|
61
|
+
|
62
|
+
Copyright (c) 2011-2012 Florian Motlik, licensed under MIT License
|
40
63
|
|
41
|
-
Copyright (c) 2011 Florian Motlik
|
42
64
|
Based on the gem template by https://github.com/goncalossilva/gem_template
|
data/gsmetrics.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "gsmetrics"
|
3
|
-
s.version = "0.0.
|
3
|
+
s.version = "0.0.4"
|
4
4
|
s.platform = Gem::Platform::RUBY
|
5
5
|
s.authors = ["Florian Motlik"]
|
6
6
|
s.email = ["flo@railsonfire.com"]
|
@@ -11,8 +11,12 @@ Gem::Specification.new do |s|
|
|
11
11
|
|
12
12
|
s.required_rubygems_version = ">= 1.3.6"
|
13
13
|
|
14
|
+
s.requirements << 'Thor and launchy gem need to be installed for the executable. Not adding them as a dependency for the whole library'
|
15
|
+
|
14
16
|
# If you have runtime dependencies, add them here
|
15
|
-
|
17
|
+
s.add_runtime_dependency(%q<httparty>, [">= 0"])
|
18
|
+
s.add_runtime_dependency(%q<builder>, [">= 0"])
|
19
|
+
s.add_runtime_dependency(%q<crack>, [">= 0"])
|
16
20
|
|
17
21
|
# If you have development dependencies, add them here
|
18
22
|
# s.add_development_dependency "another", "= 0.9"
|
@@ -20,10 +24,7 @@ Gem::Specification.new do |s|
|
|
20
24
|
# The list of files to be contained in the gem
|
21
25
|
s.files = `git ls-files`.split("\n")
|
22
26
|
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
|
23
|
-
# s.extensions = `git ls-files ext/extconf.rb`.split("\n")
|
24
27
|
|
25
28
|
s.require_path = 'lib'
|
26
29
|
|
27
|
-
# For C extensions
|
28
|
-
# s.extensions = "ext/extconf.rb"
|
29
30
|
end
|
data/lib/gsmetrics/gsmetrics.rb
CHANGED
@@ -24,7 +24,9 @@ module GSMetrics
|
|
24
24
|
|
25
25
|
private
|
26
26
|
class Worksheet
|
27
|
+
attr_accessor :check_worksheet_size
|
27
28
|
def initialize doc_id, worksheet_id, access_token
|
29
|
+
@check_worksheet_size = true
|
28
30
|
@doc_id = doc_id
|
29
31
|
@worksheet_id = worksheet_id
|
30
32
|
@access_token = access_token
|
@@ -44,33 +46,38 @@ private
|
|
44
46
|
append item
|
45
47
|
end
|
46
48
|
|
47
|
-
def save_row
|
49
|
+
def save_row row_id = nil
|
48
50
|
xmlns = {:xmlns => "http://www.w3.org/2005/Atom",
|
51
|
+
"xmlns:batch" => "http://schemas.google.com/gdata/batch",
|
49
52
|
"xmlns:gs" => "http://schemas.google.com/spreadsheets/2006"}
|
50
53
|
|
51
54
|
response = HTTParty.get(@worksheet_href, :query => @query)
|
52
55
|
|
53
|
-
row_id
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
56
|
+
row_id ||= parse(response.body)["feed"]["openSearch:totalResults"].to_i + 2
|
57
|
+
|
58
|
+
set_worksheet_size row_id if @check_worksheet_size
|
59
|
+
|
60
|
+
xml = builder.feed(xmlns) do |build|
|
61
|
+
build.id("#{@worksheet_cell_href}")
|
62
|
+
@items.each_with_index{|item, index|
|
63
|
+
col_index = index+1
|
64
|
+
col_id = "R#{row_id}C#{col_index}"
|
65
|
+
col_href="#{@worksheet_cell_href}/#{col_id}"
|
66
|
+
build.entry { |b|
|
67
|
+
b.send("batch:id", "A#{index}")
|
68
|
+
b.send("batch:operation", :type => "update")
|
69
|
+
b.id(col_href)
|
70
|
+
b.link(:rel => "edit", :type => "application/atom+xml", :href => col_href)
|
71
|
+
b.send("gs:cell", :row => row_id, :col => col_index, :inputValue => item)
|
72
|
+
}
|
73
|
+
}
|
74
|
+
end
|
75
|
+
response = HTTParty.post("#{@worksheet_cell_href}/batch", :headers => @headers, :query => @query, :body => xml)
|
76
|
+
raise Exception if response.code != 200
|
69
77
|
@items = []
|
70
78
|
end
|
71
79
|
|
72
|
-
|
73
|
-
def create_row row_id
|
80
|
+
def set_worksheet_size row_id
|
74
81
|
href = "https://spreadsheets.google.com/feeds/worksheets/#{@doc_id}/private/full/#{@worksheet_id}"
|
75
82
|
worksheet = parse(HTTParty.get(href, :query => @query))
|
76
83
|
row_count = worksheet["entry"]["gs:rowCount"].to_i
|
@@ -78,7 +85,7 @@ private
|
|
78
85
|
update_href = worksheet["entry"]["link"].last["href"]
|
79
86
|
|
80
87
|
add = builder.entry(:xmlns => "http://www.w3.org/2005/Atom", "xmlns:gs" => "http://schemas.google.com/spreadsheets/2006"){|e|
|
81
|
-
e.send("gs:rowCount",
|
88
|
+
e.send("gs:rowCount", row_id)
|
82
89
|
e.send("gs:colCount", worksheet["entry"]["gs:colCount"].to_i)
|
83
90
|
e.title(worksheet["entry"]["title"])
|
84
91
|
}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gsmetrics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,41 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
13
|
-
dependencies:
|
12
|
+
date: 2012-01-24 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: httparty
|
16
|
+
requirement: &21137520 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *21137520
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: builder
|
27
|
+
requirement: &21137020 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *21137020
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: crack
|
38
|
+
requirement: &21136540 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *21136540
|
14
47
|
description: Simple Way to open a Session with Google Docs and push data into a Google
|
15
48
|
Spreadsheet Worksheet. We use it primarily for metrics, but it can be used for basically
|
16
49
|
anything regarding google spreadsheets.
|
@@ -46,14 +79,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
46
79
|
version: '0'
|
47
80
|
segments:
|
48
81
|
- 0
|
49
|
-
hash:
|
82
|
+
hash: 577015747898279807
|
50
83
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
84
|
none: false
|
52
85
|
requirements:
|
53
86
|
- - ! '>='
|
54
87
|
- !ruby/object:Gem::Version
|
55
88
|
version: 1.3.6
|
56
|
-
requirements:
|
89
|
+
requirements:
|
90
|
+
- Thor and launchy gem need to be installed for the executable. Not adding them as
|
91
|
+
a dependency for the whole library
|
57
92
|
rubyforge_project: gsmetrics
|
58
93
|
rubygems_version: 1.8.10
|
59
94
|
signing_key:
|