mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2025-12-29 14:11:00 -05:00
Moving Fat from the controller to the Customer Model
This commit is contained in:
@@ -11,4 +11,23 @@
|
||||
class Qbo < ActiveRecord::Base
|
||||
unloadable
|
||||
validates_presence_of :token, :secret, :realmId, :token_expires_at, :reconnect_token_at
|
||||
|
||||
QB_KEY = Setting.plugin_redmine_qbo['settingsOAuthConsumerKey']
|
||||
QB_SECRET = Setting.plugin_redmine_qbo['settingsOAuthConsumerSecret']
|
||||
|
||||
$qb_oauth_consumer = OAuth::Consumer.new(QB_KEY, QB_SECRET, {
|
||||
:site => "https://oauth.intuit.com",
|
||||
:request_token_path => "/oauth/v1/get_request_token",
|
||||
:authorize_url => "https://appcenter.intuit.com/Connect/Begin",
|
||||
:access_token_path => "/oauth/v1/get_access_token"
|
||||
})
|
||||
|
||||
def self.get_auth_token
|
||||
qbo = first
|
||||
return OAuth::AccessToken.new($qb_oauth_consumer, qbo.token, qbo.secret)
|
||||
end
|
||||
|
||||
def self.get_oauth_consumer
|
||||
return $qb_oauth_consumer
|
||||
end
|
||||
end
|
||||
|
||||
@@ -12,4 +12,16 @@ class QboCustomers < ActiveRecord::Base
|
||||
unloadable
|
||||
has_many :issues
|
||||
attr_accessible :name
|
||||
|
||||
def self.update_all
|
||||
qbo = Qbo.first
|
||||
service = Quickbooks::Service::Customer.new(:company_id => qbo.realmId, :access_token => Qbo.get_auth_token)
|
||||
|
||||
# Update the customer table
|
||||
service.all.each { |customer|
|
||||
qbo_customer = QboCustomers.find_or_create_by(id: customer.id)
|
||||
qbo_customer.name = customer.display_name
|
||||
qbo_customer.save!
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user