Class: Baiwang::Api
Instance Attribute Summary collapse
-
#admin_password ⇒ Object
readonly
Returns the value of attribute admin_password.
-
#admin_salt ⇒ Object
readonly
Returns the value of attribute admin_salt.
-
#admin_username ⇒ Object
readonly
Returns the value of attribute admin_username.
-
#app_key ⇒ Object
readonly
Returns the value of attribute app_key.
-
#app_secret ⇒ Object
readonly
Returns the value of attribute app_secret.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #app_access_token ⇒ Object
-
#initialize(options = {}) ⇒ Api
constructor
A new instance of Api.
- #post(method, payload, headers = {}) ⇒ Object
- #request ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(options = {}) ⇒ Api
Returns a new instance of Api.
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/baiwang/api.rb', line 17 def initialize( = {}) @app_key = .delete(:app_key) || Baiwang.config.default_app_key @app_secret = .delete(:app_secret) || Baiwang.config.default_app_secret @admin_username = .delete(:admin_username) || Baiwang.config.default_admin_username @admin_password = .delete(:admin_password) || Baiwang.config.default_admin_password @admin_salt = .delete(:admin_salt) || Baiwang.config.default_admin_salt raise AppNotConfigException if @app_key.empty? || @app_secret.empty? || @admin_username.empty? || @admin_password.empty? || @admin_salt.empty? @options = end |
Instance Attribute Details
#admin_password ⇒ Object (readonly)
Returns the value of attribute admin_password.
15 16 17 |
# File 'lib/baiwang/api.rb', line 15 def admin_password @admin_password end |
#admin_salt ⇒ Object (readonly)
Returns the value of attribute admin_salt.
15 16 17 |
# File 'lib/baiwang/api.rb', line 15 def admin_salt @admin_salt end |
#admin_username ⇒ Object (readonly)
Returns the value of attribute admin_username.
15 16 17 |
# File 'lib/baiwang/api.rb', line 15 def admin_username @admin_username end |
#app_key ⇒ Object (readonly)
Returns the value of attribute app_key.
15 16 17 |
# File 'lib/baiwang/api.rb', line 15 def app_key @app_key end |
#app_secret ⇒ Object (readonly)
Returns the value of attribute app_secret.
15 16 17 |
# File 'lib/baiwang/api.rb', line 15 def app_secret @app_secret end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
15 16 17 |
# File 'lib/baiwang/api.rb', line 15 def @options end |
Class Method Details
.default ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/baiwang/api.rb', line 54 def default @default ||= new( app_key: Baiwang.config.default_app_key, app_secret: Baiwang.config.default_app_secret, admin_username: Baiwang.config.default_admin_username, admin_password: Baiwang.config.default_admin_password, admin_salt: Baiwang.config.default_admin_salt, ) end |
Instance Method Details
#app_access_token ⇒ Object
41 42 43 |
# File 'lib/baiwang/api.rb', line 41 def app_access_token app_token_store.token end |
#post(method, payload, headers = {}) ⇒ Object
37 38 39 |
# File 'lib/baiwang/api.rb', line 37 def post(method, payload, headers = {}) request.post method, app_access_token, payload, headers end |
#request ⇒ Object
33 34 35 |
# File 'lib/baiwang/api.rb', line 33 def request @request ||= Baiwang::Request.new end |
#valid? ⇒ Boolean
29 30 31 |
# File 'lib/baiwang/api.rb', line 29 def valid? app_token_store.valid? end |