mrkt 0.8.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +5 -5
  2. data/.rubocop.yml +59 -5
  3. data/.travis.yml +19 -10
  4. data/Gemfile.lock +68 -63
  5. data/LICENSE +21 -0
  6. data/README.md +11 -7
  7. data/lib/mrkt.rb +16 -3
  8. data/lib/mrkt/concerns/authentication.rb +27 -12
  9. data/lib/mrkt/concerns/connection.rb +2 -5
  10. data/lib/mrkt/concerns/crud_activities.rb +10 -7
  11. data/lib/mrkt/concerns/crud_asset_folders.rb +43 -0
  12. data/lib/mrkt/concerns/crud_asset_static_lists.rb +30 -0
  13. data/lib/mrkt/concerns/crud_campaigns.rb +2 -4
  14. data/lib/mrkt/concerns/crud_custom_activities.rb +3 -2
  15. data/lib/mrkt/concerns/crud_custom_objects.rb +12 -13
  16. data/lib/mrkt/concerns/crud_helpers.rb +7 -0
  17. data/lib/mrkt/concerns/crud_leads.rb +28 -15
  18. data/lib/mrkt/concerns/crud_lists.rb +13 -10
  19. data/lib/mrkt/concerns/crud_programs.rb +6 -5
  20. data/lib/mrkt/concerns/import_custom_objects.rb +24 -0
  21. data/lib/mrkt/concerns/import_leads.rb +7 -4
  22. data/lib/mrkt/errors.rb +3 -2
  23. data/lib/mrkt/version.rb +1 -1
  24. data/mrkt.gemspec +11 -12
  25. data/spec/concerns/authentication_spec.rb +57 -5
  26. data/spec/concerns/crud_activities_spec.rb +46 -7
  27. data/spec/concerns/crud_asset_folders_spec.rb +273 -0
  28. data/spec/concerns/crud_asset_static_lists_spec.rb +183 -0
  29. data/spec/concerns/crud_custom_activities_spec.rb +3 -1
  30. data/spec/concerns/crud_custom_objects_spec.rb +1 -1
  31. data/spec/concerns/crud_leads_spec.rb +103 -1
  32. data/spec/concerns/crud_lists_spec.rb +33 -0
  33. data/spec/concerns/import_custom_objects_spec.rb +89 -0
  34. data/spec/concerns/import_leads_spec.rb +3 -3
  35. data/spec/spec_helper.rb +3 -1
  36. data/spec/support/webmock.rb +1 -7
  37. metadata +43 -46
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 9c4c184b895beed1d39507db68cd1826fd709588
4
- data.tar.gz: f2fcf806aa0f17d07ee67034eeabe09159ef1b60
2
+ SHA256:
3
+ metadata.gz: c6240df5d2fc5e237cb846da72b226f71b836d86e466aff3ee96854ff0c9087f
4
+ data.tar.gz: a20eea282f97ad58e45d780bfc88c32305bae0c127feb819be7f93aa26010dc5
5
5
  SHA512:
6
- metadata.gz: eb54c671fa877899ab5161db7446d0b142684a0fed8ed05cf7b3e533827a229a32603e40e6500b971196e91dab13864bd79ef0147d9a523e3eaf2122548ba9d5
7
- data.tar.gz: bfb9caab6508464ecc878d9e0b17a3c69b0f72f75f84d3e611f60aa2e3384d2ef961dd25e4d81f904f81685791e173dac5b809cf16df763e6dfb9a631e5281b9
6
+ metadata.gz: 5e4878202b8cf696c8e9434688f21c648770f32a393d7128efe1b90e89c1e78d76b00c447c83c295f72cdc8399f7ffe6a526b7a972a45107abe1c0ea53a42217
7
+ data.tar.gz: 14c64d83473c35eaec901b1be3e921d1de1e211cf8db989fa91bb3e2fa389303d27bdf6adc7af77bcedcc9de6aaf8aaaa3adefb04f0748d12f680d29fcdcd716
@@ -1,17 +1,71 @@
1
1
  AllCops:
2
+ TargetRubyVersion: 2.5
2
3
  Exclude:
3
4
  - 'bin/**/*'
4
- Documentation:
5
+ - 'vendor/**/*'
6
+
7
+ Layout/EmptyLinesAroundAttributeAccessor:
8
+ Enabled: true
9
+ Layout/EmptyLineAfterGuardClause:
10
+ Enabled: false
11
+ Layout/FirstHashElementIndentation:
5
12
  Enabled: false
