Module: QuickbooksWebConnector
- Extended by:
- QuickbooksWebConnector
- Included in:
- QuickbooksWebConnector
- Defined in:
- lib/quickbooks_web_connector.rb,
lib/quickbooks_web_connector/job.rb,
lib/quickbooks_web_connector/user.rb,
lib/quickbooks_web_connector/config.rb,
lib/quickbooks_web_connector/engine.rb,
lib/quickbooks_web_connector/errors.rb,
lib/quickbooks_web_connector/failure.rb,
lib/quickbooks_web_connector/version.rb,
lib/quickbooks_web_connector/json_coder.rb,
lib/quickbooks_web_connector/soap_wrapper.rb,
lib/quickbooks_web_connector/soap_wrapper/default.rb,
app/controllers/quickbooks_web_connector/qwc_controller.rb,
app/helpers/quickbooks_web_connector/application_helper.rb,
app/controllers/quickbooks_web_connector/soap_controller.rb,
lib/quickbooks_web_connector/soap_wrapper/defaultServant.rb,
lib/quickbooks_web_connector/soap_wrapper/QBWebConnectorSvc.rb,
lib/quickbooks_web_connector/soap_wrapper/defaultMappingRegistry.rb,
app/controllers/quickbooks_web_connector/quickbooks_web_connector_controller.rb
Defined Under Namespace
Modules: ApplicationHelper, SoapWrapper Classes: Configuration, DecodeException, EncodeException, Engine, Failure, Job, JsonCoder, QuickbooksWebConnectorController, QwcController, ReceiveResponseXMLError, RequestXMLError, SoapController, User
Constant Summary collapse
- VERSION =
"0.8.0"
Instance Attribute Summary collapse
-
#coder ⇒ Object
Encapsulation of encode/decode.
Class Method Summary collapse
-
.config ⇒ Object
Global settings for QuickbooksWebConnector.
-
.configure {|@config ||= QuickbooksWebConnector::Configuration.new| ... } ⇒ Object
Configure global settings for QuickbooksWebConnector QuickbooksWebConnector.configure do |config| config.server_version end.
- .reset_configuration! ⇒ Object
- .set_default_configuration ⇒ Object
Instance Method Summary collapse
-
#clear_job_count_for_session ⇒ Object
Clear the temporarily stored count of jobs for the sync session.
- #decode(object) ⇒ Object
-
#dequeue(request_builder, response_handler, *args) ⇒ Object
This method can be used to conveniently remove a job from the queue.
- #encode(object) ⇒ Object
-
#enqueue(request_builder, response_handler, *args) ⇒ Object
This method can be used to conveniently add a job to the queue.
-
#job_count_for_session ⇒ Object
Fetch the saved number of jobs for the session.
-
#list_range(key, start = 0, stop = -1)) ⇒ Object
Does the dirty work of fetching a range of items from a Redis list and converting them into Ruby objects.
-
#peek ⇒ Object
Returns the next item currently queued, without removing it.
-
#pop ⇒ Object
Pops a job off the queue.
-
#push(item) ⇒ Object
The ‘item` is expected to be a hash with the following keys:.
-
#redis ⇒ Object
Returns the current Redis connection.
-
#redis=(server) ⇒ Object
Accepts: 1.
-
#remove(item) ⇒ Object
Delete any matching items.
-
#reserve ⇒ Object
This method will return a ‘QuickbooksWebConnector::Job` object or a non-true value depending on whether a job can be obtained.
-
#session_progress ⇒ Object
Figure out how many jobs are left based on the queue size when we started and how many of them are left.
-
#size ⇒ Object
Returns an integer representing the size of the queue.
-
#store_job_count_for_session ⇒ Object
Store how many jobs we’re starting with so that during the sync, we can determine the progress we’ve made.
Instance Attribute Details
#coder ⇒ Object
Encapsulation of encode/decode. Overwrite this to use it across QuickbooksWebConnector. This defaults to JSON for backwards compatibilty.
65 66 67 |
# File 'lib/quickbooks_web_connector.rb', line 65 def coder @coder ||= JsonCoder.new end |
Class Method Details
.config ⇒ Object
Global settings for QuickbooksWebConnector
13 14 15 |
# File 'lib/quickbooks_web_connector/config.rb', line 13 def self.config @config end |
.configure {|@config ||= QuickbooksWebConnector::Configuration.new| ... } ⇒ Object
Configure global settings for QuickbooksWebConnector
QuickbooksWebConnector.configure do |config|
config.server_version
end
8 9 10 |
# File 'lib/quickbooks_web_connector/config.rb', line 8 def self.configure(&block) yield @config ||= QuickbooksWebConnector::Configuration.new end |
.reset_configuration! ⇒ Object
17 18 19 20 |
# File 'lib/quickbooks_web_connector/config.rb', line 17 def self.reset_configuration! @config = QuickbooksWebConnector::Configuration.new set_default_configuration end |
.set_default_configuration ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/quickbooks_web_connector/config.rb', line 22 def self.set_default_configuration configure do |config| config.server_version = '1.0.0' config.minimum_web_connector_client_version = nil config.parent_controller = 'ApplicationController' config.app_name = 'My QBWC App' config.app_description = 'My QBWC App Description' end end |
Instance Method Details
#clear_job_count_for_session ⇒ Object
Clear the temporarily stored count of jobs for the sync session.
112 113 114 |
# File 'lib/quickbooks_web_connector.rb', line 112 def clear_job_count_for_session redis.del :queue_size end |
#decode(object) ⇒ Object
179 180 181 |
# File 'lib/quickbooks_web_connector.rb', line 179 def decode(object) coder.decode object end |
#dequeue(request_builder, response_handler, *args) ⇒ Object
This method can be used to conveniently remove a job from the queue.
86 87 88 |
# File 'lib/quickbooks_web_connector.rb', line 86 def dequeue(request_builder, response_handler, *args) Job.destroy(request_builder, response_handler, *args) end |
#encode(object) ⇒ Object
175 176 177 |
# File 'lib/quickbooks_web_connector.rb', line 175 def encode(object) coder.encode object end |
#enqueue(request_builder, response_handler, *args) ⇒ Object
This method can be used to conveniently add a job to the queue. It assumes the class you’re passing it is a real Ruby class (not a string or reference).
77 78 79 80 81 82 83 |
# File 'lib/quickbooks_web_connector.rb', line 77 def enqueue(request_builder, response_handler, *args) if redis.exists(:queue_size) redis.incr(:queue_size) end Job.create(request_builder, response_handler, *args) end |
#job_count_for_session ⇒ Object
Fetch the saved number of jobs for the session
107 108 109 |
# File 'lib/quickbooks_web_connector.rb', line 107 def job_count_for_session redis.get(:queue_size).to_i end |
#list_range(key, start = 0, stop = -1)) ⇒ Object
Does the dirty work of fetching a range of items from a Redis list and converting them into Ruby objects
169 170 171 172 173 |
# File 'lib/quickbooks_web_connector.rb', line 169 def list_range(key, start = 0, stop = -1) Array(redis.lrange(key, start, stop)).map do |item| decode item end end |
#peek ⇒ Object
Returns the next item currently queued, without removing it.
158 159 160 |
# File 'lib/quickbooks_web_connector.rb', line 158 def peek decode redis.lindex :queue, 0 end |
#pop ⇒ Object
Pops a job off the queue.
Returns a Ruby object.
148 149 150 |
# File 'lib/quickbooks_web_connector.rb', line 148 def pop decode redis.lpop(:queue) end |
#push(item) ⇒ Object
The ‘item` is expected to be a hash with the following keys:
xml - The XML to send to Quickbooks as a String.
class - The String name of the response handler.
args - An Array of arguments to pass the handler. Usually passed
via `class.to_class.perform(*args)`.
Example
QuickbooksWebConnector.push('xml' => '<some><xml></xml></some>', class' => 'CustomerAddResponseHandler', 'args' => [ 35 ])
Returns nothing
141 142 143 |
# File 'lib/quickbooks_web_connector.rb', line 141 def push(item) redis.rpush :queue, encode(item) end |
#redis ⇒ Object
Returns the current Redis connection. If none has been created, will create a new one.
57 58 59 60 61 |
# File 'lib/quickbooks_web_connector.rb', line 57 def redis return @redis if @redis self.redis = Redis.respond_to?(:connect) ? Redis.connect(:thread_safe => true) : "localhost:6379" self.redis end |
#redis=(server) ⇒ Object
Accepts:
1. A 'hostname:port' String
2. A 'hostname:port:db' String (to select the Redis db)
3. A 'hostname:port/namespace' String (to set the Redis namespace)
4. A Redis URL String 'redis://host:port'
5. An instance of `Redis`, `Redis::Client`, `Redis::DistRedis`,
or `Redis::Namespace`.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/quickbooks_web_connector.rb', line 34 def redis=(server) case server when String if server['redis://'] redis = Redis.connect(:url => server, :thread_safe => true) else server, namespace = server.split('/', 2) host, port, db = server.split(':') redis = Redis.new(:host => host, :port => port, :thread_safe => true, :db => db) end namespace ||= :qwc @redis = Redis::Namespace.new(namespace, :redis => redis) when Redis::Namespace @redis = server else @redis = Redis::Namespace.new(:qwc, :redis => server) end end |
#remove(item) ⇒ Object
Delete any matching items
163 164 165 |
# File 'lib/quickbooks_web_connector.rb', line 163 def remove(item) redis.lrem :queue, 0, encode(item) end |
#reserve ⇒ Object
This method will return a ‘QuickbooksWebConnector::Job` object or a non-true value depending on whether a job can be obtained.
92 93 94 |
# File 'lib/quickbooks_web_connector.rb', line 92 def reserve Job.reserve end |
#session_progress ⇒ Object
Figure out how many jobs are left based on the queue size when we started and how many of them are left
118 119 120 121 |
# File 'lib/quickbooks_web_connector.rb', line 118 def session_progress completed_jobs_count = job_count_for_session - QuickbooksWebConnector.size (completed_jobs_count.fdiv(job_count_for_session) * 100).ceil end |
#size ⇒ Object
Returns an integer representing the size of the queue.
153 154 155 |
# File 'lib/quickbooks_web_connector.rb', line 153 def size redis.llen :queue end |
#store_job_count_for_session ⇒ Object
Store how many jobs we’re starting with so that during the sync, we can determine the progress we’ve made.
102 103 104 |
# File 'lib/quickbooks_web_connector.rb', line 102 def store_job_count_for_session redis.set :queue_size, QuickbooksWebConnector.size end |