Class: Awis::API::Base

Inherits:
Object
  • Object
show all
Includes:
Utils::Extra
Defined in:
lib/awis/api/base.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utils::Extra

camelize

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



7
8
9
# File 'lib/awis/api/base.rb', line 7

def arguments
  @arguments
end

#response_bodyObject (readonly)

Returns the value of attribute response_body.



7
8
9
# File 'lib/awis/api/base.rb', line 7

def response_body
  @response_body
end

Class Method Details

.loading_data_from_xml(xml_file_path) ⇒ Object



48
49
50
# File 'lib/awis/api/base.rb', line 48

def loading_data_from_xml(xml_file_path)
  MultiXml.parse(File.new(xml_file_path))
end

Instance Method Details

#action_nameObject



32
33
34
# File 'lib/awis/api/base.rb', line 32

def action_name
  self.class.name.split(/\:\:/)[-1]
end

#before_validation_arguments(arguments) ⇒ Object

Raises:



42
43
44
45
# File 'lib/awis/api/base.rb', line 42

def before_validation_arguments(arguments)
  raise ArgumentError, "Invalid arguments. should be like { url: 'site.com' }" unless arguments.is_a?(Hash)
  raise ArgumentError, 'Invalid arguments. the url must be configured.' unless arguments.key?(:url)
end

#fetch(arguments = {}) ⇒ Object



9
10
11
12
13
14
# File 'lib/awis/api/base.rb', line 9

def fetch(arguments = {})
  validation_arguments!(arguments)

  loading_response_body
  self
end

#load_request_uri(params) ⇒ Object



36
37
38
39
40
# File 'lib/awis/api/base.rb', line 36

def load_request_uri(params)
  collection = Awis::Connection.new
  collection.set_params(params)
  collection.send(:uri)
end

#loading_response_bodyObject



24
25
26
# File 'lib/awis/api/base.rb', line 24

def loading_response_body
  @response_body = Awis::Connection.new.get(params)
end

#parsed_bodyObject



20
21
22
# File 'lib/awis/api/base.rb', line 20

def parsed_body
  @parsed_body ||= MultiXml.parse(response_body)
end

#request_description_paramsObject



16
17
18
# File 'lib/awis/api/base.rb', line 16

def request_description_params
  arguments[:descriptions].to_s.capitalize
end

#root_node_nameObject



28
29
30
# File 'lib/awis/api/base.rb', line 28

def root_node_name
  "#{action_name}Response"
end