zoho_books 0.0.4 → 0.0.6
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.
- checksums.yaml +4 -4
- data/lib/zoho_books/auth.rb +0 -2
- data/lib/zoho_books/config.rb +30 -0
- data/lib/zoho_books/connection.rb +62 -0
- data/lib/zoho_books/contact.rb +27 -0
- data/lib/zoho_books/estimate.rb +27 -0
- data/lib/zoho_books/estimates/template.rb +12 -0
- data/lib/zoho_books/item.rb +23 -0
- data/lib/zoho_books/tax.rb +27 -0
- data/lib/zoho_books.rb +9 -6
- metadata +14 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 50914272ab350678fb813567bd0874a2c31b6e2ada8172d4e9635ec3c583d21e
|
|
4
|
+
data.tar.gz: 4f57bffb652672d0eee31050bbce58bc63c27fcdbad5ba92c7b9cb3363a271f5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 99ab636fbf3388b19b602be15726b0636dad6800995a25021f14b1d31ea7571a0ff8d80abdad2653f90f3a43e1f6e279dfc80df6e76cdc3c6f9a25fb86ad724c
|
|
7
|
+
data.tar.gz: deb65b9772fc6dd360ab8efb25aae0bc96796121b364bbcc659862414e8363f5df8492c4a661c463b556a511f55c81698cd75d490531f9226ec3186a7dc13fee
|
data/lib/zoho_books/auth.rb
CHANGED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
module ZohoBooks
|
|
2
|
+
class Config
|
|
3
|
+
attr_accessor :client_id, :client_secret, :redirect_uri, :refresh_token, :base_url,
|
|
4
|
+
:portal_id, :access_token, :organization_id, :refresh_token, :access_token_expires_at
|
|
5
|
+
|
|
6
|
+
DEFAULT_BASE_URL = "https://accounts.zoho.eu".freeze
|
|
7
|
+
|
|
8
|
+
def initialize(config = {})
|
|
9
|
+
@base_url = config["base_url"] || DEFAULT_BASE_URL
|
|
10
|
+
@portal_id = config["portal_id"]
|
|
11
|
+
@access_token = config["access_token"]
|
|
12
|
+
@client_id = config["client_id"]
|
|
13
|
+
@client_secret = config["client_secret"]
|
|
14
|
+
@redirect_uri = config["redirect_uri"]
|
|
15
|
+
@organization_id = config["organization_id"]
|
|
16
|
+
@refresh_token = config["refresh_token"]
|
|
17
|
+
|
|
18
|
+
@access_token_expires_at = nil
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
class << self
|
|
23
|
+
attr_accessor :config
|
|
24
|
+
|
|
25
|
+
def configure
|
|
26
|
+
self.config ||= Config.new
|
|
27
|
+
yield(config)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'httparty'
|
|
3
|
+
|
|
4
|
+
module ZohoBooks
|
|
5
|
+
BASE_URL='https://www.zohoapis.eu/books/v3'
|
|
6
|
+
|
|
7
|
+
class Connection
|
|
8
|
+
|
|
9
|
+
def self.get(url)
|
|
10
|
+
response = HTTParty.get(url, headers: headers)
|
|
11
|
+
|
|
12
|
+
return ZohoBooks::Error.new(response.code, response["error"]) if response.code != 200
|
|
13
|
+
|
|
14
|
+
response
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def self.post(url, body)
|
|
18
|
+
response = HTTParty.post(url, body: body, headers: headers)
|
|
19
|
+
|
|
20
|
+
return render_error(response) if response.code != 201
|
|
21
|
+
|
|
22
|
+
response
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def self.put(url, body)
|
|
26
|
+
response = HTTParty.put(url, body: body, headers: headers)
|
|
27
|
+
|
|
28
|
+
return render_error(response) if response.code != 200
|
|
29
|
+
|
|
30
|
+
response
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def self.delete(url)
|
|
34
|
+
response = HTTParty.delete(url, headers: headers)
|
|
35
|
+
|
|
36
|
+
return render_error(response) if response.code != 200
|
|
37
|
+
|
|
38
|
+
response
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
private
|
|
42
|
+
|
|
43
|
+
def self.headers
|
|
44
|
+
{
|
|
45
|
+
'Authorization' => "Zoho-oauthtoken #{access_token}",
|
|
46
|
+
'Content-Type' => 'application/json'
|
|
47
|
+
}
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def self.access_token
|
|
51
|
+
if ZohoBooks.config.access_token_expires_at.nil? || ZohoBooks.config.access_token_expires_at < Time.now.to_i
|
|
52
|
+
ZohoBooks::Auth.refresh_access_token
|
|
53
|
+
else
|
|
54
|
+
ZohoBooks.config.access_token
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def self.render_error(response)
|
|
59
|
+
ZohoBooks::Error.new(response.code, response["message"] || '')
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'httparty'
|
|
3
|
+
|
|
4
|
+
module ZohoBooks
|
|
5
|
+
class Contact
|
|
6
|
+
def self.list(opts = {})
|
|
7
|
+
query = opts.map { |k, v| "#{k}=#{v}" }.join('&')
|
|
8
|
+
ZohoBooks::Connection.get("#{BASE_URL}/contacts?organization_id=#{ZohoBooks.config.organization_id}&#{query}")
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.get(id, opts = {})
|
|
12
|
+
ZohoBooks::Connection.get("#{BASE_URL}/contacts/#{id}?organization_id=#{ZohoBooks.config.organization_id}")
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.create(body, opts = {})
|
|
16
|
+
ZohoBooks::Connection.post("#{BASE_URL}/contacts?organization_id=#{ZohoBooks.config.organization_id}", body.to_json)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def self.update(id, body, opts = {})
|
|
20
|
+
ZohoBooks::Connection.put("#{BASE_URL}/contacts/#{id}?organization_id=#{ZohoBooks.config.organization_id}", body.to_json)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def self.delete(id, opts = {})
|
|
24
|
+
ZohoBooks::Connection.delete("#{BASE_URL}/contacts/#{id}?organization_id=#{ZohoBooks.config.organization_id}")
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'httparty'
|
|
3
|
+
|
|
4
|
+
module ZohoBooks
|
|
5
|
+
class Estimate
|
|
6
|
+
def self.list(opts = {})
|
|
7
|
+
query = opts.map { |k, v| "#{k}=#{v}" }.join('&')
|
|
8
|
+
ZohoBooks::Connection.get("#{BASE_URL}/estimates?organization_id=#{ZohoBooks.config.organization_id}&#{query}")
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.get(id, opts = {})
|
|
12
|
+
ZohoBooks::Connection.get("#{BASE_URL}/estimates/#{id}?organization_id=#{ZohoBooks.config.organization_id}")
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.create(body, opts = {})
|
|
16
|
+
ZohoBooks::Connection.post("#{BASE_URL}/estimates?organization_id=#{ZohoBooks.config.organization_id}", body.to_json)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def self.update(id, body, opts = {})
|
|
20
|
+
ZohoBooks::Connection.put("#{BASE_URL}/estimates/#{id}?organization_id=#{ZohoBooks.config.organization_id}", body.to_json)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def self.delete(id, opts = {})
|
|
24
|
+
ZohoBooks::Connection.delete("#{BASE_URL}/estimates/#{id}?organization_id=#{ZohoBooks.config.organization_id}")
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'httparty'
|
|
3
|
+
|
|
4
|
+
module ZohoBooks
|
|
5
|
+
module Estimates
|
|
6
|
+
class Template
|
|
7
|
+
def self.list
|
|
8
|
+
ZohoBooks::Connection.get("#{BASE_URL}/estimates/templates?organization_id=#{ZohoBooks.config.organization_id}")
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'httparty'
|
|
3
|
+
|
|
4
|
+
module ZohoBooks
|
|
5
|
+
class Item
|
|
6
|
+
def self.list(opts = {})
|
|
7
|
+
query = opts.map { |k, v| "#{k}=#{v}" }.join('&')
|
|
8
|
+
ZohoBooks::Connection.get("#{BASE_URL}/items?organization_id=#{ZohoBooks.config.organization_id}&#{query}")
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.create(body, opts = {})
|
|
12
|
+
ZohoBooks::Connection.post("#{BASE_URL}/items?organization_id=#{ZohoBooks.config.organization_id}", body.to_json)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.update(id, body, opts = {})
|
|
16
|
+
ZohoBooks::Connection.put("#{BASE_URL}/items/#{id}?organization_id=#{ZohoBooks.config.organization_id}", body.to_json)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def self.delete(id, opts = {})
|
|
20
|
+
ZohoBooks::Connection.delete("#{BASE_URL}/items/#{id}?organization_id=#{ZohoBooks.config.organization_id}")
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'httparty'
|
|
3
|
+
|
|
4
|
+
module ZohoBooks
|
|
5
|
+
class Tax
|
|
6
|
+
def self.list(opts = {})
|
|
7
|
+
query = opts.map { |k, v| "#{k}=#{v}" }.join('&')
|
|
8
|
+
ZohoBooks::Connection.get("#{BASE_URL}/settings/taxes?organization_id=#{ZohoBooks.config.organization_id}&#{query}")
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.get(id, opts = {})
|
|
12
|
+
ZohoBooks::Connection.get("#{BASE_URL}/settings/taxes/#{id}?organization_id=#{ZohoBooks.config.organization_id}")
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.create(body, opts = {})
|
|
16
|
+
ZohoBooks::Connection.post("#{BASE_URL}/settings/taxes?organization_id=#{ZohoBooks.config.organization_id}", body.to_json)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def self.update(id, body, opts = {})
|
|
20
|
+
ZohoBooks::Connection.put("#{BASE_URL}/settings/taxes/#{id}?organization_id=#{ZohoBooks.config.organization_id}", body.to_json)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def self.delete(id, opts = {})
|
|
24
|
+
ZohoBooks::Connection.delete("#{BASE_URL}/settings/taxes/#{id}?organization_id=#{ZohoBooks.config.organization_id}")
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
data/lib/zoho_books.rb
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
module ZohoBooks
|
|
2
2
|
end
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
require 'zoho_books/auth'
|
|
5
|
+
require 'zoho_books/error'
|
|
6
|
+
require 'zoho_books/connection'
|
|
7
|
+
require 'zoho_books/item'
|
|
8
|
+
require 'zoho_books/config'
|
|
9
|
+
require 'zoho_books/contact'
|
|
10
|
+
require 'zoho_books/estimate'
|
|
11
|
+
require 'zoho_books/estimates/template'
|
|
12
|
+
require 'zoho_books/tax'
|
metadata
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: zoho_books
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- PapaLoup
|
|
8
8
|
- Raphtml
|
|
9
|
-
|
|
9
|
+
- theobcl
|
|
10
|
+
autorequire:
|
|
10
11
|
bindir: bin
|
|
11
12
|
cert_chain: []
|
|
12
|
-
date: 2023-
|
|
13
|
+
date: 2023-10-10 00:00:00.000000000 Z
|
|
13
14
|
dependencies:
|
|
14
15
|
- !ruby/object:Gem::Dependency
|
|
15
16
|
name: httparty
|
|
@@ -33,12 +34,19 @@ extra_rdoc_files: []
|
|
|
33
34
|
files:
|
|
34
35
|
- lib/zoho_books.rb
|
|
35
36
|
- lib/zoho_books/auth.rb
|
|
37
|
+
- lib/zoho_books/config.rb
|
|
38
|
+
- lib/zoho_books/connection.rb
|
|
39
|
+
- lib/zoho_books/contact.rb
|
|
36
40
|
- lib/zoho_books/error.rb
|
|
41
|
+
- lib/zoho_books/estimate.rb
|
|
42
|
+
- lib/zoho_books/estimates/template.rb
|
|
43
|
+
- lib/zoho_books/item.rb
|
|
44
|
+
- lib/zoho_books/tax.rb
|
|
37
45
|
homepage: https://rubygems.org/gems/zoho_books
|
|
38
46
|
licenses:
|
|
39
47
|
- MIT
|
|
40
48
|
metadata: {}
|
|
41
|
-
post_install_message:
|
|
49
|
+
post_install_message:
|
|
42
50
|
rdoc_options: []
|
|
43
51
|
require_paths:
|
|
44
52
|
- lib
|
|
@@ -53,8 +61,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
53
61
|
- !ruby/object:Gem::Version
|
|
54
62
|
version: '0'
|
|
55
63
|
requirements: []
|
|
56
|
-
rubygems_version: 3.
|
|
57
|
-
signing_key:
|
|
64
|
+
rubygems_version: 3.1.6
|
|
65
|
+
signing_key:
|
|
58
66
|
specification_version: 4
|
|
59
67
|
summary: Zoho Books API wrapper
|
|
60
68
|
test_files: []
|