mrkt 0.9.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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: 4121a615d6e3099a58b81831bcfc5831aba8f331d22d3cfb98501ebcfb7c2272
4
+ data.tar.gz: b7b345f6f78c47bef04395b88924bc62231b1fd49a27ce9dd91564ca87557db4
5
5
  SHA512:
6
- metadata.gz: 5cfa98036ebf42268a7cd349f17e09e38df7b8c9e06e8dad87094e588ce43f16e8e0671f2fa86fa7b7074ace75bce4de3629c601704ad6c2656c82e1c93da7b7
7
- data.tar.gz: 36d67c8ad9811b8e8cd60dd18df61e0d6bc7cae124dc75904c44831d4bafe6d9e6a97782dfd8c39437bd12f7d8783f6b21d613b5d703527f7ec218b5caa6ef7d
6
+ metadata.gz: a40cf98b97f10e619bb6066637567a946f26a6fef586c55bdfe7341ae102550be1d812e5e468cd13ca4cc12dfa772b9f697e431aeda728464e2150ea1148b4d7
7
+ data.tar.gz: 2fccf0ded04505d6c7a0049bff1040876e74540adab38543aa7b35aa667f7f266f52df739158921547031796ffc9a18c2b89fd35f2a4c0a7b13ff97f0de86048
@@ -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: 120
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:
@@ -1,10 +1,9 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.0.0
4
- - 2.1.10
5
- - 2.2.8
6
- - 2.3.5
7
- - 2.4.2
3
+ - 2.3.6
4
+ - 2.4.3
5
+ - 2.5.0
6
+ - 2.6.0
8
7
  addons:
9
8
  code_climate:
10
9
  repo_token: 45cd2174f49b570406e294ff393d456c4ae8532cf16dd6430abb06d8a0722a28
@@ -1,90 +1,92 @@
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 (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.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.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.10.1)
22
+ faraday (0.15.4)
23
23
  multipart-post (>= 1.2, < 3)
24
- faraday_middleware (0.10.1)
24
+ faraday_middleware (0.13.1)
25
25
  faraday (>= 0.7.4, < 1.0)
26
- json (2.1.0)
27
- method_source (0.8.2)
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
- parser (2.4.0.0)
30
- ast (~> 2.2)
31
- powerpack (0.1.1)
32
- pry (0.10.4)
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.8.1)
35
- slop (~> 3.4)
36
- pry-byebug (3.4.2)
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
- 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)
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.6.0)
52
- rspec-mocks (3.6.0)
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.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)
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 (~> 1.0, >= 1.0.1)
62
- ruby-progressbar (1.8.1)
63
- safe_yaml (1.0.4)
64
- simplecov (0.14.1)
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.1)
69
- slop (3.6.0)
70
- unicode-display_width (1.3.0)
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.0)
83
+ codeclimate-test-reporter (~> 1.0)
81
84
  mrkt!
82
- pry-byebug (~> 3.4.0)
83
- rake (~> 10.0)
85
+ pry-byebug (~> 3.7)
86
+ rake (~> 12.3)
84
87
  rspec (~> 3.2)
85
- rubocop (~> 0.45.0)
86
- simplecov (~> 0.14.1)
87
- webmock (~> 1.21.0)
88
+ rubocop (~> 0.66.0)
89
+ webmock (~> 3.1)
88
90
 
89
91
  BUNDLED WITH
90
- 1.15.4
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.
@@ -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
- %i(get post delete).each do |http_method|
53
- define_method(http_method) do |path, payload = {}, &block|
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.call(req) unless block.nil?
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
- 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
@@ -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("/rest/v1/activities/types.json")
4
+ get('/rest/v1/activities/types.json')
5
5
  end
6
6
 
7
7
  def get_paging_token(since_datetime)
8
- params = {
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
- get("/rest/v1/activities.json", params)
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 == "" || value.empty?
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
- post("/rest/v1/campaigns/#{id}/trigger.json") do |req|
5
- params = {
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