smooth_operator 1.9.2 → 1.10.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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- Y2IzODZkZGVmNjNlY2UwODZhZWM3MTMyMjU5ZGVhYWMxNzY4ZDI4Yw==
4
+ ZjJmMWRkYmQxMzdiOTM2MDJiYzViZTk5ZmY1MDI1OGUxYWM0MjAyZg==
5
5
  data.tar.gz: !binary |-
6
- M2E5Zjk0YTQyY2RlZmQ5YTkwMzIxNmU2NTFjMmMyN2U2NGM1NmNkMA==
6
+ MGZiODc4YzY5OTAwY2EzYzRkNTE4NWJlOWNjMmM3YTliNTg0ZWM4Yg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- Mzg5YmMxOTI1NWFiM2RhMjY3OWQ2YjZmZGJhNmY2OGY0YTViN2RmNDVmNDNm
10
- MzA3ZDdkNGM5NGM4YmU4Y2FjNWM5MWE4OWFmZTRmMTkwMWU1YmE0ZTM3Y2Nl
11
- MjA5YTk4ZjBjZDcxZjU4YWE4ZWFmMWRjMjY4MDRkY2IyYzAxNTk=
9
+ OGRhMjljNWE2MmI4YmRkZTkwN2FhYzIxMDdhYzhiMjA0Y2Y3NTJiYTk4NTAz
10
+ ZmQ2MmI2YWRkMzI4ODBjZGI2YTY3N2U4ZjY3NTRhZTk2MjUyNzhhNDdiMDU3
11
+ ZWNmZWY3NjExMjQyY2E1NjNjNDhiNTM5NjlhNDhiN2RlNGM2ZGY=
12
12
  data.tar.gz: !binary |-
13
- YzRmYTk3ZWE3MTk3NTI2ZDM4NTUxMjFmNjMwNTQ2NWIzNzYzOGZkNWFhMGJm
14
- N2U0NWIyYTFlNmEzMDQxZTZhOGJjZWI2NzE5NTU1MTY4YWRjZTBkNTRjYTFl
15
- MWUyNmVmZWZmZGFlNmNiNGJiYWJjZGM5NjEzODRjM2U3YWM3ZDA=
13
+ MDRkZmQxNGMwODg4MmQ0NTdhYWU3NGYyYWQ4MDU3YzAxZGQyMmUxZmIzMWU1
14
+ ZjU5NGI0ZjhlZjMyOWIwNTExZTVlMjY2Y2RiOGZiOWYyZmMwZWM3ZTE2Mzc5
15
+ MGJhOGNhZDdkMDU1YTJmZGFmNDQzMWE3NDUxOGM5ZjAxZDdlMDI=
data/Gemfile CHANGED
@@ -8,6 +8,7 @@ gem 'simplecov', :require => false, :group => :test
8
8
  group :development, :test do
9
9
  gem "pry"
10
10
  gem "sinatra"
11
+ gem "typhoeus"
11
12
  gem "sinatra-contrib"
12
13
  gem "rspec", "~> 3.0.0.beta1"
13
14
  gem "factory_girl", "~> 4.0"
data/console.rb CHANGED
@@ -7,5 +7,14 @@ require "spec/spec_helper"
7
7
 
8
8
  #User::Base.post('', { user: { age: 1, posts: [{ body: 'post1' }, 2] } })
9
9
 
10
+
11
+ conn = SmoothOperator::Base.generate_parallel_connection
12
+
13
+ conn.in_parallel do
14
+ remote_call = User::Base.find('http://localhost:4567/users', nil, { connection: conn })
15
+ end
16
+
17
+ remote_call
18
+
10
19
  binding.pry
11
20
 
@@ -1,8 +1,7 @@
1
- require 'faraday'
2
- # require 'typhoeus'
3
- # require 'faraday_middleware'
4
- # require 'typhoeus/adapters/faraday'
5
1
  require "smooth_operator/remote_call/base"
2
+ require "smooth_operator/operator_call/base"
3
+ require "smooth_operator/operator_call/faraday"
4
+ require "smooth_operator/operator_call/typhoeus"
6
5
 
7
6
  module SmoothOperator
8
7
 
@@ -19,10 +18,10 @@ module SmoothOperator
19
18
 
20
19
  HTTP_VERBS.each { |http_verb| define_method(http_verb) { |relative_path = '', params = {}, options = {}| make_the_call(http_verb, relative_path, params, options) } }
21
20
 
22
-
23
21
  def headers
24
22
  Helpers.get_instance_variable(self, :headers, {})
25
23
  end
24
+
26
25
  attr_writer :headers
27
26
 
28
27
 
@@ -35,84 +34,28 @@ module SmoothOperator
35
34
  options ||= {}
