cinch-news 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/cinch/plugins/news.rb +89 -0
  3. metadata +6 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
- metadata.gz: 8c7fb9c7dc2b467ce126f189ba2ab342aca3a75e
4
- data.tar.gz: 0de4f9ddc2aa6c9c3d89e8b2f2d8194d5086a3e6
3
+ metadata.gz: 66bb861417cb43f4104ca0063d91267a4898cb2c
4
+ data.tar.gz: 141ff2d85f4c1665794d9c9644a39cd2001e4c1e
5
5
  SHA512:
6
- metadata.gz: 917234af37fa8651e4b3533c6d13e4a6cef6e747a5ac2fdae6d248d2de4de979dedf8b5d4189fb095ef49dbb37ef007d985a90df6d19118cfc71d991ece37c06
7
- data.tar.gz: 731e3fe309e9160227848e48df7aeee2817d51498ccbec87f51a76ce8cd184a43663cdb6236c90e4fdf370bc74eb102b8aae45147596003e9d9830ce1f55e198
6
+ metadata.gz: 21751bdbc3838edea21510528732446d5da105336ef9fd8a19987818697818ccd40b4921a444cd7650e60e459b6618bd6b3e8813ebaeb17107b58b87b6f09953
7
+ data.tar.gz: 991040fbe9be311764ad1515d60f7e8e9be59480deb62e937f97f673515b626e1e0e2c9bc69a8dc6725b09e850d23990c47cbc8ab1ff95eae122bbefde1bea57
@@ -0,0 +1,89 @@
1
+ # @author Richard Banks <namaste@rawrnet.net>
2
+
3
+ # Feel free to join us in #Lobby on irc://rawr.sinsira.net where you can test this gem and get help!
4
+
5
+ require 'cinch'
6
+ require 'ostruct'
7
+ require 'open-uri'
8
+ require 'json'
9
+ require 'cgi'
10
+ require 'cinch/toolbox'
11
+
12
+ module Cinch
13
+ module Plugins
14
+ class News
15
+ include Cinch::Plugin
16
+
17
+ match /news$/, method: :top_news
18
+
19
+ match /news (tech|money|travel|sports|life|weather|nation|offbeat|washington|world|religion|opinion|health|nfl|mlb|nba|nhl|collegefootball|collegebasketball|highschool|motorsports|golf|soccer|olympics|horseracing|people|books|music|movies)/, method: :category_news
20
+
21
+ match /s-news (.+)/, method: :search_news
22
+
23
+ def top_news(m)
24
+ data = fetch_news(m)
25
+ return m.reply "There was a problem fetching the news." if data.empty?
26
+ output_news(m, data)
27
+ end
28
+
29
+ def category_news(m, category)
30
+ data = fetch_category(m, category)
31
+ return m.reply "There was a problem fetching the news for #{category}." if data.empty?
32
+ output_news(m, data)
33
+ end
34
+
35
+ def search_news(m, terms)
36
+ data = fetch_search(m, terms)
37
+ return m.reply "No news results found for #{terms}." if data == false
38
+ output_news(m, data)
39
+ end
40
+
41
+ def fetch_news(m)
42
+ key = config[:key]
43
+ data = JSON.parse(open("http://api.usatoday.com/open/articles/topnews?api_key=#{key}&encoding=json&count=3").read)
44
+ stories = data['stories']
45
+ output = []
46
+ stories.each{|i|
47
+ url = i['link']
48
+ url.gsub! /apidata./, ''
49
+ url = Cinch::Toolbox.shorten(url)
50
+ output.push("News: | \"%s\" | Description: %s [ #{url} ]" % [i['title'], i['description']])}
51
+ return output
52
+ end
53
+
54
+ def fetch_category(m, category)
55
+ key = config[:key]
56
+ data = JSON.parse(open("http://api.usatoday.com/open/articles/topnews/#{category}?api_key=#{key}&encoding=json&count=3").read)
57
+ stories = data['stories']
58
+ output = []
59
+ stories.each{|i|
60
+ url = i['link']
61
+ url.gsub! /apidata./, ''
62
+ url = Cinch::Toolbox.shorten(url)
63
+ output.push("News: | \"%s\" | Description: %s [ #{url} ]" % [i['title'], i['description']])}
64
+ return output
65
+ end
66
+
67
+ def fetch_search(m, terms)
68
+ key = config[:key]
69
+ search_uri = URI.encode("http://api.usatoday.com/open/articles?tag=#{terms}&count=3&api_key=#{key}&encoding=json")
70
+ data = JSON.parse(open("#{search_uri}").read)
71
+ stories = data['stories']
72
+ output = []
73
+ stories.each{|i|
74
+ url = i['link']
75
+ url.gsub! /apidata./, ''
76
+ url = Cinch::Toolbox.shorten(url)
77
+ output.push("News: | \"%s\" | Description: %s [ #{url} ]" % [i['title'], i['description']])}
78
+ return output
79
+ rescue JSON::ParserError
80
+ return false
81
+ end
82
+
83
+ def output_news(m, data)
84
+ return if data == false
85
+ data[0..2].each{|i| m.reply i}
86
+ end
87
+ end
88
+ end
89
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cinch-news
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Banks
@@ -38,14 +38,16 @@ dependencies:
38
38
  - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: 1.1.2
41
- description: A news gem/plugin for the Cinch IRC bot framework that uses a USA Today
42
- API.
41
+ description: ! 'A news gem/plugin for the Cinch IRC bot framework that uses a USA
42
+ Today API. You can visit irc://rawr.sinsira.net #Lobby to get help, report issues
43
+ , test the gem, or just chat.'
43
44
  email:
44
45
  - namaste@rawrnet.net
45
46
  executables: []
46
47
  extensions: []
47
48
  extra_rdoc_files: []
48
- files: []
49
+ files:
50
+ - lib/cinch/plugins/news.rb
49
51
  homepage: https://github.com/RawrNet/cinch-news
50
52
  licenses:
51
53
  - MIT