ruby_hubspot 1.0.0 → 1.0.2

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: b8af2ad903e1a672868c2f6757a2ab8da3e40e37cbf4ba313d2555b225573b77
4
+ data.tar.gz: ee56a7bfa400e723ee9fa61c213f49aebdf5e0909a7a8c8ddbc1877338827f37
5
5
  SHA512:
6
- metadata.gz: cfcd28ef611dfbe36c99513f3e8c964284f3ab4f3c2a8e3cf2cef16afb7650963298a5cb10f09254bd575f6120748c8b3e004972afc82a323a06594b9b20552d
7
- data.tar.gz: dae19d601f3664ce858875f2defb165f73cf654b7434f50bda8195df18c0d11c9dbf5fbe3d70bbd122e661962fd83d9abfe2ee561beaba444e17706d2f30e4ab
6
+ metadata.gz: 8fd784b6059bc371265e1812d99d49b43d322e496e0f308f976f1748ce69743450accb276ecb458a5ed75a246d82a912dbc6ca4c7e56c316fb7ab04d09cc6f68
7
+ data.tar.gz: a0188d60c29d1642c317b948d0ddbf7f217ec99762054a85d174474ac8f34cb17afb2ee73434d3b3a06d1333c6ed06ef3965464205764d6920866734febaff7a
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Companies module adds methods for Company objects
4
+ module Companies
5
+ include Constants
6
+
7
+ # returns all companies
8
+ def all_companies
9
+ validate_access_token
10
+
11
+ response(GET, ALL_COMPANIES)
12
+ end
13
+
14
+ # creates a company
15
+ def create_company(**params)
16
+ validate_access_token
17
+
18
+ response(POST, INDIVIDUAL_COMPANY, params)
19
+ end
20
+
21
+ # shows a company
22
+ def show_company(**params)
23
+ validate_access_token
24
+ id_handler(params[:id])
25
+
26
+ response(GET, individual_company_path(params[:id]))
27
+ end
28
+
29
+ # updates a company
30
+ def update_company(**params)
31
+ validate_access_token
32
+ id_handler(params[:id])
33
+
34
+ params_to_update = params.dup
35
+ params_to_update.delete(:id)
36
+
37
+ response(PUT, individual_company_path(params[:id]), params_to_update)
38
+ end
39
+
40
+ # deletes a company
41
+ def delete_company(**params)
42
+ validate_access_token
43
+ id_handler(params[:id])
44
+
45
+ response(DELETE, individual_company_path(params[:id]))
46
+ end
47
+
48
+ # creates an idintificator
49
+ def individual_company_path(id)
50
+ INDIVIDUAL_COMPANY + id.to_s
51
+ end
52
+ end
@@ -1,8 +1,45 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Constants module
3
+ # Constants module includes all constants
4
4
  module Constants
5
- API_URL = 'https://api.hubapi.com/'
6
- CONTENT_TYPE = 'application/json'
7
- AUTHORIZATION_KEY = 'Bearer '
5
+ # hubspot api url
6
+ API_URL = 'https://api.hubapi.com/'
7
+ # content type for request
8
+ CONTENT_TYPE = 'application/json'
9
+ # authorization key for access
10
+ AUTHORIZATION_KEY = 'Bearer '
11
+ # method get for request
12
+ GET = :get
13
+ # method post for request
14
+ POST = :post
15
+ # method patch for request
16
+ PATCH = :patch
17
+ # method put for request
18
+ PUT = :put
19
+ # method delete for request
20
+ DELETE = :delete
21
+ # hubspot all contacts request path
22
+ ALL_CONTACTS = 'crm/v4/objects/contacts'
23
+ # hubspot all companies request path
24
+ ALL_COMPANIES = 'crm/v3/properties/companies'
25
+ # hubspot all deals request path
26
+ ALL_DEALS = 'crm/v4/objects/deals'
27
+ # hubspot all submitions request path
28
+ ALL_SUBMITIONS = 'crm/v4/objects/feedback_submissions'
29
+ # hubspot individual contact request path
30
+ INDIVIDUAL_CONTACT = 'contacts/v1/contact'
31
+ # hubspot individual company request path
32
+ INDIVIDUAL_COMPANY = 'companies/v2/companies/'
33
+ # hubspot individual deal request path
34
+ INDIVIDUAL_DEAL = 'deals/v1/deal'
35
+ # hubspot individual sub request path
36
+ INDIVIDUAL_SUB = 'feedback_submissions/v1/feedback_submission'
37
+ # hubspot create or update request path
38
+ CREATE_OR_UPDATE = '/createOrUpdate'
39
+ # hubspot vid request path
40
+ VID = '/vid/'
41
+ # hubspot email request path
42
+ EMAIL = '/email/'
43
+ # hubspot profile request path
44
+ PROFILE = '/profile'
8
45
  end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Companies module adds methods for Contact objects
