ghost_reader 1.0.1 → 1.1.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.
@@ -1,10 +1,15 @@
1
1
  require 'rubygems'
2
2
  require 'excon'
3
3
  require 'json'
4
+ require 'ruby-debug'
4
5
 
5
6
  # Excon.ssl_verify_peer = false
6
7
 
7
- address = 'http://0.0.0.0:3000/api/91885ca9ec4feb9b2ed2423cdbdeda32/translations.json'
8
+ host = '0.0.0.0:3001'
9
+ host = 'ghost.panter.ch'
10
+ api_key = '91885ca9ec4feb9b2ed2423cdbdeda32' # dummy local
11
+ api_key = 'e0e948efc3606e00c4b981bb2d3f7463' # CSP Live
12
+ address = "http://#{host}/api/#{api_key}/translations.json"
8
13
  excon = Excon.new(address)
9
14
  puts
10
15
 
@@ -33,6 +38,7 @@ puts
33
38
 
34
39
  puts "(3) Incremental request... (GET with If-Modified-Since)"
35
40
  headers = { 'If-Modified-Since' => @last_modified }
41
+ #debugger
36
42
  response = excon.get(:headers => headers)
37
43
  puts
38
44
  puts " Status: #{response.status}"
@@ -8,14 +8,6 @@ require 'i18n/backend/flatten'
8
8
  module GhostReader
9
9
  class Backend
10
10
 
11
- module DebugLookup
12
- def lookup(*args)
13
- config.logger.debug "Lookup: #{args.inspect}"
14
- # debugger
15
- super
16
- end
17
- end
18
-
19
11
  module Implementation
20
12
 
21
13
  attr_accessor :config, :missings
@@ -82,6 +74,7 @@ module GhostReader
82
74
  end
83
75
  rescue => ex
84
76
  config.logger.error "Exception in retriever loop: #{ex}"
77
+ config.logger.debug ex.backtrace.join("\n")
85
78
  end
86
79
  end
87
80
  rescue => ex
@@ -107,7 +100,8 @@ module GhostReader
107
100
  config.logger.debug "Reporting request omitted, nothing to report."
108
101
  end
109
102
  else
110
- config.logger.debug "Reporting request omitted, not yet initialized, waiting for intial request."
103
+ config.logger.debug "Reporting request omitted, not yet initialized," +
104
+ " waiting for intial request."
111
105
  end
112
106
  rescue => ex
113
107
  config.logger.error "Exception in reporter thread: #{ex}"
@@ -143,7 +137,8 @@ module GhostReader
143
137
  :report_interval => 10,
144
138
  :fallback => nil, # a I18n::Backend (mandatory)
145
139
  :logfile => nil, # a path
146
- :log_level => nil, # Log level, the options are Config::(FATAL, ERROR, WARN, INFO and DEBUG) (http://www.ruby-doc.org/stdlib/libdoc/logger/rdoc/Logger.html)
140
+ # see http://www.ruby-doc.org/stdlib/libdoc/logger/rdoc/Logger.html
141
+ :log_level => nil, # Log levels: FATAL, ERROR, WARN, INFO and DEBUG
147
142
  :service => {} # nested hash, see GhostReader::Client#default_config
148
143
  }
149
144
  end
@@ -153,7 +148,6 @@ module GhostReader
153
148
  include Implementation
154
149
  include I18n::Backend::Memoize # provides @memoized_lookup
155
150
  include I18n::Backend::Flatten # provides #flatten_translations
156
- include DebugLookup
157
151
  end
158
152
  end
159
153
 
@@ -54,21 +54,25 @@ module GhostReader
54
54
  end
55
55
 
56
56
  def service
57
- @service ||= Excon.new(address)
57
+ Excon.new(address)
58
58
  end
59
59
 
60
60
  def address
61
61
  raise 'no api_key provided' if config.api_key.nil?
62
- @address ||= config.uri.sub(':api_key', config.api_key)
62
+ @address ||= config.uri.
63
+ sub(':protocol', config.protocol).
64
+ sub(':host', config.host).
65
+ sub(':api_key', config.api_key)
63
66
  end
64
67
 
65
68
  # Wrapper method for retrying the connection
66
69
  # :method - http method (post and get supported at the moment)
67
70
  # :params - parameters sent to the service (excon)
68
71
  def connect_with_retry(method = :get, params = {})
72
+ config.logger.debug "Request: #{method} #{params.inspect}"
69
73
  retries = self.config.connection_retries
70
74
  while (retries > 0) do
71
- response = service.send(method, params)
75
+ response = service.request(params.merge(:method => method))
72
76
 
73
77
  if response.status == 408
74
78
  config.logger.error "Connection time-out. Retrying... #{retries}"
@@ -82,8 +86,10 @@ module GhostReader
82
86
 
83
87
  def default_config
84
88
  {
85
- :uri => 'http://ghost.panter.ch/api/:api_key/translations.json',
89
+ :protocol => 'http'
90
+ :host => 'ghost.panter.ch',
86
91
  :api_key => nil,
92
+ :uri => ':protocol://:host/api/:api_key/translations.json',
87
93
  :connection_retries => 3
88
94
  }
89
95
  end
@@ -1,3 +1,3 @@
1
1
  module GhostReader
2
- VERSION = "1.0.1"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ghost_reader
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
- - 0
9
8
  - 1
10
- version: 1.0.1
9
+ - 0
10
+ version: 1.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Andreas K\xC3\xB6nig"
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-10-10 00:00:00 +02:00
19
+ date: 2011-10-11 00:00:00 +02:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency