zoho_ruby 0.0.2 → 0.0.3
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/README.md +1 -1
- data/docs/inventory/README.md +1 -0
- data/docs/inventory/item_groups.md +101 -0
- data/docs/inventory/items.md +9 -10
- data/lib/zoho/configuration.rb +1 -1
- data/lib/zoho/inventory/api.rb +40 -0
- data/lib/zoho/inventory/item.rb +23 -105
- data/lib/zoho/inventory/item_group.rb +43 -0
- data/lib/zoho/version.rb +1 -1
- data/lib/zoho.rb +2 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15566afc6b08355d0fe1aaacaa35dd0a922ccce3
|
4
|
+
data.tar.gz: acaba96cd216f58c89003f7491b84d1152ac6663
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc947e76b7d3551b2eca39d5d24b25f9ab8012f7d58579f8e1ca18b6c6d1fd3a6b56bf6f62e8faf394d4f9e838373f6c31e2738531898bdf231ad93c9de8f198
|
7
|
+
data.tar.gz: c33a931def604719024ec61a456dee0ad6784749c4fb671b1faf0aecb598b8d15dcd7eb53b1422aef69beb8607d6d485f91a72445d9ac14df775b9a3e29aa60b
|
data/README.md
CHANGED
@@ -27,7 +27,7 @@ If you have the `organization_id` and `auth_token` already, here's what you need
|
|
27
27
|
Zoho.configure do |config|
|
28
28
|
config.organization_id = 'your_organization_id'
|
29
29
|
config.auth_token = 'your_auth_token'
|
30
|
-
config.per_page = 20 # Default and maximum items per page is
|
30
|
+
config.per_page = 20 # Default and maximum items per page is 50
|
31
31
|
end
|
32
32
|
```
|
33
33
|
## Usage
|
data/docs/inventory/README.md
CHANGED
@@ -0,0 +1,101 @@
|
|
1
|
+
# Item Groups
|
2
|
+
|
3
|
+
Item Group are the products that you sell or services that you render to various clients and can be purchased from various vendors in a business. Create and manage the item groups your business deals with and also create price lists for specific item and clients. For more details check https://www.zoho.com/inventory/api/v1/#Item_Groups
|
4
|
+
|
5
|
+
##### Create an Item Group
|
6
|
+
|
7
|
+
A new Item Group can a be created.
|
8
|
+
|
9
|
+
<!-- {.file-heading} -->
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
params = { group_name: 'Bags', unit: 'qty' }
|
13
|
+
|
14
|
+
Zoho::Inventory::ItemGroup.create(params)
|
15
|
+
```
|
16
|
+
Check https://www.zoho.com/inventory/api/v1/#Item_Groups_Create_an_Item_Group for more arguments that you can pass as params.
|
17
|
+
|
18
|
+
##### Retrieve an Item Group
|
19
|
+
|
20
|
+
Fetches the details for an existing Item Group.
|
21
|
+
|
22
|
+
<!-- {.file-heading} -->
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
itemgroup_id = '1234567890'
|
26
|
+
|
27
|
+
Zoho::Inventory::ItemGroup.find(itemgroup_id)
|
28
|
+
```
|
29
|
+
|
30
|
+
##### Update an Item Group
|
31
|
+
|
32
|
+
Updates the details of an existing Item Group.
|
33
|
+
|
34
|
+
<!-- {.file-heading} -->
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
itemgroup_id = '1234567890'
|
38
|
+
params = { group_name: 'Bags', unit: 'qty' }
|
39
|
+
|
40
|
+
Zoho::Inventory::ItemGroup.update(itemgroup_id, params)
|
41
|
+
```
|
42
|
+
Check https://www.zoho.com/inventory/api/v1/#Item_Groups_Update_an_Item_Group for more arguments that you can pass as params.
|
43
|
+
|
44
|
+
##### Delete an Item Group
|
45
|
+
|
46
|
+
Deletes an existing Item Group from Zoho Inventory.
|
47
|
+
|
48
|
+
<!-- {.file-heading} -->
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
itemgroup_id = '1234567890'
|
52
|
+
|
53
|
+
Zoho::Inventory::ItemGroup.destroy(itemgroup_id)
|
54
|
+
```
|
55
|
+
|
56
|
+
##### Mark as active
|
57
|
+
|
58
|
+
Marks an Item group as Active.
|
59
|
+
|
60
|
+
<!-- {.file-heading} -->
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
itemgroup_id = '1234567890'
|
64
|
+
|
65
|
+
Zoho::Inventory::ItemGroup.active!(itemgroup_id)
|
66
|
+
```
|
67
|
+
|
68
|
+
##### Mark as inactive
|
69
|
+
|
70
|
+
Marks as Item Group as Inactive.
|
71
|
+
|
72
|
+
<!-- {.file-heading} -->
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
itemgroup_id = '1234567890'
|
76
|
+
|
77
|
+
Zoho::Inventory::ItemGroup.inactive!(itemgroup_id)
|
78
|
+
```
|
79
|
+
|
80
|
+
##### List all Item Groups
|
81
|
+
|
82
|
+
Lists all the Item Groups that are present in the Zoho Inventory organization.
|
83
|
+
|
84
|
+
<!-- {.file-heading} -->
|
85
|
+
|
86
|
+
```ruby
|
87
|
+
Zoho::Inventory::ItemGroup.all
|
88
|
+
```
|
89
|
+
|
90
|
+
##### List all the items based on arguments passed
|
91
|
+
|
92
|
+
<!-- {.file-heading} -->
|
93
|
+
|
94
|
+
```ruby
|
95
|
+
Zoho::Inventory::ItemGroup.all(filter_by: 'Status.Active', sort_column: 'created_time',
|
96
|
+
sort_order: 'D', search_text: 'Bags', page: 1, per_page: 20)
|
97
|
+
|
98
|
+
# filter_by (`Status.All`, `Status.Active`, `Status.Inactive`)
|
99
|
+
# sort_column (`name`, `rate`, `created_time`)
|
100
|
+
# sort_order ('D', 'A')
|
101
|
+
```
|
data/docs/inventory/items.md
CHANGED
@@ -11,7 +11,7 @@ Creates a new item in Zoho Inventory.
|
|
11
11
|
```ruby
|
12
12
|
params = { name: 'Bags-small', rate: 10, purchase_rate: 10 }
|
13
13
|
|
14
|
-
Zoho::Inventory::Item.
|
14
|
+
Zoho::Inventory::Item.create(params)
|
15
15
|
```
|
16
16
|
Check https://www.zoho.com/inventory/api/v1/#Items_Create_an_item for more arguments that you can pass as params.
|
17
17
|
|
@@ -24,7 +24,7 @@ Fetches the details for an existing item.
|
|
24
24
|
```ruby
|
25
25
|
item_id = '1234567890'
|
26
26
|
|
27
|
-
Zoho::Inventory::
|
27
|
+
Zoho::Inventory::Item.find(item_id)
|
28
28
|
```
|
29
29
|
|
30
30
|
##### Update an item
|
@@ -37,7 +37,7 @@ Update the details of an item.
|
|
37
37
|
item_id = '1234567890'
|
38
38
|
params = { name: 'Bags small', rate: 5 }
|
39
39
|
|
40
|
-
Zoho::Inventory::Item.
|
40
|
+
Zoho::Inventory::Item.update(item_id, params)
|
41
41
|
```
|
42
42
|
Check https://www.zoho.com/inventory/api/v1/#Items_Update_an_item for more arguments that you can pass as params.
|
43
43
|
|
@@ -50,7 +50,7 @@ Deletes an existing item from Zoho Inventory.
|
|
50
50
|
```ruby
|
51
51
|
item_id = '1234567890'
|
52
52
|
|
53
|
-
Zoho::Inventory::Item.
|
53
|
+
Zoho::Inventory::Item.destroy(item_id)
|
54
54
|
```
|
55
55
|
|
56
56
|
##### Mark as active
|
@@ -62,7 +62,7 @@ Changes the status of an item to active.
|
|
62
62
|
```ruby
|
63
63
|
item_id = '1234567890'
|
64
64
|
|
65
|
-
Zoho::Inventory::Item.
|
65
|
+
Zoho::Inventory::Item.active!(item_id)
|
66
66
|
```
|
67
67
|
|
68
68
|
##### Mark as inactive
|
@@ -74,7 +74,7 @@ Mark an item as inactive.
|
|
74
74
|
```ruby
|
75
75
|
item_id = '1234567890'
|
76
76
|
|
77
|
-
Zoho::Inventory::Item.
|
77
|
+
Zoho::Inventory::Item.inactive!(item_id)
|
78
78
|
```
|
79
79
|
|
80
80
|
##### List all the items
|
@@ -84,7 +84,7 @@ Lists all the items present in Zoho Inventory.
|
|
84
84
|
<!-- {.file-heading} -->
|
85
85
|
|
86
86
|
```ruby
|
87
|
-
Zoho::Inventory.
|
87
|
+
Zoho::Inventory::Item.all
|
88
88
|
```
|
89
89
|
|
90
90
|
##### List all the items based on arguments passed
|
@@ -92,9 +92,8 @@ Zoho::Inventory.new.all
|
|
92
92
|
<!-- {.file-heading} -->
|
93
93
|
|
94
94
|
```ruby
|
95
|
-
Zoho::Inventory.
|
96
|
-
|
97
|
-
sort_order: 'D', search_text: 'Bags')
|
95
|
+
Zoho::Inventory::Item.all(filter_by: 'Status.Active', sort_column: 'created_time',
|
96
|
+
sort_order: 'D', search_text: 'Bags', page: 1, per_page: 20)
|
98
97
|
|
99
98
|
# filter_by (`Status.All`, `Status.Active`, `Status.Inactive`)
|
100
99
|
# sort_column (`name`, `rate`, `created_time`)
|
data/lib/zoho/configuration.rb
CHANGED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Zoho
|
5
|
+
module Inventory
|
6
|
+
class API
|
7
|
+
BASE_URI = 'https://inventory.zoho.com/api/v1/'.freeze
|
8
|
+
|
9
|
+
attr_reader :type
|
10
|
+
|
11
|
+
def initialize(type:)
|
12
|
+
@type = type
|
13
|
+
end
|
14
|
+
|
15
|
+
def construct_uri(path = '')
|
16
|
+
URI.parse("#{BASE_URI}#{type}#{path}#{config_uri}")
|
17
|
+
end
|
18
|
+
|
19
|
+
def request(uri, method, params = {})
|
20
|
+
response = HTTParty.send(method, uri, params)
|
21
|
+
JSON.parse(response.body)
|
22
|
+
end
|
23
|
+
|
24
|
+
def merge_options(options = {})
|
25
|
+
options.map { |key, value| "#{key}=#{value}" }.join('&')
|
26
|
+
end
|
27
|
+
|
28
|
+
def default_options
|
29
|
+
{ page: 1, per_page: Zoho.configuration.per_page }
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def config_uri
|
35
|
+
"?authtoken=#{Zoho.configuration.auth_token}" \
|
36
|
+
"&organization_id=#{Zoho.configuration.organization_id}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/zoho/inventory/item.rb
CHANGED
@@ -1,124 +1,42 @@
|
|
1
|
-
require 'active_support/core_ext/hash/indifferent_access'
|
2
|
-
require 'httparty'
|
3
|
-
require 'json'
|
4
|
-
|
5
1
|
module Zoho
|
6
2
|
module Inventory
|
7
3
|
class Item
|
8
|
-
|
9
|
-
|
10
|
-
def initialize(page: 1)
|
11
|
-
@page = page
|
12
|
-
end
|
13
|
-
|
14
|
-
def all
|
15
|
-
uri = "#{BASE_URI}#{config_uri}&page=#{@page}" \
|
16
|
-
"&per_page=#{Zoho.configuration.per_page}"
|
17
|
-
|
18
|
-
return_items_with_image_link(uri)
|
19
|
-
end
|
20
|
-
|
21
|
-
def where(**args)
|
22
|
-
uri = "#{BASE_URI}#{config_uri}&page=#{@page}" \
|
23
|
-
"&per_page=#{Zoho.configuration.per_page}"
|
24
|
-
uri << filter_uri(args[:filter_by])
|
25
|
-
uri << sort_uri(args[:sort_column], args[:sort_order])
|
26
|
-
uri << search_uri(args[:search_text])
|
27
|
-
|
28
|
-
return_items_with_image_link(uri)
|
29
|
-
end
|
30
|
-
|
31
|
-
def create(params)
|
32
|
-
uri = "#{BASE_URI}#{config_uri}"
|
33
|
-
result = request_item('post', uri, body: { JSONString: params.to_json })
|
34
|
-
add_image_link(result[:item]) if result[:item]
|
35
|
-
|
36
|
-
result
|
37
|
-
end
|
38
|
-
|
39
|
-
def update(item_id, params)
|
40
|
-
uri = "#{BASE_URI}/#{item_id}#{config_uri}"
|
41
|
-
result = request_item('put', uri, body: { JSONString: params.to_json })
|
42
|
-
add_image_link(result[:item]) if result[:item]
|
43
|
-
|
44
|
-
result
|
45
|
-
end
|
46
|
-
|
47
|
-
def find(item_id)
|
48
|
-
uri = "#{BASE_URI}/#{item_id}#{config_uri}"
|
49
|
-
result = request_item('get', uri)
|
50
|
-
add_image_link(result[:item]) if result[:item]
|
51
|
-
|
52
|
-
result
|
53
|
-
end
|
54
|
-
|
55
|
-
def destroy(item_id)
|
56
|
-
uri = "#{BASE_URI}/#{item_id}#{config_uri}"
|
4
|
+
@api = Zoho::Inventory::API.new(type: 'items')
|
57
5
|
|
58
|
-
|
6
|
+
def self.all(options = @api.default_options)
|
7
|
+
uri = @api.construct_uri
|
8
|
+
uri.query = [uri.query, @api.merge_options(options)].join('&')
|
9
|
+
@api.request(uri, 'get')
|
59
10
|
end
|
60
11
|
|
61
|
-
def
|
62
|
-
uri = "
|
63
|
-
|
64
|
-
request_item('post', uri)
|
12
|
+
def self.find(item_id)
|
13
|
+
uri = @api.construct_uri("/#{item_id}")
|
14
|
+
@api.request(uri, 'get')
|
65
15
|
end
|
66
16
|
|
67
|
-
def
|
68
|
-
uri =
|
69
|
-
|
70
|
-
request_item('post', uri)
|
17
|
+
def self.create(params)
|
18
|
+
uri = @api.construct_uri
|
19
|
+
@api.request(uri, 'post', body: { JSONString: params.to_json })
|
71
20
|
end
|
72
21
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
"?authtoken=#{Zoho.configuration.auth_token}" \
|
77
|
-
"&organization_id=#{Zoho.configuration.organization_id}"
|
22
|
+
def self.update(item_id, params)
|
23
|
+
uri = @api.construct_uri("/#{item_id}")
|
24
|
+
@api.request(uri, 'put', body: { JSONString: params.to_json })
|
78
25
|
end
|
79
26
|
|
80
|
-
def
|
81
|
-
|
27
|
+
def self.destroy(item_id)
|
28
|
+
uri = @api.construct_uri("/#{item_id}")
|
29
|
+
@api.request(uri, 'delete')
|
82
30
|
end
|
83
31
|
|
84
|
-
def
|
85
|
-
uri =
|
86
|
-
uri
|
87
|
-
uri << "&sort_order=#{sort_order}"
|
88
|
-
|
89
|
-
sort_column.nil? ? '' : uri
|
90
|
-
end
|
91
|
-
|
92
|
-
def search_uri(text)
|
93
|
-
text.nil? ? '' : "&search_text=#{text}"
|
94
|
-
end
|
95
|
-
|
96
|
-
def image_uri(item_id)
|
97
|
-
"#{BASE_URI}/#{item_id}/image#{config_uri}"
|
98
|
-
end
|
99
|
-
|
100
|
-
def add_image_link(item)
|
101
|
-
item[:image_link] = unless item[:image_name].empty?
|
102
|
-
image_uri(item[:item_id])
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
def items_add_image_link(items)
|
107
|
-
items.map do |item|
|
108
|
-
add_image_link(item) if item
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
def return_items_with_image_link(uri)
|
113
|
-
result = request_item('get', uri)
|
114
|
-
items_add_image_link(result[:items]) if result[:items]
|
115
|
-
|
116
|
-
result
|
32
|
+
def self.active!(item_id)
|
33
|
+
uri = @api.construct_uri("/#{item_id}/active")
|
34
|
+
@api.request(uri, 'post')
|
117
35
|
end
|
118
36
|
|
119
|
-
def
|
120
|
-
|
121
|
-
|
37
|
+
def self.inactive!(item_id)
|
38
|
+
uri = @api.construct_uri("/#{item_id}/inactive")
|
39
|
+
@api.request(uri, 'post')
|
122
40
|
end
|
123
41
|
end
|
124
42
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Zoho
|
2
|
+
module Inventory
|
3
|
+
class ItemGroup
|
4
|
+
@api = Zoho::Inventory::API.new(type: 'itemgroups')
|
5
|
+
|
6
|
+
def self.all(options = @api.default_options)
|
7
|
+
uri = @api.construct_uri
|
8
|
+
uri.query = [uri.query, @api.merge_options(options)].join('&')
|
9
|
+
@api.request(uri, 'get')
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.find(itemgroup_id)
|
13
|
+
uri = @api.construct_uri("/#{itemgroup_id}")
|
14
|
+
@api.request(uri, 'get')
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.create(params)
|
18
|
+
uri = @api.construct_uri
|
19
|
+
@api.request(uri, 'post', body: { JSONString: params.to_json })
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.update(itemgroup_id, params)
|
23
|
+
uri = @api.construct_uri("/#{itemgroup_id}")
|
24
|
+
@api.request(uri, 'put', body: { JSONString: params.to_json })
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.destroy(itemgroup_id)
|
28
|
+
uri = @api.construct_uri("/#{itemgroup_id}")
|
29
|
+
@api.request(uri, 'delete')
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.active!(itemgroup_id)
|
33
|
+
uri = @api.construct_uri("/#{itemgroup_id}/active")
|
34
|
+
@api.request(uri, 'post')
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.inactive!(itemgroup_id)
|
38
|
+
uri = @api.construct_uri("/#{itemgroup_id}/inactive")
|
39
|
+
@api.request(uri, 'post')
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/zoho/version.rb
CHANGED
data/lib/zoho.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zoho_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patrick Ofilada
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-02-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -85,10 +85,13 @@ files:
|
|
85
85
|
- bin/setup
|
86
86
|
- docs/README.md
|
87
87
|
- docs/inventory/README.md
|
88
|
+
- docs/inventory/item_groups.md
|
88
89
|
- docs/inventory/items.md
|
89
90
|
- lib/zoho.rb
|
90
91
|
- lib/zoho/configuration.rb
|
92
|
+
- lib/zoho/inventory/api.rb
|
91
93
|
- lib/zoho/inventory/item.rb
|
94
|
+
- lib/zoho/inventory/item_group.rb
|
92
95
|
- lib/zoho/version.rb
|
93
96
|
- lib/zoho_ruby.rb
|
94
97
|
- zoho.gemspec
|
@@ -112,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
115
|
version: '0'
|
113
116
|
requirements: []
|
114
117
|
rubyforge_project:
|
115
|
-
rubygems_version: 2.6.
|
118
|
+
rubygems_version: 2.6.13
|
116
119
|
signing_key:
|
117
120
|
specification_version: 4
|
118
121
|
summary: Ruby wrapper for Zoho API.
|