gaea 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4e92f131d442e8fe2c246ff46fd3b2ef8d4fb0e8
4
+ data.tar.gz: e64b1f4872cf6cdae4f3e23977f8cf920c16185d
5
+ SHA512:
6
+ metadata.gz: 95e213d303bbf17069bb1ebd9a0c4cce7f5921a9c1cadb6afa1e986c2d63daa05327d45f00b35ddccfac991e7d94edab69dabe84e38ccfdd5e9a47ce424e3ddc
7
+ data.tar.gz: 04cb85eb67e2bd6efa004f6b446ece498dfe72d53595b2f34ad6bc55d4ef3aa719bb6741c856d92beedfe3122b347177422ce843437edfdf7e19ed89360485a6
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'gaea'
5
+ require 'irb'
6
+
7
+ IRB.start
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'gaea'
4
+ Gaea::CLI::Looksfor.start(ARGV)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,8 @@
1
+ require 'gaea/version'
2
+ require 'gaea/invalid_source'
3
+ require 'gaea/option_missing'
4
+ require 'gaea/cli'
5
+
6
+ module Gaea
7
+ # Your code goes here...
8
+ end
@@ -0,0 +1,8 @@
1
+ require 'thor'
2
+ require 'httparty'
3
+ require 'rainbow'
4
+ require 'terminal-table'
5
+ require 'gaea/cli/lookfor'
6
+ require 'gaea/lib/stackoverflow'
7
+ require 'gaea/lib/rubygems'
8
+ require 'gaea/lib/confreaks'
@@ -0,0 +1,41 @@
1
+ module Gaea
2
+ module CLI
3
+ class Looksfor < Thor
4
+ # Search from multiple sources
5
+ #
6
+ # Options
7
+ #
8
+ # keyword - The keyword relate contents you wanna search
9
+ # source(require) - One of 3 values: 'stackoverflow', 'gems', 'confreaks'
10
+ # year(optional) - The year - will use with source confreaks
11
+ #
12
+ # Returns the results depend on source and keyword
13
+ desc 'looksfor', 'Search from multiple sources'
14
+ option :keyword, aliases: '-k', banner: 'The keyword relate to contents you wanna search'
15
+ option :source, aliases: '-s', banner: 'The source - 3 default values: stackoverflow, gems and confreaks'
16
+ option :year, aliases: '-y', banner: 'The year - only avalaible with source confreaks'
17
+ def looksfor
18
+ keyword = options[:keyword]
19
+
20
+ results = case options[:source]
21
+ when 'stackoverflow'
22
+ raise OptionMissing, 'Oops, man, make sure you have the keyword option in your command' unless keyword
23
+ stack = StackOverFlow.new(keyword)
24
+ stack.questions
25
+ when 'gems'
26
+ raise OptionMissing, 'Oops, man, make sure you have the keyword option in your command' unless keyword
27
+ rgem = RubyGems.new(keyword)
28
+ rgem.gems
29
+ when 'confreaks'
30
+ year = options[:year]
31
+ raise OptionMissing, 'Oops, man, make sure you have the year option in your command' unless year
32
+ conf = Confreaks.new(year)
33
+ keyword ? conf.events_of_year(keyword) : conf.events_of_year
34
+ else
35
+ raise InvalidSource, 'Hey man, you wrong the source. Please check again!'
36
+ end
37
+ puts Rainbow(results).bisque
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1 @@
1
+ class InvalidSource < StandardError; end
@@ -0,0 +1,110 @@
1
+ require 'date'
2
+
3
+ class Confreaks
4
+ # Attribute reader
5
+ attr_reader :year
6
+
7
+ # Include HTTParty
8
+ include HTTParty
9
+
10
+ base_uri 'confreaks.tv/api'
11
+
12
+ # Create constructor for Confreaks object
13
+ #
14
+ # year - The string of year
15
+ #
16
+ # Examples
17
+ #
18
+ # Confreaks.new('2015')
19
+ #
20
+ # Returns nothing
21
+ def initialize(year)
22
+ @year = year
23
+ end
24
+
25
+ # List events of year
26
+ #
27
+ # Examples
28
+ #
29
+ # conf = Confreaks.new('2015')
30
+ # conf.events_of_year or conf.events_of_year
31
+ # # =>
32
+ # +-----------------------------+------------------------------------------------------+------------+------------+
33
+ # | Event | Link | Start date | End date |
34
+ # +-----------------------------+------------------------------------------------------+------------+------------+
35
+ # | Ruby Kaigi 2015 | http://confreaks.tv/events/rubykaigi2015 | 2015-12-11 | 2015-12-13 |
36
+ # | Alter Conf Los Angeles 2015 | http://confreaks.tv/events/alterconf2015-los-angeles | 2015-11-21 | 2015-11-21 |
37
+ # | DockerCon EU 2015 | http://confreaks.tv/events/Dockerconeu2015 | 2015-11-15 | 2015-11-17 |
38
+ # | Ruby Conference 2015 | http://confreaks.tv/events/rubyconf2015 | 2015-11-15 | 2015-11-17 |
39
+ # +-----------------------------+------------------------------------------------------+------------+------------+
40
+ #
41
+ # Returns the table
42
+ def events_of_year(field = nil)
43
+ results = field ? events.select!{ |event| event['short_code'].downcase.include? field } : events
44
+
45
+ parse_events(results)
46
+ end
47
+
48
+ private
49
+
50
+ # Private: Create table of events
51
+ #
52
+ # events: List of events
53
+ #
54
+ # Examples
55
+ #
56
+ # parse_events
57
+ #
58
+ # Returns Terminal Table object
59
+ def parse_events(events)
60
+ event_rows = []
61
+ unless events.nil? || events.empty?
62
+ events.each do |event|
63
+ event_rows << [event['display_name'], "http://confreaks.tv/events/#{event['short_code']}", event_date(event['start_at']), event_date(event['end_at'])] if event_of_year?(event['short_code'])
64
+ end
65
+ return nil if event_rows.empty?
66
+ Terminal::Table.new headings: ['Event', 'Link', 'Start date', 'End date'], rows: event_rows
67
+ else
68
+ nil
69
+ end
70
+ end
71
+
72
+ # Private: List of events
73
+ #
74
+ # Examples
75
+ #
76
+ # events
77
+ #
78
+ # Returns the JSON list of events
79
+ def events
80
+ response = self.class.get('/v1/events.json')
81
+ response.code == 200 ? JSON.parse(response.body) : nil
82
+ end
83
+
84
+ # Private: Check event belongs year
85
+ #
86
+ # event - The event name
87
+ #
88
+ # Examples
89
+ #
90
+ # event_of_year?('Hello world 2015')
91
+ #
92
+ # Returns Boolean
93
+ def event_of_year?(event)
94
+ event.include? year
95
+ end
96
+
97
+ # Private: Converts string to date
98
+ #
99
+ # date - The string date
100
+ #
101
+ # Examples
102
+ #
103
+ # event_date("2015-09-25T00:00:00.000Z")
104
+ # # => "2015-09-25"
105
+ #
106
+ # Return Date
107
+ def event_date(date)
108
+ DateTime.parse(date).to_date.to_s
109
+ end
110
+ end
@@ -0,0 +1,76 @@
1
+ class RubyGems
2
+ # Attribute reader
3
+ attr_reader :option
4
+
5
+ # Include HTTParty
6
+ include HTTParty
7
+
8
+ base_uri 'rubygems.org/api/'
9
+
10
+ # Create constructor for RubyGems object
11
+ #
12
+ # query - The query
13
+ #
14
+ # Examples
15
+ #
16
+ # RubyGems.new('weather')
17
+ #
18
+ # Returns nothing
19
+ def initialize(query)
20
+ @option = { query: { query: query } }
21
+ end
22
+
23
+ # List of gems match with query
24
+ #
25
+ # Examples
26
+ #
27
+ # rgs = RubyGems.new('weather')
28
+ # rgs.gems
29
+ # # =>
30
+ # +------+-----------------------------------------------+----------------------------------+-------------+-----------+
31
+ # | Name | Info | URL | Authors | Downloads |
32
+ # +------+-----------------------------------------------+----------------------------------+-------------+-----------+
33
+ # | weer | Display the weather information of your city. | https://github.com/vinhnglx/weer | Vinh Nguyen | 134 |
34
+ # +------+-----------------------------------------------+----------------------------------+-------------+-----------+
35
+ # Returns the table
36
+ def gems
37
+ # TODO: need to get more questions - Apply paginates
38
+ parse_gems
39
+ end
40
+
41
+ private
42
+
43
+ # Private: List of raw gems
44
+ #
45
+ # option - The query option
46
+ #
47
+ # Examples
48
+ #
49
+ # connect(option)
50
+ #
51
+ # Returns the JSON list of raw gems.
52
+ def connect(option)
53
+ response = self.class.get('/v1/search.json', option)
54
+ response.code == 200 ? JSON.parse(response.body) : nil
55
+ end
56
+
57
+ # Private: Create table list of gems
58
+ #
59
+ # Examples
60
+ #
61
+ # parse_gems
62
+ #
63
+ # Returns terminal table object
64
+ def parse_gems
65
+ gem_rows = []
66
+ raws = connect(option)
67
+ unless raws.nil? || raws.empty?
68
+ raws.each do |g|
69
+ gem_rows << [g['name'], g['info'][0..60], g['project_uri'], g['authors'], g['downloads']]
70
+ end
71
+ Terminal::Table.new headings: ['Name', 'Info', 'URL', 'Authors', 'Downloads'], rows: gem_rows
72
+ else
73
+ nil
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,90 @@
1
+ class StackOverFlow
2
+ # Attribute reader
3
+ attr_reader :options
4
+
5
+ # Include HTTParty
6
+ include HTTParty
7
+
8
+ # Page size
9
+ PAGE_SIZE = 10
10
+
11
+ base_uri 'api.stackexchange.com'
12
+
13
+ # Create constructor for StackOverFlow object.
14
+ #
15
+ # keywords - The keywords will match all questions.
16
+ #
17
+ # Examples
18
+ #
19
+ # StackOverFlow.new('Ruby on Rails')
20
+ #
21
+ # Returns nothing
22
+ def initialize(keywords)
23
+ @options = { query: { pagesize: PAGE_SIZE, q: keywords, accepted: true, site: 'stackoverflow' } }
24
+ end
25
+
26
+ # List of ten questions based on attributes.
27
+ #
28
+ # Examples
29
+ #
30
+ # stackoverflow = StackOverFlow.new('activerecord nomethod error', true)
31
+ # stackoverflow.questions
32
+ # # =>
33
+ # +---------------+-----------------------------------------------------------------------------------+-------------------------------------+-------------------------------------+
34
+ # | Owner | Title | Question | Accepted Answer |
35
+ # +---------------+-----------------------------------------------------------------------------------+-------------------------------------+-------------------------------------+
36
+ # | Daniel Cukier | Discover errors in Invalid Record factory girl | http://stackoverflow.com/q/23374576 | http://stackoverflow.com/a/23374747 |
37
+ # | Chris Mendla | Rails delete record fails | http://stackoverflow.com/q/35232445 | http://stackoverflow.com/a/35235143 |
38
+ # | Jorrin | Manually assigning parent ID with has_many/belongs_to association in custom class | http://stackoverflow.com/q/35193155 | http://stackoverflow.com/a/35201406 |
39
+ # | simonmorley | Rails i18n Attributes Not Working via JSON API | http://stackoverflow.com/q/35113584 | http://stackoverflow.com/a/35117092 |
40
+ # | NeoP5 | Sonarqube 5.3: Error installing on Oracle 12 - columns missing | http://stackoverflow.com/q/34807593 | http://stackoverflow.com/a/35008747 |
41
+ # | kannet | Invalid single-table inheritance type: dog is not a subclass of Pet | http://stackoverflow.com/q/34988853 | http://stackoverflow.com/a/34989090 |
42
+ # | Brittany | NoMethodError in Users#show error? | http://stackoverflow.com/q/34980742 | http://stackoverflow.com/a/34980943 |
43
+ # | Mac | Python POST binary data | http://stackoverflow.com/q/14365027 | http://stackoverflow.com/a/14448953 |
44
+ # | CuriousMind | railstutorial.org, Chapter 6. unknown attribute: password | http://stackoverflow.com/q/12142374 | http://stackoverflow.com/a/12142417 |
45
+ # | Brittany | Empty database, user already exists message? | http://stackoverflow.com/q/34862365 | http://stackoverflow.com/a/34862683 |
46
+ # +---------------+-----------------------------------------------------------------------------------+-------------------------------------+-------------------------------------+
47
+ #
48
+ # Returns the table
49
+ def questions
50
+ # TODO: need to get more questions - Apply paginates
51
+ parse_questions
52
+ end
53
+
54
+ private
55
+
56
+ # Private: List of raw question
57
+ #
58
+ # options - The query options
59
+ #
60
+ # Examples
61
+ #
62
+ # connect(options)
63
+ #
64
+ # Returns the JSON list of raw questions
65
+ def connect(options)
66
+ response = self.class.get('/2.2/search/advanced', options)
67
+ response.code == 200 ? JSON.parse(response.body)['items'] : nil
68
+ end
69
+
70
+ # Private: Create table list of questions
71
+ #
72
+ # Examples
73
+ #
74
+ # parse_questions
75
+ #
76
+ # Returns terminal table object
77
+ def parse_questions
78
+ question_rows = []
79
+ raws = connect(options)
80
+ unless raws.nil? || raws.empty?
81
+ raws.each do |q|
82
+ owner = q['owner']
83
+ question_rows << [owner['display_name'], q['title'], "http://stackoverflow.com/q/#{q['question_id']}", "http://stackoverflow.com/a/#{q['accepted_answer_id']}"]
84
+ end
85
+ Terminal::Table.new headings: ['Owner', 'Title', 'Question', 'Accepted Answer'], rows: question_rows
86
+ else
87
+ nil
88
+ end
89
+ end
90
+ end
@@ -0,0 +1 @@
1
+ class OptionMissing < StandardError; end
@@ -0,0 +1,3 @@
1
+ module Gaea
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,183 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gaea
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Vinh Nguyen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-02-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: coveralls
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: thor
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: httparty
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: terminal-table
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rainbow
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: Search everything from StackOverFlow, Rubygems.
140
+ email:
141
+ - vinh.nglx@gmail.com
142
+ executables:
143
+ - gaea
144
+ extensions: []
145
+ extra_rdoc_files: []
146
+ files:
147
+ - bin/console
148
+ - bin/gaea
149
+ - bin/setup
150
+ - lib/gaea.rb
151
+ - lib/gaea/cli.rb
152
+ - lib/gaea/cli/lookfor.rb
153
+ - lib/gaea/invalid_source.rb
154
+ - lib/gaea/lib/confreaks.rb
155
+ - lib/gaea/lib/rubygems.rb
156
+ - lib/gaea/lib/stackoverflow.rb
157
+ - lib/gaea/option_missing.rb
158
+ - lib/gaea/version.rb
159
+ homepage: http://www.todayifoundout.net/
160
+ licenses:
161
+ - MIT
162
+ metadata: {}
163
+ post_install_message:
164
+ rdoc_options: []
165
+ require_paths:
166
+ - lib
167
+ required_ruby_version: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - ">="
170
+ - !ruby/object:Gem::Version
171
+ version: '0'
172
+ required_rubygems_version: !ruby/object:Gem::Requirement
173
+ requirements:
174
+ - - ">="
175
+ - !ruby/object:Gem::Version
176
+ version: '0'
177
+ requirements: []
178
+ rubyforge_project:
179
+ rubygems_version: 2.4.8
180
+ signing_key:
181
+ specification_version: 4
182
+ summary: Gaea - Simple search CLI tool.
183
+ test_files: []