mrkt 0.9.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) 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 +4 -1
  7. data/lib/mrkt.rb +14 -3
  8. data/lib/mrkt/concerns/authentication.rb +27 -12
  9. data/lib/mrkt/concerns/connection.rb +13 -7
  10. data/lib/mrkt/concerns/crud_activities.rb +12 -9
  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 +13 -14
  16. data/lib/mrkt/concerns/crud_helpers.rb +7 -0
  17. data/lib/mrkt/concerns/crud_leads.rb +35 -20
  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 +1 -1
  21. data/lib/mrkt/concerns/import_leads.rb +8 -5
  22. data/lib/mrkt/errors.rb +3 -2
  23. data/lib/mrkt/faraday.rb +4 -0
  24. data/lib/mrkt/faraday/params_encoder.rb +20 -0
  25. data/lib/mrkt/faraday_middleware.rb +3 -7
  26. data/lib/mrkt/version.rb +1 -1
  27. data/mrkt.gemspec +11 -12
  28. data/spec/concerns/authentication_spec.rb +57 -5
  29. data/spec/concerns/crud_activities_spec.rb +46 -7
  30. data/spec/concerns/crud_asset_folders_spec.rb +273 -0
  31. data/spec/concerns/crud_asset_static_lists_spec.rb +183 -0
  32. data/spec/concerns/crud_custom_activities_spec.rb +3 -1
  33. data/spec/concerns/crud_custom_objects_spec.rb +1 -1
  34. data/spec/concerns/crud_leads_spec.rb +104 -2
  35. data/spec/concerns/crud_lists_spec.rb +33 -0
  36. data/spec/concerns/import_leads_spec.rb +3 -3
  37. data/spec/faraday/params_encoder_spec.rb +24 -0
  38. data/spec/spec_helper.rb +3 -1
  39. data/spec/support/webmock.rb +1 -7
  40. metadata +44 -46
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: beebfadd98f11b8793c2be39ed96246c24ca2a52
4
- data.tar.gz: 4ff4f2b76abafae545b29ead006d4afbd90affb1
2
+ SHA256:
3
+ metadata.gz: 8b9a26db5da0ff83b251b40c276517013a120bccac5e0723d2cb23f751bc9817
4
+ data.tar.gz: 74a55a3fde8f192301e8995c7391fc5f88c7f8d9fa0163a1f2ef633cf9ade4bf
5
5
  SHA512:
6
- metadata.gz: 5cfa98036ebf42268a7cd349f17e09e38df7b8c9e06e8dad87094e588ce43f16e8e0671f2fa86fa7b7074ace75bce4de3629c601704ad6c2656c82e1c93da7b7
7
- data.tar.gz: 36d67c8ad9811b8e8cd60dd18df61e0d6bc7cae124dc75904c44831d4bafe6d9e6a97782dfd8c39437bd12f7d8783f6b21d613b5d703527f7ec218b5caa6ef7d
6
+ metadata.gz: 365eaf2f0ea0ffc9a9a47af40b9834bab11de69438bb44a42dc23720f19b705b8918c097164c49cc2d82ce02dfb8b1add9f761cb6ae3ee99df69091493fb3b32
7
+ data.tar.gz: 7a184f5ce07e10e3e88f9cfe988adfdf2633271e229f55da2290e04ac78b3282a46eb77c87d01f00c3e3493e77920abf7a38bc1be8edf3cc565224aa8ecb8bff
@@ -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.9.0)
5
- faraday (> 0.9.0, < 0.14.0)
6
- faraday_middleware (> 0.9.0, < 0.13.0)
4
+ mrkt (1.0.1)
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
@@ -32,6 +32,7 @@ Get the following from your Marketo admin:
32
32
  * hostname, i.e. `'123-abc-123.mktorest.com'`
33
33
  * client id, e.g. `'4567e1cdf-0fae-4685-a914-5be45043f2d8'`
34
34
  * client secret, e.g. `'7Gn0tuiHZiDHnzeu9P14uDQcSx9xIPPt'`
35
+ * partner id, e.g. `'335b1c91511b8d8b49c7bbf66f53288f16f37b60_a0147938d3135f8ddb5a75850ea3c39313fd23c4'` (optional)
35
36
 
