metonym 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Metonym
2
- VERSION = "1.0.0"
4
+ VERSION = '1.0.1'
3
5
  end
@@ -1,41 +1,43 @@
1
+ # frozen_string_literal: true
1
2
 
2
- lib = File.expand_path("../lib", __FILE__)
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "metonym/version"
5
+ require 'metonym/version'
5
6
 
6
7
  Gem::Specification.new do |spec|
7
- spec.name = "metonym"
8
+ spec.name = 'metonym'
8
9
  spec.version = Metonym::VERSION
9
- spec.authors = ["Vic Carrasco"]
10
- spec.email = ["vic@viccarrasco.com"]
11
- spec.summary = "The unofficial Google News API gem"
12
- spec.description = "Query news from Google News' sources"
13
- spec.homepage = "https://github.com/viccarrasco/metonym"
14
- spec.license = "MIT"
10
+ spec.authors = ['Vic Carrasco']
11
+ spec.email = ['vic@viccarrasco.com']
12
+ spec.summary = 'The unofficial Google News API gem'
13
+ spec.description = 'Query news from Google News\' sources'
14
+ spec.homepage = 'https://github.com/viccarrasco/metonym'
15
+ spec.license = 'MIT'
15
16
 
16
17
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
18
  # to allow pushing to a single host or delete this section to allow pushing to any host.
18
19
  if spec.respond_to?(:metadata)
19
- spec.metadata["allowed_push_host"] = "https://rubygems.org"
20
- spec.metadata["homepage_uri"] = spec.homepage
21
- spec.metadata["source_code_uri"] = "https://github.com/viccarrasco/metonym"
22
- spec.metadata["changelog_uri"] = "https://github.com/viccarrasco/metonym/blob/master/CHANGE_LOG.md"
20
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
21
+ spec.metadata['homepage_uri'] = spec.homepage
22
+ spec.metadata['source_code_uri'] = 'https://github.com/viccarrasco/metonym'
23
+ spec.metadata['changelog_uri'] = 'https://github.com/viccarrasco/metonym/blob/master/CHANGE_LOG.md'
23
24
  else
24
- raise "RubyGems 2.0 or newer is required to protect against " \
25
- "public gem pushes."
25
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
26
+ 'public gem pushes.'
26
27
  end
27
28
 
28
29
  # Specify which files should be added to the gem when it is released.
29
30
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
30
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
31
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
31
32
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
32
33
  end
33
- spec.bindir = "exe"
34
+ spec.bindir = 'exe'
34
35
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
35
- spec.require_paths = ["lib"]
36
+ spec.require_paths = ['lib']
36
37
 
37
- spec.add_development_dependency "bundler", "~> 2.0"
38
- spec.add_development_dependency "rake", "~> 10.0"
39
- spec.add_development_dependency "rspec", "~> 3.0"
40
- spec.add_development_dependency "byebug"
38
+ spec.add_development_dependency 'bundler', '~> 2.0'
39
+ spec.add_development_dependency 'byebug'
40
+ spec.add_development_dependency 'guard'
41
+ spec.add_development_dependency 'rake', '~> 12.3.3'
42
+ spec.add_development_dependency 'rspec', '~> 3.0'
41
43
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metonym
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vic Carrasco
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-05-24 00:00:00.000000000 Z
11
+ date: 2020-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -25,47 +25,61 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
28
+ name: byebug
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rspec
42
+ name: guard
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
59
  - - "~>"
46
60
  - !ruby/object:Gem::Version
47
- version: '3.0'
61
+ version: 12.3.3
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
66
  - - "~>"
53
67
  - !ruby/object:Gem::Version
54
- version: '3.0'
68
+ version: 12.3.3
55
69
  - !ruby/object:Gem::Dependency
56
- name: byebug
70
+ name: rspec
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
- - - ">="
73
+ - - "~>"
60
74
  - !ruby/object:Gem::Version
61
- version: '0'
75
+ version: '3.0'
62
76
  type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
- - - ">="
80
+ - - "~>"
67
81
  - !ruby/object:Gem::Version
