hubspot-api-ruby 0.13.0 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fbc9af3c6a5820b29c4afdaaa0310b77da1fcd8f505698e62faf14a7a060264d
4
- data.tar.gz: 41440a802151fe4bcc8f223ad771c945dcb15ba03febfb7435d9a78db870b044
3
+ metadata.gz: effa2b66c983b7633d912e80b23c1bc2c6faa6fee1905ad3ddcd571fcc2d619f
4
+ data.tar.gz: 7049786deace29ba3a0eaa8196ae3ab8baee711758517f4493570e9af5927554
5
5
  SHA512:
6
- metadata.gz: b51c194631e766b2b4739edd6216e975491f010c6ec51adaa3d76041a926e5ac9ac03cd02361fee386d28ee12f3e6f23de6361aa7fd57a3bb6d7bf2f54a44c76
7
- data.tar.gz: 5b37fc63393678c531a2c3d3c3a62e9ccce4bbb9d0133bc0f0eb8b1fa002b889df6f95f77e5f542433777fe01ccbf32824842aa9bb2a9828a42d4f0f78b46d26
6
+ metadata.gz: 868839e40b04820791f786a3cb082a1fc6f081062b25f69af3f05792c1aa6f4a37dd4935a095065acb2aa23284f5d75826e0080e66ce11bc656620b90b90ecb5
7
+ data.tar.gz: fedec9a5eae9e6fd8df0465f9fd7bc9c383eaab0600671713e8c6b876c4e94be591f85e27f82da05daf023c9ccb7b773a954d920515ba41facc37d171d845efe
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "hubspot-api-ruby"
3
- s.version = "0.13.0"
3
+ s.version = "0.14.0"
4
4
  s.require_paths = ["lib"]
5
5
  s.authors = ["Jonathan"]
6
6
  s.email = ["jonathan@hoggo.com"]
@@ -7,11 +7,42 @@ module Hubspot
7
7
  #
8
8
  # {https://developers.hubspot.com/docs/api/crm/meetings}
9
9
  #
10
- CREATE_MEETING_PATH = '/crm/v3/objects/meetings'
10
+ MEETINGS_PATH = '/crm/v3/objects/meetings'
11
11
  MEETING_PATH = '/crm/v3/objects/meetings/:meeting_id'
12
+ MEETING_SEARCH_PATH = '/crm/v3/objects/meetings/search'
12
13
  ASSOCIATE_MEETING_PATH = '/crm/v3/objects/meetings/:meeting_id/associations/Contact/:contact_id/meeting_event_to_contact'
13
14
 
15
+ BASE_PROPERTIES = %w[hubspot_owner_id hs_meeting_title hs_meeting_body hs_meeting_start_time hs_meeting_end_time].freeze
16
+
14
17
  class << self
18
+ def all(opts = {})
19
+ options = { properties: BASE_PROPERTIES.join(','), **opts.compact }
20
+ response = Hubspot::Connection.get_json(MEETINGS_PATH, options)
21
+ meetings = response['results'].map { |result| new(result) }
22
+
23
+ {
24
+ meetings: meetings,
25
+ after: response.dig('paging', 'next', 'after')
26
+ }
27
+ end
28
+
29
+ def find(id)
30
+ response = Hubspot::Connection.get_json(MEETING_PATH, { meeting_id: id, properties: BASE_PROPERTIES.join(',') })
31
+ new(response)
32
+ end
33
+
34
+ def find_by_contact(contact_id)
35
+ response = Hubspot::Connection.post_json(MEETING_SEARCH_PATH, {
36
+ params: {},
37
+ body: {
38
+ properties: BASE_PROPERTIES,
39
+ filters: [{ propertyName: 'associations.contact', 'operator': 'EQ', value: contact_id }]
40
+ }
41
+ }
42
+ )
43
+ response['results'].map { |f| new(f) }
44
+ end
45
+
15
46
  def create!(owner_id, meeting_title, meeting_body, start_date_time, end_date_time)
16
47
  body = {
17
48
  properties: {
@@ -24,7 +55,7 @@ module Hubspot
24
55
  hs_meeting_outcome: 'SCHEDULED'
25
56
  }
26
57
  }
27
- response = Hubspot::Connection.post_json(CREATE_MEETING_PATH, params: {}, body: body)
58
+ response = Hubspot::Connection.post_json(MEETINGS_PATH, params: {}, body: body)
28
59
  HashWithIndifferentAccess.new(response)
29
60
  end
30
61
 
@@ -40,5 +71,19 @@ module Hubspot
40
71
  })
41
72
  end
42
73
  end
74
+
75
+ attr_reader :id
76
+ attr_reader :properties
77
+
78
+ def initialize(hash)
79
+ self.send(:assign_properties, hash)
80
+ end
81
+
82
+ private
83
+
84
+ def assign_properties(hash)
85
+ @id = hash['id']
86
+ @properties = hash['properties'].deep_symbolize_keys
87
+ end
43
88
  end
44
89
  end
@@ -5,6 +5,6 @@ FactoryBot.define do
5
5
 
6
6
  firstname { Faker::Name.first_name }
7
7
  lastname { Faker::Name.last_name }
8
- email { Faker::Internet.safe_email("#{Time.new.to_i.to_s[-5..-1]}#{(0..3).map { (65 + rand(26)).chr }.join}") }
8
+ email { Faker::Internet.safe_email(name: "#{Time.new.to_i.to_s[-5..-1]}#{(0..3).map { (65 + rand(26)).chr }.join}") }
9
9
  end
10
- end
10
+ end
@@ -42,7 +42,7 @@ RSpec.describe Hubspot::Contact do
42
42
  context 'without properties' do
