active_campaign 0.0.4 → 0.0.5

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
2
  SHA1:
3
- metadata.gz: 71cc0d05d22a72685dd8fe8a97d36277fad291f3
4
- data.tar.gz: a13ed393bbc6d29ca068f54998aff7d4bb5ab103
3
+ metadata.gz: cb45bc281708e6be460d3e33379cd2c74c26d737
4
+ data.tar.gz: 12b0835d724fd3e093e1ffd0cf78db46cbc03a8f
5
5
  SHA512:
6
- metadata.gz: 85f9631f348f3b8b976c15e17526c784846b89a49ac241f15d7a6977b46fc6be5033f86e45c5c43fd6be8fd008a989346c7fdfb743401382d9ebfc2bb3b78f52
7
- data.tar.gz: eec62992ab70374e3ae5db4d6c5d1ec759efbbe51ba96f8726042c8c4fbfdf56342f2ae5b15262a38d333ea65835c583b73e13e70973e25b9470e0b50504a465
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
@@ -1,3 +1,3 @@
1
1
  module ActiveCampaign
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -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
- response = new.send(method, *args, &block)
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 }
@@ -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
- list = @client.list_list "ids" => 'all'
43
+ lists = @client.list_list "ids" => 'all'
44
44
  binding.pry
45
- expect(list["0"].name).to eq "Swedish Players"
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
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