68
- version: '0'
82
+ version: '3.0'
69
83
  description: Query news from Google News' sources
70
84
  email:
71
85
  - vic@viccarrasco.com
@@ -88,7 +102,15 @@ files:
88
102
  - lib/metonym.rb
89
103
  - lib/metonym/lib/gnews.rb
90
104
  - lib/metonym/lib/news_api.rb
91
- - lib/metonym/lib/validate.rb
105
+ - lib/metonym/lib/presenters/base_response_presenter.rb
106
+ - lib/metonym/lib/presenters/gnews_response_presenter.rb
107
+ - lib/metonym/lib/presenters/news_api_response_presenter.rb
108
+ - lib/metonym/lib/repositories/base_repository.rb
109
+ - lib/metonym/lib/repositories/gnews_repository.rb
110
+ - lib/metonym/lib/repositories/news_api_repository.rb
111
+ - lib/metonym/lib/validators/base_validator.rb
112
+ - lib/metonym/lib/validators/gnews_query_validator.rb
113
+ - lib/metonym/lib/validators/news_api_query_validator.rb
92
114
  - lib/metonym/version.rb
93
115
  - metonym.gemspec
94
116
  homepage: https://github.com/viccarrasco/metonym
@@ -114,8 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
136
  - !ruby/object:Gem::Version
115
137
  version: '0'
116
138
  requirements: []
117
- rubyforge_project:
118
- rubygems_version: 2.7.7
139
+ rubygems_version: 3.0.0
119
140
  signing_key:
120
141
  specification_version: 4
121
142
  summary: The unofficial Google News API gem
