tms_client 0.4.0 → 0.4.1

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 ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YWFkYWUyYTcyMmRkN2M0MDFjYTE2YzI3ZDBiNWY4NGVjZGI3MDZjNw==
5
+ data.tar.gz: !binary |-
6
+ MmVjM2Y4ODVkNDYyZjAwYzUxMDc3N2VkNmU1OTgwNmI1MTIwZGYyMw==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ ZTZhMDI0MjA4MjhmNjM2YzRhOGYxMGQ4NGE2Y2JhNWM5ZGM4OWUwMjE0MjMx
10
+ MDdjZTRmZDQ0OGNkNTNjMjAzNDdmNzhhMTBkMjcyMGY3YTNiMmViODdkY2U5
11
+ OGNkNGFiMWY4ZjkwZTIwOWQxODdlNTVmYzFmODA5N2YyOWZjODM=
12
+ data.tar.gz: !binary |-
13
+ NGZmNTJkYjFlMTllNjk2YjE5N2M1ZjU1OTU5MDVlMDBjNGMyZWM2ZThiM2M3
14
+ OTU0OWRiN2Y3ZjhiYzdkMGQwN2FiYjE0ZThjZjQyOTRiN2M3OGQ4MmRkNGM2
15
+ ZjNjNDViYmI1MmMwMmUxYzVkMjQ1MTZiZDYwNDAzZjdiYzJkZDk=
@@ -21,9 +21,9 @@ class TMS::Client
21
21
  # :logger => Logger.new(STDOUT)})
22
22
  #
23
23
  def initialize(auth_token, options = DEFAULTS)
24
- @api_root = options.delete(:api_root)
25
- @logger = options.delete(:logger) || setup_logging(options.delete(:debug))
26
- connect!(auth_token, options)
24
+ @api_root = options[:api_root]
25
+ @logger = options[:logger] || setup_logging(options[:debug])
26
+ connect!(auth_token, options.except(:api_root, :logger, :debug))
27
27
  discover!
28
28
  end
29
29
 
@@ -1,5 +1,5 @@
1
1
  class TMS::Connection
2
- attr_accessor :auth_token, :api_root, :connection, :logger, :debug
2
+ attr_accessor :auth_token, :api_root, :connection, :logger
3
3
 
4
4
  def get(href)
5
5
  resp = connection.get("#{href}.json")
@@ -14,7 +14,6 @@ class TMS::Connection
14
14
  self.auth_token = opts[:auth_token]
15
15
  self.api_root = opts[:api_root]
16
16
  self.logger = opts[:logger]
17
- self.debug = opts[:debug]
18
17
  setup_connection
19
18
  end
20
19
 
@@ -22,7 +21,6 @@ class TMS::Connection
22
21
  self.connection = Faraday.new(:url => self.api_root) do |faraday|
23
22
  faraday.use TMS::Logger, self.logger if self.logger
24
23
  faraday.request :json
25
- setup_logging(faraday)
26
24
  faraday.headers['X-AUTH-TOKEN'] = auth_token
27
25
  faraday.headers[:user_agent] = "GovDelivery Ruby TMS::Client #{TMS::VERSION}"
28
26
  faraday.response :json, :content_type => /\bjson$/
@@ -30,16 +28,6 @@ class TMS::Connection
30
28
  end
31
29
  end
32
30
 
33
- def setup_logging(faraday)
34
- faraday.use FaradayMiddleware::Instrumentation, {:name => 'tms_client'}
35
- ActiveSupport::Notifications.subscribe('tms_client') do |name, starts, ends, _, env|
36
- duration = ends - starts
37
- logger.info "#{env[:method].to_s.upcase.ljust(7)}#{env[:status].to_s.ljust(4)}#{env[:url]} (#{duration} seconds)"
38
- logger.debug('response headers') { JSON.pretty_generate env[:response_headers] }
39
- logger.debug('response body') { env[:body] }
40
- end
41
- end
42
-
43
31
  def dump_headers(headers)
44
32
  headers.map { |k, v| "#{k}: #{v.inspect}" }.join("\n")
45
33
  end
@@ -14,9 +14,23 @@ module TMS #:nodoc:
14
14
 
15
15
  def call(env)
16
16
  debug "performing #{env[:method].to_s.upcase.ljust(7)} #{env[:url]}"
17
- super
17
+
18
+ start = Time.now
19
+
20
+ # In order to log request duration in a threadsafe way, `start` must be a local variable instead of instance variable.
21
+ @app.call(env).on_complete do |environment|
22
+ on_complete(environment)
23
+ log_stuff(start, environment)
24
+ end
18
25
  end
19
26
 
27
+ private
20
28
 
29
+ def log_stuff(start, environment)
30
+ duration = Time.now - start
31
+ info "#{environment[:method].to_s.upcase.ljust(7)}#{environment[:status].to_s.ljust(4)}#{environment[:url]} (#{duration} seconds)"
32
+ debug('response headers') { JSON.pretty_generate environment[:response_headers] }
33
+ debug('response body') { environment[:body] }
34
+ end
21
35
  end
22
- end
36
+ end
@@ -1,3 +1,3 @@
1
1
  module TMS #:nodoc:
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tms_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
5
- prerelease:
4
+ version: 0.4.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - GovDelivery
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-12-05 00:00:00.000000000 Z
11
+ date: 2013-12-13 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: activesupport
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ! '>='
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ! '>='
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: faraday
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ! '>='
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ! '>='
44
39
  - !ruby/object:Gem::Version
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: faraday_middleware
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ! '>='
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ! '>='
60
53
  - !ruby/object:Gem::Version
@@ -112,33 +105,26 @@ files:
112
105
  - spec/tms_client_spec.rb
113
106
  homepage: http://govdelivery.com
114
107
  licenses: []
108
+ metadata: {}
115
109
  post_install_message:
116
110
  rdoc_options: []
117
111
  require_paths:
118
112
  - lib
119
113
  required_ruby_version: !ruby/object:Gem::Requirement
120
- none: false
121
114
  requirements:
122
115
  - - ! '>='
123
116
  - !ruby/object:Gem::Version
124
117
  version: '0'
125
- segments:
126
- - 0
127
- hash: 825628313063111602
128
118
  required_rubygems_version: !ruby/object:Gem::Requirement
129
- none: false
130
119
  requirements:
131
120
  - - ! '>='
132
121
  - !ruby/object:Gem::Version
133
122
  version: '0'
134
- segments:
135
- - 0
136
- hash: 825628313063111602
137
123
  requirements: []
138
124
  rubyforge_project:
139
- rubygems_version: 1.8.25
125
+ rubygems_version: 2.0.7
140
126
  signing_key:
141
- specification_version: 3
127
+ specification_version: 4
142
128
  summary: A ruby client to interact with the GovDelivery TMS REST API.
143
129
  test_files:
144
130
  - spec/client_spec.rb
@@ -153,3 +139,4 @@ test_files:
153
139
  - spec/sms_messages_spec.rb
154
140
  - spec/spec_helper.rb
155
141
  - spec/tms_client_spec.rb
142
+ has_rdoc: