Class: Baiwang::Api

Inherits:
Object
  • Object
show all
Includes:
Helper
Defined in:
lib/baiwang/api.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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(options = {})
  @app_key = options.delete(:app_key) || Baiwang.config.default_app_key
  @app_secret = options.delete(:app_secret) || Baiwang.config.default_app_secret
  @admin_username = options.delete(:admin_username) || Baiwang.config.default_admin_username
  @admin_password = options.delete(:admin_password) || Baiwang.config.default_admin_password
  @admin_salt = options.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 = options
end

Instance Attribute Details

#admin_passwordObject (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_saltObject (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_usernameObject (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_keyObject (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_secretObject (readonly)

Returns the value of attribute app_secret.



15
16
17
# File 'lib/baiwang/api.rb', line 15

def app_secret
  @app_secret
end

#optionsObject (readonly)

Returns the value of attribute options.



15
16
17
# File 'lib/baiwang/api.rb', line 15

def options
  @options
end

Class Method Details

.defaultObject



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_tokenObject



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

#requestObject



33
34
35
# File 'lib/baiwang/api.rb', line 33

def request
  @request ||= Baiwang::Request.new
end

#valid?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/baiwang/api.rb', line 29

def valid?
  app_token_store.valid?
end