ruby_hubspot 1.0.0 → 1.0.1

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: 73a758e2f280d0f2037dafdd54d2c1d33f14ce51def4d2dcfbe7ac22bc56dd9d
4
- data.tar.gz: 6e3da77a360119e2e9ce4ec501319b6fa84c287d8bde548786152a9d986b7a9c
3
+ metadata.gz: 21cd2b84ae331bcecbb2efcca76b818420ad5bf3519c783134ba18d3dfa38533
4
+ data.tar.gz: e7cbd736a5ef3795560e8b98144b3c65bac6857ef2a3592cf8f0655e154a04e9
5
5
  SHA512:
6
- metadata.gz: cfcd28ef611dfbe36c99513f3e8c964284f3ab4f3c2a8e3cf2cef16afb7650963298a5cb10f09254bd575f6120748c8b3e004972afc82a323a06594b9b20552d
7
- data.tar.gz: dae19d601f3664ce858875f2defb165f73cf654b7434f50bda8195df18c0d11c9dbf5fbe3d70bbd122e661962fd83d9abfe2ee561beaba444e17706d2f30e4ab
6
+ metadata.gz: a98ec51d08a95627f0a0e2d6f5983d4ef609277ff2d0cd139c88dac10a5a5d99efb9bdd91c03432324175a10871ad8906dede9b2cd9634116e50032ea131f42e
7
+ data.tar.gz: 4bd71dd3cb75fb2c067ff4d55d93d1884a5ddfbf973db56cd0ec467cd38da44db945c44b332090a0e2debd9dd840fd14b5034e41a1168759e88b3e8704ad9b7c
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Companies module
4
+ module Companies
5
+ include Constants
6
+
7
+ def all_companies
8
+ validate_access_token
9
+
10
+ response(GET, ALL_COMPANIES)
11
+ end
12
+
13
+ def create_company(**params)
14
+ validate_access_token
15
+
16
+ response(POST, INDIVIDUAL_COMPANY, params)
17
+ end
18
+
19
+ def show_company(**params)
20
+ validate_access_token
21
+ id_handler(params[:id])
22
+
23
+ response(GET, individual_company_path(params[:id]))
24
+ end
25
+
26
+ def update_company(**params)
27
+ validate_access_token
28
+ id_handler(params[:id])
29
+
30
+ params_to_update = params.dup
31
+ params_to_update.delete(:id)
32
+
33
+ response(PUT, individual_company_path(params[:id]), params_to_update)
34
+ end
35
+
36
+ def delete_company(**params)
37
+ validate_access_token
38
+ id_handler(params[:id])
39
+
40
+ response(DELETE, individual_company_path(params[:id]))
41
+ end
42
+
43
+ def individual_company_path(id)
44
+ INDIVIDUAL_COMPANY + id.to_s
45
+ end
46
+ end
@@ -2,7 +2,24 @@
2
2
 
3
3
  # Constants module
4
4
  module Constants
5
- API_URL = 'https://api.hubapi.com/'
6
- CONTENT_TYPE = 'application/json'
7
- AUTHORIZATION_KEY = 'Bearer '
5
+ API_URL = 'https://api.hubapi.com/'
6
+ CONTENT_TYPE = 'application/json'
7
+ AUTHORIZATION_KEY = 'Bearer '
8
+ GET = :get
9
+ POST = :post
10
+ PATCH = :patch
11
+ PUT = :put
12
+ DELETE = :delete
13
+ ALL_CONTACTS = 'crm/v4/objects/contacts'
14
+ ALL_COMPANIES = 'crm/v3/properties/companies'
15
+ ALL_DEALS = 'crm/v4/objects/deals'
16
+ ALL_SUBMITIONS = 'crm/v4/objects/feedback_submissions'
17
+ INDIVIDUAL_CONTACT = 'contacts/v1/contact'
18
+ INDIVIDUAL_COMPANY = 'companies/v2/companies/'
19
+ INDIVIDUAL_DEAL = 'deals/v1/deal'
20
+ INDIVIDUAL_SUB = 'feedback_submissions/v1/feedback_submission'
21
+ CREATE_OR_UPDATE = '/createOrUpdate'
22
+ VID = '/vid/'
23
+ EMAIL = '/email/'
24
+ PROFILE = '/profile'
8
25
  end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Contacts module
