zoho_hub 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/bin/console +1 -3
- data/lib/zoho_hub.rb +3 -0
- data/lib/zoho_hub/connection.rb +5 -0
- data/lib/zoho_hub/errors.rb +3 -0
- data/lib/zoho_hub/records/base_record.rb +12 -16
- data/lib/zoho_hub/records/funder.rb +9 -0
- data/lib/zoho_hub/records/potential.rb +1 -3
- data/lib/zoho_hub/records/product.rb +9 -0
- data/lib/zoho_hub/records/quote.rb +34 -0
- data/lib/zoho_hub/response.rb +10 -0
- data/lib/zoho_hub/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d8a71de9f706d946eff1f922d60eff71402959da1661595d6681df43eab9bb4
|
4
|
+
data.tar.gz: 7609bda6aeff1132269dd46c2ce6aa358b2cebabc1731104893a7b6257758965
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8f06f6439c94caeb6463e1fcb96bf58fc4afe60694babdb8817132e4bfb60e12ec0eef30ae87cf76a94ff220cd87714ebafd40a69ab5fc30b6770a0b3ba716a
|
7
|
+
data.tar.gz: ba0097136d9e8aba75c2ac00c70025e9166fc43a556f02acf2416753064613dc0fa8db29044f3801f7488484d1c8806ee758c8c669b5e32402269153ae740338
|
data/Gemfile.lock
CHANGED
data/bin/console
CHANGED
@@ -11,13 +11,11 @@ ZohoHub.configure do |config|
|
|
11
11
|
config.client_id = ENV['ZOHO_CLIENT_ID']
|
12
12
|
config.secret = ENV['ZOHO_SECRET']
|
13
13
|
config.redirect_uri = ENV['ZOHO_OAUTH_REDIRECT_URL']
|
14
|
-
|
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
|
-
include ZohoHub # rubocop:disable Style/MixinUsage
|
21
|
-
|
22
20
|
require 'pry'
|
23
21
|
Pry.start
|
data/lib/zoho_hub.rb
CHANGED
@@ -12,6 +12,9 @@ require 'zoho_hub/records/contact'
|
|
12
12
|
require 'zoho_hub/records/potential'
|
13
13
|
require 'zoho_hub/records/campaign'
|
14
14
|
require 'zoho_hub/records/account'
|
15
|
+
require 'zoho_hub/records/quote'
|
16
|
+
require 'zoho_hub/records/funder'
|
17
|
+
require 'zoho_hub/records/product'
|
15
18
|
|
16
19
|
module ZohoHub
|
17
20
|
module_function
|
data/lib/zoho_hub/connection.rb
CHANGED
@@ -10,6 +10,9 @@ require 'zoho_hub/response'
|
|
10
10
|
module ZohoHub
|
11
11
|
class Connection
|
12
12
|
attr_accessor :debug, :access_token, :expires_in, :api_domain, :refresh_token
|
13
|
+
|
14
|
+
# This is a block to be run when the token is refreshed. This way you can do whatever you want
|
15
|
+
# with the new parameters returned by the refresh method.
|
13
16
|
attr_accessor :on_refresh_cb
|
14
17
|
|
15
18
|
DEFAULT_DOMAIN = 'https://www.zohoapis.eu'
|
@@ -75,6 +78,8 @@ module ZohoHub
|
|
75
78
|
@access_token = params[:access_token]
|
76
79
|
|
77
80
|
http_response = yield
|
81
|
+
elsif response.authentication_failure?
|
82
|
+
raise ZohoAPIError, response.msg
|
78
83
|
end
|
79
84
|
|
80
85
|
http_response
|
data/lib/zoho_hub/errors.rb
CHANGED
@@ -5,16 +5,10 @@ require 'zoho_hub/response'
|
|
5
5
|
module ZohoHub
|
6
6
|
class BaseRecord
|
7
7
|
class << self
|
8
|
-
def
|
9
|
-
@
|
10
|
-
@
|
11
|
-
@
|
12
|
-
end
|
13
|
-
|
14
|
-
def list_name(name = nil)
|
15
|
-
@list_name = name if name
|
16
|
-
@list_name ||= to_s.demodulize.pluralize.downcase
|
17
|
-
@list_name
|
8
|
+
def request_path(name = nil)
|
9
|
+
@request_path = name if name
|
10
|
+
@request_path ||= to_s.demodulize.pluralize
|
11
|
+
@request_path
|
18
12
|
end
|
19
13
|
|
20
14
|
def attributes(*attributes)
|
@@ -40,18 +34,20 @@ module ZohoHub
|
|
40
34
|
end
|
41
35
|
|
42
36
|
def find(id)
|
43
|
-
body = get(File.join(
|
37
|
+
body = get(File.join(request_path, id.to_s))
|
44
38
|
response = build_response(body)
|
45
39
|
|
46
40
|
if response.empty?
|
47
|
-
raise RecordNotFound, "Couldn't find #{
|
41
|
+
raise RecordNotFound, "Couldn't find #{request_path.singularize} with 'id'=#{id}"
|
48
42
|
end
|
49
43
|
|
50
44
|
new(response.data)
|
51
45
|
end
|
52
46
|
|
53
47
|
def where(params)
|
54
|
-
|
48
|
+
path = File.join(request_path, 'search')
|
49
|
+
|
50
|
+
response = get(path, params)
|
55
51
|
data = response[:data]
|
56
52
|
|
57
53
|
data.map { |info| new(info) }
|
@@ -70,7 +66,7 @@ module ZohoHub
|
|
70
66
|
options[:page] ||= 1
|
71
67
|
options[:per_page] ||= 200
|
72
68
|
|
73
|
-
body = get(
|
69
|
+
body = get(request_path, options)
|
74
70
|
response = build_response(body)
|
75
71
|
|
76
72
|
data = response.nil? ? [] : response.data
|
@@ -126,9 +122,9 @@ module ZohoHub
|
|
126
122
|
|
127
123
|
def save
|
128
124
|
body = if new_record? # create new record
|
129
|
-
post(self.class.
|
125
|
+
post(self.class.request_path, data: [to_params])
|
130
126
|
else # update existing record
|
131
|
-
path = File.join(self.class.
|
127
|
+
path = File.join(self.class.request_path, id)
|
132
128
|
put(path, data: [to_params])
|
133
129
|
end
|
134
130
|
|
@@ -4,13 +4,11 @@ require 'zoho_hub/records/base_record'
|
|
4
4
|
|
5
5
|
module ZohoHub
|
6
6
|
class Potential < BaseRecord
|
7
|
-
list_name 'Potentials'
|
8
|
-
|
9
7
|
attributes :id, :code, :deal_name, :amount, :description, :stage
|
10
8
|
attributes :company_age_years, :company_age_months, :term, :use_proceeds, :proceeds_detail
|
11
9
|
attributes :currency, :territory, :employee_count, :turnover, :industry, :region
|
12
10
|
attributes :review_outcome, :first_created, :last_modified, :preferred_term
|
13
|
-
attributes :campaign_id, :account_id, :contact_id, :campaign_detail
|
11
|
+
attributes :campaign_id, :account_id, :contact_id, :campaign_detail, :reviewers_comment
|
14
12
|
|
15
13
|
DEFAULTS = {
|
16
14
|
currency: 'GBP',
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'zoho_hub/records/base_record'
|
4
|
+
|
5
|
+
module ZohoHub
|
6
|
+
class Quote < BaseRecord
|
7
|
+
attributes :id, :stage, :subject
|
8
|
+
attributes :potential_id
|
9
|
+
|
10
|
+
attribute_translation(
|
11
|
+
id: :id,
|
12
|
+
stage: :Quote_Stage
|
13
|
+
)
|
14
|
+
|
15
|
+
def initialize(params)
|
16
|
+
puts Rainbow(params).bright.red
|
17
|
+
attributes.each do |attr|
|
18
|
+
zoho_key = attr_to_zoho_key(attr)
|
19
|
+
|
20
|
+
send("#{attr}=", params[zoho_key] || params[attr])
|
21
|
+
end
|
22
|
+
|
23
|
+
@potential_id ||= params.dig(:Deal_Name, :id)
|
24
|
+
@lender_organisation_id ||= params.dig(:Account_Name, :id)
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_params
|
28
|
+
params = super
|
29
|
+
|
30
|
+
params[:Deal_Name] = { id: @potential_id } if @potential_id
|
31
|
+
params[:Account_Name] = { id: @lender_organisation_id } if @lender_organisation_id
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/zoho_hub/response.rb
CHANGED
@@ -7,14 +7,24 @@ module ZohoHub
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def invalid_data?
|
10
|
+
return false if data.is_a?(Array)
|
11
|
+
|
10
12
|
data[:code] == 'INVALID_DATA'
|
11
13
|
end
|
12
14
|
|
13
15
|
# {:code=>"INVALID_TOKEN", :details=>{}, :message=>"invalid oauth token", :status=>"error"}
|
14
16
|
def invalid_token?
|
17
|
+
return false if data.is_a?(Array)
|
18
|
+
|
15
19
|
data[:code] == 'INVALID_TOKEN'
|
16
20
|
end
|
17
21
|
|
22
|
+
def authentication_failure?
|
23
|
+
return false if data.is_a?(Array)
|
24
|
+
|
25
|
+
data[:code] == 'AUTHENTICATION_FAILURE'
|
26
|
+
end
|
27
|
+
|
18
28
|
def empty?
|
19
29
|
@params.empty?
|
20
30
|
end
|
data/lib/zoho_hub/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zoho_hub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
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-07
|
11
|
+
date: 2018-08-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -234,7 +234,10 @@ files:
|
|
234
234
|
- lib/zoho_hub/records/base_record.rb
|
235
235
|
- lib/zoho_hub/records/campaign.rb
|
236
236
|
- lib/zoho_hub/records/contact.rb
|
237
|
+
- lib/zoho_hub/records/funder.rb
|
237
238
|
- lib/zoho_hub/records/potential.rb
|
239
|
+
- lib/zoho_hub/records/product.rb
|
240
|
+
- lib/zoho_hub/records/quote.rb
|
238
241
|
- lib/zoho_hub/response.rb
|
239
242
|
- lib/zoho_hub/version.rb
|
240
243
|
- zoho_hub.gemspec
|