36
35
  url, timeout = (options[:endpoint] || self.endpoint), (options[:timeout] || self.timeout)
37
36
 
38
- Faraday.new(url: url) do |builder|
39
- # builder.options.params_encoder = Faraday::NestedParamsEncoder # to properly encode arrays
37
+ ::Faraday.new(url: url) do |builder|
40
38
  builder.options[:timeout] = timeout unless Helpers.blank?(timeout)
41
39
  builder.request :url_encoded
42
40
  builder.adapter adapter
43
41
  end
44
42
  end
45
43
 
46
-
47
- protected ################ PROTECTED ################
48
-
49
- # TODO: COMPLEX METHOD
50
44
  def make_the_call(http_verb, relative_path = '', data = {}, options = {})
51
- params, body = strip_params(http_verb, data)
52
-
53
- connection, operator_options, options = strip_options(options)
54
-
55
- relative_path = build_relative_path(relative_path, options)
56
-
57
- begin
58
- set_basic_authentication(connection, operator_options)
59
-
60
- response = connection.send(http_verb) do |request|
61
- operator_options.each { |key, value| request.options.send("#{key}=", value) }
62
- options[:headers].each { |key, value| request.headers[key] = value }
63
- params.each { |key, value| request.params[key] = value }
64
-
65
- request.url relative_path
66
- request.body = body
67
- end
68
-
69
- RemoteCall::Base.new(response)
70
- # rescue Faraday::ConnectionFailed
71
- rescue Faraday::Error::ConnectionFailed
72
- RemoteCall::Errors::ConnectionFailed.new(response)
73
- rescue Faraday::Error::TimeoutError
74
- RemoteCall::Errors::Timeout.new(response)
75
- end
76
- end
77
-
78
- def query_string(options)
79
- options
80
- end
81
-
82
-
83
- private ################# PRIVATE ###################
84
-
85
- def build_relative_path(relative_path, options)
86
- table_name = options[:table_name] || self.table_name
87
-
88
- if Helpers.present?(table_name)
89
- Helpers.present?(relative_path) ? "#{table_name}/#{relative_path}" : table_name
45
+ if Helpers.present?(options[:hydra])
46
+ operator_call = OperatorCall::Faraday.new(self, http_verb, relative_path, data, options)
90
47
  else
91
- relative_path
48
+ operator_call = OperatorCall::Typhoeus.new(self, http_verb, relative_path, data, options)
92
49
  end
93
- end
94
50
 
95
- def strip_params(http_verb, data)
96
- data ||= {}
97
-
98
- ([:get, :head, :delete].include?(http_verb) ? [query_string(data), nil] : [query_string({}), data])
51
+ operator_call.make_the_call
99
52
  end
100
53
 
101
- def strip_options(options)
102
- options ||= {}
103
-
104
- options[:headers] = self.headers.merge(options[:headers] || {})
105
- operator_options = options.delete(:operator_options) || {}
106
- connection = options.delete(:connection) || generate_connection(nil, operator_options)
107
54
 
108
- [connection, operator_options, options]
109
- end
110
-
111
- def set_basic_authentication(connection, options)
112
- endpoint_user = options[:endpoint_user] || self.endpoint_user
113
- endpoint_pass = options[:endpoint_pass] || self.endpoint_pass
55
+ protected ################ PROTECTED ################
114
56
 
115
- connection.basic_auth(endpoint_user, endpoint_pass) if Helpers.present?(endpoint_user)
57
+ def query_string(params)
58
+ params
116
59
  end
117
60
 
118
61
  end
