Class: Aliyun::Services::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/aliyun/services/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Base

Returns a new instance of Base.



17
18
19
20
# File 'lib/aliyun/services/base.rb', line 17

def initialize(options)
  self.access_key_id = options[:access_key_id]
  self.access_key_secret = options[:access_key_secret]
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/aliyun/services/base.rb', line 22

def method_missing(method, *args, &block)
  if service_actions.include?(action = method.to_sym)
    params = args[0].nil? ? {} : args[0]
    send_request(action, params)
  else
    super
  end
end

Instance Attribute Details

#access_key_idObject

Returns the value of attribute access_key_id.



15
16
17
# File 'lib/aliyun/services/base.rb', line 15

def access_key_id
  @access_key_id
end

#access_key_secretObject

Returns the value of attribute access_key_secret.



15
16
17
# File 'lib/aliyun/services/base.rb', line 15

def access_key_secret
  @access_key_secret
end

Instance Method Details

#api_versionObject



63
64
65
# File 'lib/aliyun/services/base.rb', line 63

def api_version
  service_definition[:version]
end

#base_urlObject



39
40
41
# File 'lib/aliyun/services/base.rb', line 39

def base_url
  "#{request_schema}://#{request_host}"
end

#http_methodObject



71
72
73
# File 'lib/aliyun/services/base.rb', line 71

def http_method
  'GET'
end

#nameObject



47
48
49
# File 'lib/aliyun/services/base.rb', line 47

def name
  self.class::NAME
end

#request_hostObject



51
52
53
# File 'lib/aliyun/services/base.rb', line 51

def request_host
  service_definition[:host]
end

#request_schemaObject



55
56
57
# File 'lib/aliyun/services/base.rb', line 55

def request_schema
  service_definition[:schema] || Aliyun.config.default_schema || 'https'
end

#respond_to?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
34
35
36
37
# File 'lib/aliyun/services/base.rb', line 31

def respond_to?(method, include_private = false)
  if service_actions.include?(method.to_sym)
    true
  else
    super
  end
end

#response_formatObject



59
60
61
# File 'lib/aliyun/services/base.rb', line 59

def response_format
  service_definition[:format] || Aliyun.config.default_format || 'JSON'
end

#secure?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/aliyun/services/base.rb', line 43

def secure?
  request_schema == 'https'
end

#separatorObject



67
68
69
# File 'lib/aliyun/services/base.rb', line 67

def separator
  "&"
end

#service_action_definitionsObject



87
88
89
# File 'lib/aliyun/services/base.rb', line 87

def service_action_definitions
  self.class.load_service_action_definitions(name)
end

#service_actionsObject



83
84
85
# File 'lib/aliyun/services/base.rb', line 83

def service_actions
  service_action_definitions.keys
end

#service_definitionObject



79
80
81
# File 'lib/aliyun/services/base.rb', line 79

def service_definition
  self.class.load_service_definition(name)
end

#signature_methodObject



75
76
77
# File 'lib/aliyun/services/base.rb', line 75

def signature_method
  Aliyun::SignatureMethods[service_definition[:signature_method]]
end