active_campaign 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/active_campaign/connection.rb +2 -0
- data/lib/active_campaign/version.rb +1 -1
- data/lib/active_campaign.rb +1 -8
- data/lib/faraday/response/json_normalizer.rb +39 -0
- data/spec/client/lists_spec.rb +2 -2
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb45bc281708e6be460d3e33379cd2c74c26d737
|
4
|
+
data.tar.gz: 12b0835d724fd3e093e1ffd0cf78db46cbc03a8f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5f30055cd574ede7437056b3dde2cca94043a45a06033e13af3f478e91bd42e47629be65bc62d298c4ceb42eaec1837f985e423e9a1f095bf2e4edc0f018517
|
7
|
+
data.tar.gz: 77b9c9106c0fd0bba33cb1eb626a293cf131d5d54d82be44d42a2ad7bcde54316222cc6aa48bb29c8cae4899852ed342a0960bd8bf504889f09eab4ac7e470e6
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'faraday_middleware'
|
2
2
|
require 'faraday/response/raise_active_campaign_error'
|
3
3
|
require 'faraday/response/body_logger'
|
4
|
+
require 'faraday/response/json_normalizer'
|
4
5
|
|
5
6
|
module ActiveCampaign
|
6
7
|
|
@@ -32,6 +33,7 @@ module ActiveCampaign
|
|
32
33
|
conn.use FaradayMiddleware::FollowRedirects
|
33
34
|
if api_output == 'json'
|
34
35
|
conn.response :mashify, content_type: /\bjson$/
|
36
|
+
conn.response :json_normalizer
|
35
37
|
conn.response :json, content_type: /\bjson$/
|
36
38
|
end
|
37
39
|
faraday_config_block.call(conn) if faraday_config_block
|
data/lib/active_campaign.rb
CHANGED
@@ -24,14 +24,7 @@ module ActiveCampaign
|
|
24
24
|
# Delegate to ActiveCampaign::Client.new
|
25
25
|
def method_missing(method, *args, &block)
|
26
26
|
return super unless new.respond_to?(method)
|
27
|
-
|
28
|
-
results = response.reject{|k,v| %w(result_code result_message result_output).include?(k) }
|
29
|
-
response.results = results.values
|
30
|
-
results.keys.each do |key|
|
31
|
-
response.delete(key)
|
32
|
-
end
|
33
|
-
|
34
|
-
response
|
27
|
+
new.send(method, *args, &block)
|
35
28
|
end
|
36
29
|
|
37
30
|
def respond_to?(method, include_private=false)
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'faraday/response'
|
3
|
+
|
4
|
+
module Faraday
|
5
|
+
class Response::JsonNormalizer < Response::Middleware
|
6
|
+
def initialize(app, logger = nil)
|
7
|
+
super(app)
|
8
|
+
end
|
9
|
+
|
10
|
+
def call(environment)
|
11
|
+
@app.call(environment).on_complete do |env|
|
12
|
+
if env[:body].is_a?(Hash)
|
13
|
+
env[:body] = normalize(env[:body])
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def normalize(response)
|
21
|
+
keys, values = keys_values(response)
|
22
|
+
response[:results] = values
|
23
|
+
keys.each do |key|
|
24
|
+
response.delete(key)
|
25
|
+
end
|
26
|
+
response
|
27
|
+
end
|
28
|
+
|
29
|
+
def keys_values(response)
|
30
|
+
results = results(response)
|
31
|
+
[results.keys, results.values]
|
32
|
+
end
|
33
|
+
|
34
|
+
def results(response)
|
35
|
+
response.reject{|k,v| %w(result_code result_message result_output).include?(k) }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
Faraday.register_middleware :response, json_normalizer: lambda { Faraday::Response::JsonNormalizer }
|
data/spec/client/lists_spec.rb
CHANGED
@@ -40,9 +40,9 @@ describe ActiveCampaign::Client::Lists do
|
|
40
40
|
# stub_get("list_view", name: "Swedish Players").
|
41
41
|
# to_return json_response("list_view.json")
|
42
42
|
|
43
|
-
|
43
|
+
lists = @client.list_list "ids" => 'all'
|
44
44
|
binding.pry
|
45
|
-
expect(
|
45
|
+
expect(lists.results[0].name).to eq "Swedish Players"
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_campaign
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mikael Henriksson
|
@@ -123,6 +123,7 @@ files:
|
|
123
123
|
- lib/active_campaign/request.rb
|
124
124
|
- lib/active_campaign/version.rb
|
125
125
|
- lib/faraday/response/body_logger.rb
|
126
|
+
- lib/faraday/response/json_normalizer.rb
|
126
127
|
- lib/faraday/response/raise_active_campaign_error.rb
|
127
128
|
- spec/active_campaign_spec.rb
|
128
129
|
- spec/client/contacts_spec.rb
|