Class: NewsMonitor::API
- Inherits:
-
Object
- Object
- NewsMonitor::API
- Includes:
- HTTParty
- Defined in:
- lib/news_monitor/api.rb
Instance Method Summary collapse
- #find_article(article_id, options = {}) ⇒ Object
- #find_cluster(cluster_id, options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ API
constructor
A new instance of API.
- #search(query, options = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ API
Returns a new instance of API.
11 12 13 14 15 |
# File 'lib/news_monitor/api.rb', line 11 def initialize(={}) @auth = {} @auth[:username] = .fetch :username, ENV['NEWSMONITOR_USERNAME'] @auth[:password] = .fetch :password, ENV['NEWSMONITOR_PASSWORD'] end |
Instance Method Details
#find_article(article_id, options = {}) ⇒ Object
26 27 28 29 30 |
# File 'lib/news_monitor/api.rb', line 26 def find_article(article_id, ={}) .merge! basic_auth: @auth response = get "/article/#{article_id}", Article.parse(response) end |
#find_cluster(cluster_id, options = {}) ⇒ Object
32 33 34 35 36 |
# File 'lib/news_monitor/api.rb', line 32 def find_cluster(cluster_id, ={}) .merge! basic_auth: @auth response = get "/cluster/#{cluster_id}", Cluster.parse response['results'].first end |
#search(query, options = {}) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/news_monitor/api.rb', line 17 def search(query, ={}) conditions = ERB::Util.url_encode(query) .merge! basic_auth: @auth response = get "/search/#{conditions}", response['results'].map! do |cluster| Cluster.parse(cluster) end end |