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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c6240df5d2fc5e237cb846da72b226f71b836d86e466aff3ee96854ff0c9087f
4
- data.tar.gz: a20eea282f97ad58e45d780bfc88c32305bae0c127feb819be7f93aa26010dc5
3
+ metadata.gz: 8b9a26db5da0ff83b251b40c276517013a120bccac5e0723d2cb23f751bc9817
4
+ data.tar.gz: 74a55a3fde8f192301e8995c7391fc5f88c7f8d9fa0163a1f2ef633cf9ade4bf
5
5
  SHA512:
6
- metadata.gz: 5e4878202b8cf696c8e9434688f21c648770f32a393d7128efe1b90e89c1e78d76b00c447c83c295f72cdc8399f7ffe6a526b7a972a45107abe1c0ea53a42217
7
- data.tar.gz: 14c64d83473c35eaec901b1be3e921d1de1e211cf8db989fa91bb3e2fa389303d27bdf6adc7af77bcedcc9de6aaf8aaaa3adefb04f0748d12f680d29fcdcd716
6
+ metadata.gz: 365eaf2f0ea0ffc9a9a47af40b9834bab11de69438bb44a42dc23720f19b705b8918c097164c49cc2d82ce02dfb8b1add9f761cb6ae3ee99df69091493fb3b32
7
+ data.tar.gz: 7a184f5ce07e10e3e88f9cfe988adfdf2633271e229f55da2290e04ac78b3282a46eb77c87d01f00c3e3493e77920abf7a38bc1be8edf3cc565224aa8ecb8bff
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mrkt (1.0.0)
4
+ mrkt (1.0.1)
5
5
  faraday (~> 1.0)
6
6
  faraday_middleware (~> 1.0)
7
7
 
@@ -1,4 +1,4 @@
1
- require 'mrkt/faraday_middleware'
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(url: "https://#{@host}") do |conn|
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.join(',') unless blank?(activity_type_ids)
17
- params[:leadIds] = lead_ids.join(',') unless blank?(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 CrudCustomObjects
3
3
  def get_list_of_custom_objects(names = nil)
4
4
  params = {}
5
- params[:names] = names.join(',') if names
5
+ params[:names] = names if names
6
6
 
7
7
  get('/rest/v1/customobjects.json', params)
8
8
  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&.join(',')
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.join(',')
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::Utils::ParamsHash.new
51
- params[:cookie] = cookie
50
+ params = Mrkt::Faraday::ParamsEncoder.encode(cookie: cookie)
52
51
 
53
- post_json("/rest/v1/leads/#{id}/associate.json?#{params.to_query}")
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 = Faraday::Utils::ParamsHash.new
56
+ params = {}
57
+
58
58
  params[:mergeInCRM] = merge_in_crm
59
- params[:leadIds] = losing_lead_ids.join(',') if 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?#{params.to_query}")
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)
@@ -3,7 +3,7 @@ module Mrkt
3
3
  def import_lead(file, format = 'csv', lookup_field: nil, list_id: nil, partition_name: nil)
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
  optional = {
@@ -0,0 +1,4 @@
1
+ require 'faraday'
2
+
3
+ require 'mrkt/faraday/params_encoder'
4
+ require 'mrkt/faraday_middleware'
@@ -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 'faraday'
1
+ require 'mrkt/faraday_middleware/response'
2
2
 
3
3
  module Mrkt
4
- module FaradayMiddleware
5
- autoload :Response, 'mrkt/faraday_middleware/response'
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
@@ -1,3 +1,3 @@
1
1
  module Mrkt
2
- VERSION = '1.0.0'.freeze
2
+ VERSION = '1.0.1'.freeze
3
3
  end
@@ -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.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-07 00:00:00.000000000 Z
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