36
37
 
37
38
  ## Usage
@@ -42,7 +43,9 @@ Get the following from your Marketo admin:
42
43
  client = Mrkt::Client.new(
43
44
  host: '123-abc-123.mktorest.com',
44
45
  client_id: '4567e1cdf-0fae-4685-a914-5be45043f2d8',
45
- client_secret: '7Gn0tuiHZiDHnzeu9P14uDQcSx9xIPPt')
46
+ client_secret: '7Gn0tuiHZiDHnzeu9P14uDQcSx9xIPPt',
47
+ partner_id: '335b1c91511b8d8b49c7bbf66f53288f16f37b60_a0147938d3135f8ddb5a75850ea3c39313fd23c4' # optional
48
+ )
46
49
  ```
47
50
 
48
51
  If you need verbosity during troubleshooting, enable debug mode:
@@ -13,6 +13,8 @@ require 'mrkt/concerns/import_custom_objects'
13
13
  require 'mrkt/concerns/crud_custom_objects'
14
14
  require 'mrkt/concerns/crud_custom_activities'
15
15
  require 'mrkt/concerns/crud_programs'
16
+ require 'mrkt/concerns/crud_asset_static_lists'
17
+ require 'mrkt/concerns/crud_asset_folders'
16
18
 
17
19
  module Mrkt
18
20
  class Client
@@ -28,6 +30,8 @@ module Mrkt
28
30
  include CrudCustomObjects
29
31
  include CrudCustomActivities
30
32
  include CrudPrograms
33
+ include CrudAssetStaticLists
34
+ include CrudAssetFolders
31
35
 
32
36
  attr_accessor :debug
33
37
 
@@ -36,6 +40,7 @@ module Mrkt
36
40
 
37
41
  @client_id = options.fetch(:client_id)
38
42
  @client_secret = options.fetch(:client_secret)
43
+ @partner_id = options[:partner_id]
39
44
 
40
45
  @retry_authentication = options.fetch(:retry_authentication, false)
41
46
  @retry_authentication_count = options.fetch(:retry_authentication_count, 3).to_i
@@ -49,13 +54,19 @@ module Mrkt
49
54
  @options = options
50
55
  end
51
56
 
52
- %i(get post delete).each do |http_method|
53
- 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|
54
63
  authenticate!
55
64
 
65
+ payload = merge_params(params, optional)
66
+
56
67
  resp = connection.send(http_method, path, payload) do |req|
57
68
  add_authorization(req)
58
- block.call(req) unless block.nil?
69
+ block&.call(req)
59
70
  end
60
71
 
61
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
@@ -1,4 +1,4 @@
1
- require 'mrkt/faraday_middleware'
1
+ require 'mrkt/faraday'
2
2
 
3
3
  module Mrkt
4
4
  module Connection
@@ -7,21 +7,27 @@ module Mrkt
7
7
  end
8
8
 
9
9
  def init_connection
10
- Faraday.new(url: "https://#{@host}") do |conn|
10
+ ::Faraday.new(options) do |conn|
11
11
  conn.request :multipart
12
12
  conn.request :url_encoded
13
13
 
14
- if @debug
15
- conn.response :logger, @logger, (@log_options || {})
16
- end
17
-
14
+ conn.response :logger, @logger, (@log_options || {}) if @debug
18
15
  conn.response :mkto, content_type: /\bjson$/
19
16
 
20
17
  conn.options.timeout = @options[:read_timeout] if @options.key?(:read_timeout)
21
18
  conn.options.open_timeout = @options[:open_timeout] if @options.key?(:open_timeout)
22
19
 
23
- conn.adapter Faraday.default_adapter
20
+ conn.adapter @options.fetch(:adapter, ::Faraday.default_adapter)
24
21
  end
25
22
  end
23
+
24
+ def options
25
+ {
26
+ url: "https://#{@host}",
27
+ request: {
28
+ params_encoder: Mrkt::Faraday::ParamsEncoder
29
+ }
30
+ }
31
+ end
26
32
  end
27
33
  end