cloud_connect 2.0.2 → 3.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +20 -3
- data/Gemfile +2 -1
- data/Gemfile.lock +42 -31
- data/README.md +28 -83
- data/Rakefile +7 -35
- data/cloud_connect.gemspec +27 -28
- data/lib/cloud_connect/authentication.rb +15 -0
- data/lib/cloud_connect/client/assets.rb +102 -0
- data/lib/cloud_connect/client/channels.rb +83 -16
- data/lib/cloud_connect/client/configurations.rb +54 -0
- data/lib/cloud_connect/client/custom_methods.rb +20 -0
- data/lib/cloud_connect/client/fields.rb +88 -15
- data/lib/cloud_connect/client/messages.rb +60 -48
- data/lib/cloud_connect/client/tracks.rb +46 -0
- data/lib/cloud_connect/client.rb +39 -53
- data/lib/cloud_connect/configuration.rb +60 -0
- data/lib/cloud_connect/connection.rb +49 -0
- data/lib/cloud_connect/error.rb +27 -5
- data/lib/cloud_connect/notification/notification.rb +78 -0
- data/lib/cloud_connect/notification.rb +43 -0
- data/lib/cloud_connect/request.rb +70 -0
- data/lib/cloud_connect/version.rb +1 -1
- data/lib/cloud_connect.rb +18 -35
- data/lib/faraday/response/raise_cloud_connect_error.rb +44 -0
- metadata +93 -45
- data/.yardopts +0 -7
- data/HISTORY.md +0 -33
- data/lib/cloud_connect/client/trackings.rb +0 -22
- data/lib/cloud_connect/client/units.rb +0 -77
- data/lib/cloud_connect/client/users.rb +0 -36
- data/lib/ext/hash.rb +0 -5
- data/lib/ext/module.rb +0 -59
- data/lib/ext/object.rb +0 -57
- data/lib/faraday/cookie_auth.rb +0 -21
- data/lib/faraday/raise_http_4xx.rb +0 -41
- data/lib/faraday/raise_http_5xx.rb +0 -27
data/lib/ext/module.rb
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
# From active_support
|
2
|
-
#
|
3
|
-
# http://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/module/delegation.rb
|
4
|
-
# http://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/module/remove_method.rb
|
5
|
-
class Module
|
6
|
-
|
7
|
-
# Used by delegate
|
8
|
-
# @see http://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/module/remove_method.rb
|
9
|
-
def remove_possible_method(method)
|
10
|
-
remove_method(method)
|
11
|
-
rescue NameError
|
12
|
-
end
|
13
|
-
|
14
|
-
# Provides a delegate class method to easily expose contained objects' methods
|
15
|
-
# as your own. Pass one or more methods (specified as symbols or strings)
|
16
|
-
# and the name of the target object via the <tt>:to</tt> option (also a symbol
|
17
|
-
# or string). At least one method and the <tt>:to</tt> option are required.
|
18
|
-
# @see http://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/module/delegation.rb
|
19
|
-
def delegate(*methods)
|
20
|
-
options = methods.pop
|
21
|
-
unless options.is_a?(Hash) && to = options[:to]
|
22
|
-
raise ArgumentError, "Delegation needs a target. Supply an options hash with a :to key as the last argument (e.g. delegate :hello, :to => :greeter)."
|
23
|
-
end
|
24
|
-
|
25
|
-
if options[:prefix] == true && options[:to].to_s =~ /^[^a-z_]/
|
26
|
-
raise ArgumentError, "Can only automatically set the delegation prefix when delegating to a method."
|
27
|
-
end
|
28
|
-
|
29
|
-
prefix = options[:prefix] && "#{options[:prefix] == true ? to : options[:prefix]}_" || ''
|
30
|
-
|
31
|
-
file, line = caller.first.split(':', 2)
|
32
|
-
line = line.to_i
|
33
|
-
|
34
|
-
methods.each do |method|
|
35
|
-
on_nil =
|
36
|
-
if options[:allow_nil]
|
37
|
-
'return'
|
38
|
-
else
|
39
|
-
%(raise "#{self}##{prefix}#{method} delegated to #{to}.#{method}, but #{to} is nil: \#{self.inspect}")
|
40
|
-
end
|
41
|
-
|
42
|
-
module_eval(<<-EOS, file, line - 5)
|
43
|
-
if instance_methods(false).map(&:to_s).include?("#{prefix}#{method}")
|
44
|
-
remove_possible_method("#{prefix}#{method}")
|
45
|
-
end
|
46
|
-
|
47
|
-
def #{prefix}#{method}(*args, &block) # def customer_name(*args, &block)
|
48
|
-
#{to}.__send__(#{method.inspect}, *args, &block) # client.__send__(:name, *args, &block)
|
49
|
-
rescue NoMethodError # rescue NoMethodError
|
50
|
-
if #{to}.nil? # if client.nil?
|
51
|
-
#{on_nil} # return # depends on :allow_nil
|
52
|
-
else # else
|
53
|
-
raise # raise
|
54
|
-
end # end
|
55
|
-
end # end
|
56
|
-
EOS
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
data/lib/ext/object.rb
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
class Object
|
2
|
-
# mainly from active_support on http://github.com/rails/rails/
|
3
|
-
|
4
|
-
# Returns +value+ after yielding +value+ to the block. This simplifies the
|
5
|
-
# process of constructing an object, performing work on the object, and then
|
6
|
-
# returning the object from a method. It is a Ruby-ized realization of the K
|
7
|
-
# combinator, courtesy of Mikael Brockman.
|
8
|
-
#
|
9
|
-
# ==== Examples
|
10
|
-
#
|
11
|
-
# # Without returning
|
12
|
-
# def foo
|
13
|
-
# values = []
|
14
|
-
# values << "bar"
|
15
|
-
# values << "baz"
|
16
|
-
# return values
|
17
|
-
# end
|
18
|
-
#
|
19
|
-
# foo # => ['bar', 'baz']
|
20
|
-
#
|
21
|
-
# # returning with a local variable
|
22
|
-
# def foo
|
23
|
-
# returning values = [] do
|
24
|
-
# values << 'bar'
|
25
|
-
# values << 'baz'
|
26
|
-
# end
|
27
|
-
# end
|
28
|
-
#
|
29
|
-
# foo # => ['bar', 'baz']
|
30
|
-
#
|
31
|
-
# # returning with a block argument
|
32
|
-
# def foo
|
33
|
-
# returning [] do |values|
|
34
|
-
# values << 'bar'
|
35
|
-
# values << 'baz'
|
36
|
-
# end
|
37
|
-
# end
|
38
|
-
#
|
39
|
-
# foo # => ['bar', 'baz']
|
40
|
-
def returning(value)
|
41
|
-
yield(value)
|
42
|
-
value
|
43
|
-
end
|
44
|
-
|
45
|
-
# Tries to send the method only if object responds to it. Return +nil+ otherwise.
|
46
|
-
#
|
47
|
-
# ==== Example :
|
48
|
-
#
|
49
|
-
# # Without try
|
50
|
-
# @person ? @person.name : nil
|
51
|
-
#
|
52
|
-
# With try
|
53
|
-
# @person.try(:name)
|
54
|
-
def try(method, *args, &block)
|
55
|
-
send(method, *args, &block) if respond_to?(method, true)
|
56
|
-
end
|
57
|
-
end
|
data/lib/faraday/cookie_auth.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
module Faraday
|
2
|
-
class Request::CookieAuth < Faraday::Middleware
|
3
|
-
delegate :cookie, :cookie=, :to => :@client, :allow_nil => true
|
4
|
-
|
5
|
-
def call(env)
|
6
|
-
env[:request_headers]['Cookie'] = cookie if cookie
|
7
|
-
|
8
|
-
env[:response].on_complete do |finished_env|
|
9
|
-
if finished_env[:response_headers]['set-cookie']
|
10
|
-
self.cookie = finished_env[:response_headers]['set-cookie'].split('; ')[0]
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
@app.call(env)
|
15
|
-
end
|
16
|
-
|
17
|
-
def initialize(app, client = nil)
|
18
|
-
@app, @client = app, client
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
module Faraday
|
2
|
-
class Response::RaiseHttp4xx < Response::Middleware
|
3
|
-
def self.register_on_complete(env)
|
4
|
-
env[:response].on_complete do |response|
|
5
|
-
case response[:status].to_i
|
6
|
-
when 400
|
7
|
-
raise CloudConnect::BadRequest, error_message(response)
|
8
|
-
when 401
|
9
|
-
raise CloudConnect::Unauthorized, error_message(response)
|
10
|
-
when 403
|
11
|
-
raise CloudConnect::Forbidden, error_message(response)
|
12
|
-
when 404
|
13
|
-
raise CloudConnect::NotFound, error_message(response)
|
14
|
-
when 406
|
15
|
-
raise CloudConnect::NotAcceptable, error_message(response)
|
16
|
-
when 422
|
17
|
-
raise CloudConnect::UnprocessableEntity, error_message(response)
|
18
|
-
#when 420
|
19
|
-
# raise CloudConnect::EnhanceYourCalm.new error_message(response), response[:response_headers]
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def initialize(app)
|
25
|
-
super
|
26
|
-
@parser = nil
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
def self.error_message(response)
|
32
|
-
if response[:body] && response[:body].is_a?(Hash) && response[:body]['error']
|
33
|
-
"#{response[:method].to_s.upcase} #{response[:url].to_s}: #{response[:response_headers]['status']}: #{(response[:body]['error'])}"
|
34
|
-
elsif response[:body] && response[:body].is_a?(Array)
|
35
|
-
"#{response[:method].to_s.upcase} #{response[:url].to_s}: #{response[:response_headers]['status']}: #{(response[:body].join(', '))}"
|
36
|
-
else
|
37
|
-
"#{response[:method].to_s.upcase} #{response[:url].to_s}: #{response[:response_headers]['status']}: #{(response[:body])}"
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
module Faraday
|
2
|
-
class Response::RaiseHttp5xx < Response::Middleware
|
3
|
-
def self.register_on_complete(env)
|
4
|
-
env[:response].on_complete do |response|
|
5
|
-
case response[:status].to_i
|
6
|
-
when 500
|
7
|
-
raise CloudConnect::InternalServerError, error_message(response, "Something is technically wrong.")
|
8
|
-
when 502
|
9
|
-
raise CloudConnect::BadGateway, error_message(response, "CloudConnect is down or being upgraded.")
|
10
|
-
when 503
|
11
|
-
raise CloudConnect::ServiceUnavailable, error_message(response, "(__-){ CloudConnect is over capacity.")
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def initialize(app)
|
17
|
-
super
|
18
|
-
@parser = nil
|
19
|
-
end
|
20
|
-
|
21
|
-
private
|
22
|
-
|
23
|
-
def self.error_message(response, body=nil)
|
24
|
-
"#{response[:method].to_s.upcase} #{response[:url].to_s}: #{response[:response_headers]['status']}:#{(' ' + body) if body} Check http://status.g8teway.com/ for updates on the status of the CloudConnect service."
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|