Module: EffectiveQbOnline
- Includes:
- EffectiveGem
- Defined in:
- lib/effective_qb_online.rb,
lib/effective_qb_online/engine.rb,
lib/effective_qb_online/version.rb,
lib/generators/effective_qb_online/install_generator.rb
Defined Under Namespace
Modules: Generators Classes: Engine
Constant Summary collapse
- VERSION =
'0.9.8'.freeze
Class Method Summary collapse
- .api(realm: nil) ⇒ Object
- .config_keys ⇒ Object
- .mailer_class ⇒ Object
- .oauth2_client ⇒ Object
- .skip_order!(order) ⇒ Object
-
.sync_item_names! ⇒ Object
Syncs the QuickBooks Online item names down into Effective::ItemName.
- .sync_order!(order, perform_now: false) ⇒ Object
Class Method Details
.api(realm: nil) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/effective_qb_online.rb', line 37 def self.api(realm: nil) realm ||= Effective::QbRealm.first return nil if realm.blank? Effective::QbApi.new(realm: realm) end |
.config_keys ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/effective_qb_online.rb', line 9 def self.config_keys [ :qb_realms_table_name, :qb_receipts_table_name, :qb_receipt_items_table_name, :mailer, :parent_mailer, :deliver_method, :mailer_layout, :mailer_sender, :mailer_admin, :mailer_subject, :oauth_client_id, :oauth_client_secret, :layout, :sync_error_cc_recipients ] end |
.mailer_class ⇒ Object
20 21 22 |
# File 'lib/effective_qb_online.rb', line 20 def self.mailer_class mailer&.constantize || Effective::QbOnlineMailer end |
.oauth2_client ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/effective_qb_online.rb', line 24 def self.oauth2_client @oauth2_client ||= OAuth2::Client.new( oauth_client_id, oauth_client_secret, site: 'https://appcenter.intuit.com/connect/oauth2', authorize_url: 'https://appcenter.intuit.com/connect/oauth2', token_url: 'https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer', connection_opts: { request: { open_timeout: 10, timeout: 30 } } ) end |
.skip_order!(order) ⇒ Object
57 58 59 60 61 62 |
# File 'lib/effective_qb_online.rb', line 57 def self.skip_order!(order) raise 'expected a purchased Effective::Order' unless order.kind_of?(Effective::Order) && order.purchased? qb_receipt = Effective::QbReceipt.create_from_order!(order) qb_receipt.skip! end |
.sync_item_names! ⇒ Object
Syncs the QuickBooks Online item names down into Effective::ItemName
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/effective_qb_online.rb', line 65 def self.sync_item_names! client = api() raise 'expected a connected QuickBooks Online realm' if client.blank? qb_item_names = client.item_names raise 'QuickBooks Online returned no items' if qb_item_names.blank? qb_item_names.each do |name| item_name = Effective::ItemName.where(name: name).first_or_initialize if item_name.new_record? item_name.save! elsif item_name.archived? item_name.unarchive! end end Effective::ItemName.unarchived.where.not(name: qb_item_names).find_each do |item_name| item_name.archive! end true end |
.sync_order!(order, perform_now: false) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/effective_qb_online.rb', line 44 def self.sync_order!(order, perform_now: false) raise 'expected a purchased Effective::Order' unless order.kind_of?(Effective::Order) && order.purchased? if perform_now qb_receipt = Effective::QbReceipt.create_from_order!(order) qb_receipt.sync! else QbSyncOrderJob.perform_later(order) end true end |