Class: BusinessCentral::Client
- Inherits:
-
Object
- Object
- BusinessCentral::Client
- Includes:
- Object::ObjectHelper
- Defined in:
- lib/business_central/client.rb
Constant Summary collapse
- DEFAULT_LOGIN_URL =
'https://login.microsoftonline.com/common'
- DEFAULT_URL =
'https://api.businesscentral.dynamics.com/v2.0/production/api/v1.0'
Instance Attribute Summary collapse
-
#application_id ⇒ Object
readonly
Returns the value of attribute application_id.
-
#debug ⇒ Object
readonly
Returns the value of attribute debug.
-
#default_company_id ⇒ Object
readonly
Returns the value of attribute default_company_id.
-
#oauth2_access_token ⇒ Object
(also: #access_token)
readonly
Returns the value of attribute oauth2_access_token.
-
#oauth2_login_url ⇒ Object
readonly
Returns the value of attribute oauth2_login_url.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#secret_key ⇒ Object
readonly
Returns the value of attribute secret_key.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
-
#web_service_url ⇒ Object
readonly
Returns the value of attribute web_service_url.
Instance Method Summary collapse
- #authorize(params = {}, oauth_authorize_callback: '') ⇒ Object
- #authorize_from_token(token: '', refresh_token: '', expires_at: nil, expires_in: nil) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #refresh_token ⇒ Object
- #request_token(code = '', oauth_token_callback: '') ⇒ Object
- #web_service ⇒ Object
Methods included from Object::ObjectHelper
#method_missing, #respond_to_missing?
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/business_central/client.rb', line 26 def initialize( = {}) opts = .dup @username = opts.delete(:username) @password = opts.delete(:password) @url = opts.delete(:url) || DEFAULT_URL @web_service_url = opts.delete(:web_service_url) @application_id = opts.delete(:application_id) @secret_key = opts.delete(:secret_key) @oauth2_login_url = opts.delete(:oauth2_login_url) || DEFAULT_LOGIN_URL @default_company_id = opts.delete(:default_company_id) @debug = opts.delete(:debug) || false end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class BusinessCentral::Object::ObjectHelper
Instance Attribute Details
#application_id ⇒ Object (readonly)
Returns the value of attribute application_id.
13 14 15 |
# File 'lib/business_central/client.rb', line 13 def application_id @application_id end |
#debug ⇒ Object (readonly)
Returns the value of attribute debug.
13 14 15 |
# File 'lib/business_central/client.rb', line 13 def debug @debug end |
#default_company_id ⇒ Object (readonly)
Returns the value of attribute default_company_id.
13 14 15 |
# File 'lib/business_central/client.rb', line 13 def default_company_id @default_company_id end |
#oauth2_access_token ⇒ Object (readonly) Also known as: access_token
Returns the value of attribute oauth2_access_token.
13 14 15 |
# File 'lib/business_central/client.rb', line 13 def oauth2_access_token @oauth2_access_token end |
#oauth2_login_url ⇒ Object (readonly)
Returns the value of attribute oauth2_login_url.
13 14 15 |
# File 'lib/business_central/client.rb', line 13 def oauth2_login_url @oauth2_login_url end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
13 14 15 |
# File 'lib/business_central/client.rb', line 13 def password @password end |
#secret_key ⇒ Object (readonly)
Returns the value of attribute secret_key.
13 14 15 |
# File 'lib/business_central/client.rb', line 13 def secret_key @secret_key end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
13 14 15 |
# File 'lib/business_central/client.rb', line 13 def url @url end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
13 14 15 |
# File 'lib/business_central/client.rb', line 13 def username @username end |
#web_service_url ⇒ Object (readonly)
Returns the value of attribute web_service_url.
13 14 15 |
# File 'lib/business_central/client.rb', line 13 def web_service_url @web_service_url end |
Instance Method Details
#authorize(params = {}, oauth_authorize_callback: '') ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/business_central/client.rb', line 39 def (params = {}, oauth_authorize_callback: '') params[:redirect_uri] = begin oauth2_client.auth_code.(params) rescue OAuth2::Error => e handle_error(e) end end |
#authorize_from_token(token: '', refresh_token: '', expires_at: nil, expires_in: nil) ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/business_central/client.rb', line 54 def (token: '', refresh_token: '', expires_at: nil, expires_in: nil) @oauth2_access_token = OAuth2::AccessToken.new( oauth2_client, token, refresh_token: refresh_token, expires_at: expires_at, expires_in: expires_in ) end |
#refresh_token ⇒ Object
64 65 66 67 68 |
# File 'lib/business_central/client.rb', line 64 def refresh_token @oauth2_access_token.refresh! rescue OAuth2::Error => e handle_error(e) end |
#request_token(code = '', oauth_token_callback: '') ⇒ Object
48 49 50 51 52 |
# File 'lib/business_central/client.rb', line 48 def request_token(code = '', oauth_token_callback: '') oauth2_client.auth_code.get_token(code, redirect_uri: oauth_token_callback) rescue OAuth2::Error => e handle_error(e) end |
#web_service ⇒ Object
70 71 72 |
# File 'lib/business_central/client.rb', line 70 def web_service @web_service ||= BusinessCentral::WebService.new(client: self, url: web_service_url) end |