43
43
  cassette
44
44
 
45
- let(:email) { Faker::Internet.safe_email("#{(0..3).map { (65 + rand(26)).chr }.join}#{Time.new.to_i.to_s[-5..-1]}") }
45
+ let(:email) { Faker::Internet.safe_email(name: "#{(0..3).map { (65 + rand(26)).chr }.join}#{Time.new.to_i.to_s[-5..-1]}") }
46
46
  subject { described_class.create email }
47
47
 
48
48
  it 'creates a new contact' do
@@ -54,7 +54,7 @@ RSpec.describe Hubspot::Contact do
54
54
  context 'with properties' do
55
55
  cassette
56
56
 
57
- let(:email) { Faker::Internet.safe_email("#{(0..3).map { (65 + rand(26)).chr }.join}#{Time.new.to_i.to_s[-5..-1]}") }
57
+ let(:email) { Faker::Internet.safe_email(name: "#{(0..3).map { (65 + rand(26)).chr }.join}#{Time.new.to_i.to_s[-5..-1]}") }
58
58
  let(:firstname) { "Allison" }
59
59
  let(:properties) { { firstname: firstname } }
60
60
 
@@ -12,6 +12,87 @@ RSpec.describe Hubspot::Meeting do
12
12
  let(:hs_meeting_start_time) { DateTime.strptime('2022-05-03T10:00:00+01:00', '%Y-%m-%dT%H:%M:%S%z') }
13
13
  let(:hs_meeting_end_time) { DateTime.strptime('2022-05-03T10:15:00+01:00', '%Y-%m-%dT%H:%M:%S%z') }
14
14
 
15
+ describe '.all' do
16
+ let(:options) { {} }
17
+ subject(:all) do
18
+ described_class.all(options)
19
+ end
20
+
21
+ it 'retrieves all the meetings with default limit' do
22
+ VCR.use_cassette 'meeting_all' do
23
+ meetings = all
24
+ expect(meetings).not_to be_nil
25
+ expect(meetings[:meetings].many?).to be true
26
+ expect(meetings[:meetings].first).to be_a(Hubspot::Meeting)
27
+ end
28
+ end
29
+
30
+ context 'with a limit' do
31
+ let(:options) { { limit: 2 } }
32
+ it 'retrieves all the meetings within limit' do
33
+ VCR.use_cassette 'meeting_all_limit' do
34
+ meetings = all
35
+ expect(meetings).not_to be_nil
36
+ expect(meetings[:meetings].count).to eq 2
37
+ expect(meetings[:meetings].first).to be_a(Hubspot::Meeting)
38
+ expect(meetings[:after]).not_to be nil
39
+ end
40
+ end
41
+ end
42
+
43
+ context 'with a limit and an after param' do
44
+ let(:options) { { limit: 3, after: '12642400565' } }
45
+
46
+ it 'retrives the next meetings within limit after a given id' do
47
+ VCR.use_cassette 'meeting_all_limit_after' do
48
+ meetings = all
49
+ expect(meetings).not_to be_nil
50
+ expect(meetings[:meetings].count).to eq 3
51
+ expect(meetings[:meetings].first).to be_a(Hubspot::Meeting)
52
+ expect(meetings[:after]).not_to be nil
53
+ end
54
+ end
55
+ end
56
+ end
57
+
58
+ describe '.find' do
59
+ subject(:find) do
60
+ described_class.find(27195487241)
61
+ end
62
+
63
+ it 'retrieves the meeting' do
64
+ VCR.use_cassette 'meeting_find' do
65
+ meeting = find
66
+ expect(meeting).not_to be_nil
67
+ expect(meeting.properties[:hubspot_owner_id]).not_to be nil
68
+ expect(meeting.properties[:hs_meeting_title]).not_to be nil
69
+ expect(meeting.properties[:hs_meeting_body]).not_to be nil
70
+ expect(meeting.properties[:hs_meeting_start_time]).not_to be nil
71
+ expect(meeting.properties[:hs_meeting_end_time]).not_to be nil
72
+ end
73
+ end
74
+ end
75
+
76
+ describe ".find_by_contact" do
77
+ subject(:find_by_contact) do
78
+ described_class.find_by_contact(1451)
79
+ end
80
+
81
+ it 'retrieves meetings' do
82
+ VCR.use_cassette 'meeting_find_by_contact' do
83
+ meetings = find_by_contact
84
+ first_meeting = meetings.first
85
+ expect(meetings).not_to be_nil
86
+ expect(first_meeting).not_to be_nil
87
+ expect(first_meeting.properties[:hubspot_owner_id]).not_to be nil
88
+ expect(first_meeting.properties[:hs_meeting_title]).not_to be nil
89
+ expect(first_meeting.properties[:hs_meeting_body]).not_to be nil
90
+ expect(first_meeting.properties[:hs_meeting_start_time]).not_to be nil
91
+ expect(first_meeting.properties[:hs_meeting_end_time]).not_to be nil
92
+ end
93
+ end
94
+ end
95
+
15
96
  describe '.create' do
16
97
  context 'with properties' do
17
98
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hubspot-api-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.0
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-27 00:00:00.000000000 Z
11
+ date: 2022-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -346,7 +346,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
346
346
  - !ruby/object:Gem::Version
347
347
  version: '0'
348
348
  requirements: []
349
- rubygems_version: 3.2.33
349
+ rubygems_version: 3.1.2
350
350
  signing_key:
351
351
  specification_version: 4
352
352
  summary: hubspot-api-ruby is a wrapper for the HubSpot REST API