Class: Shortwave::Facade::Build::RemoteMethod

Inherits:
Object
  • Object
show all
Defined in:
lib/shortwave/facade/build/facade_builder.rb

Overview

Represents an available method in the Last FM 'rest' api. Provides information about how to call the method.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(html) ⇒ RemoteMethod

Creates a RemoteMethod, given an html page from the Last FM API documentation.



186
187
188
189
190
191
192
193
194
195
# File 'lib/shortwave/facade/build/facade_builder.rb', line 186

def initialize(html)
  doc = Nokogiri::HTML(html)

  @remote_name     = doc.css(METHOD_NAME_CSS).text.strip
  @name            = @remote_name.sub(STARTS_WITH_GET,'').camel_to_snake.to_sym
  @parameters      = Parameter.parse(doc)
  @description     = doc.css(DESCRIPTION_CSS).text.strip.gsub(/\s+/, ' ')
  @http_method     = doc.css(METHOD_TYPE_CSS).text.include?("HTTP POST") ? :post : :get
  @sample_response = doc.css(SAMPLE_CSS).text.strip
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



183
184
185
# File 'lib/shortwave/facade/build/facade_builder.rb', line 183

def description
  @description
end

#http_methodObject (readonly)

Returns the value of attribute http_method.



183
184
185
# File 'lib/shortwave/facade/build/facade_builder.rb', line 183

def http_method
  @http_method
end

#nameObject (readonly)

Returns the value of attribute name.



183
184
185
# File 'lib/shortwave/facade/build/facade_builder.rb', line 183

def name
  @name
end

#parametersObject (readonly)

Returns the value of attribute parameters.



183
184
185
# File 'lib/shortwave/facade/build/facade_builder.rb', line 183

def parameters
  @parameters
end

#remote_nameObject (readonly)

Returns the value of attribute remote_name.



183
184
185
# File 'lib/shortwave/facade/build/facade_builder.rb', line 183

def remote_name
  @remote_name
end

#sample_responseObject (readonly)

Returns the value of attribute sample_response.



183
184
185
# File 'lib/shortwave/facade/build/facade_builder.rb', line 183

def sample_response
  @sample_response
end