zoho_hub 0.1.9 → 0.1.10

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: d1933605b1424c79d11d50143faf939f90094d5eb4cbb5cc99ea827395d4a2bc
4
- data.tar.gz: 86f38c60b4e2e6b54d44f8cb437f5e3d154a94ad47fa30a9675f720abf369a30
3
+ metadata.gz: 85ad0f4580d7758046129affd8819a1cc96560f0f2b4637b20647db3231de092
4
+ data.tar.gz: cb637f4961be8aaec37b56624b41301911aa4102a5bda48db526f4ed7b8d6a5e
5
5
  SHA512:
6
- metadata.gz: 53d977f695726080789a7fc647847bf5b7d3b642bf9ecfac115e9149927cac6c0ba4123eebbc728cc4e1f8017b140bd76823ee2eb3d75a4efa70e19563af0269
7
- data.tar.gz: 12049cff9d41065c98d2be36504a1cf69ba35374c48b62c6a9c41ddd2264e9d751dd6cc710324ef791c122c67080f81dad4e4a0fafd3d9a8e07f02641e5a6b76
6
+ metadata.gz: 7ab15bd80340c46e2c8e4d2a6c68eae51bc156b65b92cd0ea3f0bf206d68923e6a5eacf8b16c355e1bc4e21d3d4212a253b394138c948824be0f811326ddb485
7
+ data.tar.gz: b828374accd2189ca276a0f6de4a55b5c7c00d1d1491c09fb9aecbaecdf5fc9ea91db661570617fa5cf6c6ca2b6fba409cafdaa08e69ac5c5eccd2f742120bbd
data/.rspec CHANGED
@@ -1,4 +1,3 @@
1
1
  --format documentation
2
2
  --color
3
3
  --require spec_helper
4
- --order rand
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.5.3
1
+ 2.5.1
data/.travis.yml CHANGED
@@ -1,9 +1,5 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.1.10
5
- - 2.2.10
6
- - 2.3.7
7
- - 2.4.4
8
- - 2.5.3
4
+ - 2.5.0
9
5
  before_install: gem install bundler -v 1.16.1
data/Gemfile.lock CHANGED
@@ -1,31 +1,41 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- zoho_hub (0.1.9)
5
- addressable
6
- faraday
7
- faraday_middleware
8
- multi_json
9
- rainbow
4
+ zoho_hub (0.1.10)
5
+ activesupport (~> 5.2)
6
+ addressable (~> 2.5)
7
+ faraday (~> 0.15)
8
+ faraday_middleware (~> 0.12)
9
+ multi_json (~> 1.13)
10
+ rainbow (~> 3.0)
10
11
 
11
12
  GEM
12
13
  remote: https://rubygems.org/
13
14
  specs:
15
+ activesupport (5.2.2)
16
+ concurrent-ruby (~> 1.0, >= 1.0.2)
17
+ i18n (>= 0.7, < 2)
18
+ minitest (~> 5.1)
19
+ tzinfo (~> 1.1)
14
20
  addressable (2.5.2)
15
21
  public_suffix (>= 2.0.2, < 4.0)
16
22
  ast (2.4.0)
17
- byebug (9.0.6)
23
+ byebug (10.0.2)
18
24
  coderay (1.1.2)
25
+ concurrent-ruby (1.1.3)
19
26
  diff-lcs (1.3)
20
27
  docile (1.3.1)
21
28
  dotenv (2.5.0)
22
- faraday (0.15.3)
29
+ faraday (0.15.4)
23
30
  multipart-post (>= 1.2, < 3)
24
31
  faraday_middleware (0.12.2)
25
32
  faraday (>= 0.7.4, < 1.0)
33
+ i18n (1.2.0)
34
+ concurrent-ruby (~> 1.0)
26
35
  jaro_winkler (1.5.1)
27
36
  json (2.1.0)
28
37
  method_source (0.9.0)
38
+ minitest (5.11.3)
29
39
  multi_json (1.13.1)
30
40
  multipart-post (2.0.0)
31
41
  parallel (1.12.1)
@@ -35,55 +45,58 @@ GEM
35
45
  pry (0.11.3)
36
46
  coderay (~> 1.1.0)
37
47
  method_source (~> 0.9.0)
38
- pry-byebug (3.4.3)
39
- byebug (>= 9.0, < 9.1)
48
+ pry-byebug (3.6.0)
49
+ byebug (~> 10.0)
40
50
  pry (~> 0.10)
41
51
  public_suffix (3.0.3)
42
52
  rainbow (3.0.0)
43
- rake (12.3.1)
44
- rspec (3.8.0)
45
- rspec-core (~> 3.8.0)
46
- rspec-expectations (~> 3.8.0)
47
- rspec-mocks (~> 3.8.0)
48
- rspec-core (3.8.0)
49
- rspec-support (~> 3.8.0)
50
- rspec-expectations (3.8.2)
53
+ rake (10.5.0)
54
+ rspec (3.7.0)
55
+ rspec-core (~> 3.7.0)
56
+ rspec-expectations (~> 3.7.0)
57
+ rspec-mocks (~> 3.7.0)
58
+ rspec-core (3.7.1)
59
+ rspec-support (~> 3.7.0)
60
+ rspec-expectations (3.7.0)
51
61
  diff-lcs (>= 1.2.0, < 2.0)
