zoho_books 0.0.43 → 0.0.45

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b0ce3462390ba5629004a1efe606ed08782f898003746fa9ade5b119982ad050
4
- data.tar.gz: 3210d1dcefc680b66f4ba122e3691ad45fcf4fc182c083dd2f13c179ea23af4b
3
+ metadata.gz: d10898ba736048c15918586c788cac2143561b109f971c8545a5229cba6e7492
4
+ data.tar.gz: 1071a97787b80830e156a056fc5032309fa61e24bd9c67f94262eb9786b1e65a
5
5
  SHA512:
6
- metadata.gz: 5880bbf96b8bec379729116e3ab4c09e6833472e5c2a6ea7b68ef37188f01568214d0f0bc716f8f7bf816996dc3013437a21056a24fbee800cc81253c6886535
7
- data.tar.gz: 07efd3818cac9859d2f77d506fa1755c16d6f1e294aa0b9190e904683c1d45f7c183a76fcc44ad6267bf8e98ef31d406d09abed2b0c44e6f62ce76a6c03728ed
6
+ metadata.gz: fba83c64621ce304bb85f78721a86d9de098bc6425a093d68a5694c44945039879006f83f0695f4724f15483ab92d9d2bf4767e42dc99e53fce5e41bebc2e662
7
+ data.tar.gz: e6da82300eeea028d57a54a665710a5b0b8d59e473043bf78ece0a267c88351f2d67bb3a85a1be0e82873f00873d26f70b0c4c107a33ed761b156e94742e485c
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+ require 'httparty'
3
+
4
+ module ZohoBooks
5
+ class Connection
6
+
7
+ def self.get(url)
8
+ response = HTTParty.get(url, headers: headers)
9
+
10
+ return ZohoBooks::Error.new(response.code, response["error"]) if response.code != 200
11
+
12
+ response
13
+ end
14
+
15
+ def self.post(url, body)
16
+ response = HTTParty.post(url, body: body, headers: headers)
17
+
18
+ return render_error(response) if response.code != 201
19
+
20
+ response
21
+ end
22
+
23
+ def self.put(url, body)
24
+ response = HTTParty.put(url, body: body, headers: headers)
25
+
26
+ return render_error(response) if response.code != 200
27
+
28
+ response
29
+ end
30
+
31
+ def self.delete(url)
32
+ response = HTTParty.delete(url, headers: headers)
33
+
34
+ return render_error(response) if response.code != 200
35
+
36
+ response
37
+ end
38
+
39
+ private
40
+
41
+ def self.headers
42
+ {
43
+ 'Authorization' => "Zoho-oauthtoken #{access_token}",
44
+ 'Content-Type' => 'application/json'
45
+ }
46
+ end
47
+
48
+ def self.access_token
49
+ if ZohoBooks.config.access_token_expires_at.nil? || ZohoBooks.config.access_token_expires_at >= Time.now.to_i
50
+ ZohoBooks::Auth.refresh_access_token
51
+ else
52
+ ZohoBooks.config.access_token
53
+ end
54
+ end
55
+
56
+ def self.render_error(response)
57
+ ZohoBooks::Error.new(response.code, response["error"] || '')
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+ require 'httparty'
3
+
4
+ module ZohoBooks
5
+ BASE_URL='https://www.zohoapis.eu/books/v3'
6
+
7
+ class Item
8
+ def self.list(opts = {})
9
+ query = opts.map { |k, v| "#{k}=#{v}" }.join('&')
10
+ ZohoBooks::Connection.get("#{BASE_URL}/items?organization_id=#{ZohoBooks.config.organization_id}&#{query}")
11
+ end
12
+
13
+ def self.create(body, opts = {})
14
+ ZohoBooks::Connection.post("#{BASE_URL}/items?organization_id=#{ZohoBooks.config.organization_id}", body.to_json)
15
+ end
16
+
17
+ def self.update(id, body, opts = {})
18
+ ZohoBooks::Connection.put("#{BASE_URL}/items/#{id}?organization_id=#{ZohoBooks.config.organization_id}", body.to_json)
19
+ end
20
+
21
+ def self.delete(id, opts = {})
22
+ ZohoBooks::Connection.delete("#{BASE_URL}/items/#{id}?organization_id=#{ZohoBooks.config.organization_id}")
23
+ end
24
+ end
25
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zoho_books
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.43
4
+ version: 0.0.45
5
5
  platform: ruby
6
6
  authors:
7
7
  - PapaLoup
@@ -34,7 +34,9 @@ files:
34
34
  - lib/zoho_books.rb
35
35
  - lib/zoho_books/auth.rb
36
36
  - lib/zoho_books/config.rb
37
+ - lib/zoho_books/connection.rb
37
38
  - lib/zoho_books/error.rb
39
+ - lib/zoho_books/item.rb
38
40
  homepage: https://rubygems.org/gems/zoho_books
39
41
  licenses:
40
42
  - MIT