mrkt 0.9.0 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +15 -1
- data/.travis.yml +4 -5
- data/Gemfile.lock +58 -56
- data/LICENSE +21 -0
- data/lib/mrkt.rb +13 -3
- data/lib/mrkt/concerns/authentication.rb +11 -8
- data/lib/mrkt/concerns/connection.rb +2 -5
- data/lib/mrkt/concerns/crud_activities.rb +10 -7
- 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 +3 -2
- data/lib/mrkt/concerns/crud_custom_objects.rb +12 -13
- data/lib/mrkt/concerns/crud_helpers.rb +7 -0
- data/lib/mrkt/concerns/crud_leads.rb +28 -15
- data/lib/mrkt/concerns/crud_lists.rb +13 -10
- data/lib/mrkt/concerns/crud_programs.rb +6 -5
- data/lib/mrkt/concerns/import_leads.rb +7 -4
- data/lib/mrkt/errors.rb +3 -2
- data/lib/mrkt/version.rb +1 -1
- data/mrkt.gemspec +10 -12
- data/spec/concerns/authentication_spec.rb +19 -5
- data/spec/concerns/crud_activities_spec.rb +46 -7
- 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 +3 -1
- data/spec/concerns/crud_custom_objects_spec.rb +1 -1
- data/spec/concerns/crud_leads_spec.rb +103 -1
- data/spec/concerns/crud_lists_spec.rb +33 -0
- data/spec/concerns/import_leads_spec.rb +2 -2
- metadata +33 -41
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4121a615d6e3099a58b81831bcfc5831aba8f331d22d3cfb98501ebcfb7c2272
|
4
|
+
data.tar.gz: b7b345f6f78c47bef04395b88924bc62231b1fd49a27ce9dd91564ca87557db4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a40cf98b97f10e619bb6066637567a946f26a6fef586c55bdfe7341ae102550be1d812e5e468cd13ca4cc12dfa772b9f697e431aeda728464e2150ea1148b4d7
|
7
|
+
data.tar.gz: 2fccf0ded04505d6c7a0049bff1040876e74540adab38543aa7b35aa667f7f266f52df739158921547031796ffc9a18c2b89fd35f2a4c0a7b13ff97f0de86048
|
data/.rubocop.yml
CHANGED
@@ -1,16 +1,30 @@
|
|
1
1
|
AllCops:
|
2
|
+
TargetRubyVersion: 2.3
|
2
3
|
Exclude:
|
3
4
|
- 'bin/**/*'
|
4
5
|
Documentation:
|
5
6
|
Enabled: false
|
6
7
|
LineLength:
|
7
8
|
Enabled: true
|
8
|
-
Max:
|
9
|
+
Max: 128
|
9
10
|
MethodLength:
|
10
11
|
Max: 20
|
11
12
|
IndentHash:
|
12
13
|
Enabled: false
|
13
14
|
|
15
|
+
Layout/AlignHash:
|
16
|
+
Enabled: false
|
17
|
+
Layout/EmptyLineAfterGuardClause:
|
18
|
+
Enabled: false
|
19
|
+
Layout/MultilineMethodCallIndentation:
|
20
|
+
EnforcedStyle: indented
|
21
|
+
Naming/AccessorMethodName:
|
22
|
+
Enabled: false
|
23
|
+
Metrics/BlockLength:
|
24
|
+
Exclude:
|
25
|
+
- 'spec/**/*'
|
26
|
+
Metrics/ParameterLists:
|
27
|
+
Max: 6
|
14
28
|
Style/ClassAndModuleChildren:
|
15
29
|
Enabled: false
|
16
30
|
Style/FrozenStringLiteralComment:
|
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,90 +1,92 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
mrkt (0.
|
5
|
-
faraday (> 0.9.0, < 0.
|
6
|
-
faraday_middleware (> 0.9.0, < 0.
|
4
|
+
mrkt (0.10.0)
|
5
|
+
faraday (> 0.9.0, < 0.16.0)
|
6
|
+
faraday_middleware (> 0.9.0, < 0.16.0)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
addressable (2.
|
12
|
-
public_suffix (
|
13
|
-
ast (2.
|
14
|
-
byebug (
|
15
|
-
codeclimate-test-reporter (1.0.
|
16
|
-
simplecov
|
17
|
-
coderay (1.1.
|
11
|
+
addressable (2.6.0)
|
12
|
+
public_suffix (>= 2.0.2, < 4.0)
|
13
|
+
ast (2.4.0)
|
14
|
+
byebug (11.0.1)
|
15
|
+
codeclimate-test-reporter (1.0.9)
|
16
|
+
simplecov (<= 0.13)
|
17
|
+
coderay (1.1.2)
|
18
18
|
crack (0.4.3)
|
19
19
|
safe_yaml (~> 1.0.0)
|
20
20
|
diff-lcs (1.3)
|
21
21
|
docile (1.1.5)
|
22
|
-
faraday (0.
|
22
|
+
faraday (0.15.4)
|
23
23
|
multipart-post (>= 1.2, < 3)
|
24
|
-
faraday_middleware (0.
|
24
|
+
faraday_middleware (0.13.1)
|
25
25
|
faraday (>= 0.7.4, < 1.0)
|
26
|
-
|
27
|
-
|
26
|
+
hashdiff (0.3.8)
|
27
|
+
jaro_winkler (1.5.2)
|
28
|
+
json (2.2.0)
|
29
|
+
method_source (0.9.2)
|
28
30
|
multipart-post (2.0.0)
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
pry (0.
|
31
|
+
parallel (1.14.0)
|
32
|
+
parser (2.6.2.0)
|
33
|
+
ast (~> 2.4.0)
|
34
|
+
pry (0.12.2)
|
33
35
|
coderay (~> 1.1.0)
|
34
|
-
method_source (~> 0.
|
35
|
-
|
36
|
-
|
37
|
-
byebug (~> 9.0)
|
36
|
+
method_source (~> 0.9.0)
|
37
|
+
pry-byebug (3.7.0)
|
38
|
+
byebug (~> 11.0)
|
38
39
|
pry (~> 0.10)
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
rake (
|
43
|
-
rspec (3.
|
44
|
-
rspec-core (~> 3.
|
45
|
-
rspec-expectations (~> 3.
|
46
|
-
rspec-mocks (~> 3.
|
47
|
-
rspec-core (3.
|
48
|
-
rspec-support (~> 3.
|
49
|
-
rspec-expectations (3.
|
40
|
+
psych (3.1.0)
|
41
|
+
public_suffix (3.0.3)
|
42
|
+
rainbow (3.0.0)
|
43
|
+
rake (12.3.2)
|
44
|
+
rspec (3.8.0)
|
45
|
+
rspec-core (~> 3.8.0)
|
46
|
+
rspec-expectations (~> 3.8.0)
|
47
|
+
rspec-mocks (~> 3.8.0)
|
48
|
+
rspec-core (3.8.0)
|
49
|
+
rspec-support (~> 3.8.0)
|
50
|
+
rspec-expectations (3.8.2)
|
50
51
|
diff-lcs (>= 1.2.0, < 2.0)
|
51
|
-
rspec-support (~> 3.
|
52
|
-
rspec-mocks (3.
|
52
|
+
rspec-support (~> 3.8.0)
|
53
|
+
rspec-mocks (3.8.0)
|
53
54
|
diff-lcs (>= 1.2.0, < 2.0)
|
54
|
-
rspec-support (~> 3.
|
55
|
-
rspec-support (3.
|
56
|
-
rubocop (0.
|
57
|
-
|
58
|
-
|
59
|
-
|
55
|
+
rspec-support (~> 3.8.0)
|
56
|
+
rspec-support (3.8.0)
|
57
|
+
rubocop (0.66.0)
|
58
|
+
jaro_winkler (~> 1.5.1)
|
59
|
+
parallel (~> 1.10)
|
60
|
+
parser (>= 2.5, != 2.5.1.1)
|
61
|
+
psych (>= 3.1.0)
|
62
|
+
rainbow (>= 2.2.2, < 4.0)
|
60
63
|
ruby-progressbar (~> 1.7)
|
61
|
-
unicode-display_width (
|
62
|
-
ruby-progressbar (1.
|
63
|
-
safe_yaml (1.0.
|
64
|
-
simplecov (0.
|
64
|
+
unicode-display_width (>= 1.4.0, < 1.6)
|
65
|
+
ruby-progressbar (1.10.0)
|
66
|
+
safe_yaml (1.0.5)
|
67
|
+
simplecov (0.13.0)
|
65
68
|
docile (~> 1.1.0)
|
66
69
|
json (>= 1.8, < 3)
|
67
70
|
simplecov-html (~> 0.10.0)
|
68
|
-
simplecov-html (0.10.
|
69
|
-
|
70
|
-
|
71
|
-
webmock (1.21.0)
|
71
|
+
simplecov-html (0.10.2)
|
72
|
+
unicode-display_width (1.5.0)
|
73
|
+
webmock (3.5.1)
|
72
74
|
addressable (>= 2.3.6)
|
73
75
|
crack (>= 0.3.2)
|
76
|
+
hashdiff
|
74
77
|
|
75
78
|
PLATFORMS
|
76
79
|
ruby
|
77
80
|
|
78
81
|
DEPENDENCIES
|
79
82
|
bundler (~> 1.3)
|
80
|
-
codeclimate-test-reporter (~> 1.0
|
83
|
+
codeclimate-test-reporter (~> 1.0)
|
81
84
|
mrkt!
|
82
|
-
pry-byebug (~> 3.
|
83
|
-
rake (~>
|
85
|
+
pry-byebug (~> 3.7)
|
86
|
+
rake (~> 12.3)
|
84
87
|
rspec (~> 3.2)
|
85
|
-
rubocop (~> 0.
|
86
|
-
|
87
|
-
webmock (~> 1.21.0)
|
88
|
+
rubocop (~> 0.66.0)
|
89
|
+
webmock (~> 3.1)
|
88
90
|
|
89
91
|
BUNDLED WITH
|
90
|
-
1.
|
92
|
+
1.17.2
|
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/lib/mrkt.rb
CHANGED
@@ -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
|
|
@@ -49,13 +53,19 @@ module Mrkt
|
|
49
53
|
@options = options
|
50
54
|
end
|
51
55
|
|
52
|
-
|
53
|
-
|
56
|
+
def merge_params(params, optional)
|
57
|
+
params.merge(optional.keep_if { |_key, value| value })
|
58
|
+
end
|
59
|
+
|
60
|
+
%i[get post delete].each do |http_method|
|
61
|
+
define_method(http_method) do |path, params = {}, optional = {}, &block|
|
54
62
|
authenticate!
|
55
63
|
|
64
|
+
payload = merge_params(params, optional)
|
65
|
+
|
56
66
|
resp = connection.send(http_method, path, payload) do |req|
|
57
67
|
add_authorization(req)
|
58
|
-
block
|
68
|
+
block&.call(req)
|
59
69
|
end
|
60
70
|
|
61
71
|
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
|
-
|
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
|
@@ -11,16 +11,13 @@ module Mrkt
|
|
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
|
26
23
|
end
|
@@ -1,29 +1,32 @@
|
|
1
1
|
module Mrkt
|
2
2
|
module CrudActivities
|
3
3
|
def get_activity_types
|
4
|
-
get(
|
4
|
+
get('/rest/v1/activities/types.json')
|
5
5
|
end
|
6
6
|
|
7
7
|
def get_paging_token(since_datetime)
|
8
|
-
|
9
|
-
sinceDatetime: since_datetime.iso8601
|
10
|
-
}
|
11
|
-
get("/rest/v1/activities/pagingtoken.json", params)
|
8
|
+
get('/rest/v1/activities/pagingtoken.json', sinceDatetime: since_datetime.iso8601)
|
12
9
|
end
|
13
10
|
|
14
11
|
def get_activities(next_page_token, activity_type_ids: [], lead_ids: [])
|
15
12
|
params = {
|
16
13
|
nextPageToken: next_page_token
|
17
14
|
}
|
15
|
+
|
18
16
|
params[:activityTypeIds] = activity_type_ids.join(',') unless blank?(activity_type_ids)
|
19
17
|
params[:leadIds] = lead_ids.join(',') unless blank?(lead_ids)
|
20
|
-
|
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)
|
21
24
|
end
|
22
25
|
|
23
26
|
private
|
24
27
|
|
25
28
|
def blank?(value)
|
26
|
-
!value || value ==
|
29
|
+
!value || value == '' || value.empty?
|
27
30
|
end
|
28
31
|
end
|
29
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
|