smooth_operator 1.21.4 → 1.22.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MzVmNDBmNGNhOWJmMjk0MDJhZDRhYTE0YmNhOGI3ZmQxMDQ4YWMyOQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NzU4MDBlMWQzNTU2NzhmZjIyMjE2Y2ZjMTk3ZjU5MjAxMjY4NzJhMQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NzAwZDJlNDM1OTJlMjg3MDVlYjViYmI4N2NjNTk4YjFkNmZiNjQzZWUyYjFk
|
10
|
+
MGUzZmEzNDliMjNjMGQ3ZTI5YjI2MTQzY2QxZTgyZTZiZmNmMzQyMjJhY2Jj
|
11
|
+
MDhiMGYwZGRlZDdlZDVlNTJiNDQ0OWIzNGYyNzgzZDAzNDZjNTk=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OTE5YjlmYmRlYjVhYWZiODI2NjQ4YWI5OGRkNzRmNjk4YTdjMTQ5ZWRiZDRi
|
14
|
+
ZjJmY2FlOTIxMTZmNDBmYTllY2EwNjAzNjc1NjcxNjkzNWY2N2RiMjRlNGMx
|
15
|
+
ZTJlMzYyNDQ1MWViN2Q2M2U4NTUzOGIzMDZmYzRmZDRjN2I4MzM=
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module SmoothOperator
|
2
|
+
class CookieJar < Hash
|
3
|
+
|
4
|
+
def to_s
|
5
|
+
self.map { |key, value| "#{key}=#{value}"}.join("; ")
|
6
|
+
end
|
7
|
+
|
8
|
+
def parse(*cookie_strings)
|
9
|
+
cookie_strings.each do |cookie_string|
|
10
|
+
next unless cookie_string.is_a?(String)
|
11
|
+
|
12
|
+
key, value = cookie_string.split('; ').first.split('=', 2)
|
13
|
+
|
14
|
+
self[key] = value
|
15
|
+
end
|
16
|
+
|
17
|
+
self
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -20,7 +20,9 @@ module SmoothOperator
|
|
20
20
|
options[:resources_name] ||= "#{parent_object.class.resources_name}/#{id}/#{self.class.resources_name}"
|
21
21
|
end
|
22
22
|
|
23
|
-
|
23
|
+
call_args = before_request(http_verb, relative_path, data, options)
|
24
|
+
|
25
|
+
self.class.make_the_call(*call_args) do |remote_call|
|
24
26
|
yield(remote_call)
|
25
27
|
end
|
26
28
|
end
|
@@ -41,9 +43,15 @@ module SmoothOperator
|
|
41
43
|
base.extend(ClassMethods)
|
42
44
|
end
|
43
45
|
|
46
|
+
protected ################# PROTECTED ####################
|
47
|
+
|
48
|
+
def before_request(http_verb, relative_path, data, options)
|
49
|
+
[http_verb, relative_path, data, options]
|
50
|
+
end
|
51
|
+
|
44
52
|
module ClassMethods
|
45
53
|
|
46
|
-
OPTIONS = [:endpoint, :endpoint_user, :endpoint_pass, :timeout]
|
54
|
+
OPTIONS = [:endpoint, :endpoint_user, :endpoint_pass, :timeout, :server_name]
|
47
55
|
|
48
56
|
OPTIONS.each do |option|
|
49
57
|
define_method(option) { Helpers.get_instance_variable(self, option, '') }
|
@@ -62,6 +70,8 @@ module SmoothOperator
|
|
62
70
|
|
63
71
|
resource_path = resource_path(relative_path, options)
|
64
72
|
|
73
|
+
http_verb, resource_path, data, options = before_request(http_verb, resource_path, data, options)
|
74
|
+
|
65
75
|
params, data = *HelperMethods.strip_params(self, http_verb, data)
|
66
76
|
|
67
77
|
operator = HelperMethods.get_me_an_operator(options)
|
@@ -85,6 +95,12 @@ module SmoothOperator
|
|
85
95
|
end
|
86
96
|
end
|
87
97
|
|
98
|
+
protected ################# PROTECTED ####################
|
99
|
+
|
100
|
+
def before_request(http_verb, relative_path, data, options)
|
101
|
+
[http_verb, relative_path, data, options]
|
102
|
+
end
|
103
|
+
|
88
104
|
end
|
89
105
|
|
90
106
|
module HelperMethods
|
@@ -49,19 +49,15 @@ module SmoothOperator
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def save(relative_path = nil, data = {}, options = {})
|
52
|
-
data =
|
52
|
+
data = resource_body(data, options)
|
53
53
|
|
54
54
|
method = new_record? ? :create : :update
|
55
55
|
|
56
|
-
|
57
|
-
|
58
|
-
end
|
59
|
-
end
|
56
|
+
make_a_persistence_call(method, relative_path, data, options) do |remote_call|
|
57
|
+
@new_record = false if method == :create && remote_call.status
|
60
58
|
|
61
|
-
def save!(relative_path = nil, data = {}, options = {})
|
62
|
-
save(relative_path, data, options) do |remote_call|
|
63
59
|
block_given? ? yield(remote_call) : remote_call.status
|
64
|
-
end
|
60
|
+
end
|
65
61
|
end
|
66
62
|
|
67
63
|
def destroy(relative_path = nil, data = {}, options = {})
|
@@ -74,23 +70,15 @@ module SmoothOperator
|
|
74
70
|
end
|
75
71
|
end
|
76
72
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
@new_record = false if remote_call.status
|
82
|
-
|
83
|
-
block_given? ? yield(remote_call) : remote_call
|
84
|
-
end
|
73
|
+
def save!(relative_path = nil, data = {}, options = {})
|
74
|
+
save(relative_path, data, options) do |remote_call|
|
75
|
+
block_given? ? yield(remote_call) : remote_call.status
|
76
|
+
end || raise('RecordNotSaved')
|
85
77
|
end
|
86
78
|
|
87
|
-
|
88
|
-
make_a_persistence_call(:update, relative_path, data, options) do |remote_call|
|
89
|
-
block_given? ? yield(remote_call) : remote_call
|
90
|
-
end
|
91
|
-
end
|
79
|
+
protected ######################### PROTECTED ##################
|
92
80
|
|
93
|
-
def
|
81
|
+
def resource_body(data, options)
|
94
82
|
data = Helpers.stringify_keys(data)
|
95
83
|
|
96
84
|
hash = serializable_hash(options[:serializable_options]).dup
|
@@ -1,5 +1,6 @@
|
|
1
|
-
|
1
|
+
require "smooth_operator/cookie_jar"
|
2
2
|
|
3
|
+
module SmoothOperator
|
3
4
|
module RemoteCall
|
4
5
|
|
5
6
|
class Base
|
@@ -66,6 +67,10 @@ module SmoothOperator
|
|
66
67
|
object.nil? ? parsed_response : object
|
67
68
|
end
|
68
69
|
|
70
|
+
def cookie(header_field = 'set-cookie')
|
71
|
+
CookieJar.new.parse(headers[header_field])
|
72
|
+
end
|
73
|
+
|
69
74
|
end
|
70
75
|
end
|
71
76
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smooth_operator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.22.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- João Gonçalves
|
@@ -87,6 +87,7 @@ files:
|
|
87
87
|
- lib/smooth_operator/associations/has_many_relation.rb
|
88
88
|
- lib/smooth_operator/associations/reflection.rb
|
89
89
|
- lib/smooth_operator/attribute_assignment.rb
|
90
|
+
- lib/smooth_operator/cookie_jar.rb
|
90
91
|
- lib/smooth_operator/delegation.rb
|
91
92
|
- lib/smooth_operator/finder_methods.rb
|
92
93
|
- lib/smooth_operator/helpers.rb
|