Class: MajesticSeo::Api::Response
- Inherits:
-
Object
- Object
- MajesticSeo::Api::Response
- Defined in:
- lib/majestic_seo/api/response.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#code ⇒ Object
Returns the value of attribute code.
-
#error_message ⇒ Object
Returns the value of attribute error_message.
-
#full_error ⇒ Object
Returns the value of attribute full_error.
-
#global_variables ⇒ Object
Returns the value of attribute global_variables.
-
#items ⇒ Object
Returns the value of attribute items.
-
#response ⇒ Object
Returns the value of attribute response.
-
#success ⇒ Object
Returns the value of attribute success.
-
#table_key ⇒ Object
Returns the value of attribute table_key.
-
#tables ⇒ Object
Returns the value of attribute tables.
Instance Method Summary collapse
-
#initialize(response = nil) ⇒ Response
constructor
This method returns a new instance of the Response class.
- #parse_global_variables ⇒ Object
- #parse_response ⇒ Object
- #parse_table(table) ⇒ Object
- #parse_tables ⇒ Object
- #stacktrace ⇒ Object
- #success? ⇒ Boolean
Constructor Details
#initialize(response = nil) ⇒ Response
This method returns a new instance of the Response class. If one of the parameters are not provided, it will default to nil.
42 43 44 45 46 47 48 49 |
# File 'lib/majestic_seo/api/response.rb', line 42 def initialize(response = nil) @response = response @global_variables = {} @tables = {} @success = false parse_response end |
Instance Attribute Details
#code ⇒ Object
Returns the value of attribute code.
37 38 39 |
# File 'lib/majestic_seo/api/response.rb', line 37 def code @code end |
#error_message ⇒ Object
Returns the value of attribute error_message.
37 38 39 |
# File 'lib/majestic_seo/api/response.rb', line 37 def @error_message end |
#full_error ⇒ Object
Returns the value of attribute full_error.
37 38 39 |
# File 'lib/majestic_seo/api/response.rb', line 37 def full_error @full_error end |
#global_variables ⇒ Object
Returns the value of attribute global_variables.
38 39 40 |
# File 'lib/majestic_seo/api/response.rb', line 38 def global_variables @global_variables end |
#items ⇒ Object
Returns the value of attribute items.
38 39 40 |
# File 'lib/majestic_seo/api/response.rb', line 38 def items @items end |
#response ⇒ Object
Returns the value of attribute response.
36 37 38 |
# File 'lib/majestic_seo/api/response.rb', line 36 def response @response end |
#success ⇒ Object
Returns the value of attribute success.
38 39 40 |
# File 'lib/majestic_seo/api/response.rb', line 38 def success @success end |
#table_key ⇒ Object
Returns the value of attribute table_key.
36 37 38 |
# File 'lib/majestic_seo/api/response.rb', line 36 def table_key @table_key end |
#tables ⇒ Object
Returns the value of attribute tables.
36 37 38 |
# File 'lib/majestic_seo/api/response.rb', line 36 def tables @tables end |
Instance Method Details
#parse_global_variables ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/majestic_seo/api/response.rb', line 76 def parse_global_variables vars = @response.at_xpath("//GlobalVars") vars.attributes.each do |key, attribute| @global_variables[key.underscore] = attribute.value end if (vars && vars.attributes.any?) end |
#parse_response ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/majestic_seo/api/response.rb', line 51 def parse_response if (@response.is_a?(Nokogiri::XML::Document)) @response = (@response && @response.root) ? @response.root : nil elsif (@response.is_a?(Faraday::Response)) @response = (@response && @response.body) ? ::Nokogiri::XML(@response.body, nil, "utf-8").try(:root) : nil end if (@response) @response.attributes.each do |key, attribute| self.send("#{key.underscore}=", attribute.value) end @success = (@code && @code.downcase.eql?("ok")) if (success?) parse_global_variables parse_tables end end end |
#parse_table(table) ⇒ Object
104 105 106 107 |
# File 'lib/majestic_seo/api/response.rb', line 104 def parse_table(table) parsed_table = MajesticSeo::Api::DataTable.new(table) @tables[parsed_table.name] = parsed_table end |
#parse_tables ⇒ Object
96 97 98 99 100 101 102 |
# File 'lib/majestic_seo/api/response.rb', line 96 def parse_tables tables = @response.xpath("//DataTables/DataTable") tables.each do |table| parse_table(table) end if (tables && tables.any?) end |
#stacktrace ⇒ Object
84 85 86 |
# File 'lib/majestic_seo/api/response.rb', line 84 def stacktrace @full_error end |
#success? ⇒ Boolean
72 73 74 |
# File 'lib/majestic_seo/api/response.rb', line 72 def success? @success end |