4
+ module Contacts
5
+ include Constants
6
+
7
+ # returns all contacts
8
+ def all_contacts
9
+ validate_access_token
10
+
11
+ response(GET, ALL_CONTACTS)
12
+ end
13
+
14
+ # creates a contact
15
+ def create_contact(**params)
16
+ validate_access_token
17
+
18
+ response(POST, INDIVIDUAL_CONTACT, params)
19
+ end
20
+
21
+ # creates or updates a contact
22
+ def create_or_update_contact(**params)
23
+ validate_access_token
24
+ email_handler(params[:email])
25
+
26
+ response(POST, INDIVIDUAL_CONTACT + CREATE_OR_UPDATE + EMAIL + params[:email].to_s, params)
27
+ end
28
+
29
+ # shows a contact
30
+ def show_contact(**params)
31
+ validate_access_token
32
+
33
+ response(GET, INDIVIDUAL_CONTACT + find_idintificator(params) + PROFILE)
34
+ end
35
+
36
+ # updates a contact
37
+ def update_contact(**params)
38
+ validate_access_token
39
+
40
+ params_to_update = params.dup
41
+ params_to_update.delete(:id)
42
+
43
+ response(POST, INDIVIDUAL_CONTACT + find_idintificator(params) + PROFILE, params_to_update)
44
+ end
45
+
46
+ # deletes a contact
47
+ def delete_contact(**params)
48
+ validate_access_token
49
+
50
+ response(DELETE, INDIVIDUAL_CONTACT + find_idintificator(params))
51
+ end
52
+
53
+ # checks and finds an idintificator
54
+ def find_idintificator(params)
55
+ identificator_handler(
56
+ %i[email id].any? do |key|
57
+ if params.key?(key)
58
+ identificator_handler(params[key])
59
+
60
+ return key == :email ? EMAIL + params[key].to_s : VID + params[key].to_s
61
+ end
62
+ end
63
+ )
64
+ end
65
+ end
@@ -1,12 +1,35 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Error module
3
+ # Error module adds new error methods
4
4
  module ErrorHandler
5
- ACCESS_TOKEN_ERROR = 'Access Token should exist'
5
+ # access token error
6
+ ACCESS_TOKEN_ERROR = 'Access Token should exist'
7
+ # email error
8
+ EMAIL_ERROR = 'Email should exist'
9
+ # identificator error
10
+ IDENTIFICATOR_ERROR = 'Email or id should exist'
11
+ # id error
12
+ ID_ERROR = 'Id should exist'
6
13
 
7
14
  protected
8
15
 
16
+ # checks access token presence
9
17
  def access_token_handler(access_token)
10
18
  raise ArgumentError, ACCESS_TOKEN_ERROR unless access_token
11
19
  end
20
+
21
+ # checks email presence
22
+ def email_handler(email)
23
+ raise ArgumentError, EMAIL_ERROR unless email
24
+ end
25
+
26
+ # checks id presence
27
+ def id_handler(id)
28
+ raise ArgumentError, ID_ERROR unless id
29
+ end
30
+
31
+ # checks identificator presence
32
+ def identificator_handler(identificator)
33
+ raise ArgumentError, IDENTIFICATOR_ERROR unless identificator
34
+ end
12
35
  end
@@ -3,18 +3,24 @@
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
- # Hubspot main
9
+ # Hubspot main controls and regulate all methods and constants
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
 
18
+ # initializes Hubspot with access token
14
19
  def initialize(access_token:)
15
20
  @access_token = access_token
16
21
  end
17
22
 
23
+ # sends a request to Hubspot with access token and params
18
24
  def request(http_method, path, **params)
19
25
  validate_access_token
20
26
 
@@ -27,7 +33,7 @@ class Hubspot
27
33
  Faraday.send(http_method) do |request|
28
34
  request.url(API_URL + path)
29
35
  request.headers = headers
30
- request.body = body(params)
36
+ request.body = body(path, params)
31
37
  end
32
38
  end
33
39
 
@@ -38,15 +44,27 @@ class Hubspot
38
44
  }
39
45
  end
40
46
 
41
- def body(**params)
47
+ def body(path, **params)
42
48
  return unless params
43
49
 
44
50
  {
45
- properties: properties(params)
51
+ properties: properties(path, params)
46
52
  }.to_json
47
53
  end
48
54
 
49
- def properties(params)
55
+ def properties(path, params)
56
+ return special_fields(params) if path.include? INDIVIDUAL_COMPANY
57
+
58
+ usual_fields(params)
59
+ end
60
+
61
+ def special_fields(params)
62
+ params.map do |key, value|
63
+ { "name": key, "value": value }
64
+ end
65
+ end
66
+
67
+ def usual_fields(params)
50
68
  params.map do |key, value|
51
69
  { "property": key, "value": value }
52
70
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Version module
3
4
  module RubyHubspot
4
- VERSION = '1.0.0'
5
+ # gem version
6
+ VERSION = '1.0.2'
5
7
  end
data/lib/ruby_hubspot.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Ruby Hubspot includes version and Hubspot class
3
4
  require_relative 'ruby_hubspot/version'
4
5
  require_relative 'ruby_hubspot/hubspot'
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.2
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-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rdoc
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rspec
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -115,7 +129,9 @@ extensions: []
115
129
  extra_rdoc_files: []
116
130
  files:
117
131
  - lib/ruby_hubspot.rb
132
+ - lib/ruby_hubspot/companies.rb
118
133
  - lib/ruby_hubspot/constants.rb
134
+ - lib/ruby_hubspot/contacts.rb
119
135
  - lib/ruby_hubspot/error_handler.rb
120
136
  - lib/ruby_hubspot/hubspot.rb
121
137
  - lib/ruby_hubspot/version.rb