6
- LineLength:
13
+ Layout/HashAlignment:
14
+ Enabled: false
15
+ Layout/LineLength:
16
+ Max: 128
17
+ Layout/MultilineMethodCallIndentation:
18
+ EnforcedStyle: indented
19
+ Layout/SpaceAroundMethodCallOperator:
20
+ Enabled: true
21
+
22
+ Lint/DeprecatedOpenSSLConstant:
7
23
  Enabled: true
8
- Max: 120
9
- MethodLength:
24
+ Lint/MixedRegexpCaptureTypes:
25
+ Enabled: true
26
+ Lint/RaiseException:
27
+ Enabled: true
28
+ Lint/StructNewOverride:
29
+ Enabled: true
30
+
31
+ Metrics/AbcSize:
32
+ Max: 17
33
+ Metrics/BlockLength:
34
+ Exclude:
35
+ - 'spec/**/*'
36
+ Metrics/MethodLength:
10
37
  Max: 20
11
- IndentHash:
38
+ Metrics/ParameterLists:
39
+ Max: 6
40
+
41
+ Naming/AccessorMethodName:
12
42
  Enabled: false
13
43
 
44
+ Style/AccessorGrouping:
45
+ Enabled: true
46
+ Style/BisectedAttrAccessor:
47
+ Enabled: true
14
48
  Style/ClassAndModuleChildren:
15
49
  Enabled: false
50
+ Style/Documentation:
51
+ Enabled: false
52
+ Style/ExponentialNotation:
53
+ Enabled: true
16
54
  Style/FrozenStringLiteralComment:
17
55
  Enabled: false
56
+ Style/HashEachMethods:
57
+ Enabled: true
58
+ Style/HashTransformKeys:
59
+ Enabled: true
60
+ Style/HashTransformValues:
61
+ Enabled: true
62
+ Style/RedundantAssignment:
63
+ Enabled: true
64
+ Style/RedundantFetchBlock:
65
+ Enabled: true
66
+ Style/RedundantRegexpCharacterClass:
67
+ Enabled: true
68
+ Style/RedundantRegexpEscape:
69
+ Enabled: true
70
+ Style/SlicingWithRange:
71
+ Enabled: true
@@ -1,12 +1,21 @@
1
+ env:
2
+ global:
3
+ - CC_TEST_REPORTER_ID=45cd2174f49b570406e294ff393d456c4ae8532cf16dd6430abb06d8a0722a28
4
+ - COVERAGE=on
1
5
  language: ruby
2
6
  rvm:
