hubspot-api-ruby 0.9.0 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,12 +1,11 @@
1
1
  describe Hubspot::Owner do
2
2
  let(:example_owners) do
3
3
  VCR.use_cassette('owner_example') do
4
- HTTParty.get('https://api.hubapi.com/owners/v2/owners?hapikey=demo&portalId=62515').parsed_response
4
+ headers = { Authorization: "Bearer #{ENV.fetch('HUBSPOT_ACCESS_TOKEN')}" }
5
+ HTTParty.get('https://api.hubapi.com/owners/v2/owners', headers: headers).parsed_response
5
6
  end
6
7
  end
7
8
 
8
- before { Hubspot.configure(hapikey: 'demo') }
9
-
10
9
  describe '.all' do
11
10
  cassette 'owner_all'
12
11
 
@@ -1,4 +1,6 @@
1
1
  describe Hubspot::Utils do
2
+ API_HEADERS = { Authorization: "Bearer #{ENV.fetch('HUBSPOT_ACCESS_TOKEN')}" }.freeze
3
+
2
4
  describe ".properties_to_hash" do
3
5
  let(:properties) do
4
6
  {
@@ -32,13 +34,13 @@ describe Hubspot::Utils do
32
34
  describe '.compare_property_lists for ContactProperties' do
33
35
  let(:example_groups) do
34
36
  VCR.use_cassette('contact_properties/groups_example') do
35
- HTTParty.get('https://api.hubapi.com/contacts/v2/groups?hapikey=demo').parsed_response
37
+ HTTParty.get('https://api.hubapi.com/contacts/v2/groups', headers: API_HEADERS).parsed_response
36
38
  end
37
39
  end
38
40
 
39
41
  let(:example_properties) do
40
42
  VCR.use_cassette('contact_properties/properties_example') do
41
- HTTParty.get('https://api.hubapi.com/contacts/v2/properties?hapikey=demo').parsed_response
43
+ HTTParty.get('https://api.hubapi.com/contacts/v2/properties', headers: API_HEADERS).parsed_response
42
44
  end
43
45
  end
44
46
 
@@ -81,13 +83,13 @@ describe Hubspot::Utils do
81
83
  describe '.compare_property_lists for DealProperties' do
82
84
  let(:example_groups) do
83
85
  VCR.use_cassette('deal_groups_example') do
84
- HTTParty.get('https://api.hubapi.com/deals/v1/groups?hapikey=demo').parsed_response
86
+ HTTParty.get('https://api.hubapi.com/deals/v1/groups', headers: API_HEADERS).parsed_response
85
87
  end
86
88
  end
87
89
 
88
90
  let(:example_properties) do
89
91
  VCR.use_cassette('deal_properties_example') do
90
- HTTParty.get('https://api.hubapi.com/deals/v1/properties?hapikey=demo').parsed_response
92
+ HTTParty.get('https://api.hubapi.com/deals/v1/properties', headers: API_HEADERS).parsed_response
91
93
  end
92
94
  end
93
95
 
@@ -126,39 +128,4 @@ describe Hubspot::Utils do
126
128
  end
127
129
  end
128
130
  end
129
-
130
- describe ".dump_properties" do
131
- it "prints a deprecation warning" do
132
- VCR.use_cassette("dump_deal_properties_and_groups") do
133
- api_key = "demo"
134
-
135
- output = capture_stderr do
136
- Hubspot::Utils.dump_properties(Hubspot::DealProperties, api_key)
137
- end
138
-
139
- expected_warning = "Hubspot::Utils.dump_properties is deprecated"
140
- expect(output).to include(expected_warning)
141
- end
142
- end
143
- end
144
-
145
- describe ".restore_properties" do
146
- it "prints a deprecation warning" do
147
- VCR.use_cassette("restore_deal_properties_and_groups") do
148
- api_key = "demo"
149
- properties = {"groups" => {}, "properties" => {}}
150
-
151
- output = capture_stderr do
152
- Hubspot::Utils.restore_properties(
153
- Hubspot::DealProperties,
154
- api_key,
155
- properties
156
- )
157
- end
158
-
159
- expected_warning = "Hubspot::Utils.restore_properties is deprecated"
160
- expect(output).to include(expected_warning)
161
- end
162
- end
163
- end
164
131
  end
@@ -1,7 +1,7 @@
1
1
  RSpec.describe Hubspot do
2
2
  describe ".configure" do
3
3
  it "delegates .configure to Hubspot::Config.configure" do
4
- options = { hapikey: "demo" }
4
+ options = { access_token: "demo" }
5
5
  allow(Hubspot::Config).to receive(:configure).with(options)
6
6
 
7
7
  Hubspot.configure(options)
data/spec/spec_helper.rb CHANGED
@@ -30,11 +30,11 @@ Dir["#{RSPEC_ROOT}/shared_examples/**/*.rb"].each {|f| require f}
30
30
 
31
31
  RSpec.configure do |config|
32
32
  config.before(:all) do
33
- Hubspot.configure(hapikey: ENV.fetch("HUBSPOT_HAPI_KEY"))
33
+ Hubspot.configure(access_token: ENV.fetch("HUBSPOT_ACCESS_TOKEN"))
34
34
  end
35
35
 
36
36
  config.before(:each) do
37
- Hubspot.configure(hapikey: ENV.fetch("HUBSPOT_HAPI_KEY"))
37
+ Hubspot.configure(access_token: ENV.fetch("HUBSPOT_ACCESS_TOKEN"))
38
38
  end
39
39
 
40
40
  # config.after(:each) do
data/spec/support/vcr.rb CHANGED
@@ -10,4 +10,5 @@ VCR.configure do |c|
10
10
  c.default_cassette_options = { record: vcr_record_mode }
11
11
  c.filter_sensitive_data("<HAPI_KEY>") { ENV.fetch("HUBSPOT_HAPI_KEY") }
12
12
  c.filter_sensitive_data("<PORTAL_ID>") { ENV.fetch("HUBSPOT_PORTAL_ID") }
13
+ c.filter_sensitive_data("<ACCESS_TOKEN>") { ENV.fetch("HUBSPOT_ACCESS_TOKEN") }
13
14
  end
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.9.0
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-29 00:00:00.000000000 Z
11
+ date: 2022-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -294,7 +294,6 @@ files:
294
294
  - lib/hubspot/subscription.rb
295
295
  - lib/hubspot/topic.rb
296
296
  - lib/hubspot/utils.rb
297
- - lib/tasks/hubspot.rake
298
297
  - spec/factories/companies.rb
299
298
  - spec/factories/contacts.rb
300
299
  - spec/lib/hubspot-ruby_spec.rb
@@ -321,21 +320,18 @@ files:
321
320
  - spec/lib/hubspot/properties_spec.rb
322
321
  - spec/lib/hubspot/resource_spec.rb
323
322
  - spec/lib/hubspot/utils_spec.rb
324
- - spec/lib/tasks/hubspot_spec.rb
325
323
  - spec/shared_examples/saveable_resource.rb
326
324
  - spec/shared_examples/updateable_resource.rb
327
325
  - spec/spec_helper.rb
328
- - spec/support/capture_output.rb
329
326
  - spec/support/cassette_helper.rb
330
327
  - spec/support/hubspot_api_helpers.rb
331
- - spec/support/rake.rb
332
328
  - spec/support/vcr.rb
333
329
  homepage: https://github.com/captaincontrat/hubspot-api-ruby
334
330
  licenses:
335
331
  - MIT
336
332
  metadata:
337
333
  changelog_uri: https://github.com/captaincontrat/hubspot-api-ruby/blob/master/History.md
338
- post_install_message:
334
+ post_install_message:
339
335
  rdoc_options: []
340
336
  require_paths:
341
337
  - lib
@@ -350,8 +346,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
350
346
  - !ruby/object:Gem::Version
351
347
  version: '0'
352
348
  requirements: []
353
- rubygems_version: 3.2.32
354
- signing_key:
349
+ rubygems_version: 3.1.2
350
+ signing_key:
355
351
  specification_version: 4
356
352
  summary: hubspot-api-ruby is a wrapper for the HubSpot REST API
357
353
  test_files: []
@@ -1,53 +0,0 @@
1
- require 'hubspot-api-ruby'
2
-
3
- namespace :hubspot do
4
- desc 'Dump properties to file'
5
- task :dump_properties, [:kind, :file, :hapikey, :include, :exclude] do |_, args|
6
- Hubspot::Deprecator.build.deprecation_warning("hubspot:dump_properties")
7
-
8
- hapikey = args[:hapikey] || ENV['HUBSPOT_API_KEY']
9
- kind = args[:kind]
10
- unless %w(contact deal).include?(kind)
11
- raise ArgumentError, ':kind must be either "contact" or "deal"'
12
- end
13
- klass = kind == 'contact' ? Hubspot::ContactProperties : Hubspot::DealProperties
14
- props = Hubspot::Utils::dump_properties(klass, hapikey, build_filter(args))
15
- if args[:file].blank?
16
- puts JSON.pretty_generate(props)
17
- else
18
- File.open(args[:file], 'w') do |f|
19
- f.write(JSON.pretty_generate(props))
20
- end
21
- end
22
- end
23
-
24
- desc 'Restore properties from file'
25
- task :restore_properties, [:kind, :file, :hapikey, :dry_run] do |_, args|
26
- Hubspot::Deprecator.build.deprecation_warning("hubspot:restore_properties")
27
-
28
- hapikey = args[:hapikey] || ENV['HUBSPOT_API_KEY']
29
- if args[:file].blank?
30
- raise ArgumentError, ':file is a required parameter'
31
- end
32
- kind = args[:kind]
33
- unless %w(contact deal).include?(kind)
34
- raise ArgumentError, ':kind must be either "contact" or "deal"'
35
- end
36
- klass = kind == 'contact' ? Hubspot::ContactProperties : Hubspot::DealProperties
37
- file = File.read(args[:file])
38
- props = JSON.parse(file)
39
- Hubspot::Utils.restore_properties(klass, hapikey, props, args[:dry_run] != 'false')
40
- end
41
-
42
- private
43
-
44
- def build_filter(args)
45
- { include: val_to_array(args[:include]),
46
- exclude: val_to_array(args[:exclude])
47
- }
48
- end
49
-
50
- def val_to_array(val)
51
- val.blank? ? val : val.split(/\W+/)
52
- end
53
- end
@@ -1,119 +0,0 @@
1
- require "rake"
2
- require "stringio"
3
- require "tempfile"
4
-
5
- RSpec.describe "hubspot rake tasks", type: :rake do
6
- let(:hapikey) { "demo" }
7
-
8
- describe "hubspot:dump_properties" do
9
- it "writes the class properties and groups to the given file" do
10
- VCR.use_cassette("dump_contact_properties_and_groups") do
11
- file = Tempfile.new
12
-
13
- invoke_rake_task("hubspot:dump_properties", ["contact", file, hapikey])
14
-
15
- result = JSON.parse(File.read(file))
16
-
17
- expect(result.count).to be > 0
18
- expect(result['groups'].count).to be > 0
19
- expect(result['properties'].count).to be > 0
20
- end
21
- end
22
-
23
- it "prints a deprecation warning" do
24
- VCR.use_cassette("dump_contact_properties_and_groups") do
25
- file = Tempfile.new ""
26
-
27
- output = capture_stderr do
28
- invoke_rake_task("hubspot:dump_properties", ["contact", file, hapikey])
29
- end
30
-
31
- expect(output).to include("hubspot:dump_properties is deprecated")
32
- end
33
- end
34
-
35
- context "given an unknown class" do
36
- it "raises an error" do
37
- file = Tempfile.new
38
-
39
- expected_error_msg = ':kind must be either "contact" or "deal"'
40
-
41
- expect do
42
- invoke_rake_task(
43
- "hubspot:dump_properties",
44
- ["unknown_class", file, hapikey]
45
- )
46
- end.to raise_error(ArgumentError, expected_error_msg)
47
- end
48
- end
49
- end
50
-
51
- describe "hubspot:restore_properties" do
52
- context "when the class properties match the existing properties" do
53
- it "should not need to make any changes" do
54
- VCR.use_cassette("restore_contact_properties_and_groups") do
55
- file = build_file_with_matching_properties("contact")
56
-
57
- results = capture_stdout do
58
- invoke_rake_task(
59
- "hubspot:restore_properties",
60
- ["contact", file, hapikey]
61
- )
62
- end
63
-
64
- expect(results).not_to include("Created: ")
65
- expect(results).not_to include("Updated: ")
66
- end
67
- end
68
- end
69
-
70
- it "prints a deprecation warning" do
71
- VCR.use_cassette("restore_contact_properties_and_groups") do
72
- file = build_file_with_matching_properties("contact")
73
-
74
- output = capture_stderr do
75
- invoke_rake_task(
76
- "hubspot:restore_properties",
77
- ["contact", file, hapikey]
78
- )
79
- end
80
-
81
- expect(output).to include("hubspot:restore_properties is deprecated")
82
- end
83
- end
84
-
85
- context "when a file is not provided" do
86
- it "raises an error" do
87
- missing_file = ""
88
- expected_error_msg = ":file is a required parameter"
89
-
90
- expect do
91
- invoke_rake_task(
92
- "hubspot:restore_properties",
93
- ["contact", missing_file, hapikey]
94
- )
95
- end.to raise_error(ArgumentError, expected_error_msg)
96
- end
97
- end
98
-
99
- context "given an unknown class" do
100
- it "raises an error" do
101
- file = Tempfile.new
102
- expected_error_msg = ':kind must be either "contact" or "deal"'
103
-
104
- expect do
105
- invoke_rake_task(
106
- "hubspot:restore_properties",
107
- ["unknown_class", file, hapikey]
108
- )
109
- end.to raise_error(ArgumentError, expected_error_msg)
110
- end
111
- end
112
- end
113
-
114
- def build_file_with_matching_properties(klass)
115
- file = Tempfile.new
116
- invoke_rake_task("hubspot:dump_properties", ["contact", file, hapikey])
117
- file
118
- end
119
- end
@@ -1,21 +0,0 @@
1
- module CaptureOutput
2
- def capture_stderr
3
- previous, $stderr = $stderr, StringIO.new
4
- yield
5
- $stderr.string
6
- ensure
7
- $stderr = previous
8
- end
9
-
10
- def capture_stdout
11
- previous, $stdout = $stdout, StringIO.new
12
- yield
13
- $stdout.string
14
- ensure
15
- $stdout = previous
16
- end
17
- end
18
-
19
- RSpec.configure do |config|
20
- config.include CaptureOutput
21
- end
data/spec/support/rake.rb DELETED
@@ -1,46 +0,0 @@
1
- require "rake"
2
-
3
- module RakeHelpers
4
- def invoke_rake_task(name, args = [])
5
- RakeTask.new(name).invoke(*args)
6
- end
7
- end
8
-
9
- class RakeTask
10
- def initialize(name)
11
- @task_name = name
12
- prep_environment
13
- end
14
-
15
- delegate :invoke, to: :task
16
-
17
- private
18
-
19
- attr_reader :task_name
20
-
21
- def prep_environment
22
- Rake.application = rake
23
- Rake.load_rakefile(full_task_path)
24
- Rake::Task.define_task(:environment)
25
- end
26
-
27
- def full_task_path
28
- "#{root_path}/lib/tasks/#{task_name.split(':').first}.rake"
29
- end
30
-
31
- def root_path
32
- File.expand_path('../..', __dir__)
33
- end
34
-
35
- def task
36
- rake[task_name]
37
- end
38
-
39
- def rake
40
- @_rake ||= Rake::Application.new
41
- end
42
- end
43
-
44
- RSpec.configure do |config|
45
- config.include RakeHelpers, type: :rake
46
- end