dagger 1.8.0 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a3be984806667b1144778e3695d47171000733ad0c2ecbc1323b36c8f97d666e
4
- data.tar.gz: e27de03a5b62085bb6de4954e6be2a15f14bc97a7c6933dfa92467fdaec33ed5
3
+ metadata.gz: 692b25152c7fd3229ad3dc13bd25250b613e55a211e489b8835258b18405db19
4
+ data.tar.gz: 5560f64e580e4f72f9e243eaf1c5eed1b389e439074607dc24bdd8fbe9c532f0
5
5
  SHA512:
6
- metadata.gz: 5237f119527a6a77f1075ab8b65048947e68c23d20fd523f1c220ebf5216997660f3b2acac75560082e956297087f7ba9f090ca118e973fbbb66c941d4ef393c
7
- data.tar.gz: 9a9a509cb9ff96338fa73fd711532704c27267916c2dda6e2e05c35446eeba4ec449f6aeba5bea2d4387ecac73ea69f18cceed325e9dbac263bd4d5811b8bc84
6
+ metadata.gz: 85d160f0130c12fde8b2723cd54bcaf4a75c4f48319cb040c4725a93e6cc09d4f8a68a7977135f33c38922583cc8de481bc078ea6d3ff5636c42c3154a5dca74
7
+ data.tar.gz: 9bd29716a9e84b75e898f71b00e8fc145550fcccd15b2c0006172e56e3e5454b62668bc4536dacde371a33b429f437a942354368de4cce0394ff73296cefa8e8
@@ -4,6 +4,7 @@ require 'dagger/parsers'
4
4
  require 'dagger/connection_manager'
5
5
  require 'net/https'
6
6
  require 'base64'
7
+ require 'erb'
7
8
 
8
9
  class URI::HTTP
9
10
  def scheme_and_host
@@ -13,19 +14,19 @@ end
13
14
 
14
15
  module Dagger
15
16
 
16
- DAGGER_NAME = "Dagger/#{VERSION}"
17
+ DAGGER_NAME = "Dagger/#{VERSION}".freeze
17
18
  REDIRECT_CODES = [301, 302, 303].freeze
18
19
  DEFAULT_RETRY_WAIT = 5.freeze # seconds
19
20
  DEFAULT_HEADERS = {
20
21
  'Accept' => '*/*',
21
22
  'User-Agent' => "#{DAGGER_NAME} (Ruby Net::HTTP wrapper, like curl)"
22
- }
23
+ }.freeze
23
24
 
24
25
  DEFAULTS = {
25
26
  open_timeout: 10,
26
27
  read_timeout: 10,
27
28
  keep_alive_timeout: 10
28
- }
29
+ }.freeze
29
30
 
30
31
  module Utils
31
32
 
@@ -1,6 +1,6 @@
1
1
  module Dagger
2
2
  MAJOR = 1
3
- MINOR = 8
3
+ MINOR = 9
4
4
  PATCH = 0
5
5
 
6
6
  VERSION = [MAJOR, MINOR, PATCH].join('.')
