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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d6d9eb280fbaf34cbf7ae8fce708a9bda910bb2b
4
- data.tar.gz: aa3c96ae047f29633d3488a67d17b3838d09f017
3
+ metadata.gz: 15566afc6b08355d0fe1aaacaa35dd0a922ccce3
4
+ data.tar.gz: acaba96cd216f58c89003f7491b84d1152ac6663
5
5
  SHA512:
6
- metadata.gz: d616c5b9ea1b87b90b243c4b658ec1d7f9229742325b4453708cdcad8788184da60a2d9e00d3e345a4f7f92ab255a10eb7a79c5538ac5a29b1e435e59ff8ca39
7
- data.tar.gz: 2374511457f3b55997ec53f48cf801376d7d47d39e1a549e182b2674b998802d5bed1fa2af56dcdaae4bf48fc6fed151794a9ef787930983bb43b3213512564c
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 200
30
+ config.per_page = 20 # Default and maximum items per page is 50
31
31
  end
32
32
  ```
33
33
  ## Usage
@@ -1,3 +1,4 @@
1
1
  # Table of contents
2
2
 
3
+ * [Item Groups](item_groups.md)
3
4
  * [Items](items.md)
@@ -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
+ ```
@@ -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.new.create(params)
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::Items.new.find(item_id)
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.new.update(item_id, params)
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.new.destroy(item_id)
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.new.active!(item_id)
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.new.inactive!(item_id)
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.new.all
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.new
96
- .where(filter_by: 'Status.Active', sort_column: 'created_time'
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`)
@@ -3,7 +3,7 @@ module Zoho
3
3
  attr_accessor :organization_id, :auth_token, :per_page
4
4
 
5
5
  def initialize
6
- @per_page = 200
6
+ @per_page = 50
7
7
  end
8
8
  end
9
9
  end
@@ -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
@@ -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
- BASE_URI = 'https://inventory.zoho.com/api/v1/items'.freeze
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
- request_item('delete', uri)
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 active!(item_id)
62
- uri = "#{BASE_URI}/#{item_id}/active#{config_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 inactive!(item_id)
68
- uri = "#{BASE_URI}/#{item_id}/inactive#{config_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
- private
74
-
75
- def config_uri
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 filter_uri(filter_by)
81
- filter_by.nil? ? '' : "&filter_by=#{filter_by}"
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 sort_uri(sort_column, sort_order = 'D')
85
- uri = ''
86
- uri << "&sort_column=#{sort_column}"
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 request_item(method, uri, params = {})
120
- response = HTTParty.send(method, uri, params)
121
- JSON.parse(response.body).with_indifferent_access
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
@@ -1,3 +1,3 @@
1
1
  module Zoho
2
- VERSION = '0.0.2'.freeze
2
+ VERSION = '0.0.3'.freeze
3
3
  end
data/lib/zoho.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require 'zoho/version'
2
2
  require 'zoho/configuration'
3
+ require 'zoho/inventory/api'
4
+ require 'zoho/inventory/item_group'
3
5
  require 'zoho/inventory/item'
4
6
 
5
7
  module Zoho
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.2
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: 2017-08-29 00:00:00.000000000 Z
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.8
118
+ rubygems_version: 2.6.13
116
119
  signing_key:
117
120
  specification_version: 4
118
121
  summary: Ruby wrapper for Zoho API.