52
- rspec-support (~> 3.8.0)
53
- rspec-mocks (3.8.0)
62
+ rspec-support (~> 3.7.0)
63
+ rspec-mocks (3.7.0)
54
64
  diff-lcs (>= 1.2.0, < 2.0)
55
- rspec-support (~> 3.8.0)
56
- rspec-support (3.8.0)
57
- rubocop (0.57.2)
65
+ rspec-support (~> 3.7.0)
66
+ rspec-support (3.7.1)
67
+ rubocop (0.58.1)
58
68
  jaro_winkler (~> 1.5.1)
59
69
  parallel (~> 1.10)
60
- parser (>= 2.5)
70
+ parser (>= 2.5, != 2.5.1.1)
61
71
  powerpack (~> 0.1)
62
72
  rainbow (>= 2.2.2, < 4.0)
63
73
  ruby-progressbar (~> 1.7)
64
74
  unicode-display_width (~> 1.0, >= 1.0.1)
65
75
  rubocop-rspec (1.27.0)
66
76
  rubocop (>= 0.56.0)
67
- ruby-progressbar (1.10.0)
77
+ ruby-progressbar (1.9.0)
68
78
  simplecov (0.16.1)
69
79
  docile (~> 1.1)
70
80
  json (>= 1.8, < 3)
71
81
  simplecov-html (~> 0.10.0)
72
82
  simplecov-html (0.10.2)
83
+ thread_safe (0.3.6)
84
+ tzinfo (1.2.5)
85
+ thread_safe (~> 0.1)
73
86
  unicode-display_width (1.4.0)
74
87
 
75
88
  PLATFORMS
76
89
  ruby
77
90
 
78
91
  DEPENDENCIES
79
- bundler
80
- dotenv
81
- pry-byebug
82
- rake
83
- rspec
84
- rubocop
85
- rubocop-rspec
86
- simplecov
92
+ bundler (~> 1.16)
93
+ dotenv (~> 2.5)
94
+ pry-byebug (~> 3.6)
95
+ rake (~> 10.0)
96
+ rspec (~> 3.0)
97
+ rubocop (~> 0.58)
98
+ rubocop-rspec (~> 1.27)
99
+ simplecov (~> 0.16)
87
100
  zoho_hub!
88
101
 
89
102
  BUNDLED WITH
data/README.md CHANGED
@@ -1,12 +1,6 @@
1
1
  # ZohoHub
2
2
 