3
- - 2.0.0
4
- - 2.1.10
5
- - 2.2.8
6
- - 2.3.5
7
- - 2.4.2
8
- addons:
9
- code_climate:
10
- repo_token: 45cd2174f49b570406e294ff393d456c4ae8532cf16dd6430abb06d8a0722a28
11
- after_success:
12
- - bundle exec codeclimate-test-reporter
7
+ - 2.5
8
+ - 2.6
9
+ - 2.7
10
+ before_install:
11
+ - gem update --system
12
+ - bundle update --bundler
13
+ before_script:
14
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
15
+ - chmod +x ./cc-test-reporter
16
+ - ./cc-test-reporter before-build
17
+ script:
18
+ - bundle exec rspec
19
+ - bundle exec rubocop
20
+ after_script:
21
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
@@ -1,90 +1,95 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mrkt (0.8.0)
5
- faraday (> 0.9.0, < 0.14.0)
6
- faraday_middleware (> 0.9.0, < 0.13.0)
4
+ mrkt (1.0.0)
5
+ faraday (~> 1.0)
6
+ faraday_middleware (~> 1.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- addressable (2.5.1)
12
- public_suffix (~> 2.0, >= 2.0.2)
13
- ast (2.3.0)
14
- byebug (9.0.6)
15
- codeclimate-test-reporter (1.0.7)
16
- simplecov
17
- coderay (1.1.1)
11
+ addressable (2.7.0)
12
+ public_suffix (>= 2.0.2, < 5.0)
13
+ ast (2.4.1)
14
+ byebug (11.1.3)
15
+ coderay (1.1.3)
18
16
  crack (0.4.3)
19
17
  safe_yaml (~> 1.0.0)
20
- diff-lcs (1.3)
21
- docile (1.1.5)
22
- faraday (0.10.1)
18
+ diff-lcs (1.4.4)
19
+ docile (1.3.2)
20
+ faraday (1.0.1)
23
21
  multipart-post (>= 1.2, < 3)
24
- faraday_middleware (0.10.1)
25
- faraday (>= 0.7.4, < 1.0)
26
- json (2.1.0)
27
- method_source (0.8.2)
28
- multipart-post (2.0.0)
29
- parser (2.4.0.0)
30
- ast (~> 2.2)
31
- powerpack (0.1.1)
32
- pry (0.10.4)
33
- coderay (~> 1.1.0)
34
- method_source (~> 0.8.1)
35
- slop (~> 3.4)
36
- pry-byebug (3.4.2)
37
- byebug (~> 9.0)
38
- pry (~> 0.10)
39
- public_suffix (2.0.5)
40
- rainbow (2.2.2)
41
- rake
42
- rake (10.5.0)
43
- rspec (3.6.0)
44
- rspec-core (~> 3.6.0)
45
- rspec-expectations (~> 3.6.0)
46
- rspec-mocks (~> 3.6.0)
47
- rspec-core (3.6.0)
48
- rspec-support (~> 3.6.0)
49
- rspec-expectations (3.6.0)
22
+ faraday_middleware (1.0.0)
23
+ faraday (~> 1.0)
24
+ gem-release (2.1.1)
25
+ hashdiff (1.0.1)
26
+ json (2.3.1)
27
+ method_source (1.0.0)
28
+ multipart-post (2.1.1)
29
+ parallel (1.19.2)
30
+ parser (2.7.1.4)
31
+ ast (~> 2.4.1)
32
+ pry (0.13.1)
33
+ coderay (~> 1.1)
34
+ method_source (~> 1.0)
35
+ pry-byebug (3.9.0)
36
+ byebug (~> 11.0)
37
+ pry (~> 0.13.0)
38
+ public_suffix (4.0.5)
39
+ rainbow (3.0.0)
40
+ rake (12.3.3)
41
+ regexp_parser (1.7.1)
42
+ rexml (3.2.4)
43
+ rspec (3.9.0)
44
+ rspec-core (~> 3.9.0)
45
+ rspec-expectations (~> 3.9.0)
46
+ rspec-mocks (~> 3.9.0)
47
+ rspec-core (3.9.2)
48
+ rspec-support (~> 3.9.3)
49
+ rspec-expectations (3.9.2)
50
50
  diff-lcs (>= 1.2.0, < 2.0)
51
- rspec-support (~> 3.6.0)
52
- rspec-mocks (3.6.0)
51
+ rspec-support (~> 3.9.0)
52
+ rspec-mocks (3.9.1)
53
53
  diff-lcs (>= 1.2.0, < 2.0)
54
- rspec-support (~> 3.6.0)
55
- rspec-support (3.6.0)
56
- rubocop (0.45.0)
57
- parser (>= 2.3.1.1, < 3.0)
58
- powerpack (~> 0.1)
59
- rainbow (>= 1.99.1, < 3.0)
54
+ rspec-support (~> 3.9.0)
55
+ rspec-support (3.9.3)
56
+ rubocop (0.87.1)
57
+ parallel (~> 1.10)
58
+ parser (>= 2.7.1.1)
59
+ rainbow (>= 2.2.2, < 4.0)
60
+ regexp_parser (>= 1.7)
61
+ rexml
62
+ rubocop-ast (>= 0.1.0, < 1.0)
60
63
  ruby-progressbar (~> 1.7)
61
- unicode-display_width (~> 1.0, >= 1.0.1)
62
- ruby-progressbar (1.8.1)
63
- safe_yaml (1.0.4)
64
- simplecov (0.14.1)
65
- docile (~> 1.1.0)
64
+ unicode-display_width (>= 1.4.0, < 2.0)
65
+ rubocop-ast (0.1.0)
66
+ parser (>= 2.7.0.1)
67
+ ruby-progressbar (1.10.1)
68
+ safe_yaml (1.0.5)
69
+ simplecov (0.17.1)
70
+ docile (~> 1.1)
66
71
  json (>= 1.8, < 3)
67
72
  simplecov-html (~> 0.10.0)
68
- simplecov-html (0.10.1)
69
- slop (3.6.0)
70
- unicode-display_width (1.3.0)
71
- webmock (1.21.0)
73
+ simplecov-html (0.10.2)
74
+ unicode-display_width (1.7.0)
75
+ webmock (3.8.3)
72
76
  addressable (>= 2.3.6)
73
77
  crack (>= 0.3.2)
78
+ hashdiff (>= 0.4.0, < 2.0.0)
74
79
 
75
80
  PLATFORMS
76
81
  ruby
77
82
 
78
83
  DEPENDENCIES
79
84
  bundler (~> 1.3)
80
- codeclimate-test-reporter (~> 1.0.0)
85
+ gem-release (~> 2.1)
81
86
  mrkt!
82
- pry-byebug (~> 3.4.0)
83
- rake (~> 10.0)
87
+ pry-byebug (~> 3.7)
88
+ rake (~> 12.3)
84
89
  rspec (~> 3.2)
85
- rubocop (~> 0.45.0)
86
- simplecov (~> 0.14.1)
87
- webmock (~> 1.21.0)
90
+ rubocop (~> 0.87.1)
91
+ simplecov (~> 0.17.1)
92
+ webmock (~> 3.1)
88
93
 
89
94
  BUNDLED WITH
90
- 1.15.4
95
+ 1.17.3
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 KARASZI István
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -1,10 +1,11 @@
1
1
  # Mrkt
2
2
 
3
- [![Build Status](https://secure.travis-ci.org/raszi/mrkt.png)](http://travis-ci.org/raszi/mrkt)
3
+ [![Build Status](https://travis-ci.org/raszi/mrkt.svg?branch=master)](https://travis-ci.org/raszi/mrkt)
4
4
  [![Code Climate](https://codeclimate.com/github/raszi/mrkt/badges/gpa.svg)](https://codeclimate.com/github/raszi/mrkt)
5
5
  [![Test Coverage](https://codeclimate.com/github/raszi/mrkt/badges/coverage.svg)](https://codeclimate.com/github/raszi/mrkt)
6
+ [![Gem Version](https://badge.fury.io/rb/mrkt.svg)](https://badge.fury.io/rb/mrkt)
6
7
 
7
- This gem provides some level of abstraction to Marketo REST APIs. Please note that this gem is alpha quality.
8
+ This gem provides some level of abstraction to Marketo REST APIs. Please note that this gem is alpha quality.
8
9
 
9
10
 
10
11
  ## Installation
@@ -31,6 +32,7 @@ Get the following from your Marketo admin:
31
32
  * hostname, i.e. `'123-abc-123.mktorest.com'`
32
33
  * client id, e.g. `'4567e1cdf-0fae-4685-a914-5be45043f2d8'`
33
34
  * client secret, e.g. `'7Gn0tuiHZiDHnzeu9P14uDQcSx9xIPPt'`
35
+ * partner id, e.g. `'335b1c91511b8d8b49c7bbf66f53288f16f37b60_a0147938d3135f8ddb5a75850ea3c39313fd23c4'` (optional)
34
36
 
35
37
 
36
38
  ## Usage
@@ -39,17 +41,19 @@ Get the following from your Marketo admin:
39
41
 
40
42
  ```ruby
41
43
  client = Mrkt::Client.new(
42
- host: '123-abc-123.mktorest.com',
43
- client_id: '4567e1cdf-0fae-4685-a914-5be45043f2d8',
44
- client_secret: '7Gn0tuiHZiDHnzeu9P14uDQcSx9xIPPt')
44
+ host: '123-abc-123.mktorest.com',
45
+ client_id: '4567e1cdf-0fae-4685-a914-5be45043f2d8',
46
+ client_secret: '7Gn0tuiHZiDHnzeu9P14uDQcSx9xIPPt',
47
+ partner_id: '335b1c91511b8d8b49c7bbf66f53288f16f37b60_a0147938d3135f8ddb5a75850ea3c39313fd23c4' # optional
48
+ )
45
49
  ```
46
50
 
47
51
  If you need verbosity during troubleshooting, enable debug mode:
48
52
 
49
53
  ```ruby
50
54
  client = Mrkt::Client.new(
51
- host: '123-abc-123.mktorest.com',
52
- client_id: '4567e1cdf-0fae-4685-a914-5be45043f2d8',
55
+ host: '123-abc-123.mktorest.com',
56
+ client_id: '4567e1cdf-0fae-4685-a914-5be45043f2d8',
53
57
  client_secret: '7Gn0tuiHZiDHnzeu9P14uDQcSx9xIPPt',
54
58
  debug: true,
55
59
  logger: ::Logger.new("log/marketo.log"), # optional, defaults to Faraday default of logging to STDOUT
@@ -9,9 +9,12 @@ require 'mrkt/concerns/crud_campaigns'
9
9
  require 'mrkt/concerns/crud_leads'
10
10
  require 'mrkt/concerns/crud_lists'
11
11
  require 'mrkt/concerns/import_leads'
12
+ require 'mrkt/concerns/import_custom_objects'
12
13
  require 'mrkt/concerns/crud_custom_objects'
13
14
  require 'mrkt/concerns/crud_custom_activities'
14
15
  require 'mrkt/concerns/crud_programs'
16
+ require 'mrkt/concerns/crud_asset_static_lists'
17
+ require 'mrkt/concerns/crud_asset_folders'
15
18
 
16
19
  module Mrkt
17
20
  class Client
@@ -23,9 +26,12 @@ module Mrkt
23
26
  include CrudLeads
24
27
  include CrudLists
25
28
  include ImportLeads
29
+ include ImportCustomObjects
26
30
  include CrudCustomObjects
27
31
  include CrudCustomActivities
28
32
  include CrudPrograms
33
+ include CrudAssetStaticLists
34
+ include CrudAssetFolders
29
35
 
30
36
  attr_accessor :debug
31
37
 
@@ -34,6 +40,7 @@ module Mrkt
34
40
 
35
41
  @client_id = options.fetch(:client_id)
36
42
  @client_secret = options.fetch(:client_secret)
43
+ @partner_id = options[:partner_id]
37
44
 
38
45
  @retry_authentication = options.fetch(:retry_authentication, false)
39
46
  @retry_authentication_count = options.fetch(:retry_authentication_count, 3).to_i
@@ -47,13 +54,19 @@ module Mrkt
47
54
  @options = options
48
55
  end
49
56
 
50
- %i(get post delete).each do |http_method|
51
- define_method(http_method) do |path, payload = {}, &block|
57
+ def merge_params(params, optional)
58
+ params.merge(optional.keep_if { |_key, value| value })
59
+ end
60
+
61
+ %i[get post delete].each do |http_method|
62
+ define_method(http_method) do |path, params = {}, optional = {}, &block|
52
63
  authenticate!
53
64
 
65
+ payload = merge_params(params, optional)
66
+
54
67
  resp = connection.send(http_method, path, payload) do |req|
55
68
  add_authorization(req)
56
- block.call(req) unless block.nil?
69
+ block&.call(req)
57
70
  end
58
71
 
59
72
  resp.body
@@ -5,15 +5,9 @@ module Mrkt
5
5
 
6
6
  authenticate
7
7
 
8
- if !authenticated? && @retry_authentication
9
- @retry_authentication_count.times do
10
- sleep(@retry_authentication_wait_seconds) if @retry_authentication_wait_seconds > 0
11
- authenticate
12
- break if authenticated?
13
- end
14
- end
8
+ retry_authentication if !authenticated? && @retry_authentication
15
9
 
16
- fail Mrkt::Errors::AuthorizationError, 'Client not authenticated' unless authenticated?
10
+ raise Mrkt::Errors::AuthorizationError, 'Client not authenticated' unless authenticated?
17
11
  end
18
12
 
19
13
  def authenticated?
@@ -24,6 +18,15 @@ module Mrkt
24
18
  @valid_until && Time.now < @valid_until
25
19
  end
26
20
 
21
+ def retry_authentication
22
+ @retry_authentication_count.times do
23
+ sleep(@retry_authentication_wait_seconds) if @retry_authentication_wait_seconds.positive?
24
+ authenticate
25
+
26
+ break if authenticated?
27
+ end
28
+ end
29
+
27
30
  def authenticate
28
31
  connection.get('/identity/oauth/token', authentication_params).tap do |response|
29
32
  data = response.body
@@ -36,15 +39,27 @@ module Mrkt
36
39
  end
37
40
 
38
41
  def authentication_params
42
+ merge_params(required_authentication_params, optional_authentication_params)
43
+ end
44
+
45
+ def add_authorization(req)
46
+ req.headers[:authorization] = "Bearer #{@token}"
47
+ end
48
+
49
+ private
50
+
51
+ def optional_authentication_params
52
+ {
53
+ partner_id: @partner_id
54
+ }
55
+ end
56
+
57
+ def required_authentication_params
39
58
  {
40
59
  grant_type: 'client_credentials',
41
60
  client_id: @client_id,
42
61
  client_secret: @client_secret
43
62
  }
44
63
  end
45
-
46
- def add_authorization(req)
47
- req.headers[:authorization] = "Bearer #{@token}"
48
- end
49
64
  end
50
65
  end