@@ -0,0 +1,151 @@
1
+ require_relative '../dagger'
2
+
3
+ module Dagger
4
+
5
+ module Wrapper
6
+
7
+ def self.included(base)
8
+ base.extend(ClassMethods)
9
+ end
10
+
11
+ module ClassMethods
12
+ def base_url(str = nil)
13
+ if str # set
14
+ @base_url = str
15
+ else
16
+ @base_url or raise "base_url unset!" # get
17
+ end
18
+ end
19
+
20
+ def base_options(opts = nil)
21
+ if opts # set
22
+ @base_options = opts
23
+ else
24
+ @base_options or raise "base_url unset!" # get
25
+ end
26
+ end
27
+ end
28
+
29
+ def initialize(opts = {})
30
+ @logger = opts.delete(:logger)
31
+ @options = opts
32
+ end
33
+
34
+ def get(path, params = {}, opts = {})
35
+ request(:get, path, params, opts)
36
+ end
37
+
38
+ def post(path, params = {}, opts = {})
39
+ request(:post, path, params, opts)
40
+ end
41
+
42
+ def put(path, params = {}, opts = {})
43
+ request(:put, path, params, opts)
44
+ end
45
+
46
+ def patch(path, params = {}, opts = {})
47
+ request(:patch, path, params, opts)
48
+ end
49
+
50
+ def delete(path, params = {}, opts = {})
51
+ request(:delete, path, params, opts)
52
+ end
53
+
54
+ def request(method, path, params = {}, opts = nil)
55
+ url = self.class.base_url + path
56
+ resp = benchmark("#{method} #{path}") do
57
+ http.request(method, url, params, base_options.merge(opts))
58
+ end
59
+
60
+ handle_response(resp, method, path, params)
61
+ end
62
+
63
+ def connect(&block)
64
+ open_http
65
+ if block_given?
66
+ yield
67
+ close_http
68
+ else
69
+ at_exit { close_http }
70
+ end
71
+ end
72
+
73
+ def disconnect
74
+ close_http
75
+ end
76
+
77
+ private
78
+ attr_reader :options
79
+
80
+ def handle_response(resp, method, path, params)
81
+ resp
82
+ end
83
+
84
+ def base_options
85
+ {}
86
+ end
87
+
88
+ def request_options
89
+ self.class.base_options.merge(base_options)
90
+ end
91
+
92
+ def benchmark(message, &block)
93
+ log(message)
94
+ start = Time.now
95
+ resp = yield
96
+ time = Time.now - start
97
+ log("Got response in #{time.round(2)} secs")
98
+ resp
99
+ end
100
+
101
+ def log(str)
102
+ logger.info(str)
103
+ end
104
+
105
+ def logger
106
+ @logger ||= begin
107
+ require 'logger'
108
+ Logger.new(@options[:logfile])
109
+ end
110
+ end
111
+
112
+ def http
113
+ @http || Dagger
114
+ end
115
+
116
+ def open_http
117
+ raise "Already open!" if @http
118
+ @http = Dagger.open(self.class.base_url)
119
+ end
120
+
121
+ def close_http
122
+ @http.close if @http
123
+ @http = nil
124
+ end
125
+
126
+ # def wrap(hash)
127
+ # Entity.new(hash)
128
+ # end
129
+
130
+ # class Entity
131
+ # def initialize(props)
132
+ # @props = props
133
+ # end
134
+
135
+ # def get(prop)
136
+ # val = @props[name.to_s]
137
+ # end
138
+
139
+ # def method_missing(name, args, &block)
140
+ # if @props.key?(name.to_s)
141
+ # get(name)
142
+ # else
143
+ # # raise NoMethodError, "undefined method #{name}"
144
+ # super
145
+ # end
146
+ # end
147
+ # end
148
+
149
+ end
150
+
151
+ end
@@ -122,16 +122,30 @@ describe 'Parsers' do
122
122
  <nested>
123
123
  <item>
124
124
  <title attr="downcased">foobar</title>
125
+ <category>cat</category>
126
+ <published>true</published>
125
127
  </item>
126
128
  </nested>
127
129
  </xml>
128
130
  )
129
131
 
130
- it 'works' do
131
- doc = Ox.parse(xml)
132
- obj = doc.to_node
132
+ describe '#to_node' do
133
+ it 'works as expected' do
134
+ doc = Ox.parse(xml)
135
+ obj = doc.to_node
136
+ expect(obj[:nested][:item][:title].text).to eql('foobar')
137
+ end
138
+ end
133
139
 
134
- expect(obj[:nested][:item][:title].text).to eql('foobar')
140
+ describe '#values' do
141
+ it 'works as expected' do
142
+ doc = Ox.parse(xml)
143
+ obj = doc.to_node.values
144
+ expect(obj).to eql({
145
+ "foo" => "test",
146
+ "nested" => {"item"=>{"category"=>"cat", "published"=>"true", "title"=>"foobar"}},
147
+ })
148
+ end
135
149
  end
136
150
 
137
151
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dagger
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.0
4
+ version: 1.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomás Pollak
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-13 00:00:00.000000000 Z
11
+ date: 2020-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -115,6 +115,7 @@ files:
115
115
  - lib/dagger/parsers.rb
116
116
  - lib/dagger/response.rb
117
117
  - lib/dagger/version.rb
118
+ - lib/dagger/wrapper.rb
118
119
  - spec/arguments_spec.rb
119
120
  - spec/ip_connect_spec.rb
120
121
  - spec/parsers_spec.rb