mrkt 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/mrkt/concerns/connection.rb +12 -3
- data/lib/mrkt/concerns/crud_activities.rb +2 -2
- data/lib/mrkt/concerns/crud_custom_objects.rb +1 -1
- data/lib/mrkt/concerns/crud_leads.rb +10 -8
- data/lib/mrkt/concerns/import_custom_objects.rb +1 -1
- data/lib/mrkt/concerns/import_leads.rb +1 -1
- data/lib/mrkt/faraday.rb +4 -0
- data/lib/mrkt/faraday/params_encoder.rb +20 -0
- data/lib/mrkt/faraday_middleware.rb +3 -7
- data/lib/mrkt/version.rb +1 -1
- data/spec/concerns/crud_leads_spec.rb +1 -1
- data/spec/faraday/params_encoder_spec.rb +24 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b9a26db5da0ff83b251b40c276517013a120bccac5e0723d2cb23f751bc9817
|
4
|
+
data.tar.gz: 74a55a3fde8f192301e8995c7391fc5f88c7f8d9fa0163a1f2ef633cf9ade4bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 365eaf2f0ea0ffc9a9a47af40b9834bab11de69438bb44a42dc23720f19b705b8918c097164c49cc2d82ce02dfb8b1add9f761cb6ae3ee99df69091493fb3b32
|
7
|
+
data.tar.gz: 7a184f5ce07e10e3e88f9cfe988adfdf2633271e229f55da2290e04ac78b3282a46eb77c87d01f00c3e3493e77920abf7a38bc1be8edf3cc565224aa8ecb8bff
|
data/Gemfile.lock
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'mrkt/
|
1
|
+
require 'mrkt/faraday'
|
2
2
|
|
3
3
|
module Mrkt
|
4
4
|
module Connection
|
@@ -7,7 +7,7 @@ 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
|
|
@@ -17,8 +17,17 @@ module Mrkt
|
|
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 @options.fetch(: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
|
@@ -13,8 +13,8 @@ module Mrkt
|
|
13
13
|
nextPageToken: next_page_token
|
14
14
|
}
|
15
15
|
|
16
|
-
params[:activityTypeIds] = activity_type_ids
|
17
|
-
params[:leadIds] = lead_ids
|
16
|
+
params[:activityTypeIds] = activity_type_ids unless blank?(activity_type_ids)
|
17
|
+
params[:leadIds] = lead_ids unless blank?(lead_ids)
|
18
18
|
|
19
19
|
get('/rest/v1/activities.json', params)
|
20
20
|
end
|
@@ -2,7 +2,7 @@ module Mrkt
|
|
2
2
|
module CrudLeads
|
3
3
|
def get_lead_by_id(id, fields: nil)
|
4
4
|
optional = {
|
5
|
-
fields: fields
|
5
|
+
fields: fields
|
6
6
|
}
|
7
7
|
|
8
8
|
get("/rest/v1/lead/#{id}.json", {}, optional)
|
@@ -11,7 +11,7 @@ module Mrkt
|
|
11
11
|
def get_leads(filter_type, filter_values, fields: nil, batch_size: nil, next_page_token: nil)
|
12
12
|
params = {
|
13
13
|
filterType: filter_type,
|
14
|
-
filterValues: filter_values
|
14
|
+
filterValues: filter_values
|
15
15
|
}
|
16
16
|
|
17
17
|
optional = {
|
@@ -47,18 +47,20 @@ module Mrkt
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def associate_lead(id, cookie)
|
50
|
-
params = Faraday::
|
51
|
-
params[:cookie] = cookie
|
50
|
+
params = Mrkt::Faraday::ParamsEncoder.encode(cookie: cookie)
|
52
51
|
|
53
|
-
post_json("/rest/v1/leads/#{id}/associate.json?#{params
|
52
|
+
post_json("/rest/v1/leads/#{id}/associate.json?#{params}")
|
54
53
|
end
|
55
54
|
|
56
55
|
def merge_leads(winning_lead_id, losing_lead_ids, merge_in_crm: false)
|
57
|
-
params =
|
56
|
+
params = {}
|
57
|
+
|
58
58
|
params[:mergeInCRM] = merge_in_crm
|
59
|
-
params[:leadIds] = losing_lead_ids
|
59
|
+
params[:leadIds] = losing_lead_ids if losing_lead_ids
|
60
|
+
|
61
|
+
query_params = Mrkt::Faraday::ParamsEncoder.encode(params)
|
60
62
|
|
61
|
-
post_json("/rest/v1/leads/#{winning_lead_id}/merge.json?#{
|
63
|
+
post_json("/rest/v1/leads/#{winning_lead_id}/merge.json?#{query_params}")
|
62
64
|
end
|
63
65
|
|
64
66
|
def describe_lead
|
@@ -3,7 +3,7 @@ module Mrkt
|
|
3
3
|
def import_custom_object(file, custom_object, format = 'csv')
|
4
4
|
params = {
|
5
5
|
format: format,
|
6
|
-
file: Faraday::UploadIO.new(file, 'text/csv')
|
6
|
+
file: ::Faraday::UploadIO.new(file, 'text/csv')
|
7
7
|
}
|
8
8
|
|
9
9
|
post("/bulk/v1/customobjects/#{custom_object}/import.json", params)
|
data/lib/mrkt/faraday.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module Mrkt
|
2
|
+
module Faraday
|
3
|
+
class ParamsEncoder
|
4
|
+
class << self
|
5
|
+
def encode(hash)
|
6
|
+
new_hash = hash.transform_values { |v| encode_value(v) }
|
7
|
+
::Faraday::NestedParamsEncoder.encode(new_hash)
|
8
|
+
end
|
9
|
+
|
10
|
+
def decode(string)
|
11
|
+
::Faraday::NestedParamsEncoder.decode(string)
|
12
|
+
end
|
13
|
+
|
14
|
+
def encode_value(value)
|
15
|
+
value.respond_to?(:join) ? value.join(',') : value
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -1,11 +1,7 @@
|
|
1
|
-
require '
|
1
|
+
require 'mrkt/faraday_middleware/response'
|
2
2
|
|
3
3
|
module Mrkt
|
4
|
-
|
5
|
-
|
6
|
-
end
|
7
|
-
|
8
|
-
if Faraday::Middleware.respond_to? :register_middleware
|
9
|
-
Faraday::Response.register_middleware mkto: -> { Mrkt::FaradayMiddleware::Response }
|
4
|
+
if ::Faraday::Middleware.respond_to?(:register_middleware)
|
5
|
+
::Faraday::Response.register_middleware(mkto: Mrkt::FaradayMiddleware::Response)
|
10
6
|
end
|
11
7
|
end
|
data/lib/mrkt/version.rb
CHANGED
@@ -211,7 +211,7 @@ describe Mrkt::CrudLeads do
|
|
211
211
|
subject { client.merge_leads(id, losing_lead_ids) }
|
212
212
|
|
213
213
|
before do
|
214
|
-
params = Faraday::Utils::ParamsHash.new
|
214
|
+
params = ::Faraday::Utils::ParamsHash.new
|
215
215
|
params[:mergeInCRM] = false
|
216
216
|
params[:leadIds] = losing_lead_ids.join(',') if losing_lead_ids
|
217
217
|
|
@@ -0,0 +1,24 @@
|
|
1
|
+
describe Mrkt::Faraday::ParamsEncoder do
|
2
|
+
describe '.encode' do
|
3
|
+
let(:params) do
|
4
|
+
{
|
5
|
+
string: 'foobar',
|
6
|
+
number: 1,
|
7
|
+
boolean: true,
|
8
|
+
array: [1, 2, 3]
|
9
|
+
}
|
10
|
+
end
|
11
|
+
|
12
|
+
subject { described_class.encode(params) }
|
13
|
+
|
14
|
+
it { is_expected.to eq(Faraday::Utils::ParamsHash.new.merge(params.merge(array: '1,2,3')).to_query) }
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '.decode' do
|
18
|
+
let(:value) { 'foo=foo&bar=bar' }
|
19
|
+
|
20
|
+
subject { described_class.decode(value) }
|
21
|
+
|
22
|
+
it { is_expected.to eq('foo' => 'foo', 'bar' => 'bar') }
|
23
|
+
end
|
24
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mrkt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- KARASZI István
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-07-
|
12
|
+
date: 2020-07-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
@@ -185,6 +185,8 @@ files:
|
|
185
185
|
- lib/mrkt/concerns/import_custom_objects.rb
|
186
186
|
- lib/mrkt/concerns/import_leads.rb
|
187
187
|
- lib/mrkt/errors.rb
|
188
|
+
- lib/mrkt/faraday.rb
|
189
|
+
- lib/mrkt/faraday/params_encoder.rb
|
188
190
|
- lib/mrkt/faraday_middleware.rb
|
189
191
|
- lib/mrkt/faraday_middleware/response.rb
|
190
192
|
- lib/mrkt/version.rb
|
@@ -202,6 +204,7 @@ files:
|
|
202
204
|
- spec/concerns/import_custom_objects_spec.rb
|
203
205
|
- spec/concerns/import_leads_spec.rb
|
204
206
|
- spec/errors_spec.rb
|
207
|
+
- spec/faraday/params_encoder_spec.rb
|
205
208
|
- spec/mkto_rest_spec.rb
|
206
209
|
- spec/spec_helper.rb
|
207
210
|
- spec/support/initialized_client.rb
|
@@ -243,6 +246,7 @@ test_files:
|
|
243
246
|
- spec/concerns/import_custom_objects_spec.rb
|
244
247
|
- spec/concerns/import_leads_spec.rb
|
245
248
|
- spec/errors_spec.rb
|
249
|
+
- spec/faraday/params_encoder_spec.rb
|
246
250
|
- spec/mkto_rest_spec.rb
|
247
251
|
- spec/spec_helper.rb
|
248
252
|
- spec/support/initialized_client.rb
|