Class: Ve::HTTPInterface
- Inherits:
-
Object
- Object
- Ve::HTTPInterface
- Defined in:
- lib/ve.rb
Instance Method Summary collapse
-
#initialize(language, config = {}) ⇒ HTTPInterface
constructor
A new instance of HTTPInterface.
- #method_missing(function, *args) ⇒ Object
Constructor Details
#initialize(language, config = {}) ⇒ HTTPInterface
Returns a new instance of HTTPInterface.
70 71 72 73 |
# File 'lib/ve.rb', line 70 def initialize(language, config = {}) @language = language @base_url = config[:url] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(function, *args) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/ve.rb', line 75 def method_missing(function, *args) url = "#{@base_url}/#{@language}/#{function}" uri = URI.parse(url) response = Net::HTTP.post_form(uri, {:text => args[0]}) data = JSON.parse(response.body) result = [] data.each do |obj| # TODO: Support transliterations case obj['_class'] when 'Word' result << Ve::Word.new(obj['word'], obj['lemma'], obj['part_of_speech'], obj['tokens'], obj['extra'], obj['info']) end end result end |