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.



5
6
7
# File 'lib/awis/api/base.rb', line 5

def arguments
  @arguments
end

#response_bodyObject (readonly)

Returns the value of attribute response_body.



5
6
7
# File 'lib/awis/api/base.rb', line 5

def response_body
  @response_body
end

Class Method Details

.loading_data_from_xml(xml_file_path) ⇒ Object



46
47
48
# File 'lib/awis/api/base.rb', line 46

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

Instance Method Details

#action_nameObject



30
31
32
# File 'lib/awis/api/base.rb', line 30

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

#before_validation_arguments(arguments) ⇒ Object

Raises:



40
41
42
43
# File 'lib/awis/api/base.rb', line 40

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.has_key?(:url)
end

#fetch(arguments = {}) ⇒ Object



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

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

  loading_response_body
  self
end

#load_request_uri(params) ⇒ Object



34
35
36
37
38
# File 'lib/awis/api/base.rb', line 34

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

#loading_response_bodyObject



22
23
24
# File 'lib/awis/api/base.rb', line 22

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

#parsed_bodyObject



18
19
20
# File 'lib/awis/api/base.rb', line 18

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

#request_description_paramsObject



14
15
16
# File 'lib/awis/api/base.rb', line 14

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

#root_node_nameObject



26
27
28
# File 'lib/awis/api/base.rb', line 26

def root_node_name
  "#{action_name}Response"
end