Class: ViewText
- Inherits:
-
Object
- Object
- ViewText
- Defined in:
- lib/viewtext/viewtext.rb
Instance Method Summary collapse
- #connection(url, opts = {}) ⇒ Object
- #fetch ⇒ Object
-
#initialize(target_url) ⇒ ViewText
constructor
A new instance of ViewText.
- #viewtext_url ⇒ Object
Constructor Details
#initialize(target_url) ⇒ ViewText
Returns a new instance of ViewText.
10 11 12 |
# File 'lib/viewtext/viewtext.rb', line 10 def initialize(target_url) @target_url = target_url end |
Instance Method Details
#connection(url, opts = {}) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/viewtext/viewtext.rb', line 31 def connection(url, opts={}) if ENV['http_proxy'] opts.merge!({ :proxy => ENV['http_proxy'] }) end conn = Faraday.new(url, opts) end |
#fetch ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/viewtext/viewtext.rb', line 18 def fetch conn = connection(viewtext_url) begin response = conn.get data = JSON.parse(response.body) data["content"] = Sanitize.clean(data["content"]) return ViewTextResponse.new(data) rescue Faraday::Error::ParsingError => e return nil end end |
#viewtext_url ⇒ Object
14 15 16 |
# File 'lib/viewtext/viewtext.rb', line 14 def viewtext_url "http://viewtext.org/api/text?url=#{@target_url}&format=json" end |