papertrail 0.10.1 → 0.10.3

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
  SHA1:
3
- metadata.gz: bb401f55f2bc32e9e011d42c3581a31d0968e177
4
- data.tar.gz: 310b8a52dd4940489df86183e6086802813cf766
3
+ metadata.gz: 14aa6e94744379e81f4f8685a5661e0d458598ae
4
+ data.tar.gz: 05ae27cf65df698866a0f3e597133b45e447a065
5
5
  SHA512:
6
- metadata.gz: 87b529e95bb3d3a32d8b7ec4f42f970b8b5ca41a585430578c5331690e96a640ac060bb76b844dfcbfda4fcac8927775a18c31e44b2085d9b3ae3ec16280544e
7
- data.tar.gz: f40be823af90e8b15e871a77452e1e03edd9e3399447bf8ce1a465a70b9b8c4eb5623ef436dab168403e9fe76fa69dd2cd1376a18d620f56a262d4d77fdb1149
6
+ metadata.gz: 157ce473f08894c3a1b1b8d953b24c964b8a9f389476e6eb62250da397897e2cc19da23e9c196fe604fde9a10ae9305f7208bea5cab7b1f0a228375918e9650f
7
+ data.tar.gz: 4e997ad6cd9a0ec29fbdc5121b60ecbe60db581686a92c64d4c7fbd073ba59f049b1d994e24f176cb920a5741af1bc49383a9860377c7ce0ada10e9846ac5226
data/README.md CHANGED
@@ -298,7 +298,7 @@ to your enhancement.
298
298
  [Papertrail]: http://papertrailapp.com/
299
299
  [Connection]: https://github.com/papertrail/papertrail-cli/blob/master/lib/papertrail/connection.rb
300
300
  [HTTP API]: http://help.papertrailapp.com/kb/how-it-works/http-api
301
- [User Profile]: https://papertrailapp.com/user/edit
301
+ [User Profile]: https://papertrailapp.com/account/profile
302
302
  [RubyGems]: https://rubygems.org/gems/papertrail-cli
303
303
  [lnav]: http://lnav.org/
304
304
  [escape characters]: http://en.wikipedia.org/wiki/ANSI_escape_code#Colors
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ require 'papertrail'
2
3
  require 'papertrail/cli_add_group'
3
4
 
4
5
  begin
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ require 'papertrail'
2
3
  require 'papertrail/cli_add_system'
3
4
 
4
5
  begin
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ require 'papertrail'
2
3
  require 'papertrail/cli_join_group'
3
4
 
4
5
  begin
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ require 'papertrail'
2
3
  require 'papertrail/cli_leave_group'
3
4
 
4
5
  begin
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ require 'papertrail'
2
3
  require 'papertrail/cli_remove_system'
3
4
 
4
5
  begin
data/lib/papertrail.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Papertrail
2
- VERSION = '0.10.1'
2
+ VERSION = '0.10.3'
3
3
  end
4
4
 
5
5
  require 'papertrail/connection'
@@ -46,46 +46,32 @@ module Papertrail
46
46
  end
47
47
 
48
48
  def get(path, params = {})
49
- if params.size > 0
50
- path = "#{path}?cli_version=#{Papertrail::VERSION}&#{build_nested_query(params)}"
51
- end
52
- attempts = 0
53
- begin
54
- on_complete(https.get(request_uri(path), @headers))
55
- rescue SystemCallError, Net::HTTPFatalError => e
56
- sleep 5.0
57
- attempts += 1
58
- retry if (attempts < 3)
59
- raise e
60
- end
49
+ request(:get, path, params)
61
50
  end
62
51
 
63
52
  def put(path, params)
64
- attempts = 0
65
- begin
66
- on_complete(https.put(request_uri(path), build_nested_query(params), @headers))
67
- rescue SystemCallError, Net::HTTPFatalError => e
68
- attempts += 1
69
- retry if (attempts < 3)
70
- raise e
71
- end
53
+ request(:put, path, params)
72
54
  end
73
55
 
74
56
  def post(path, params)
75
- attempts = 0
76
- begin
77
- on_complete(https.post(request_uri(path), build_nested_query(params), @headers))
78
- rescue SystemCallError, Net::HTTPFatalError => e
79
- attempts += 1
80
- retry if (attempts < 3)
81
- raise e
82
- end
57
+ request(:post, path, params)
83
58
  end
84
59
 
85
60
  def delete(path)
61
+ request(:delete, path)
62
+ end
63
+
64
+ private
65
+
66
+ def request(http_method, path, params = {})
86
67
  attempts = 0
68
+ uri = "#{request_uri(path)}?cli_version=#{Papertrail::VERSION}&"
87
69
  begin
88
- on_complete(https.delete(request_uri(path), @headers))
70
+ if http_method == :get || http_method == :delete
71
+ on_complete(https.send(http_method, uri + build_nested_query(params.merge(cli_version)), @headers))
72
+ else
73
+ on_complete(https.send(http_method, uri, build_nested_query(params), @headers))
74
+ end
89
75
  rescue SystemCallError, Net::HTTPFatalError => e
90
76
  attempts += 1
91
77
  retry if (attempts < 3)
@@ -93,8 +79,6 @@ module Papertrail
93
79
  end
94
80
  end
