naranya_ecm-sdk 0.0.55 → 0.0.56
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/lib/naranya_ecm-sdk/version.rb +1 -1
- data/lib/naranya_ecm/rest/errors.rb +29 -10
- data/lib/ncontent-sdk.rb +1 -31
- data/lib/ncontent/sdk/rest_client.rb +0 -24
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45b1ec3ac06a57187117d0560b8c75d690b560b2
|
4
|
+
data.tar.gz: 66800e1d77798cef6882095e533d3000756bfefc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8351e4377ec531396d6ba809244b16fa3d49fd16121317ccdf0227d60d55ddecf668b8fb20beac2839c3541c3e90520a67dba7cbf05e75a1a0e3b60d0a1a4542
|
7
|
+
data.tar.gz: e3a9cec8672c353cd0798a877ca381eeb92dcbb807e89eeba12e5d5a5f0e6502c7249fdc9d3131d3c241a1a52cc2a8e1112b9ef10dd341b910f433dd84a66663
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
|
1
3
|
module NaranyaEcm::Rest
|
2
4
|
# = REST Errors
|
3
5
|
#
|
@@ -8,6 +10,32 @@ module NaranyaEcm::Rest
|
|
8
10
|
|
9
11
|
def initialize(given_response, msg = "")
|
10
12
|
@response = given_response
|
13
|
+
|
14
|
+
# Generate a default message if we got a blank message:
|
15
|
+
if msg.blank?
|
16
|
+
response_env = given_response.env
|
17
|
+
msg = response_env.method.upcase.to_s
|
18
|
+
msg += " '#{response_env.url.to_s}'"
|
19
|
+
msg += " failed (HTTP #{response_env.status})"
|
20
|
+
end
|
21
|
+
|
22
|
+
# Record custom attributes in NewRelic:
|
23
|
+
if ::NContent::SDK.config.new_relic_agent_available?
|
24
|
+
ncontent_url = given_response.env.url
|
25
|
+
|
26
|
+
# Parsear el query string a hash:
|
27
|
+
ncontent_request_params = CGI.parse ncontent_url.query.to_s
|
28
|
+
|
29
|
+
# Agregar al hash de ncontent_request_params el request_body como hash:
|
30
|
+
if given_response.env.request_headers['Content-Type'] == 'application/json' && given_response.env[:request_body].present?
|
31
|
+
ncontent_request_params.merge! ActiveSupport::JSON.decode(given_response.env[:request_body])
|
32
|
+
end
|
33
|
+
|
34
|
+
::NewRelic::Agent.add_custom_attributes \
|
35
|
+
ncontent_url: ncontent_url.to_s.split('?').first,
|
36
|
+
request_params: ncontent_request_params
|
37
|
+
end
|
38
|
+
|
11
39
|
super(msg)
|
12
40
|
end
|
13
41
|
|
@@ -22,7 +50,7 @@ module NaranyaEcm::Rest
|
|
22
50
|
else RemoteFailed
|
23
51
|
end
|
24
52
|
|
25
|
-
klass.new response
|
53
|
+
klass.new response
|
26
54
|
end
|
27
55
|
|
28
56
|
##
|
@@ -102,15 +130,6 @@ module NaranyaEcm::Rest
|
|
102
130
|
end
|
103
131
|
|
104
132
|
class RemoteFailed < RestError
|
105
|
-
def initialize(given_response, msg = "")
|
106
|
-
response_env = given_response.env
|
107
|
-
|
108
|
-
# Override the message:
|
109
|
-
msg = "Request '#{response_env.method.upcase} #{response_env.url.path}' failed with HTTP status #{response_env.status}."
|
110
|
-
msg += " Request-Body: #{response_env[:request_body]}" if response_env[:request_body].present?
|
111
|
-
msg += " Response-Body: #{given_response.body.inspect}" if given_response.respond_to?(:body) && given_response.body.present?
|
112
|
-
super(given_response, msg)
|
113
|
-
end
|
114
133
|
end
|
115
134
|
|
116
135
|
end
|
data/lib/ncontent-sdk.rb
CHANGED
@@ -49,37 +49,7 @@ module NContent
|
|
49
49
|
def self.cache
|
50
50
|
@@cache ||= ActiveSupport::Cache.lookup_store *config.cache
|
51
51
|
end
|
52
|
-
|
53
|
-
def self.api_client
|
54
|
-
@@api_client ||= begin
|
55
|
-
require 'oauth2'
|
56
|
-
require 'ncontent/sdk/faraday_middleware'
|
57
|
-
|
58
|
-
OAuth2::Client.new(config.api_key, config.api_secret, site: config.api_host) do |faraday|
|
59
|
-
### Oauth2 Client (Faraday) builder:
|
60
|
-
|
61
|
-
faraday.request :url_encoded # them posts...
|
62
|
-
|
63
|
-
faraday.response :logger, NContent::SDK.logger
|
64
|
-
|
65
|
-
# faraday.use NContent::SDK::FaradayMiddleware::ResponseParser
|
66
|
-
faraday.use NContent::SDK::FaradayMiddleware::RESTAPICallBenchmark
|
67
|
-
|
68
|
-
if defined?(Patron)
|
69
|
-
faraday.adapter :patron # Prefer patron if exists
|
70
|
-
else
|
71
|
-
faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
def self.api_client_token
|
78
|
-
@@api_client_token ||= begin
|
79
|
-
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
52
|
+
|
83
53
|
end
|
84
54
|
|
85
55
|
end
|
@@ -1,7 +1,5 @@
|
|
1
1
|
require 'oauth2'
|
2
2
|
require 'ncontent/sdk/faraday_middleware'
|
3
|
-
require 'singleton'
|
4
|
-
require 'cgi'
|
5
3
|
|
6
4
|
module NContent
|
7
5
|
|
@@ -51,29 +49,7 @@ module NContent
|
|
51
49
|
# Build the error that will be raised:
|
52
50
|
error_to_raise = NaranyaEcm::Rest::RestError.build_from_failed_response(error_response)
|
53
51
|
|
54
|
-
# Send unhandled errors to NewRelic:
|
55
|
-
if error_to_raise.is_a?(NaranyaEcm::Rest::RemoteFailed) && config.new_relic_agent_available?
|
56
|
-
|
57
|
-
ncontent_url = error_response.env.url
|
58
|
-
|
59
|
-
# Parsear el query string a hash:
|
60
|
-
ncontent_request_params = CGI.parse ncontent_url.query.to_s
|
61
|
-
|
62
|
-
# Agregar al hash de ncontent_request_params el request_body como hash:
|
63
|
-
if error_response.env.request_headers['Content-Type'] == 'application/json' && error_response.env[:request_body].present?
|
64
|
-
ncontent_request_params.merge! ActiveSupport::JSON.decode(error_response.env[:request_body])
|
65
|
-
end
|
66
|
-
|
67
|
-
::NewRelic::Agent.notice_error(
|
68
|
-
error_to_raise,
|
69
|
-
uri: ncontent_url.to_s.split('?').first, # The URL without query string
|
70
|
-
metric: "Custom/NContent::SDK::RESTClient/#{verb}",
|
71
|
-
request_params: ncontent_request_params
|
72
|
-
)
|
73
|
-
end
|
74
|
-
|
75
52
|
raise error_to_raise
|
76
|
-
|
77
53
|
end
|
78
54
|
end
|
79
55
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: naranya_ecm-sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.56
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roberto Quintanilla
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|