@@ -0,0 +1,55 @@
1
+ module SmoothOperator
2
+
3
+ module OperatorCall
4
+
5
+ class Base
6
+
7
+ attr_reader :operator_class, :http_verb, :params, :body, :connection, :operator_options, :options, :relative_path, :endpoint_user, :endpoint_pass
8
+
9
+ def initialize(operator_class, http_verb, relative_path, data, options)
10
+ @operator_class, @http_verb = operator_class, http_verb
11
+
12
+ @params, @body = strip_params(http_verb, data)
13
+
14
+ @connection, @operator_options, @options = strip_options(options)
15
+
16
+ @relative_path = build_relative_path(relative_path, options)
17
+
18
+ @endpoint_user = options[:endpoint_user] || @operator_class.endpoint_user
19
+
20
+ @endpoint_pass = options[:endpoint_pass] || @operator_class.endpoint_pass
21
+ end
22
+
23
+
24
+ protected ################# PROTECTED ###################
25
+
26
+ def strip_params(http_verb, data)
27
+ data ||= {}
28
+
29
+ ([:get, :head, :delete].include?(http_verb) ? [@operator_class.query_string(data), nil] : [@operator_class.query_string({}), data])
30
+ end
31
+
32
+ def strip_options(options)
33
+ options ||= {}
34
+
35
+ options[:headers] = @operator_class.headers.merge(options[:headers] || {})
36
+ operator_options = options.delete(:operator_options) || {}
37
+ connection = options.delete(:connection) || @operator_class.generate_connection(nil, operator_options)
38
+
39
+ [connection, operator_options, options]
40
+ end
41
+
42
+ def build_relative_path(relative_path, options)
43
+ table_name = options[:table_name] || @operator_class.table_name
44
+
45
+ if Helpers.present?(table_name)
46
+ Helpers.present?(relative_path) ? "#{table_name}/#{relative_path}" : table_name
47
+ else
48
+ relative_path
49
+ end
50
+ end
51
+
52
+ end
53
+
54
+ end
55
+ end
@@ -0,0 +1,41 @@
1
+ require 'faraday'
2
+ require 'typhoeus/adapters/faraday'
3
+
4
+ module SmoothOperator
5
+
6
+ module OperatorCall
7
+
8
+ class Faraday < Base
9
+
10
+ def make_the_call
11
+ begin
12
+ set_basic_authentication
13
+
14
+ response = connection.send(http_verb) do |request|
15
+ operator_options.each { |key, value| request.options.send("#{key}=", value) }
16
+ options[:headers].each { |key, value| request.headers[key] = value }
17
+ params.each { |key, value| request.params[key] = value }
18
+
19
+ request.url relative_path
20
+ request.body = body
21
+ end
22
+
23
+ RemoteCall::Base.new(response)
24
+ rescue ::Faraday::Error::ConnectionFailed
25
+ RemoteCall::Errors::ConnectionFailed.new(response)
26
+ rescue ::Faraday::Error::TimeoutError
27
+ RemoteCall::Errors::Timeout.new(response)
28
+ end
29
+ end
30
+
31
+
32
+ protected ################ PROTECTED ################
33
+
34
+ def set_basic_authentication
35
+ connection.basic_auth(endpoint_user, endpoint_pass) if Helpers.present?(endpoint_user)
36
+ end
37
+
38
+ end
39
+
40
+ end
41
+ end
@@ -0,0 +1,40 @@
1
+ require 'typhoeus'
2
+
3
+ module SmoothOperator
4
+
5
+ module OperatorCall
6
+
7
+ class Typhoeus < Base
8
+
9
+ def make_the_call
10
+ begin
11
+ set_basic_authentication
12
+
13
+ response = connection.send(http_verb) do |request|
14
+ operator_options.each { |key, value| request.options.send("#{key}=", value) }
15
+ options[:headers].each { |key, value| request.headers[key] = value }
16
+ params.each { |key, value| request.params[key] = value }
17
+
18
+ request.url relative_path
19
+ request.body = body
20
+ end
21
+
22
+ RemoteCall::Base.new(response)
23
+ rescue ::Faraday::Error::ConnectionFailed
24
+ RemoteCall::Errors::ConnectionFailed.new(response)
25
+ rescue ::Faraday::Error::TimeoutError
26
+ RemoteCall::Errors::Timeout.new(response)
27
+ end
28
+ end
29
+
30
+
31
+ protected ################ PROTECTED ################
32
+
33
+ def set_basic_authentication
34
+ connection.basic_auth(endpoint_user, endpoint_pass) if Helpers.present?(endpoint_user)
35
+ end
36
+
37
+ end
38
+
39
+ end
40
+ end
@@ -1,3 +1,3 @@
1
1
  module SmoothOperator
2
- VERSION = "1.9.2"
2
+ VERSION = "1.10.0"
3
3
  end
@@ -24,6 +24,6 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency "bundler", "~> 1.3"
25
25
 
26
26
  spec.add_dependency "json"
27
- # spec.add_dependency 'faraday', '> 0.9.0.rc5'
27
+ spec.add_dependency 'typhoeus'
28
28
  spec.add_dependency 'faraday', '~> 0.8.1'
29
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smooth_operator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.2
4
+ version: 1.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - João Gonçalves
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-05 00:00:00.000000000 Z
11
+ date: 2014-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ! '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: typhoeus
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: faraday
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -77,6 +91,9 @@ files:
77
91
  - lib/smooth_operator/model_schema.rb
78
92
  - lib/smooth_operator/open_struct.rb
79
93
  - lib/smooth_operator/operator.rb
94
+ - lib/smooth_operator/operator_call/base.rb
95
+ - lib/smooth_operator/operator_call/faraday.rb
96
+ - lib/smooth_operator/operator_call/typhoeus.rb
80
97
  - lib/smooth_operator/persistence.rb
81
98
  - lib/smooth_operator/remote_call/base.rb
82
99
  - lib/smooth_operator/remote_call/errors/base.rb