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/config.rb,
lib/quickbooks_web_connector/engine.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,
app/controllers/quickbooks_web_connector/application_controller.rb,
lib/quickbooks_web_connector/soap_wrapper/defaultMappingRegistry.rb

Defined Under Namespace

Modules: ApplicationHelper, SoapWrapper Classes: ApplicationController, Configuration, DecodeException, EncodeException, Engine, Job, JsonCoder, QwcController, SoapController

Constant Summary collapse

VERSION =
"0.0.1"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#coderObject

Encapsulation of encode/decode. Overwrite this to use it across QuickbooksWebConnector. This defaults to JSON for backwards compatibilty.



58
59
60
# File 'lib/quickbooks_web_connector.rb', line 58

def coder
  @coder ||= JsonCoder.new
end

Class Method Details

.configObject

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

Instance Method Details

#decode(object) ⇒ Object



123
124
125
# File 'lib/quickbooks_web_connector.rb', line 123

def decode(object)
  coder.decode object
end

#encode(object) ⇒ Object



119
120
121
# File 'lib/quickbooks_web_connector.rb', line 119

def encode(object)
  coder.encode object
end

#enqueue(xml, klass, *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).



70
71
72
# File 'lib/quickbooks_web_connector.rb', line 70

def enqueue(xml, klass, *args)
  Job.create(xml, klass, *args)
end

#peekObject

Returns the next item currently queued, without removing it.



115
116
117
# File 'lib/quickbooks_web_connector.rb', line 115

def peek
  decode redis.lindex :queue, 0
end

#popObject

Pops a job off the queue.

Returns a Ruby object.



105
106
107
# File 'lib/quickbooks_web_connector.rb', line 105

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



98
99
100
# File 'lib/quickbooks_web_connector.rb', line 98

def push(item)
  redis.rpush :queue, encode(item)
end

#redisObject

Returns the current Redis connection. If none has been created, will create a new one.



50
51
52
53
54
# File 'lib/quickbooks_web_connector.rb', line 50

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`.


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/quickbooks_web_connector.rb', line 27

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

#reserveObject

This method will return a ‘QuickbooksWebConnector::Job` object or a non-true value depending on whether a job can be obtained.



76
77
78
# File 'lib/quickbooks_web_connector.rb', line 76

def reserve
  Job.reserve
end

#sizeObject

Returns an integer representing the size of the queue.



110
111
112
# File 'lib/quickbooks_web_connector.rb', line 110

def size
  redis.llen :queue
end