mrkt 0.4.0 → 0.5.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 +4 -4
- data/.travis.yml +2 -0
- data/Gemfile.lock +4 -1
- data/README.md +4 -3
- data/lib/mrkt.rb +3 -1
- data/lib/mrkt/concerns/authentication.rb +9 -7
- data/lib/mrkt/version.rb +1 -1
- data/mrkt.gemspec +4 -3
- data/spec/concerns/crud_leads_spec.rb +4 -4
- data/spec/concerns/import_leads_spec.rb +6 -10
- data/spec/spec_helper.rb +5 -0
- data/spec/support/webmock.rb +7 -1
- metadata +18 -5
- data/lib/mrkt/faraday_middleware/request.rb +0 -58
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e7f61fce15d29887b4a005927f6f194cf5ab71c
|
4
|
+
data.tar.gz: ec88ab8e0a07767870ac7696e0bbee9d93d21af5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 143a6acf4d42ed294a4d64d3367a6c4fdf1b783e25529500ba16007deb4e3c79024c5802f1be549537b3eed8d328ea5422adcf8d84afbad09a5280852f8fc90d
|
7
|
+
data.tar.gz: 001c7bced04d32e4e7118a3db7ae21b933491ee71d86bb929538bb4223986f05b5db4acb1e4fe1567804eff37bb596623faddb95f3b2010b4398d5adfb9c6dc4
|
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
mrkt (0.
|
4
|
+
mrkt (0.5.0)
|
5
5
|
faraday_middleware (~> 0.9.1)
|
6
6
|
|
7
7
|
GEM
|
@@ -10,6 +10,8 @@ GEM
|
|
10
10
|
addressable (2.3.8)
|
11
11
|
byebug (4.0.5)
|
12
12
|
columnize (= 0.9.0)
|
13
|
+
codeclimate-test-reporter (0.4.7)
|
14
|
+
simplecov (>= 0.7.1, < 1.0.0)
|
13
15
|
coderay (1.1.0)
|
14
16
|
columnize (0.9.0)
|
15
17
|
crack (0.4.2)
|
@@ -60,6 +62,7 @@ PLATFORMS
|
|
60
62
|
|
61
63
|
DEPENDENCIES
|
62
64
|
bundler (~> 1.3)
|
65
|
+
codeclimate-test-reporter (~> 0.4.7)
|
63
66
|
mrkt!
|
64
67
|
pry-byebug (~> 3.1.0)
|
65
68
|
rake (~> 10.0)
|
data/README.md
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# Mrkt
|
2
2
|
|
3
3
|
[](http://travis-ci.org/raszi/mrkt)
|
4
|
-
[](https://codeclimate.com/github/raszi/mrkt)
|
5
|
+
[](https://codeclimate.com/github/raszi/mrkt)
|
5
6
|
|
6
7
|
This gem provides some level of abstraction to Marketo REST APIs. Please note that this gem is alpha quality.
|
7
8
|
|
@@ -53,7 +54,7 @@ client.debug = true
|
|
53
54
|
|
54
55
|
```ruby
|
55
56
|
response = client.get_leads :email, 'sammy@acme.com'
|
56
|
-
response
|
57
|
+
response[:result].each do |result|
|
57
58
|
p "id: #{result[:id]}, email: #{result[:email]}"
|
58
59
|
end
|
59
60
|
```
|
@@ -62,7 +63,7 @@ end
|
|
62
63
|
|
63
64
|
```ruby
|
64
65
|
response = client.createupdate_leads([ email: 'sample@example.com', firstName: 'John' ], lookup_field: :email)
|
65
|
-
response
|
66
|
+
response[:result].each do |result|
|
66
67
|
p "id: #{result[:id]}, email: #{result[:email]}"
|
67
68
|
end
|
68
69
|
```
|
data/lib/mrkt.rb
CHANGED
@@ -28,10 +28,12 @@ module Mrkt
|
|
28
28
|
define_method(http_method) do |path, payload = {}, &block|
|
29
29
|
authenticate!
|
30
30
|
|
31
|
-
connection.send(http_method, path, payload) do |req|
|
31
|
+
resp = connection.send(http_method, path, payload) do |req|
|
32
32
|
add_authorization(req)
|
33
33
|
block.call(req) unless block.nil?
|
34
34
|
end
|
35
|
+
|
36
|
+
resp.body
|
35
37
|
end
|
36
38
|
end
|
37
39
|
end
|
@@ -14,13 +14,7 @@ module Mrkt
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def authenticate
|
17
|
-
|
18
|
-
grant_type: 'client_credentials',
|
19
|
-
client_id: @client_id,
|
20
|
-
client_secret: @client_secret
|
21
|
-
}
|
22
|
-
|
23
|
-
connection.get('/identity/oauth/token', params).tap do |response|
|
17
|
+
connection.get('/identity/oauth/token', authentication_params).tap do |response|
|
24
18
|
data = response.body
|
25
19
|
|
26
20
|
@token = data.fetch(:access_token)
|
@@ -30,6 +24,14 @@ module Mrkt
|
|
30
24
|
end
|
31
25
|
end
|
32
26
|
|
27
|
+
def authentication_params
|
28
|
+
{
|
29
|
+
grant_type: 'client_credentials',
|
30
|
+
client_id: @client_id,
|
31
|
+
client_secret: @client_secret
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
33
35
|
def add_authorization(req)
|
34
36
|
req.headers[:authorization] = "Bearer #{@token}"
|
35
37
|
end
|
data/lib/mrkt/version.rb
CHANGED
data/mrkt.gemspec
CHANGED
@@ -8,9 +8,9 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = Mrkt::VERSION
|
9
9
|
spec.authors = ['KARASZI István', 'Jacques Lemieux']
|
10
10
|
spec.email = ['github@spam.raszi.hu', 'jalemieux@gmail.com']
|
11
|
-
spec.
|
12
|
-
spec.
|
13
|
-
spec.homepage = ''
|
11
|
+
spec.summary = 'Marketo REST API Facade'
|
12
|
+
spec.description = 'This gem helps you to use the Marketo REST API'
|
13
|
+
spec.homepage = 'https://github.com/raszi/mrkt'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
@@ -28,4 +28,5 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.add_development_dependency 'webmock', '~> 1.21.0'
|
29
29
|
spec.add_development_dependency 'simplecov', '~> 0.10.0'
|
30
30
|
spec.add_development_dependency 'pry-byebug', '~> 3.1.0'
|
31
|
+
spec.add_development_dependency 'codeclimate-test-reporter', '~> 0.4.7'
|
31
32
|
end
|
@@ -28,7 +28,7 @@ describe Mrkt::CrudLeads do
|
|
28
28
|
.to_return(json_stub(response_stub))
|
29
29
|
end
|
30
30
|
|
31
|
-
it { is_expected.to
|
31
|
+
it { is_expected.to eq(response_stub) }
|
32
32
|
end
|
33
33
|
|
34
34
|
describe '#createupdate_leads' do
|
@@ -72,7 +72,7 @@ describe Mrkt::CrudLeads do
|
|
72
72
|
.to_return(json_stub(response_stub))
|
73
73
|
end
|
74
74
|
|
75
|
-
it { is_expected.to
|
75
|
+
it { is_expected.to eq(response_stub) }
|
76
76
|
end
|
77
77
|
|
78
78
|
describe '#delete_leads' do
|
@@ -101,7 +101,7 @@ describe Mrkt::CrudLeads do
|
|
101
101
|
.to_return(json_stub(response_stub))
|
102
102
|
end
|
103
103
|
|
104
|
-
it { is_expected.to
|
104
|
+
it { is_expected.to eq(response_stub) }
|
105
105
|
end
|
106
106
|
|
107
107
|
describe '#associate_lead' do
|
@@ -126,7 +126,7 @@ describe Mrkt::CrudLeads do
|
|
126
126
|
}
|
127
127
|
end
|
128
128
|
|
129
|
-
it { is_expected.to
|
129
|
+
it { is_expected.to eq(response_stub) }
|
130
130
|
end
|
131
131
|
|
132
132
|
context 'with a non-existing lead id' do
|
@@ -35,7 +35,7 @@ describe Mrkt::ImportLeads do
|
|
35
35
|
tempfile.unlink
|
36
36
|
end
|
37
37
|
|
38
|
-
it { is_expected.to
|
38
|
+
it { is_expected.to eq(response_stub) }
|
39
39
|
end
|
40
40
|
|
41
41
|
describe '#import_lead_status' do
|
@@ -63,14 +63,12 @@ describe Mrkt::ImportLeads do
|
|
63
63
|
.to_return(json_stub(response_stub))
|
64
64
|
end
|
65
65
|
|
66
|
-
it { is_expected.to
|
66
|
+
it { is_expected.to eq(response_stub) }
|
67
67
|
end
|
68
68
|
|
69
69
|
describe '#import_lead_failures' do
|
70
70
|
let(:id) { 1 }
|
71
|
-
let(:
|
72
|
-
|
73
|
-
end
|
71
|
+
let(:response_stub) { '' }
|
74
72
|
subject { client.import_lead_failures(1) }
|
75
73
|
|
76
74
|
before do
|
@@ -78,14 +76,12 @@ describe Mrkt::ImportLeads do
|
|
78
76
|
.to_return(headers: { content_length: 0 })
|
79
77
|
end
|
80
78
|
|
81
|
-
it { is_expected.to
|
79
|
+
it { is_expected.to eq(response_stub) }
|
82
80
|
end
|
83
81
|
|
84
82
|
describe '#import_lead_warnings' do
|
85
83
|
let(:id) { 1 }
|
86
|
-
let(:
|
87
|
-
|
88
|
-
end
|
84
|
+
let(:response_stub) { '' }
|
89
85
|
subject { client.import_lead_warnings(1) }
|
90
86
|
|
91
87
|
before do
|
@@ -93,6 +89,6 @@ describe Mrkt::ImportLeads do
|
|
93
89
|
.to_return(headers: { content_length: 0 })
|
94
90
|
end
|
95
91
|
|
96
|
-
it { is_expected.to
|
92
|
+
it { is_expected.to eq(response_stub) }
|
97
93
|
end
|
98
94
|
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/support/webmock.rb
CHANGED
@@ -1,10 +1,16 @@
|
|
1
1
|
require 'webmock/rspec'
|
2
2
|
|
3
|
-
RSpec.configure do
|
3
|
+
RSpec.configure do |config|
|
4
4
|
def json_stub(content_stub)
|
5
5
|
{
|
6
6
|
headers: { content_type: 'application/json' },
|
7
7
|
body: JSON.generate(content_stub)
|
8
8
|
}
|
9
9
|
end
|
10
|
+
|
11
|
+
if ENV['CODECLIMATE_REPO_TOKEN']
|
12
|
+
config.after(:suite) do
|
13
|
+
WebMock.disable_net_connect!(allow: 'codeclimate.com')
|
14
|
+
end
|
15
|
+
end
|
10
16
|
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: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- KARASZI István
|
@@ -109,7 +109,21 @@ dependencies:
|
|
109
109
|
- - "~>"
|
110
110
|
- !ruby/object:Gem::Version
|
111
111
|
version: 3.1.0
|
112
|
-
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
name: codeclimate-test-reporter
|
114
|
+
requirement: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - "~>"
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: 0.4.7
|
119
|
+
type: :development
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - "~>"
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: 0.4.7
|
126
|
+
description: This gem helps you to use the Marketo REST API
|
113
127
|
email:
|
114
128
|
- github@spam.raszi.hu
|
115
129
|
- jalemieux@gmail.com
|
@@ -132,7 +146,6 @@ files:
|
|
132
146
|
- lib/mrkt/concerns/import_leads.rb
|
133
147
|
- lib/mrkt/errors.rb
|
134
148
|
- lib/mrkt/faraday_middleware.rb
|
135
|
-
- lib/mrkt/faraday_middleware/request.rb
|
136
149
|
- lib/mrkt/faraday_middleware/response.rb
|
137
150
|
- lib/mrkt/version.rb
|
138
151
|
- mrkt.gemspec
|
@@ -144,7 +157,7 @@ files:
|
|
144
157
|
- spec/spec_helper.rb
|
145
158
|
- spec/support/initialized_client.rb
|
146
159
|
- spec/support/webmock.rb
|
147
|
-
homepage:
|
160
|
+
homepage: https://github.com/raszi/mrkt
|
148
161
|
licenses:
|
149
162
|
- MIT
|
150
163
|
metadata: {}
|
@@ -167,7 +180,7 @@ rubyforge_project:
|
|
167
180
|
rubygems_version: 2.4.3
|
168
181
|
signing_key:
|
169
182
|
specification_version: 4
|
170
|
-
summary:
|
183
|
+
summary: Marketo REST API Facade
|
171
184
|
test_files:
|
172
185
|
- spec/concerns/authentication_spec.rb
|
173
186
|
- spec/concerns/crud_leads_spec.rb
|
@@ -1,58 +0,0 @@
|
|
1
|
-
require 'faraday_middleware'
|
2
|
-
|
3
|
-
module Mrkt
|
4
|
-
module FaradayMiddleware
|
5
|
-
class Request < Faraday::Middleware
|
6
|
-
def initialize(app, client_id, client_secret)
|
7
|
-
super(app)
|
8
|
-
|
9
|
-
@client_id = client_id
|
10
|
-
@client_secret = client_secret
|
11
|
-
end
|
12
|
-
|
13
|
-
def call(env)
|
14
|
-
authenticate(env) unless authenticated? || env[:authentication]
|
15
|
-
|
16
|
-
env.request_headers[:authorization] = "Bearer #{@token}"
|
17
|
-
@app.call(env)
|
18
|
-
end
|
19
|
-
|
20
|
-
def authenticated?
|
21
|
-
@token && token_valid?
|
22
|
-
end
|
23
|
-
|
24
|
-
def token_valid?
|
25
|
-
@valid_until && Time.now < @valid_until
|
26
|
-
end
|
27
|
-
|
28
|
-
def authenticate(orig_env)
|
29
|
-
env = Faraday::Env.from(orig_env)
|
30
|
-
|
31
|
-
body = env[:body]
|
32
|
-
params = Faraday::Utils::ParamsHash.new
|
33
|
-
params.update(
|
34
|
-
grant_type: 'client_credentials',
|
35
|
-
client_id: @client_id,
|
36
|
-
client_secret: @client_secret
|
37
|
-
)
|
38
|
-
env[:authentication] = true
|
39
|
-
env[:method] = :get
|
40
|
-
|
41
|
-
env[:url] = env[:url].dup
|
42
|
-
env[:url].path = '/identity/oauth/token'
|
43
|
-
env[:url].query = params.to_query
|
44
|
-
|
45
|
-
orig_env[:body] = body
|
46
|
-
|
47
|
-
response = @app.call(env)
|
48
|
-
data = response.body
|
49
|
-
|
50
|
-
@token = data[:access_token]
|
51
|
-
@token_type = data[:token_type]
|
52
|
-
@expires_in = data[:expires_in]
|
53
|
-
@valid_until = Time.now + data[:expires_in]
|
54
|
-
@scope = data[:scope]
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|