3
- [![Build Status](https://travis-ci.com/rikas/zoho_hub.svg?branch=master)](https://travis-ci.com/rikas/zoho_hub)
4
-
5
- Simple wrapper around Zoho CRM version2, using authentication by [OAuth 2.0 protocol](https://www.zoho.com/crm/help/api/v2/#OAuth2_0).
6
-
7
- This gem reads your Module configuration and builds the corresponding classes for you.
8
-
9
- **NOTE: this gem is WIP, please try to use it and open an issue if you run into limitations / problems**
3
+ https://www.zoho.com/crm/help/api-diff/
10
4
 
11
5
  ## Installation
12
6
 
@@ -26,16 +20,7 @@ Or install it yourself as:
26
20
 
27
21
  ## Usage
28
22
 
29
- First you need to have a configuration block like the one below:
30
-
31
- ```ruby
32
- ZohoHub.configure do |config|
33
- config.client_id = 'YOUR_ZOHO_CLIENT_ID'
34
- config.secret = 'YOUR_ZOHO_SECRET'
35
- config.redirect_uri = 'YOUR_ZOHO_OAUTH_REDIRECT_URL'
36
- # config.debug = true # this will be VERY verbose, but helps to identify bugs / problems
37
- end
38
- ```
23
+ TODO: Write usage instructions here
39
24
 
40
25
  ## Development
41
26
 
@@ -43,7 +28,10 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
43
28
  the tests. You can also run `bin/console` for an interactive prompt that will allow you to
44
29
  experiment.
45
30
 
46
- To install this gem onto your local machine, run `bundle exec rake install`.
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new
32
+ version, update the version number in `version.rb`, and then run `bundle exec rake release`, which
33
+ will create a git tag for the version, push git commits and tags, and push the `.gem` file
34
+ to [rubygems.org](https://rubygems.org).
47
35
 
48
36
  ## Contributing
49
37
 
data/bin/console CHANGED
@@ -8,14 +8,16 @@ require 'dotenv'
8
8
  Dotenv.load
9
9
 
10
10
  ZohoHub.configure do |config|
11
- config.client_id = ENV['ZOHO_CLIENT_ID']
12
- config.secret = ENV['ZOHO_SECRET']
11
+ config.client_id = ENV['ZOHO_CLIENT_ID']
12
+ config.secret = ENV['ZOHO_SECRET']
13
13
  config.redirect_uri = ENV['ZOHO_OAUTH_REDIRECT_URL']
14
- config.debug = true
14
+ config.debug = true
15
15
  end
16
16
 
17
17
  token_params = ZohoHub::Auth.refresh_token(ENV['ZOHO_REFRESH_TOKEN'])
18
18
  ZohoHub.setup_connection(token_params)
19
19
 
20
+ self.send(:include, ZohoHub)
21
+
20
22
  require 'pry'
21
23
  Pry.start
data/bin/setup CHANGED
@@ -4,3 +4,5 @@ IFS=$'\n\t'
4
4
  set -vx
5
5
 
6
6
  bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -48,11 +48,11 @@ module ZohoHub
48
48
  end
49
49
 
50
50
  def access_token?
51
- @access_token
51
+ @access_token.present?
52
52
  end
53
53
 
54
54
  def refresh_token?
55
- @refresh_token
55
+ @refresh_token.present?
56
56
  end
57
57
 
58
58
  def log(text)
@@ -73,7 +73,7 @@ module ZohoHub
73
73
  log "Refreshing outdated token... #{@access_token}"
74
74
  params = ZohoHub::Auth.refresh_token(@refresh_token)
75
75
 
76
- @on_refresh_cb&.call(params)
76
+ @on_refresh_cb.call(params) if @on_refresh_cb.present?
77
77
 
78
78
  @access_token = params[:access_token]
79
79
 
@@ -1,31 +1,38 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'zoho_hub/response'
4
- require 'zoho_hub/with_connection'
5
- require 'zoho_hub/with_attributes'
6
- require 'zoho_hub/string_utils'
7
4
 
8
5
  module ZohoHub
9
6
  class BaseRecord
10
- include WithConnection
11
- include WithAttributes
12
-
13
- # Default nnumber of records when fetching all.
14
- DEFAULT_RECORDS_PER_PAGE = 200
15
-
16
- # Default page number when fetching all.
17
- DEFAULT_PAGE = 1
18
-
19
- # Minimum number of records to fetch when fetching all.
20
- MIN_RECORDS = 2
21
-
22
7
  class << self
23
8
  def request_path(name = nil)
24
9
  @request_path = name if name
25
- @request_path ||= StringUtils.pluralize(StringUtils.demodulize(to_s))
10
+ @request_path ||= to_s.demodulize.pluralize
26
11
  @request_path
27
12
  end
28
13
 
14
+ def attributes(*attributes)
15
+ @attributes ||= []
16
+
17
+ return @attributes unless attributes
18
+
19
+ attr_accessor(*attributes)
20
+
21
+ @attributes += attributes
22
+ end
23
+
24
+ def attribute_translation(translation = nil)
25
+ @attribute_translation ||= {}
26
+
27
+ return @attribute_translation unless translation
28
+
29
+ @attribute_translation = translation
30
+ end
31
+
32
+ def zoho_key_translation
33
+ @attribute_translation.to_a.map(&:rotate).to_h
34
+ end
35
+
29
36
  def find(id)
30
37
  body = get(File.join(request_path, id.to_s))
31
38
  response = build_response(body)
@@ -56,16 +63,27 @@ module ZohoHub
56
63
  end
57
64
 
58
65
  def all(options = {})
59
- options[:page] ||= DEFAULT_PAGE
60
- options[:per_page] ||= DEFAULT_RECORDS_PER_PAGE
61
- options[:per_page] = MIN_RECORDS if options[:per_page] < MIN_RECORDS
66
+ options[:page] ||= 1
67
+ options[:per_page] ||= 200
62
68
 
63
69
  body = get(request_path, options)
64
70
  response = build_response(body)
65
71
 
66
72
  data = response.nil? ? [] : response.data
67
73
 
68
- data.map { |json| new(json) }
74
+ data.map { |info| new(info) }
75
+ end
76
+
77
+ def get(path, params = {})
78
+ ZohoHub.connection.get(path, params)
79
+ end
80
+
81
+ def post(path, params = {})
82
+ ZohoHub.connection.post(path, params.to_json)
83
+ end
84
+
85
+ def put(path, params = {})
86
+ ZohoHub.connection.put(path, params.to_json)
69
87
  end
70
88
 
71
89
  def exists?(id)
@@ -86,6 +104,22 @@ module ZohoHub
86
104
  end
87
105
  end
88
106
 
107
+ def attributes
108
+ self.class.attributes
109
+ end
110
+
111
+ def get(path, params = {})
112
+ self.class.get(path, params)
113
+ end
114
+
115
+ def post(path, params = {})
116
+ self.class.post(path, params)
117
+ end
118
+
119
+ def put(path, params = {})
120
+ self.class.put(path, params)
121
+ end
122
+
89
123
  def save
90
124
  body = if new_record? # create new record
91
125
  post(self.class.request_path, data: [to_params])
@@ -100,7 +134,7 @@ module ZohoHub
100
134
  end
101
135
 
102
136
  def new_record?
103
- !id
137
+ !id.present?
104
138
  end
105
139
 
106
140
  def to_params
@@ -118,5 +152,23 @@ module ZohoHub
118
152
  def build_response(body)
119
153
  self.class.build_response(body)
120
154
  end
155
+
156
+ private
157
+
158
+ def attr_to_zoho_key(attr_name)
159
+ translations = self.class.attribute_translation
160
+
161
+ return translations[attr_name.to_sym] if translations.key?(attr_name.to_sym)
162
+
163
+ attr_name.to_s.split('_').map(&:capitalize).join('_').to_sym
164
+ end
165
+
166
+ def zoho_key_to_attr(zoho_key)
167
+ translations = self.class.zoho_key_translation
168
+
169
+ return translations[zoho_key.to_sym] if translations.key?(zoho_key.to_sym)
170
+
171
+ zoho_key.to_sym
172
+ end
121
173
  end
122
174
  end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ZohoHub
4
+ class Product < BaseRecord
5
+ attributes :id, :description, :vendor_id, :owner_id
6
+
7
+ attribute_translation(
8
+ id: :id
9
+ )
10
+
11
+ def initialize(params)
12
+ puts Rainbow(params).magenta
13
+
14
+ attributes.each do |attr|
15
+ zoho_key = attr_to_zoho_key(attr)
16
+
17
+ send("#{attr}=", params[zoho_key] || params[attr])
18
+ end
19
+
20
+ @owner_id ||= params.dig(:Owner, :id)
21
+ @vendor_id ||= params.dig(:Vendor_Name, :id)
22
+ end
23
+
24
+ def to_params
25
+ params = super
26
+
27
+ params[:Owner] = { id: @owner_id } if @owner_id
28
+ params[:Vendor_Name] = { id: @vendor_id } if @vendor_id
29
+
30
+ params
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ZohoHub
4
+ class Vendor < BaseRecord
5
+ attributes :id, :email, :description, :vendor_name, :website, :owner_id, :phone, :currency
6
+ attributes :company_reg_no
7
+
8
+ attribute_translation(
9
+ id: :id
10
+ )
11
+
12
+ DEFAULTS = {
13
+ currency: 'GBP'
14
+ }.freeze
15
+
16
+ def initialize(params)
17
+ attributes.each do |attr|
18
+ zoho_key = attr_to_zoho_key(attr)
19
+
20
+ send("#{attr}=", params[zoho_key] || params[attr] || DEFAULTS[attr])
21
+ end
22
+
23
+ @owner_id ||= params.dig(:Owner, :id)
24
+ end
25
+
26
+ def to_params
27
+ params = super
28
+
29
+ params[:Owner] = { id: @owner_id } if @owner_id
30
+
31
+ params
32
+ end
33
+ end
34
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ZohoHub
4
- VERSION = '0.1.9'
4
+ VERSION = '0.1.10'
5
5
  end
data/lib/zoho_hub.rb CHANGED
@@ -1,34 +1,32 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'backports/2.3.0/hash' if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.3.0')
3
+ require 'active_support/core_ext/object/blank'
4
+ require 'active_support/core_ext/string/inflections'
4
5
 
5
6
  require 'zoho_hub/version'
6
7
  require 'zoho_hub/auth'
7
8
  require 'zoho_hub/configuration'
8
9
  require 'zoho_hub/connection'
9
10
  require 'zoho_hub/errors'
10
- require 'zoho_hub/base_record'
11
- require 'zoho_hub/settings/module'
12
- require 'zoho_hub/module_builder'
13
-
14
- require 'multi_json'
11
+ require 'zoho_hub/records/contact'
12
+ require 'zoho_hub/records/potential'
13
+ require 'zoho_hub/records/campaign'
14
+ require 'zoho_hub/records/account'
15
+ require 'zoho_hub/records/quote'
16
+ require 'zoho_hub/records/vendor'
17
+ require 'zoho_hub/records/product'
15
18
 
16
19
  module ZohoHub
17
20
  module_function
18
21
 
19
- def root
20
- File.expand_path(File.join(__dir__, '..'))
21
- end
22
-
23
22
  def configuration
24
23
  @configuration ||= Configuration.new
25
24
  end
26
25
 
27
- def configure
28
- yield(configuration)
26
+ def connection
27
+ @connection
29
28
  end
30
29
 
31
- # Callback for when the token is refreshed.
32
30
  def on_refresh(&block)
33
31
  @connection.on_refresh_cb = block
34
32
  end
@@ -36,24 +34,24 @@ module ZohoHub
36
34
  def setup_connection(params = {})
37
35
  raise "ERROR: #{params[:error]}" if params[:error]
38
36
 
39
- connection_params = params.dup.slice(:access_token, :expires_in, :api_domain, :refresh_token)
37
+ connection_params = params.slice(:access_token, :expires_in, :api_domain, :refresh_token)
40
38
 
41
39
  @connection = Connection.new(connection_params)
42
40
  end
43
41
 
44
- def connection
45
- @connection
46
- end
47
-
48
42
  def refresh_token?
49
- return false unless connection
43
+ return false unless connection.present?
50
44
 
51
45
  connection.refresh_token?
52
46
  end
53
47
 
54
48
  def access_token?
55
- return false unless connection
49
+ return false unless connection.present?
56
50
 
57
51
  connection.access_token?
58
52
  end
53
+
54
+ def configure
55
+ yield(configuration)
56
+ end
59
57
  end
data/zoho_hub.gemspec CHANGED
@@ -23,21 +23,19 @@ Gem::Specification.new do |spec|
23
23
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
24
  spec.require_paths = ['lib']
25
25
 
26
- spec.required_ruby_version = '>= 2.1.0'
27
-
28
- spec.add_dependency 'addressable'
29
- spec.add_dependency 'backports' if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.3.0')
30
- spec.add_dependency 'faraday'
31
- spec.add_dependency 'faraday_middleware'
32
- spec.add_dependency 'multi_json'
33
- spec.add_dependency 'rainbow'
34
-
35
- spec.add_development_dependency 'bundler'
36
- spec.add_development_dependency 'dotenv'
37
- spec.add_development_dependency 'pry-byebug'
38
- spec.add_development_dependency 'rake'
39
- spec.add_development_dependency 'rspec'
40
- spec.add_development_dependency 'rubocop'
41
- spec.add_development_dependency 'rubocop-rspec'
42
- spec.add_development_dependency 'simplecov'
26
+ spec.add_dependency 'activesupport', '~> 5.2'
27
+ spec.add_dependency 'addressable', '~> 2.5'
28
+ spec.add_dependency 'faraday', '~> 0.15'
29
+ spec.add_dependency 'faraday_middleware', '~> 0.12'
30
+ spec.add_dependency 'multi_json', '~> 1.13'
31
+ spec.add_dependency 'rainbow', '~> 3.0'
32
+
33
+ spec.add_development_dependency 'bundler', '~> 1.16'
34
+ spec.add_development_dependency 'dotenv', '~> 2.5'
35
+ spec.add_development_dependency 'pry-byebug', '~> 3.6'
36
+ spec.add_development_dependency 'rake', '~> 10.0'
37
+ spec.add_development_dependency 'rspec', '~> 3.0'
38
+ spec.add_development_dependency 'rubocop', '~> 0.58'
39
+ spec.add_development_dependency 'rubocop-rspec', '~> 1.27'
40
+ spec.add_development_dependency 'simplecov', '~> 0.16'
43
41
  end
metadata CHANGED
@@ -1,197 +1,211 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zoho_hub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ricardo Otero
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-11-25 00:00:00.000000000 Z
11
+ date: 2018-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.2'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: addressable
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
- - - ">="
31
+ - - "~>"
18
32
  - !ruby/object:Gem::Version
19
- version: '0'
33
+ version: '2.5'
20
34
  type: :runtime
21
35
  prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
- - - ">="
38
+ - - "~>"
25
39
  - !ruby/object:Gem::Version
26
- version: '0'
40
+ version: '2.5'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: faraday
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
- - - ">="
45
+ - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: '0'
47
+ version: '0.15'
34
48
  type: :runtime
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
- - - ">="
52
+ - - "~>"
39
53
  - !ruby/object:Gem::Version
40
- version: '0'
54
+ version: '0.15'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: faraday_middleware
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
- - - ">="
59
+ - - "~>"
46
60
  - !ruby/object:Gem::Version
47
- version: '0'
61
+ version: '0.12'
48
62
  type: :runtime
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
- - - ">="
66
+ - - "~>"
53
67
  - !ruby/object:Gem::Version
54
- version: '0'
68
+ version: '0.12'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: multi_json
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
- - - ">="
73
+ - - "~>"
60
74
  - !ruby/object:Gem::Version
61
- version: '0'
75
+ version: '1.13'
62
76
  type: :runtime
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
- - - ">="
80
+ - - "~>"
67
81
  - !ruby/object:Gem::Version
68
- version: '0'
82
+ version: '1.13'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: rainbow
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
- - - ">="
87
+ - - "~>"
74
88
  - !ruby/object:Gem::Version
75
- version: '0'
89
+ version: '3.0'
76
90
  type: :runtime
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
- - - ">="
94
+ - - "~>"
81
95
  - !ruby/object:Gem::Version
82
- version: '0'
96
+ version: '3.0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: bundler
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
- - - ">="
101
+ - - "~>"
88
102
  - !ruby/object:Gem::Version
89
- version: '0'
103
+ version: '1.16'
90
104
  type: :development
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
- - - ">="
108
+ - - "~>"
95
109
  - !ruby/object:Gem::Version
96
- version: '0'
110
+ version: '1.16'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: dotenv
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
- - - ">="
115
+ - - "~>"
102
116
  - !ruby/object:Gem::Version
103
- version: '0'
117
+ version: '2.5'
104
118
  type: :development
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
107
121
  requirements:
108
- - - ">="
122
+ - - "~>"
109
123
  - !ruby/object:Gem::Version
110
- version: '0'
124
+ version: '2.5'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: pry-byebug
113
127
  requirement: !ruby/object:Gem::Requirement
114
128
  requirements:
115
- - - ">="
129
+ - - "~>"
116
130
  - !ruby/object:Gem::Version
117
- version: '0'
131
+ version: '3.6'
118
132
  type: :development
119
133
  prerelease: false
120
134
  version_requirements: !ruby/object:Gem::Requirement
121
135
  requirements:
122
- - - ">="
136
+ - - "~>"
123
137
  - !ruby/object:Gem::Version
124
- version: '0'
138
+ version: '3.6'
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: rake
127
141
  requirement: !ruby/object:Gem::Requirement
128
142
  requirements:
129
- - - ">="
143
+ - - "~>"
130
144
  - !ruby/object:Gem::Version
131
- version: '0'
145
+ version: '10.0'
132
146
  type: :development
133
147
  prerelease: false
134
148
  version_requirements: !ruby/object:Gem::Requirement
135
149
  requirements:
136
- - - ">="
150
+ - - "~>"
137
151
  - !ruby/object:Gem::Version
138
- version: '0'
152
+ version: '10.0'
139
153
  - !ruby/object:Gem::Dependency
140
154
  name: rspec
141
155
  requirement: !ruby/object:Gem::Requirement
142
156
  requirements:
143
- - - ">="
157
+ - - "~>"
144
158
  - !ruby/object:Gem::Version
145
- version: '0'
159
+ version: '3.0'
146
160
  type: :development
147
161
  prerelease: false
148
162
  version_requirements: !ruby/object:Gem::Requirement
149
163
  requirements:
150
- - - ">="
164
+ - - "~>"
151
165
  - !ruby/object:Gem::Version
152
- version: '0'
166
+ version: '3.0'
153
167
  - !ruby/object:Gem::Dependency
154
168
  name: rubocop
155
169
  requirement: !ruby/object:Gem::Requirement
156
170
  requirements:
157
- - - ">="
171
+ - - "~>"
158
172
  - !ruby/object:Gem::Version
159
- version: '0'
173
+ version: '0.58'
160
174
  type: :development
161
175
  prerelease: false
162
176
  version_requirements: !ruby/object:Gem::Requirement
163
177
  requirements:
164
- - - ">="
178
+ - - "~>"
165
179
  - !ruby/object:Gem::Version
166
- version: '0'
180
+ version: '0.58'
167
181
  - !ruby/object:Gem::Dependency
168
182
  name: rubocop-rspec
169
183
  requirement: !ruby/object:Gem::Requirement
170
184
  requirements:
171
- - - ">="
185
+ - - "~>"
172
186
  - !ruby/object:Gem::Version
173
- version: '0'
187
+ version: '1.27'
174
188
  type: :development
175
189
  prerelease: false
176
190
  version_requirements: !ruby/object:Gem::Requirement
177
191
  requirements:
178
- - - ">="
192
+ - - "~>"
179
193
  - !ruby/object:Gem::Version
180
- version: '0'
194
+ version: '1.27'
181
195
  - !ruby/object:Gem::Dependency
182
196
  name: simplecov
183
197
  requirement: !ruby/object:Gem::Requirement
184
198
  requirements:
185
- - - ">="
199
+ - - "~>"
186
200
  - !ruby/object:Gem::Version
187
- version: '0'
201
+ version: '0.16'
188
202
  type: :development
189
203
  prerelease: false
190
204
  version_requirements: !ruby/object:Gem::Requirement
191
205
  requirements:
192
- - - ">="
206
+ - - "~>"
193
207
  - !ruby/object:Gem::Version
194
- version: '0'
208
+ version: '0.16'
195
209
  description: Simple gem to connect to Zoho CRM API V2
196
210
  email:
197
211
  - oterosantos@gmail.com
@@ -210,30 +224,22 @@ files:
210
224
  - README.md
211
225
  - Rakefile
212
226
  - bin/console
213
- - bin/read
214
227
  - bin/setup
215
- - cache/.git_keep
216
228
  - lib/zoho_hub.rb
217
229
  - lib/zoho_hub/auth.rb
218
- - lib/zoho_hub/base_record.rb
219
230
  - lib/zoho_hub/configuration.rb
220
231
  - lib/zoho_hub/connection.rb
221
- - lib/zoho_hub/deprecated_and_only_for_reference_records/account.rb
222
- - lib/zoho_hub/deprecated_and_only_for_reference_records/campaign.rb
223
- - lib/zoho_hub/deprecated_and_only_for_reference_records/contact.rb
224
- - lib/zoho_hub/deprecated_and_only_for_reference_records/funder.rb
225
- - lib/zoho_hub/deprecated_and_only_for_reference_records/potential.rb
226
- - lib/zoho_hub/deprecated_and_only_for_reference_records/product.rb
227
- - lib/zoho_hub/deprecated_and_only_for_reference_records/quote.rb
228
232
  - lib/zoho_hub/errors.rb
229
- - lib/zoho_hub/module_builder.rb
233
+ - lib/zoho_hub/records/account.rb
234
+ - lib/zoho_hub/records/base_record.rb
235
+ - lib/zoho_hub/records/campaign.rb
236
+ - lib/zoho_hub/records/contact.rb
237
+ - lib/zoho_hub/records/potential.rb
238
+ - lib/zoho_hub/records/product.rb
239
+ - lib/zoho_hub/records/quote.rb
240
+ - lib/zoho_hub/records/vendor.rb
230
241
  - lib/zoho_hub/response.rb
231
- - lib/zoho_hub/settings/field.rb
232
- - lib/zoho_hub/settings/module.rb
233
- - lib/zoho_hub/string_utils.rb
234
242
  - lib/zoho_hub/version.rb
235
- - lib/zoho_hub/with_attributes.rb
236
- - lib/zoho_hub/with_connection.rb
237
243
  - zoho_hub.gemspec
238
244
  homepage: https://github.com/rikas/zoho_hub
239
245
  licenses:
@@ -247,7 +253,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
247
253
  requirements:
248
254
  - - ">="
249
255
  - !ruby/object:Gem::Version
250
- version: 2.1.0
256
+ version: '0'
251
257
  required_rubygems_version: !ruby/object:Gem::Requirement
252
258
  requirements:
253
259
  - - ">="
data/bin/read DELETED
@@ -1,44 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- require 'bundler/setup'
5
- require 'zoho_hub'
6
- require 'zoho_hub/settings/module'
7
- require 'zoho_hub/records/base_record'
8
-
9
- require 'dotenv'
10
- Dotenv.load
11
-
12
- ZohoHub.configure do |config|
13
- config.client_id = ENV['ZOHO_CLIENT_ID']
14
- config.secret = ENV['ZOHO_SECRET']
15
- config.redirect_uri = ENV['ZOHO_OAUTH_REDIRECT_URL']
16
- end
17
-
18
- token_params = ZohoHub::Auth.refresh_token(ENV['ZOHO_REFRESH_TOKEN'])
19
- ZohoHub.setup_connection(token_params)
20
-
21
- puts "Reading modules for client ID: #{ENV['ZOHO_CLIENT_ID']}..."
22
-
23
- modules_hashes = ZohoHub::Settings::Module.all_json
24
-
25
- puts "Found #{modules_hashes.size} modules"
26
-
27
- modules_hashes.each do |hash|
28
- puts "- Writing configuration for #{hash[:plural_label]}"
29
-
30
- file_name = File.join(ZohoHub.root, 'cache', 'modules', "#{hash[:api_name]}.json")
31
-
32
- File.open(file_name, 'w') do |file|
33
- file.write(JSON.pretty_generate(hash))
34
- end
35
-
36
- next unless hash[:api_supported]
37
-
38
- fields_array = ZohoHub::Settings::Field.all_json_for(hash[:api_name])
39
- file_name = File.join(ZohoHub.root, 'cache', 'fields', "#{hash[:api_name]}.json")
40
-
41
- File.open(file_name, 'w') do |file|
42
- file.write(JSON.pretty_generate(fields_array))
43
- end
44
- end
data/cache/.git_keep DELETED
File without changes
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ZohoHub
4
- class Vendor < BaseRecord
5
- def initialize(params)
6
- puts Rainbow(params).red.bright
7
- end
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ZohoHub
4
- class Product < BaseRecord
5
- def initialize(params)
6
- puts Rainbow(params).red.bright
7
- end
8
- end
9
- end
@@ -1,61 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'zoho_hub/string_utils'
4
-
5
- module ZohoHub
6
- class ModuleBuilder
7
- class << self
8
- def build_from_cache
9
- cached_module_definitions.map do |file|
10
- json = MultiJson.load(File.read(file), symbolize_keys: true)
11
-
12
- create_module(json)
13
- end
14
- end
15
-
16
- def cached_module_definitions
17
- Dir[File.join(ZohoHub.root, 'cache', 'modules', '**')]
18
- end
19
-
20
- def create_module(json)
21
- fields = cached_module_fields(json[:api_name])
22
-
23
- klass = Class.new(ZohoHub::BaseRecord) do
24
- request_path json[:api_name]
25
-
26
- translations = {}
27
- fields.each do |field|
28
- key = StringUtils.underscore(field[:api_name])
29
-
30
- translations[key] = field[:api_name]
31
- end
32
-
33
- if translations.any?
34
- attributes(*translations.keys)
35
- attribute_translation(translations)
36
- end
37
-
38
- def initialize(params)
39
- attributes.each do |attr|
40
- zoho_key = attr_to_zoho_key(attr)
41
-
42
- send("#{attr}=", params[zoho_key] || params[attr])
43
- end
44
- end
45
- end
46
-
47
- ZohoHub.const_set(StringUtils.camelize(json[:singular_label]), klass)
48
- end
49
-
50
- def cached_module_fields(module_name)
51
- file = File.join(ZohoHub.root, 'cache', 'fields', "#{module_name}.json")
52
-
53
- return [] unless File.exist?(file)
54
-
55
- json_content = File.read(file)
56
-
57
- MultiJson.load(json_content, symbolize_keys: true)
58
- end
59
- end
60
- end
61
- end
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'zoho_hub/with_connection'
4
- require 'zoho_hub/with_attributes'
5
-
6
- module ZohoHub
7
- module Settings
8
- class Field
9
- include WithConnection
10
- include WithAttributes
11
-
12
- REQUEST_PATH = 'settings/fields'
13
-
14
- attributes :custom_field, :lookup, :convert_mapping, :visible, :field_label, :length,
15
- :view_type, :read_only, :api_name, :unique, :data_type, :formula, :currency, :id,
16
- :decimal_place, :pick_list_values, :auto_number
17
-
18
- def self.all_for(module_name)
19
- fields = all_json_for(module_name)
20
- fields.map { |json| new(json) }
21
- end
22
-
23
- def self.all_json_for(module_name)
24
- response = get(REQUEST_PATH, module: module_name)
25
- response[:fields]
26
- end
27
-
28
- def initialize(json = {})
29
- attributes.each { |attr| send("#{attr}=", json[attr]) }
30
- end
31
- end
32
- end
33
- end
@@ -1,49 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'zoho_hub/with_connection'
4
- require 'zoho_hub/with_attributes'
5
-
6
- require 'zoho_hub/settings/field'
7
-
8
- module ZohoHub
9
- module Settings
10
- # Zoho CRM has standard modules such as, Leads, Accounts, Contacts, Deals, Forecasts,
11
- # Activities, etc,. Using Zoho CRM REST API, you can retrieve the list of available modules.
12
- #
13
- # convertable: Describes if the user can convert the record into another type of record.
14
- # For example: Convert Leads in to Deals.
15
- # creatable: Checks if the user can create a record in the current module.
16
- # generated_type: Describes the type of module which would be generated by the user. There are
17
- # 4 types: default, web, custom, linking.
18
- # api_supported: The modules which are currently not accessible by APIs have value as "false".
19
- # If the modules are supported in the future, the value automatically changes
20
- # to "true".
21
- # modified_time: The date and time of changes made by the user.
22
- #
23
- # More details: https://www.zoho.com/crm/help/api/v2/#Modules-APIs
24
- class Module
25
- include WithConnection
26
- include WithAttributes
27
-
28
- REQUEST_PATH = 'settings/modules'
29
-
30
- attributes :convertable, :editable, :deletable, :web_link, :singular_label, :modified_time,
31
- :viewable, :api_supported, :creatable, :plural_label, :api_name, :modified_by,
32
- :generated_type, :id, :module_name, :fields
33
-
34
- def self.all
35
- modules = all_json
36
- modules.map { |json| new(json) }
37
- end
38
-
39
- def self.all_json
40
- response = get(REQUEST_PATH)
41
- response[:modules]
42
- end
43
-
44
- def initialize(json = {})
45
- attributes.each { |attr| send("#{attr}=", json[attr]) }
46
- end
47
- end
48
- end
49
- end
@@ -1,34 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ZohoHub
4
- class StringUtils
5
- class << self
6
- def demodulize(text)
7
- text.split('::').last
8
- end
9
-
10
- def pluralize(text)
11
- "#{text}s"
12
- end
13
-
14
- def camelize(text)
15
- result = text.split(/[_\s]/)
16
-
17
- return result.first if result.size == 1
18
-
19
- result.map(&:capitalize).join
20
- end
21
-
22
- def underscore(text)
23
- return text unless text =~ /[A-Z-]/
24
-
25
- result = text.dup
26
- result.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
27
- result.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
28
- result.tr!('-', '_')
29
- result.downcase!
30
- result
31
- end
32
- end
33
- end
34
- end
@@ -1,74 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ZohoHub
4
- # Allows adding attributes to a class, as <tt>attr_accessors</tt> that can then be listed from the
5
- # class or an instance of that class.
6
- #
7
- # === Example
8
- #
9
- # class User
10
- # include ZohoHub::WithAttributes
11
- #
12
- # attributes :first_name, :last_name, :email
13
- # end
14
- #
15
- # User.attributes # => [:first_name, :last_name, :email]
16
- # User.new.attributes # => [:first_name, :last_name, :email]
17
- #
18
- # user = User.new
19
- # user.first_name = 'Ricardo'
20
- # user.last_name = 'Otero'
21
- # user.first_name # => "Ricardo"
22
- module WithAttributes
23
- def self.included(base)
24
- base.extend ClassMethods
25
- end
26
-
27
- module ClassMethods
28
- def attributes(*attributes)
29
- @attributes ||= []
30
-
31
- return @attributes unless attributes
32
-
33
- attr_accessor(*attributes)
34
-
35
- @attributes += attributes
36
- end
37
-
38
- def attribute_translation(translation = nil)
39
- @attribute_translation ||= {}
40
-
41
- return @attribute_translation unless translation
42
-
43
- @attribute_translation = translation
44
- end
45
-
46
- def zoho_key_translation
47
- @attribute_translation.to_a.map(&:rotate).to_h
48
- end
49
- end
50
-
51
- # Returns the list of attributes defined for the instance class.
52
- def attributes
53
- self.class.attributes
54
- end
55
-
56
- private
57
-
58
- def attr_to_zoho_key(attr_name)
59
- translations = self.class.attribute_translation
60
-
61
- return translations[attr_name.to_sym] if translations.key?(attr_name.to_sym)
62
-
63
- attr_name.to_s.split('_').map(&:capitalize).join('_').to_sym
64
- end
65
-
66
- def zoho_key_to_attr(zoho_key)
67
- translations = self.class.zoho_key_translation
68
-
69
- return translations[zoho_key.to_sym] if translations.key?(zoho_key.to_sym)
70
-
71
- zoho_key.to_sym
72
- end
73
- end
74
- end
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ZohoHub
4
- # Adds the ability to do API requests (GET / PUT and POST requests) when included in a class.
5
- module WithConnection
6
- def self.included(base)
7
- base.extend ClassMethods
8
- end
9
-
10
- module ClassMethods
11
- def get(path, params = {})
12
- ZohoHub.connection.get(path, params)
13
- end
14
-
15
- def post(path, params = {})
16
- ZohoHub.connection.post(path, params.to_json)
17
- end
18
-
19
- def put(path, params = {})
20
- ZohoHub.connection.put(path, params.to_json)
21
- end
22
- end
23
-
24
- def get(path, params = {})
25
- self.class.get(path, params)
26
- end
27
-
28
- def post(path, params = {})
29
- self.class.post(path, params)
30
- end
31
-
32
- def put(path, params = {})
33
- self.class.put(path, params)
34
- end
35
- end
36
- end