zoho 0.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.
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use ruby-1.9.2-p180@zoho --create
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in zoho.gemspec
4
+ gemspec
@@ -0,0 +1,28 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ zoho (0.0.1)
5
+ rest-client (~> 1.6.7)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.1.3)
11
+ mime-types (1.19)
12
+ rest-client (1.6.7)
13
+ mime-types (>= 1.16)
14
+ rspec (2.11.0)
15
+ rspec-core (~> 2.11.0)
16
+ rspec-expectations (~> 2.11.0)
17
+ rspec-mocks (~> 2.11.0)
18
+ rspec-core (2.11.1)
19
+ rspec-expectations (2.11.2)
20
+ diff-lcs (~> 1.1.3)
21
+ rspec-mocks (2.11.2)
22
+
23
+ PLATFORMS
24
+ ruby
25
+
26
+ DEPENDENCIES
27
+ rspec (~> 2.11.0)
28
+ zoho!
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Paul Victor Raj
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,4 @@
1
+ zoho
2
+ ====
3
+
4
+ Zoho API library
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,5 @@
1
+ require 'rest-client'
2
+ require 'json'
3
+ require "zoho/version"
4
+ require "zoho/client"
5
+ require "zoho/sheet"
@@ -0,0 +1,16 @@
1
+ module Zoho
2
+ class Client
3
+ attr_accessor :ticket, :api_key
4
+ def initialize(params)
5
+ nil_params = [:LOGIN_ID, :PASSWORD, :servicename] - params.keys
6
+ if nil_params.size != 0
7
+ raise "#{nil_params.join(', ')} are nil"
8
+ end
9
+ @api_key = params['key']
10
+ login_resp = RestClient.post("https://accounts.zoho.com/login", params)
11
+ split_arr = login_resp.split(/\n|\=/)
12
+ ticket_index = split_arr.index('TICKET') + 1
13
+ @ticket = split_arr[ticket_index]
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,65 @@
1
+ module Zoho
2
+ class Sheet
3
+
4
+ attr_accessor :cli
5
+ attr_accessor :wb_id
6
+ attr_accessor :wb_name
7
+ attr_accessor :update_lock
8
+
9
+ def self.auth_with(auth_params)
10
+ @@auth_params = auth_params.merge({:servicename => 'ZohoSheet', :FROM_AGENT => 'true'})
11
+ end
12
+
13
+ def self.list(args = nil)
14
+ raise "Zoho::Sheet uninitialized" if @@auth_params.nil?
15
+ cli = Zoho::Client.new(@@auth_params)
16
+ sheets_list_url = "https://sheet.zoho.com/api/private/json/books?apikey=#{cli.api_key}&ticket=#{cli.ticket}"
17
+ if args
18
+ args_in_url_format = ""
19
+ args.each_pair{|k,v| args_in_url_format << "#{k}=#{v}"}
20
+ sheets_list_url << "&" + args_in_url_format
21
+ end
22
+ resp = RestClient.get(sheets_list_url)
23
+ JSON.parse(resp)['response']['result']
24
+ end
25
+
26
+ def download(format = 'csv')
27
+ raise "Zoho::Sheet uninitialized" if @@auth_params.nil?
28
+ cli = Zoho::Client.new(@@auth_params)
29
+ resp = RestClient.get "https://sheet.zoho.com/api/private/#{format}/download/#{wb_id}?apikey=#{cli.api_key}&ticket=#{cli.ticket}"
30
+ end
31
+
32
+ def initialize(workbook_id)
33
+ raise "Zoho::Sheet uninitialized" if @@auth_params.nil?
34
+ @cli = Zoho::Client.new(@@auth_params)
35
+ all_docs = self.class.list
36
+ all_wbs = all_docs['workbooks']['workbook']
37
+ @details = all_wbs.select{|sheet|
38
+ sheet["workbookId"] == workbook_id || sheet['workbookName'] == workbook_id
39
+ }[0]
40
+ @wb_id = @details['workbookId']
41
+ @wb_name = @details['workbookName']
42
+ @update_lock = @details['updateLock']
43
+ @created_time = @details['createdTime']
44
+ end
45
+
46
+ def replace_with(file_name, contenttype = 'csv')
47
+ raise "Zoho::Sheet uninitialized" if @@auth_params.nil?
48
+ cli = Zoho::Client.new(@@auth_params)
49
+ resp = RestClient.post "https://sheet.zoho.com/api/private/json/savebook/#{wb_id}?apikey=#{cli.api_key}&ticket=#{cli.ticket}&contentType=#{contenttype}&updateLock=#{update_lock}&isOverwrite=true", :content => File.new(file_name, 'rb')
50
+ end
51
+
52
+ def update(new_row = "")
53
+ # New row is a CSV row.
54
+ # The fields have to be enclosed with \"<field>\"
55
+ existing_data = download || ""
56
+ max_commas = existing_data.split("\n").inject(0){|memo, line|
57
+ memo > line.count(",") ? memo : line.count(",")
58
+ }
59
+ new_row += "," * (max_commas - new_row.count(','))
60
+ updated_data = existing_data + "\n" + new_row + "\n"
61
+ File.open("/tmp/#{@wb_name}.csv", 'w') {|f| f.write(updated_data) }
62
+ replace_with("/tmp/#{@wb_name}.csv")
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,3 @@
1
+ module Zoho
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/zoho/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Paul Victor Raj"]
6
+ gem.email = ["paulvictor@gmail.com"]
7
+ gem.description = %q{Ruby interface to ZOHO docs}
8
+ gem.summary = %q{Ruby interface to ZOHO docs}
9
+ gem.homepage = "http://github.com/paulvictor/zoho.git"
10
+
11
+ gem.add_dependency "rest-client", "~> 1.6.7"
12
+ gem.add_development_dependency "rspec", "~> 2.11.0"
13
+
14
+ gem.files = `git ls-files`.split($\)
15
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
+ gem.name = "zoho"
18
+ gem.require_paths = ["lib"]
19
+ gem.version = Zoho::VERSION
20
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zoho
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Paul Victor Raj
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2012-09-04 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rest-client
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: 1.6.7
24
+ type: :runtime
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: rspec
28
+ prerelease: false
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: 2.11.0
35
+ type: :development
36
+ version_requirements: *id002
37
+ description: Ruby interface to ZOHO docs
38
+ email:
39
+ - paulvictor@gmail.com
40
+ executables: []
41
+
42
+ extensions: []
43
+
44
+ extra_rdoc_files: []
45
+
46
+ files:
47
+ - .gitignore
48
+ - .rvmrc
49
+ - Gemfile
50
+ - Gemfile.lock
51
+ - LICENSE
52
+ - README.md
53
+ - Rakefile
54
+ - lib/zoho.rb
55
+ - lib/zoho/client.rb
56
+ - lib/zoho/sheet.rb
57
+ - lib/zoho/version.rb
58
+ - zoho.gemspec
59
+ homepage: http://github.com/paulvictor/zoho.git
60
+ licenses: []
61
+
62
+ post_install_message:
63
+ rdoc_options: []
64
+
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: "0"
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: "0"
79
+ requirements: []
80
+
81
+ rubyforge_project:
82
+ rubygems_version: 1.8.24
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: Ruby interface to ZOHO docs
86
+ test_files: []
87
+