95
81
 
96
- private
97
-
98
82
  def request_uri(path)
99
83
  path.start_with?('/api/v1/') ? path : "/api/v1/#{path}"
100
84
  end
@@ -115,6 +99,10 @@ module Papertrail
115
99
  http
116
100
  end
117
101
 
102
+ def cli_version
103
+ { :cli_version => Papertrail::VERSION }
104
+ end
105
+
118
106
  def ssl_verify_mode
119
107
  @ssl[:verify_mode] || begin
120
108
  if @ssl.fetch(:verify, true)
data/papertrail.gemspec CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |s|
9
9
  ## If your rubyforge_project name is different, then edit it and comment out
10
10
  ## the sub! line in the Rakefile
11
11
  s.name = 'papertrail'
12
- s.version = '0.10.1'
13
- s.date = '2016-12-08'
12
+ s.version = '0.10.3'
13
+ s.date = '2017-07-10'
14
14
  s.rubyforge_project = 'papertrail'
15
15
 
16
16
  ## Make sure your summary is short. The description may be as long
@@ -55,6 +55,10 @@ Gem::Specification.new do |s|
55
55
  s.add_development_dependency('minitest')
56
56
  s.add_development_dependency('mocha')
57
57
 
58
+ if RUBY_VERSION > '1.9'
59
+ s.add_development_dependency('addressable', '~> 2.4.0')
60
+ s.add_development_dependency('webmock', '~> 1.24.6')
61
+ end
58
62
  if RUBY_VERSION > '2.2.4' # ruby_dep dependency
59
63
  s.add_development_dependency('guard', '~> 2.14.0')
60
64
  s.add_development_dependency('guard-minitest', '~> 2.4.6')
@@ -93,6 +97,7 @@ Gem::Specification.new do |s|
93
97
  lib/papertrail/search_result.rb
94
98
  papertrail.gemspec
95
99
  test/connection_test.rb
100
+ test/http_client_test.rb
96
101
  test/search_query_test.rb
97
102
  test/test_helper.rb
98
103
  ]
@@ -0,0 +1,35 @@
1
+ require 'test_helper'
2
+
3
+ class HttpClientTest < Minitest::Test
4
+ let(:http) { Papertrail::HttpClient.new({}) }
5
+ describe "http methods" do
6
+
7
+ def test_cli_version_present_in_http_methods
8
+ return if RUBY_VERSION < '2.0'
9
+ # if webmock.disable_net_connect intervenes with a stack trace,
10
+ # we know the http methods are not sending cli_version in params
11
+ stub_request(:get, "https://papertrailapp.com/api/v1/some-path?cli_version=#{Papertrail::VERSION}&").to_return(:status => 200, :body => '', :headers => {})
12
+ http.get('some-path')
13
+
14
+ stub_request(:post, "https://papertrailapp.com/api/v1/some-path?cli_version=#{Papertrail::VERSION}&").to_return(:status => 200, :body => '', :headers => {})
15
+ http.post('some-path', {})
16
+
17
+
18
+ stub_request(:put, "https://papertrailapp.com/api/v1/some-path?cli_version=#{Papertrail::VERSION}&").to_return(:status => 200, :body => '', :headers => {})
19
+ http.put('some-path', {})
20
+
21
+ stub_request(:delete, "https://papertrailapp.com/api/v1/some-path?cli_version=#{Papertrail::VERSION}&").to_return(:status => 200, :body => '', :headers => {})
22
+ http.delete('some-path')
23
+ end
24
+ end
25
+ describe "build_nested_query" do
26
+ def test_value_accepts_hash
27
+ assert_equal(http.send(:build_nested_query, {}), "")
28
+ assert_equal(http.send(:build_nested_query, {:a => 1}), "a=1")
29
+ end
30
+ def test_value_accepts_array
31
+ assert_equal(http.send(:build_nested_query, []), "")
32
+ assert_equal(http.send(:build_nested_query, [1,2]), "%5B%5D=1&%5B%5D=2")
33
+ end
34
+ end
35
+ end
data/test/test_helper.rb CHANGED
@@ -1,6 +1,11 @@
1
+ gem "minitest"
1
2
  require 'minitest/autorun'
2
3
  require 'minitest/pride' # Color!
3
4
  require 'mocha/mini_test'
5
+ unless RUBY_VERSION < '1.9'
6
+ require 'webmock/minitest'
7
+ WebMock.disable_net_connect!
8
+ end
4
9
 
5
10
  require 'pp'
6
11
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: papertrail
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.1
4
+ version: 0.10.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Papertrail
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-08 00:00:00.000000000 Z
11
+ date: 2017-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chronic
@@ -80,6 +80,34 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: addressable
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 2.4.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 2.4.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 1.24.6
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 1.24.6
83
111
  - !ruby/object:Gem::Dependency
84
112
  name: guard
85
113
  requirement: !ruby/object:Gem::Requirement
@@ -150,6 +178,7 @@ files:
150
178
  - lib/papertrail/search_result.rb
151
179
  - papertrail.gemspec
152
180
  - test/connection_test.rb
181
+ - test/http_client_test.rb
153
182
  - test/search_query_test.rb
154
183
  - test/test_helper.rb
155
184
  homepage: http://github.com/papertrail/papertrail-cli