mrkt 0.6.2 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/dependabot.yml +11 -0
- data/.github/workflows/ruby.yml +41 -0
- data/.rubocop.yml +31 -6
- data/Gemfile.lock +95 -69
- data/LICENSE +21 -0
- data/README.md +35 -7
- data/lib/mrkt/concerns/authentication.rb +32 -6
- data/lib/mrkt/concerns/connection.rb +13 -4
- data/lib/mrkt/concerns/crud_activities.rb +32 -0
- data/lib/mrkt/concerns/crud_asset_folders.rb +43 -0
- data/lib/mrkt/concerns/crud_asset_static_lists.rb +30 -0
- data/lib/mrkt/concerns/crud_campaigns.rb +2 -4
- data/lib/mrkt/concerns/crud_custom_activities.rb +36 -0
- data/lib/mrkt/concerns/crud_custom_objects.rb +14 -15
- data/lib/mrkt/concerns/crud_helpers.rb +7 -0
- data/lib/mrkt/concerns/crud_leads.rb +41 -15
- data/lib/mrkt/concerns/crud_lists.rb +13 -10
- data/lib/mrkt/concerns/crud_programs.rb +6 -5
- data/lib/mrkt/concerns/import_custom_objects.rb +24 -0
- data/lib/mrkt/concerns/import_leads.rb +8 -5
- data/lib/mrkt/errors.rb +23 -3
- data/lib/mrkt/faraday/params_encoder.rb +20 -0
- data/lib/mrkt/faraday.rb +4 -0
- data/lib/mrkt/faraday_middleware/response.rb +4 -4
- data/lib/mrkt/faraday_middleware.rb +3 -7
- data/lib/mrkt/version.rb +1 -1
- data/lib/mrkt.rb +29 -3
- data/mrkt.gemspec +13 -12
- data/spec/concerns/authentication_spec.rb +95 -0
- data/spec/concerns/crud_activities_spec.rb +279 -0
- data/spec/concerns/crud_asset_folders_spec.rb +273 -0
- data/spec/concerns/crud_asset_static_lists_spec.rb +183 -0
- data/spec/concerns/crud_custom_activities_spec.rb +172 -0
- data/spec/concerns/crud_custom_objects_spec.rb +99 -89
- data/spec/concerns/crud_leads_spec.rb +151 -1
- data/spec/concerns/crud_lists_spec.rb +33 -0
- data/spec/concerns/import_custom_objects_spec.rb +89 -0
- data/spec/concerns/import_leads_spec.rb +3 -3
- data/spec/faraday/params_encoder_spec.rb +24 -0
- data/spec/spec_helper.rb +3 -6
- data/spec/support/initialized_client.rb +1 -1
- data/spec/support/webmock.rb +1 -7
- metadata +82 -40
- data/.travis.yml +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 41d861185c2759674a5688a61bd06294e6ca18460bd1ff868df05bc3932018d5
|
4
|
+
data.tar.gz: e52dac6cb6ebbba08e079634c7ca72545c358e23305feffb254e243b3b741786
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5de0d92b43516840e7e71a83253414e157e5812ba00b6bb4bdada5b665c80a06cc24e6a89aec6e01b19515e72032cc6428075adf17acf56d12b48d7caee38545
|
7
|
+
data.tar.gz: 010fbf3fb5baa8f5a904c1858c938f6fd4d3f344c324b782aa1080a08343b6c7a8fd5f7f1a8c93a4c666cb361a7a2d2c9fd773a18f3bfe2ad6f39e7ce7f056c5
|
@@ -0,0 +1,41 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [master]
|
6
|
+
pull_request:
|
7
|
+
branches: [master]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
test:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
|
13
|
+
strategy:
|
14
|
+
matrix:
|
15
|
+
ruby: [2.5, 2.6, 2.7, 3.0]
|
16
|
+
|
17
|
+
steps:
|
18
|
+
- uses: actions/checkout@v2.3.4
|
19
|
+
|
20
|
+
- name: Set up Ruby
|
21
|
+
uses: ruby/setup-ruby@v1
|
22
|
+
with:
|
23
|
+
ruby-version: ${{ matrix.ruby }}
|
24
|
+
bundler-cache: true
|
25
|
+
|
26
|
+
- name: Update the RubyGems system software
|
27
|
+
run: gem update --system
|
28
|
+
|
29
|
+
- name: Update Bundler
|
30
|
+
run: bundle update --bundler
|
31
|
+
|
32
|
+
- name: Install dependencies
|
33
|
+
run: bundle install
|
34
|
+
|
35
|
+
- name: Run tests and publish coverage
|
36
|
+
uses: paambaati/codeclimate-action@v2.7.5
|
37
|
+
env:
|
38
|
+
COVERAGE: on
|
39
|
+
CC_TEST_REPORTER_ID: 45cd2174f49b570406e294ff393d456c4ae8532cf16dd6430abb06d8a0722a28
|
40
|
+
with:
|
41
|
+
coverageCommand: bundle exec rspec
|
data/.rubocop.yml
CHANGED
@@ -1,15 +1,40 @@
|
|
1
|
+
require: rubocop-rake
|
2
|
+
|
1
3
|
AllCops:
|
4
|
+
TargetRubyVersion: 2.5
|
2
5
|
Exclude:
|
3
6
|
- 'bin/**/*'
|
4
|
-
|
7
|
+
- 'vendor/**/*'
|
8
|
+
NewCops: enable
|
9
|
+
|
10
|
+
Layout/EmptyLineAfterGuardClause:
|
11
|
+
Enabled: false
|
12
|
+
Layout/FirstHashElementIndentation:
|
5
13
|
Enabled: false
|
6
|
-
|
7
|
-
Enabled:
|
8
|
-
|
9
|
-
|
14
|
+
Layout/HashAlignment:
|
15
|
+
Enabled: false
|
16
|
+
Layout/LineLength:
|
17
|
+
Max: 128
|
18
|
+
Layout/MultilineMethodCallIndentation:
|
19
|
+
EnforcedStyle: indented
|
20
|
+
|
21
|
+
Metrics/AbcSize:
|
22
|
+
Exclude:
|
23
|
+
- 'lib/mrkt/concerns/connection.rb'
|
24
|
+
Metrics/BlockLength:
|
25
|
+
Exclude:
|
26
|
+
- 'spec/**/*'
|
27
|
+
Metrics/MethodLength:
|
10
28
|
Max: 20
|
11
|
-
|
29
|
+
Metrics/ParameterLists:
|
30
|
+
Max: 6
|
31
|
+
|
32
|
+
Naming/AccessorMethodName:
|
12
33
|
Enabled: false
|
13
34
|
|
14
35
|
Style/ClassAndModuleChildren:
|
15
36
|
Enabled: false
|
37
|
+
Style/Documentation:
|
38
|
+
Enabled: false
|
39
|
+
Style/FrozenStringLiteralComment:
|
40
|
+
Enabled: false
|
data/Gemfile.lock
CHANGED
@@ -1,89 +1,115 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
mrkt (
|
5
|
-
|
4
|
+
mrkt (1.2.0)
|
5
|
+
faraday (~> 1.0)
|
6
|
+
faraday_middleware (~> 1.0)
|
6
7
|
|
7
8
|
GEM
|
8
9
|
remote: https://rubygems.org/
|
9
10
|
specs:
|
10
|
-
addressable (2.
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
11
|
+
addressable (2.8.0)
|
12
|
+
public_suffix (>= 2.0.2, < 5.0)
|
13
|
+
ast (2.4.2)
|
14
|
+
byebug (11.1.3)
|
15
|
+
coderay (1.1.3)
|
16
|
+
crack (0.4.5)
|
17
|
+
rexml
|
18
|
+
diff-lcs (1.4.4)
|
19
|
+
docile (1.3.5)
|
20
|
+
faraday (1.7.1)
|
21
|
+
faraday-em_http (~> 1.0)
|
22
|
+
faraday-em_synchrony (~> 1.0)
|
23
|
+
faraday-excon (~> 1.1)
|
24
|
+
faraday-httpclient (~> 1.0.1)
|
25
|
+
faraday-net_http (~> 1.0)
|
26
|
+
faraday-net_http_persistent (~> 1.1)
|
27
|
+
faraday-patron (~> 1.0)
|
28
|
+
faraday-rack (~> 1.0)
|
25
29
|
multipart-post (>= 1.2, < 3)
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
30
|
+
ruby2_keywords (>= 0.0.4)
|
31
|
+
faraday-em_http (1.0.0)
|
32
|
+
faraday-em_synchrony (1.0.0)
|
33
|
+
faraday-excon (1.1.0)
|
34
|
+
faraday-httpclient (1.0.1)
|
35
|
+
faraday-net_http (1.0.1)
|
36
|
+
faraday-net_http_persistent (1.2.0)
|
37
|
+
faraday-patron (1.0.0)
|
38
|
+
faraday-rack (1.0.0)
|
39
|
+
faraday_middleware (1.1.0)
|
40
|
+
faraday (~> 1.0)
|
41
|
+
gem-release (2.2.2)
|
42
|
+
hashdiff (1.0.1)
|
43
|
+
method_source (1.0.0)
|
44
|
+
multipart-post (2.1.1)
|
45
|
+
parallel (1.20.1)
|
46
|
+
parser (3.0.2.0)
|
47
|
+
ast (~> 2.4.1)
|
48
|
+
pry (0.13.1)
|
49
|
+
coderay (~> 1.1)
|
50
|
+
method_source (~> 1.0)
|
51
|
+
pry-byebug (3.9.0)
|
52
|
+
byebug (~> 11.0)
|
53
|
+
pry (~> 0.13.0)
|
54
|
+
public_suffix (4.0.6)
|
55
|
+
rainbow (3.0.0)
|
56
|
+
rake (13.0.6)
|
57
|
+
regexp_parser (2.1.1)
|
58
|
+
rexml (3.2.5)
|
59
|
+
rspec (3.10.0)
|
60
|
+
rspec-core (~> 3.10.0)
|
61
|
+
rspec-expectations (~> 3.10.0)
|
62
|
+
rspec-mocks (~> 3.10.0)
|
63
|
+
rspec-core (3.10.1)
|
64
|
+
rspec-support (~> 3.10.0)
|
65
|
+
rspec-expectations (3.10.1)
|
50
66
|
diff-lcs (>= 1.2.0, < 2.0)
|
51
|
-
rspec-support (~> 3.
|
52
|
-
rspec-mocks (3.2
|
67
|
+
rspec-support (~> 3.10.0)
|
68
|
+
rspec-mocks (3.10.2)
|
53
69
|
diff-lcs (>= 1.2.0, < 2.0)
|
54
|
-
rspec-support (~> 3.
|
55
|
-
rspec-support (3.
|
56
|
-
rubocop (
|
57
|
-
|
58
|
-
parser (>=
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
70
|
+
rspec-support (~> 3.10.0)
|
71
|
+
rspec-support (3.10.2)
|
72
|
+
rubocop (1.20.0)
|
73
|
+
parallel (~> 1.10)
|
74
|
+
parser (>= 3.0.0.0)
|
75
|
+
rainbow (>= 2.2.2, < 4.0)
|
76
|
+
regexp_parser (>= 1.8, < 3.0)
|
77
|
+
rexml
|
78
|
+
rubocop-ast (>= 1.9.1, < 2.0)
|
79
|
+
ruby-progressbar (~> 1.7)
|
80
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
81
|
+
rubocop-ast (1.11.0)
|
82
|
+
parser (>= 3.0.1.1)
|
83
|
+
rubocop-rake (0.6.0)
|
84
|
+
rubocop (~> 1.0)
|
85
|
+
ruby-progressbar (1.11.0)
|
86
|
+
ruby2_keywords (0.0.5)
|
87
|
+
simplecov (0.21.2)
|
88
|
+
docile (~> 1.1)
|
89
|
+
simplecov-html (~> 0.11)
|
90
|
+
simplecov_json_formatter (~> 0.1)
|
91
|
+
simplecov-html (0.12.3)
|
92
|
+
simplecov_json_formatter (0.1.3)
|
93
|
+
unicode-display_width (2.0.0)
|
94
|
+
webmock (3.14.0)
|
95
|
+
addressable (>= 2.8.0)
|
72
96
|
crack (>= 0.3.2)
|
97
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
73
98
|
|
74
99
|
PLATFORMS
|
75
100
|
ruby
|
76
101
|
|
77
102
|
DEPENDENCIES
|
78
|
-
bundler (~>
|
79
|
-
|
103
|
+
bundler (~> 2.0)
|
104
|
+
gem-release (~> 2.1)
|
80
105
|
mrkt!
|
81
|
-
pry-byebug (~> 3.
|
82
|
-
rake (~>
|
106
|
+
pry-byebug (~> 3.7)
|
107
|
+
rake (~> 13.0)
|
83
108
|
rspec (~> 3.2)
|
84
|
-
rubocop (~>
|
85
|
-
|
86
|
-
|
109
|
+
rubocop (~> 1.20.0)
|
110
|
+
rubocop-rake (~> 0.6.0)
|
111
|
+
simplecov (~> 0.21.2)
|
112
|
+
webmock (~> 3.1)
|
87
113
|
|
88
114
|
BUNDLED WITH
|
89
|
-
1.
|
115
|
+
2.1.4
|
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,12 @@
|
|
1
1
|
# Mrkt
|
2
2
|
|
3
|
-
[![Build Status](https://
|
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)
|
7
|
+
[![Total Downloads](https://badgen.net/rubygems/dt/mrkt)](https://rubygems.org/gems/mrkt)
|
6
8
|
|
7
|
-
This gem provides some level of abstraction to Marketo REST APIs. Please note that this gem is alpha quality.
|
9
|
+
This gem provides some level of abstraction to Marketo REST APIs. Please note that this gem is alpha quality.
|
8
10
|
|
9
11
|
|
10
12
|
## Installation
|
@@ -31,6 +33,7 @@ Get the following from your Marketo admin:
|
|
31
33
|
* hostname, i.e. `'123-abc-123.mktorest.com'`
|
32
34
|
* client id, e.g. `'4567e1cdf-0fae-4685-a914-5be45043f2d8'`
|
33
35
|
* client secret, e.g. `'7Gn0tuiHZiDHnzeu9P14uDQcSx9xIPPt'`
|
36
|
+
* partner id, e.g. `'335b1c91511b8d8b49c7bbf66f53288f16f37b60_a0147938d3135f8ddb5a75850ea3c39313fd23c4'` (optional)
|
34
37
|
|
35
38
|
|
36
39
|
## Usage
|
@@ -39,17 +42,42 @@ Get the following from your Marketo admin:
|
|
39
42
|
|
40
43
|
```ruby
|
41
44
|
client = Mrkt::Client.new(
|
42
|
-
host: '123-abc-123.mktorest.com',
|
43
|
-
client_id: '4567e1cdf-0fae-4685-a914-5be45043f2d8',
|
44
|
-
client_secret: '7Gn0tuiHZiDHnzeu9P14uDQcSx9xIPPt'
|
45
|
+
host: '123-abc-123.mktorest.com',
|
46
|
+
client_id: '4567e1cdf-0fae-4685-a914-5be45043f2d8',
|
47
|
+
client_secret: '7Gn0tuiHZiDHnzeu9P14uDQcSx9xIPPt',
|
48
|
+
partner_id: '335b1c91511b8d8b49c7bbf66f53288f16f37b60_a0147938d3135f8ddb5a75850ea3c39313fd23c4' # optional
|
49
|
+
)
|
45
50
|
```
|
46
51
|
|
47
|
-
If you need verbosity during troubleshooting,
|
52
|
+
If you need verbosity during troubleshooting, enable debug mode:
|
48
53
|
|
49
54
|
```ruby
|
50
|
-
client
|
55
|
+
client = Mrkt::Client.new(
|
56
|
+
host: '123-abc-123.mktorest.com',
|
57
|
+
client_id: '4567e1cdf-0fae-4685-a914-5be45043f2d8',
|
58
|
+
client_secret: '7Gn0tuiHZiDHnzeu9P14uDQcSx9xIPPt',
|
59
|
+
debug: true,
|
60
|
+
logger: ::Logger.new("log/marketo.log"), # optional, defaults to Faraday default of logging to STDOUT
|
61
|
+
log_options: {bodies: true}) # optional, defaults to Faraday default of only logging headers
|
62
|
+
```
|
63
|
+
|
64
|
+
### Retry authentication
|
65
|
+
|
66
|
+
Since the Marketo API provides API access keys with a validity of 3600 seconds, if you are running an hourly cronjob it's possible that your subsequent call receives the same key from the previous hour, which is then immediately expired. If this is the case, you can configure the client to retry until receiving a valid key:
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
client = Mrkt::Client.new(
|
70
|
+
host: '123-abc-123.mktorest.com',
|
71
|
+
client_id: '4567e1cdf-0fae-4685-a914-5be45043f2d8',
|
72
|
+
client_secret: '7Gn0tuiHZiDHnzeu9P14uDQcSx9xIPPt',
|
73
|
+
retry_authentication: true,
|
74
|
+
retry_authentication_count: 3, # default: 3
|
75
|
+
retry_authentication_wait_seconds: 1, # default: 0
|
76
|
+
)
|
51
77
|
```
|
52
78
|
|
79
|
+
This is turned off by default.
|
80
|
+
|
53
81
|
### Get leads matching an email, print their id and email
|
54
82
|
|
55
83
|
```ruby
|
@@ -1,8 +1,13 @@
|
|
1
1
|
module Mrkt
|
2
2
|
module Authentication
|
3
3
|
def authenticate!
|
4
|
-
|
5
|
-
|
4
|
+
return if authenticated?
|
5
|
+
|
6
|
+
authenticate
|
7
|
+
|
8
|
+
retry_authentication if !authenticated? && @retry_authentication
|
9
|
+
|
10
|
+
raise Mrkt::Errors::AuthorizationError, 'Client not authenticated' unless authenticated?
|
6
11
|
end
|
7
12
|
|
8
13
|
def authenticated?
|
@@ -13,6 +18,15 @@ module Mrkt
|
|
13
18
|
@valid_until && Time.now < @valid_until
|
14
19
|
end
|
15
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
|
+
|
16
30
|
def authenticate
|
17
31
|
connection.get('/identity/oauth/token', authentication_params).tap do |response|
|
18
32
|
data = response.body
|
@@ -25,15 +39,27 @@ module Mrkt
|
|
25
39
|
end
|
26
40
|
|
27
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
|
28
58
|
{
|
29
59
|
grant_type: 'client_credentials',
|
30
60
|
client_id: @client_id,
|
31
61
|
client_secret: @client_secret
|
32
62
|
}
|
33
63
|
end
|
34
|
-
|
35
|
-
def add_authorization(req)
|
36
|
-
req.headers[:authorization] = "Bearer #{@token}"
|
37
|
-
end
|
38
64
|
end
|
39
65
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'mrkt/
|
1
|
+
require 'mrkt/faraday'
|
2
2
|
|
3
3
|
module Mrkt
|
4
4
|
module Connection
|
@@ -7,18 +7,27 @@ module Mrkt
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def init_connection
|
10
|
-
Faraday.new(
|
10
|
+
::Faraday.new(options) do |conn|
|
11
11
|
conn.request :multipart
|
12
12
|
conn.request :url_encoded
|
13
13
|
|
14
|
-
conn.response :logger if @debug
|
14
|
+
conn.response :logger, @logger, (@log_options || {}) if @debug
|
15
15
|
conn.response :mkto, content_type: /\bjson$/
|
16
16
|
|
17
17
|
conn.options.timeout = @options[:read_timeout] if @options.key?(:read_timeout)
|
18
18
|
conn.options.open_timeout = @options[:open_timeout] if @options.key?(:open_timeout)
|
19
19
|
|
20
|
-
conn.adapter Faraday.default_adapter
|
20
|
+
conn.adapter @options.fetch(:adapter, ::Faraday.default_adapter)
|
21
21
|
end
|
22
22
|
end
|
23
|
+
|
24
|
+
def options
|
25
|
+
{
|
26
|
+
url: "https://#{@host}",
|
27
|
+
request: {
|
28
|
+
params_encoder: Mrkt::Faraday::ParamsEncoder
|
29
|
+
}
|
30
|
+
}
|
31
|
+
end
|
23
32
|
end
|
24
33
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Mrkt
|
2
|
+
module CrudActivities
|
3
|
+
def get_activity_types
|
4
|
+
get('/rest/v1/activities/types.json')
|
5
|
+
end
|
6
|
+
|
7
|
+
def get_paging_token(since_datetime)
|
8
|
+
get('/rest/v1/activities/pagingtoken.json', sinceDatetime: since_datetime.iso8601)
|
9
|
+
end
|
10
|
+
|
11
|
+
def get_activities(next_page_token, activity_type_ids: [], lead_ids: [])
|
12
|
+
params = {
|
13
|
+
nextPageToken: next_page_token
|
14
|
+
}
|
15
|
+
|
16
|
+
params[:activityTypeIds] = activity_type_ids unless blank?(activity_type_ids)
|
17
|
+
params[:leadIds] = lead_ids unless blank?(lead_ids)
|
18
|
+
|
19
|
+
get('/rest/v1/activities.json', params)
|
20
|
+
end
|
21
|
+
|
22
|
+
def get_deleted_leads(next_page_token)
|
23
|
+
get('/rest/v1/activities/deletedleads.json', nextPageToken: next_page_token)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def blank?(value)
|
29
|
+
!value || value == '' || value.empty?
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Mrkt
|
2
|
+
module CrudAssetFolders
|
3
|
+
def create_folder(name, parent, description: nil)
|
4
|
+
post('/rest/asset/v1/folders.json') do |req|
|
5
|
+
params = {
|
6
|
+
name: name,
|
7
|
+
parent: JSON.generate(parent)
|
8
|
+
}
|
9
|
+
|
10
|
+
optional = {
|
11
|
+
description: description
|
12
|
+
}
|
13
|
+
|
14
|
+
req.body = merge_params(params, optional)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def get_folder_by_id(id, type: nil)
|
19
|
+
params = {}
|
20
|
+
params[:type] = type if type
|
21
|
+
|
22
|
+
get("/rest/asset/v1/folder/#{id}.json", params)
|
23
|
+
end
|
24
|
+
|
25
|
+
def get_folder_by_name(name, type: nil, root: nil, work_space: nil)
|
26
|
+
params = {
|
27
|
+
name: name
|
28
|
+
}
|
29
|
+
|
30
|
+
optional = {
|
31
|
+
root: root&.to_json,
|
32
|
+
type: type,
|
33
|
+
workSpace: work_space
|
34
|
+
}
|
35
|
+
|
36
|
+
get('/rest/asset/v1/folder/byName.json', params, optional)
|
37
|
+
end
|
38
|
+
|
39
|
+
def delete_folder(id)
|
40
|
+
post("/rest/asset/v1/folder/#{id}/delete.json")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Mrkt
|
2
|
+
module CrudAssetStaticLists
|
3
|
+
def create_static_list(name, folder, description: nil)
|
4
|
+
post('/rest/asset/v1/staticLists.json') do |req|
|
5
|
+
params = {
|
6
|
+
name: name,
|
7
|
+
folder: JSON.generate(folder)
|
8
|
+
}
|
9
|
+
|
10
|
+
optional = {
|
11
|
+
description: description
|
12
|
+
}
|
13
|
+
|
14
|
+
req.body = merge_params(params, optional)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def get_static_list_by_id(id)
|
19
|
+
get("/rest/asset/v1/staticList/#{id}.json")
|
20
|
+
end
|
21
|
+
|
22
|
+
def get_static_list_by_name(name)
|
23
|
+
get('/rest/asset/v1/staticList/byName.json', name: name)
|
24
|
+
end
|
25
|
+
|
26
|
+
def delete_static_list(id)
|
27
|
+
post("/rest/asset/v1/staticList/#{id}/delete.json")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -1,15 +1,13 @@
|
|
1
1
|
module Mrkt
|
2
2
|
module CrudCampaigns
|
3
3
|
def request_campaign(id, lead_ids, tokens = {})
|
4
|
-
|
5
|
-
|
4
|
+
post_json("/rest/v1/campaigns/#{id}/trigger.json") do
|
5
|
+
{
|
6
6
|
input: {
|
7
7
|
leads: map_lead_ids(lead_ids),
|
8
8
|
tokens: tokens
|
9
9
|
}
|
10
10
|
}
|
11
|
-
|
12
|
-
json_payload(req, params)
|
13
11
|
end
|
14
12
|
end
|
15
13
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'time'
|
2
|
+
|
3
|
+
module Mrkt
|
4
|
+
module CrudCustomActivities
|
5
|
+
def get_list_of_custom_activity_types
|
6
|
+
warn 'DEPRECATED: Use #get_activity_types instead of #get_list_of_custom_activity_types!'
|
7
|
+
get_activity_types
|
8
|
+
end
|
9
|
+
|
10
|
+
def create_custom_activity(lead_id, activity_type_id, primary_attribute_value, attributes: {}, date: nil)
|
11
|
+
date ||= Time.now
|
12
|
+
date = date.utc.iso8601
|
13
|
+
converted_attributes = convert_attribute_hash(attributes)
|
14
|
+
|
15
|
+
input = [{
|
16
|
+
leadId: lead_id,
|
17
|
+
activityDate: date,
|
18
|
+
activityTypeId: activity_type_id,
|
19
|
+
primaryAttributeValue: primary_attribute_value,
|
20
|
+
attributes: converted_attributes
|
21
|
+
}]
|
22
|
+
|
23
|
+
post_json('/rest/v1/activities/external.json') do
|
24
|
+
{ input: input }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def convert_attribute_hash(attributes)
|
31
|
+
attributes.map do |key, value|
|
32
|
+
{ name: key, value: value }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|