4
+ module Contacts
5
+ include Constants
6
+
7
+ def all_contacts
8
+ validate_access_token
9
+
10
+ response(GET, ALL_CONTACTS)
11
+ end
12
+
13
+ def create_contact(**params)
14
+ validate_access_token
15
+
16
+ response(POST, INDIVIDUAL_CONTACT, params)
17
+ end
18
+
19
+ def create_or_update_contact(**params)
20
+ validate_access_token
21
+ email_handler(params[:email])
22
+
23
+ response(POST, INDIVIDUAL_CONTACT + CREATE_OR_UPDATE + EMAIL + params[:email].to_s, params)
24
+ end
25
+
26
+ def show_contact(**params)
27
+ validate_access_token
28
+
29
+ response(GET, INDIVIDUAL_CONTACT + find_idintificator(params) + PROFILE)
30
+ end
31
+
32
+ def update_contact(**params)
33
+ validate_access_token
34
+
35
+ params_to_update = params.dup
36
+ params_to_update.delete(:id)
37
+
38
+ response(POST, INDIVIDUAL_CONTACT + find_idintificator(params) + PROFILE, params_to_update)
39
+ end
40
+
41
+ def delete_contact(**params)
42
+ validate_access_token
43
+
44
+ response(DELETE, INDIVIDUAL_CONTACT + find_idintificator(params))
45
+ end
46
+
47
+ def find_idintificator(params)
48
+ identificator_handler(
49
+ %i[email id].any? do |key|
50
+ if params.key?(key)
51
+ identificator_handler(params[key])
52
+
53
+ return key == :email ? EMAIL + params[key].to_s : VID + params[key].to_s
54
+ end
55
+ end
56
+ )
57
+ end
58
+ end
@@ -2,11 +2,26 @@
2
2
 
3
3
  # Error module
4
4
  module ErrorHandler
5
- ACCESS_TOKEN_ERROR = 'Access Token should exist'
5
+ ACCESS_TOKEN_ERROR = 'Access Token should exist'
6
+ EMAIL_ERROR = 'Email should exist'
7
+ IDENTIFICATOR_ERROR = 'Email or id should exist'
8
+ ID_ERROR = 'Id should exist'
6
9
 
7
10
  protected
8
11
 
9
12
  def access_token_handler(access_token)
10
13
  raise ArgumentError, ACCESS_TOKEN_ERROR unless access_token
11
14
  end
15
+
16
+ def email_handler(email)
17
+ raise ArgumentError, EMAIL_ERROR unless email
18
+ end
19
+
20
+ def id_handler(id)
21
+ raise ArgumentError, ID_ERROR unless id
22
+ end
23
+
24
+ def identificator_handler(identificator)
25
+ raise ArgumentError, IDENTIFICATOR_ERROR unless identificator
26
+ end
12
27
  end
@@ -3,11 +3,15 @@
3
3
  require 'faraday'
4
4
  require_relative 'error_handler'
5
5
  require_relative 'constants'
6
+ require_relative 'contacts'
7
+ require_relative 'companies'
6
8
 
7
9
  # Hubspot main
8
10
  class Hubspot
9
11
  include ErrorHandler
10
12
  include Constants
13
+ include Contacts
14
+ include Companies
11
15
 
12
16
  attr_accessor :access_token
13
17
 
@@ -27,7 +31,7 @@ class Hubspot
27
31
  Faraday.send(http_method) do |request|
28
32
  request.url(API_URL + path)
29
33
  request.headers = headers
30
- request.body = body(params)
34
+ request.body = body(path, params)
31
35
  end
32
36
  end
33
37
 
@@ -38,15 +42,27 @@ class Hubspot
38
42
  }
39
43
  end
40
44
 
41
- def body(**params)
45
+ def body(path, **params)
42
46
  return unless params
43
47
 
44
48
  {
45
- properties: properties(params)
49
+ properties: properties(path, params)
46
50
  }.to_json
47
51
  end
48
52
 
49
- def properties(params)
53
+ def properties(path, params)
54
+ return special_fields(params) if path.include? INDIVIDUAL_COMPANY
55
+
56
+ usual_fields(params)
57
+ end
58
+
59
+ def special_fields(params)
60
+ params.map do |key, value|
61
+ { "name": key, "value": value }
62
+ end
63
+ end
64
+
65
+ def usual_fields(params)
50
66
  params.map do |key, value|
51
67
  { "property": key, "value": value }
52
68
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubyHubspot
4
- VERSION = '1.0.0'
4
+ VERSION = '1.0.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_hubspot
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - sofiyareverse
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-23 00:00:00.000000000 Z
11
+ date: 2023-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -115,7 +115,9 @@ extensions: []
115
115
  extra_rdoc_files: []
116
116
  files:
117
117
  - lib/ruby_hubspot.rb
118
+ - lib/ruby_hubspot/companies.rb
118
119
  - lib/ruby_hubspot/constants.rb
120
+ - lib/ruby_hubspot/contacts.rb
119
121
  - lib/ruby_hubspot/error_handler.rb
120
122
  - lib/ruby_hubspot/hubspot.rb
121
123
  - lib/ruby_hubspot/version.rb