@@ -1,124 +0,0 @@
1
- module Validate
2
- class Validator
3
- def is_key_present?(args)
4
- return !args.nil?
5
- end
6
-
7
- def is_language_valid?(args)
8
- if args['lang'].nil?
9
- true
10
- else
11
- return [
12
- 'af','ak','sq','am','ar','hy','az','eu','be','bem','bn','bs','bh','br','bg','km','ca','chr','ny','zh-CN',
13
- 'zh-TW','co','hr','cs','da','nl','en','eo','et','ee','fo','tl','fi','fr','fy','gl','ka','de','el','gn','gu',
14
- 'ht','ha','haw','iw','hi','hu','is','ig','id','ia','ga','it','ja','jw','kn','kk','rw','rn','kg','ko','kri',
15
- 'ku','ckb','ky','lo','la','lv','ln','lt','loz','lg','ach','mk','mg','ms','ml','mt','mi','mr','mfe','mo','mn',
16
- 'sr-ME','ne','nso','no','nn','oc','or','om','ps','fa','pl','pt-BR','pt-PT','pa','qu','ro','rm','nyn','ru','gd',
17
- 'sr','sh','st','tn','crs','sn','sd','si','sk','sl','so','es','sp-419','su','sw','sv','tg','ta','tt','te','th','ti',
18
- 'to','lua','tum','tr','tk','tw','ug','uk','ur','uz','vi','cy','wo','xh','yi','yo','zu'
19
- ].include?(args['lang'].downcase)
20
- end
21
- end
22
-
23
- def is_format_valid?(args)
24
- template = %w(json hash)
25
-
26
- if args.nil?
27
- true
28
- else
29
- template.include?(args.downcase)
30
- end
31
- end
32
- end
33
-
34
- class GnewsValidator < Validator
35
- COUNTRIES = [
36
- 'af','al','dz','as','ad','ao','ai','aq','ag','ar','am','aw','au','at','az','bs','bh','bd','bb','by',
37
- 'be','bz','bj','bm','bt','bo','ba','bw','bv','br','io','bn','bg','bf','bi','kh','cm','ca','cv','ky',
38
- 'cf','td','cl','cn','cx','cc','co','km','cg','cd','ck','cr','ci','hr','cu','cy','cz','dk','dj','dm',
39
- 'do','ec','eg','sv','gq','er','ee','et','fk','fo','fj','fi','fr','gf','pf','tf','ga','gm','ge','de',
40
- 'gh','gi','gr','gl','gd','gp','gu','gt','gn','gw','gy','ht','hm','va','hn','hk','hu','is','in','id',
41
- 'ir','iq','ie','il','it','jm','jp','jo','kz','ke','ki','kp','kr','kw','kg','la','lv','lb','ls','lr',
42
- 'ly','li','lt','lu','mo','mk','mg','mw','my','mv','ml','mt','mh','mq','mr','mu','yt','mx','fm','md',
43
- 'mc','mn','ms','ma','mz','mm','na','nr','np','nl','an','nc','nz','ni','ne','ng','nu','nf','mp','no',
44
- 'om','pk','pw','ps','pa','pg','py','pe','ph','pn','pl','pt','pr','qa','re','ro','ru','rw','sh','kn',
45
- 'lc','pm','vc','ws','sm','st','sa','sn','cs','sc','sl','sg','sk','si','sb','so','za','gs','sp','lk',
46
- 'sd','sr','sj','sz','se','ch','sy','tw','tj','tz','th','tl','tg','tk','to','tt','tn','tr','tm','tc',
47
- 'tv','ug','ua','ae','uk','us','um','uy','uz','vu','ve','vn','vg','vi','wf','eh','ye','zm','zw'
48
- ]
49
-
50
- def is_query_valid?(args)
51
- template = %w(q max lang country mindate maxdate in)
52
- return (args.keys - template).empty?
53
- end
54
-
55
- def is_country_valid?(args)
56
- if args['country'].nil?
57
- true
58
- else
59
- return COUNTRIES.include?(args['country'].downcase)
60
- end
61
- end
62
-
63
- def is_date_valid?(args)
64
- if (args['mindate'].nil? && args['maxdate'].nil?)
65
- true
66
- elsif (args['mindate'] && args['maxdate'])
67
- return (args['mindate'].respond_to?(:strftime) && args['maxdate'].respond_to?(:strftime))
68
- elsif (args['mindate'] && args['maxdate'].nil?)
69
- return args['mindate'].respond_to?(:strftime)
70
- elsif (args['mindate'].nil? && args['maxdate'])
71
- return args['maxdate'].respond_to?(:strftime)
72
- end
73
- end
74
- end
75
-
76
- class NewsApiValidator < Validator
77
- COUNTRIES = %w(ar au at be br bg ca cn co cu cz eg fr de gr hk hu in id ie il it jp lv lt my mx ma nl nz ng no ph pl pt ro ru sa rs sg sk si za kr se ch tw th tr ae ua gb us ve)
78
- CATEGORIES = %w(business entertainment general health science sports technology)
79
-
80
- def is_query_valid?(args, endpoint = 'top-headlines')
81
- case endpoint
82
- when 'top-headlines'
83
- template = %w(q country category sources page_size page)
84
- when 'everything'
85
- template = %w(q sources domains excludeDomains from to language sortBy pageSize page)
86
- when 'sources'
87
- template = %w(category language country)
88
- end
89
-
90
- if (endpoint == 'top-headlines' && (args.include?('sources') && (args.include?('country') || args.include?('category'))))
91
- false
92
- elsif (endpoint == "sources") && (args.has_key?("category")) && (CATEGORIES.include?(args["category"]) == false)
93
- false
94
- else
95
- (args.keys - template).empty?
96
- end
97
- end
98
-
99
- def is_country_valid?(args)
100
- if args['country'].nil?
101
- true
102
- else
103
- return COUNTRIES.include?(args['country'].downcase)
104
- end
105
- end
106
-
107
- def is_category_valid?(args)
108
- template = %w(business entertainment general health science sports technology)
109
- return template.include?(args['country'])
110
- end
111
-
112
- def is_date_valid?(args)
113
- if (args['from'].nil? && args['to'].nil?)
114
- true
115
- elsif (args['from'] && args['to'])
116
- return (args['from'].respond_to?(:strftime) && args['to'].respond_to?(:strftime))
117
- elsif (args['from'] && args['to'].nil?)
118
- return args['from'].respond_to?(:strftime)
119
- elsif (args['from'].nil? && args['to'])
120
- return args['from'].respond_to?(:strftime)
121
- end
122
- end
123
- end
124
- end