api_queries 0.1.0 → 0.1.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c64e9805ef0a8fd7b2f26c439d1823ea72ba7caf
4
- data.tar.gz: 06de73a1bc1fc1f887afd9c1c44a4991f9673b47
2
+ SHA256:
3
+ metadata.gz: '035792eaecd25557415143ee13ee931c867db5ea34c91be1e46b7208d383c6f0'
4
+ data.tar.gz: f8c56e6ce4dbf5cf557881f041c52265c72c4bc92778d9134fdf25d0d413a8fc
5
5
  SHA512:
6
- metadata.gz: 0ffa94e88e5d4cfebabfc62cb8eddd6d6d201793c2d067e3084e4a6807b3058f02d242b3feb0d70ec0aa8ea8a922945bbc5668840dce537b30e7b647645e00ad
7
- data.tar.gz: c0cb2237d1ca123792d8587752e43d497c118e428207cde3065760f830f3e6ec5cff57f56173762e78219219c6d29b716a6f3f4c39913cc083c231c03f3ced71
6
+ metadata.gz: 157b747cc1aed01f4e49f1306e87bc3da10206234fad87c8c631aec4a43ff189c5a3ebc0e9baff09f69e4e8fc40fad4ad86b86319bddef0ec65d950f837cd88e
7
+ data.tar.gz: a92ca37da8898038c988d4f03d11f33d8b5c222a6712bfebe671b10db6fcb6362099030e39409030ce8256edeabe61c19fdcd3efc5491bdcb09c110fa371b26b
data/.gitignore CHANGED
@@ -1,9 +1,9 @@
1
1
  /.bundle/
2
2
  /.yardoc
3
- /Gemfile.lock
4
3
  /_yardoc/
5
4
  /coverage/
6
5
  /doc/
7
6
  /pkg/
8
7
  /spec/reports/
9
8
  /tmp/
9
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rspec_status ADDED
@@ -0,0 +1,10 @@
1
+ example_id | status | run_time |
2
+ --------------------------------- | ------ | --------------- |
3
+ ./spec/api_queries_spec.rb[1:1:1] | passed | 0.00575 seconds |
4
+ ./spec/api_queries_spec.rb[1:1:2] | passed | 0.01577 seconds |
5
+ ./spec/api_queries_spec.rb[1:1:3] | passed | 0.00065 seconds |
6
+ ./spec/api_queries_spec.rb[1:1:4] | passed | 0.00657 seconds |
7
+ ./spec/api_queries_spec.rb[1:1:5] | passed | 0.006 seconds |
8
+ ./spec/api_queries_spec.rb[1:1:6] | passed | 0.00563 seconds |
9
+ ./spec/api_queries_spec.rb[1:1:7] | passed | 0.00295 seconds |
10
+ ./spec/api_queries_spec.rb[1:1:8] | passed | 0.0023 seconds |
data/.rubocop.yml ADDED
@@ -0,0 +1 @@
1
+ inherit_from: .rubocop_todo.yml
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,201 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2018-07-21 23:51:29 +0800 using RuboCop version 0.58.1.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 1
10
+ # Cop supports --auto-correct.
11
+ # Configuration parameters: Include, TreatCommentsAsGroupSeparators.
12
+ # Include: **/*.gemspec
13
+ Gemspec/OrderedDependencies:
14
+ Exclude:
15
+
16
+
17
+ # Offense count: 1
18
+ # Cop supports --auto-correct.
19
+ # Configuration parameters: EnforcedStyle, IndentationWidth.
20
+ # SupportedStyles: outdent, indent
21
+ Layout/AccessModifierIndentation:
22
+ Exclude:
23
+
24
+
25
+ # Offense count: 1
26
+ # Cop supports --auto-correct.
27
+ Layout/EmptyLineAfterMagicComment:
28
+ Exclude:
29
+
30
+ # Offense count: 2
31
+ # Cop supports --auto-correct.
32
+ # Configuration parameters: EnforcedStyle.
33
+ # SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines
34
+ Layout/EmptyLinesAroundModuleBody:
35
+ Exclude:
36
+
37
+
38
+ # Offense count: 31
39
+ # Cop supports --auto-correct.
40
+ # Configuration parameters: Width, IgnoredPatterns.
41
+ Layout/IndentationWidth:
42
+ Exclude:
43
+
44
+
45
+
46
+ # Offense count: 1
47
+ # Cop supports --auto-correct.
48
+ # Configuration parameters: .
49
+ # SupportedStyles: space, no_space
50
+ Layout/SpaceAroundEqualsInParameterDefault:
51
+ EnforcedStyle: no_space
52
+
53
+ # Offense count: 57
54
+ # Cop supports --auto-correct.
55
+ # Configuration parameters: IndentationWidth.
56
+ Layout/Tab:
57
+ Exclude:
58
+
59
+
60
+ # Offense count: 4
61
+ # Cop supports --auto-correct.
62
+ # Configuration parameters: EnforcedStyle.
63
+ # SupportedStyles: final_newline, final_blank_line
64
+ Layout/TrailingBlankLines:
65
+ Exclude:
66
+
67
+ # Offense count: 8
68
+ # Cop supports --auto-correct.
69
+ # Configuration parameters: AllowInHeredoc.
70
+ Layout/TrailingWhitespace:
71
+ Exclude:
72
+
73
+ # Offense count: 1
74
+ Lint/UselessAssignment:
75
+ Exclude:
76
+
77
+ # Offense count: 1
78
+ Metrics/AbcSize:
79
+ Max: 53
80
+
81
+ # Offense count: 2
82
+ # Configuration parameters: CountComments, ExcludedMethods.
83
+ # ExcludedMethods: refine
84
+ Metrics/BlockLength:
85
+ Max: 55
86
+
87
+ # Offense count: 1
88
+ Metrics/CyclomaticComplexity:
89
+ Max: 14
90
+
91
+ # Offense count: 1
92
+ # Configuration parameters: CountComments.
93
+ Metrics/MethodLength:
94
+ Max: 31
95
+
96
+ # Offense count: 1
97
+ Metrics/PerceivedComplexity:
98
+ Max: 17
99
+
100
+ # Offense count: 2
101
+ # Cop supports --auto-correct.
102
+ # Configuration parameters: MaxKeyValuePairs.
103
+ Performance/RedundantMerge:
104
+ Exclude:
105
+
106
+ # Offense count: 2
107
+ # Cop supports --auto-correct.
108
+ # Configuration parameters: EnforcedStyle.
109
+ # SupportedStyles: is_a?, kind_of?
110
+ Style/ClassCheck:
111
+ Exclude:
112
+
113
+ # Offense count: 1
114
+ Style/DateTime:
115
+ Exclude:
116
+
117
+ # Offense count: 2
118
+ Style/Documentation:
119
+ Exclude:
120
+
121
+ # Offense count: 1
122
+ # Cop supports --auto-correct.
123
+ Style/Encoding:
124
+ Exclude:
125
+
126
+ # Offense count: 1
127
+ # Cop supports --auto-correct.
128
+ Style/ExpandPathArguments:
129
+ Exclude:
130
+
131
+ # Offense count: 2
132
+ # Configuration parameters: MinBodyLength.
133
+ Style/GuardClause:
134
+ Exclude:
135
+ # - 'lib/api_queries.rb'
136
+
137
+ # Offense count: 1
138
+ # Cop supports --auto-correct.
139
+ # Configuration parameters: EnforcedStyle, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
140
+ # SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
141
+ Style/HashSyntax:
142
+ Exclude:
143
+
144
+ # Offense count: 2
145
+ # Cop supports --auto-correct.
146
+ Style/IfUnlessModifier:
147
+ Exclude:
148
+
149
+ # Offense count: 2
150
+ # Cop supports --auto-correct.
151
+ # Configuration parameters: EnforcedStyle.
152
+ # SupportedStyles: require_parentheses, require_no_parentheses, require_no_parentheses_except_multiline
153
+ Style/MethodDefParentheses:
154
+ Exclude:
155
+
156
+ # Offense count: 1
157
+ Style/MixinUsage:
158
+ Exclude:
159
+ - 'spec/db/helper.rb'
160
+
161
+ # Offense count: 1
162
+ # Cop supports --auto-correct.
163
+ Style/MutableConstant:
164
+ Exclude:
165
+
166
+ # Offense count: 2
167
+ # Cop supports --auto-correct.
168
+ # Configuration parameters: PreferredDelimiters.
169
+ Style/PercentLiteralDelimiters:
170
+ Exclude:
171
+
172
+ # Offense count: 3
173
+ # Cop supports --auto-correct.
174
+ Style/RedundantSelf:
175
+ Exclude:
176
+
177
+ # Offense count: 1
178
+ # Cop supports --auto-correct.
179
+ Style/RescueModifier:
180
+ Exclude:
181
+ - 'spec/db/helper.rb'
182
+
183
+ # Offense count: 30
184
+ # Cop supports --auto-correct.
185
+ # Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
186
+ # SupportedStyles: single_quotes, double_quotes
187
+ Style/StringLiterals:
188
+ Exclude:
189
+
190
+
191
+ # Offense count: 2
192
+ # Cop supports --auto-correct.
193
+ Style/UnneededPercentQ:
194
+ Exclude:
195
+
196
+
197
+ # Offense count: 24
198
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
199
+ # URISchemes: http, https
200
+ Metrics/LineLength:
201
+ Max: 129
data/.travis.yml ADDED
@@ -0,0 +1,23 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ services: mysql
6
+ before_install: gem install bundler -v 1.16.1
7
+ notifications: false
8
+
9
+ env:
10
+ global:
11
+ - CC_TEST_REPORTER_ID=808ac5a7a22827ca94cd442e9a0cbc2a8b5ba51c70633ed2ba870aa209a73616
12
+
13
+ before_script:
14
+ - bundle exec rspec && CODECLIMATE_REPO_TOKEN=808ac5a7a22827ca94cd442e9a0cbc2a8b5ba51c70633ed2ba870aa209a73616
15
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
16
+ - chmod +x ./cc-test-reporter
17
+ - ./cc-test-reporter before-build
18
+
19
+ scripts:
20
+ - bundle exec rspec spec
21
+
22
+ after_script:
23
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
data/Gemfile CHANGED
@@ -1,6 +1,11 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in api_queries.gemspec
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in globe_labs_sms.gemspec
4
6
  gemspec
5
7
 
6
- gem 'will_paginate', '~> 3.1.0'
8
+ group :test do
9
+ gem 'simplecov'
10
+ gem 'simplecov-console'
11
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,95 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ api_queries (0.1.1)
5
+ activerecord (>= 4.2)
6
+ will_paginate (~> 3.1)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activemodel (4.2.10)
12
+ activesupport (= 4.2.10)
13
+ builder (~> 3.1)
14
+ activerecord (4.2.10)
15
+ activemodel (= 4.2.10)
16
+ activesupport (= 4.2.10)
17
+ arel (~> 6.0)
18
+ activesupport (4.2.10)
19
+ i18n (~> 0.7)
20
+ minitest (~> 5.1)
21
+ thread_safe (~> 0.3, >= 0.3.4)
22
+ tzinfo (~> 1.1)
23
+ ansi (1.5.0)
24
+ arel (6.0.4)
25
+ ast (2.4.0)
26
+ builder (3.2.3)
27
+ concurrent-ruby (1.0.5)
28
+ diff-lcs (1.3)
29
+ docile (1.3.1)
30
+ hirb (0.7.3)
31
+ i18n (0.9.5)
32
+ concurrent-ruby (~> 1.0)
33
+ jaro_winkler (1.5.1)
34
+ json (2.1.0)
35
+ minitest (5.11.3)
36
+ mysql2 (0.3.21)
37
+ parallel (1.12.1)
38
+ parser (2.5.1.2)
39
+ ast (~> 2.4.0)
40
+ powerpack (0.1.2)
41
+ rainbow (3.0.0)
42
+ rake (10.5.0)
43
+ rspec (3.7.0)
44
+ rspec-core (~> 3.7.0)
45
+ rspec-expectations (~> 3.7.0)
46
+ rspec-mocks (~> 3.7.0)
47
+ rspec-core (3.7.1)
48
+ rspec-support (~> 3.7.0)
49
+ rspec-expectations (3.7.0)
50
+ diff-lcs (>= 1.2.0, < 2.0)
51
+ rspec-support (~> 3.7.0)
52
+ rspec-mocks (3.7.0)
53
+ diff-lcs (>= 1.2.0, < 2.0)
54
+ rspec-support (~> 3.7.0)
55
+ rspec-support (3.7.1)
56
+ rubocop (0.58.1)
57
+ jaro_winkler (~> 1.5.1)
58
+ parallel (~> 1.10)
59
+ parser (>= 2.5, != 2.5.1.1)
60
+ powerpack (~> 0.1)
61
+ rainbow (>= 2.2.2, < 4.0)
62
+ ruby-progressbar (~> 1.7)
63
+ unicode-display_width (~> 1.0, >= 1.0.1)
64
+ ruby-progressbar (1.9.0)
65
+ simplecov (0.16.1)
66
+ docile (~> 1.1)
67
+ json (>= 1.8, < 3)
68
+ simplecov-html (~> 0.10.0)
69
+ simplecov-console (0.4.2)
70
+ ansi
71
+ hirb
72
+ simplecov
73
+ simplecov-html (0.10.2)
74
+ thread_safe (0.3.6)
75
+ tzinfo (1.2.5)
76
+ thread_safe (~> 0.1)
77
+ unicode-display_width (1.4.0)
78
+ will_paginate (3.1.6)
79
+
80
+ PLATFORMS
81
+ ruby
82
+
83
+ DEPENDENCIES
84
+ activesupport (~> 4.2)
85
+ api_queries!
86
+ bundler (~> 1.12)
87
+ mysql2 (>= 0.3.13, < 0.4.0)
88
+ rake (~> 10.0)
89
+ rspec (~> 3.0)
90
+ rubocop
91
+ simplecov
92
+ simplecov-console
93
+
94
+ BUNDLED WITH
95
+ 1.16.1
data/README.md CHANGED
@@ -1,8 +1,7 @@
1
+ [![Build Status](https://travis-ci.org/denmarkmeralpis/api_queries.svg?branch=master)](https://travis-ci.org/denmarkmeralpis/api_queries) [![Maintainability](https://api.codeclimate.com/v1/badges/93675db98a1701fb4686/maintainability)](https://codeclimate.com/github/denmarkmeralpis/api_queries/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/93675db98a1701fb4686/test_coverage)](https://codeclimate.com/github/denmarkmeralpis/api_queries/test_coverage)
1
2
  # ApiQueries
2
3
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/api_queries`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
4
+ Manage you api using `api_q` method.
6
5
 
7
6
  ## Installation
8
7
 
@@ -10,6 +9,7 @@ Add this line to your application's Gemfile:
10
9
 
11
10
  ```ruby
12
11
  gem 'api_queries'
12
+ gem 'will_paginate', '~> 3.1.0'
13
13
  ```
14
14
 
15
15
  And then execute:
@@ -22,7 +22,45 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
- TODO: Write usage instructions here
25
+ Add this to the model you want to add an api queries.
26
+
27
+ ```ruby
28
+ include ApiQueries
29
+ ```
30
+
31
+ Optional Parameters:
32
+ - `active_only [1, 0]`
33
+ - `page [1 ~ n]`
34
+
35
+ Get data filtered by date:
36
+ - `after`
37
+ - `before`
38
+ - `from`
39
+ - `to`
40
+
41
+ Available Queries:
42
+ - `q=count`
43
+ - `q=last_updated_at`
44
+
45
+ Example:
46
+ ```ruby
47
+ # Get active products(assuming you have a status column)
48
+ Product.api_q({ active_only: 1 })
49
+
50
+ # Get active products and go to page 2
51
+ Product.api_q({ active_only: 1, page: 2 })
52
+
53
+ # Get all dates using from and to
54
+ # Date format should be: YYYY-MM-DDTHH:MM:SSZ
55
+ Product.api_q({ from: '2016-01-01T12:00:00Z', to: '2016-01-31T12:00:00Z' })
56
+
57
+ # Count all products
58
+ Product.api_q({ q: 'count' })
59
+
60
+ # Get last updated_at
61
+ Product.api_q({ q: 'last_updated_at' })
62
+
63
+ ```
26
64
 
27
65
  ## Development
28
66
 
@@ -32,7 +70,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
70
 
33
71
  ## Contributing
34
72
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/api_queries. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
73
+ Bug reports and pull requests are welcome on GitHub at https://github.com/denmarkmeralpis/api_queries. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
74
 
37
75
 
38
76
  ## License
data/Rakefile CHANGED
@@ -1,2 +1,4 @@
1
- require "bundler/gem_tasks"
2
- task :default => :spec
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ task default: :spec
data/api_queries.gemspec CHANGED
@@ -1,32 +1,35 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path('lib', __dir__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require 'api_queries/version'
5
4
 
6
5
  Gem::Specification.new do |spec|
7
- spec.name = "api_queries"
6
+ spec.name = 'api_queries'
8
7
  spec.version = ApiQueries::VERSION
9
- spec.authors = ["denmarkmeralpis"]
10
- spec.email = ["denmark@nueca.net"]
8
+ spec.authors = ['denmarkmeralpis']
9
+ spec.email = ['denmark@nueca.net']
11
10
 
12
- spec.summary = %q{This will wrap all the api methods in just a single call.}
13
- spec.description = %q{A lightweight rails plugin that is very useful for developers.}
14
- spec.homepage = "http://genmcrg.com"
15
- spec.license = "MIT"
11
+ spec.summary = 'This will wrap all the api methods in just a single call.'
12
+ spec.description = 'A lightweight rails plugin that is very useful for developers.'
13
+ spec.homepage = 'https://github.com/denmarkmeralpis/api_queries'
14
+ spec.license = 'MIT'
16
15
 
17
16
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
17
  # to allow pushing to a single host or delete this section to allow pushing to any host.
19
- # if spec.respond_to?(:metadata)
20
- # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
- # else
22
- # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
- # end
18
+ raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.' unless spec.respond_to?(:metadata)
19
+
20
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org/gems/api_queries'
24
21
 
25
22
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
- spec.bindir = "exe"
23
+ spec.bindir = 'exe'
27
24
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
- spec.require_paths = ["lib"]
25
+ spec.require_paths = ['lib']
29
26
 
30
- spec.add_development_dependency "bundler", "~> 1.12"
31
- spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_dependency 'activerecord', '>= 4.2'
28
+ spec.add_dependency 'will_paginate', '~> 3.1'
29
+ spec.add_development_dependency 'activesupport', '~> 4.2'
30
+ spec.add_development_dependency 'bundler', '~> 1.12'
31
+ spec.add_development_dependency 'mysql2', '>= 0.3.13', '< 0.4.0'
32
+ spec.add_development_dependency 'rake', '~> 10.0'
33
+ spec.add_development_dependency 'rspec', '~> 3.0'
34
+ spec.add_development_dependency 'rubocop'
32
35
  end
data/bin/console CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "api_queries"
3
+ require 'bundler/setup'
4
+ require 'api_queries'
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +10,5 @@ require "api_queries"
10
10
  # require "pry"
11
11
  # Pry.start
12
12
 
13
- require "irb"
13
+ require 'irb'
14
14
  IRB.start
data/lib/api_queries.rb CHANGED
@@ -1,67 +1,60 @@
1
- require "api_queries/version"
1
+ require 'active_support'
2
+ require 'api_queries/version'
2
3
 
4
+ # ApiQueries
3
5
  module ApiQueries
4
- extend ActiveSupport::Concern
5
- module ClassMethods
6
-
7
- def api_q opts={}
8
-
9
- # last updated at q
10
- if opts[:q] == 'last_updated_at'
11
- if self.count > 0
12
- return { last_updated_at: self.order('updated_at DESC').limit(1).first.updated_at.strftime('%Y-%m-%dT%H:%M:%SZ') }
13
- else
14
- return { last_updated_at: nil }
15
- end
16
- end
17
-
18
- # condition hash
19
- conditions = {}
20
-
21
- # AFTER: updated_at > given_date
22
- if opts[:after].present?
23
- conditions = { updated_at: ((fdate(opts[:after]) + 1.second)..Time.now.utc) }
24
-
25
- # BEFORE: updated_at < given_date
26
- elsif opts[:before].present?
27
- conditions = { updated_at: (Time.at(0)..(fdate(opts[:before]) - 1.second)) }
28
-
29
- # FROM & TO: between "from date" to "to date"
30
- elsif opts[:from].present? && opts[:to].present?
31
- conditions = { updated_at: (fdate(opts[:from])..fdate(opts[:to])) }
32
-
33
- # FROM: updated_at >= given_date
34
- elsif opts[:from].present?
35
- conditions = { updated_at: (fdate(opts[:from])..Time.now.utc) }
36
-
37
- # TO: updated_at <= given_date
38
- elsif opts[:to].present?
39
- conditions = { updated_at: (Time.at(0)..fdate(opts[:to])) }
40
- end
41
-
42
- # get by status
43
- if opts[:active_only].to_s == '1'
44
- conditions = conditions.merge(status: 'active')
45
- end
46
-
47
- # return hash
48
- q = self.where(conditions)
49
-
50
- # count
51
- if opts[:q] == 'count'
52
- q = { count: q.count }
53
- else
54
- q.paginate(page: opts[:page], per_page: 50)
55
- end
6
+ extend ActiveSupport::Concern
7
+ # class method
8
+ module ClassMethods
9
+ def api_q(opts={})
10
+ # last updated at q
11
+ if opts[:q] == 'last_updated_at'
12
+ return { last_updated_at: (begin
13
+ order('updated_at DESC').limit(1).first.updated_at.strftime('%Y-%m-%dT%H:%M:%SZ')
14
+ rescue StandardError
15
+ nil
16
+ end) }
56
17
  end
57
18
 
58
- private
19
+ # condition hash
20
+ conditions = {}
21
+
22
+ # AFTER: updated_at > given_date
23
+ if opts[:after].present?
24
+ conditions = ['updated_at > ?', fdate(opts[:after])]
25
+ # BEFORE: updated_at < given_date
26
+ elsif opts[:before].present?
27
+ conditions = ['updated_at < ?', fdate(opts[:before])]
28
+ # FROM & TO: between "from date" to "to date"
29
+ elsif opts[:from].present? && opts[:to].present?
30
+ conditions[:updated_at] = (fdate(opts[:from])..fdate(opts[:to]))
31
+ # FROM: updated_at >= given_date
32
+ elsif opts[:from].present?
33
+ conditions = ['updated_at >= ?', fdate(opts[:from])]
34
+ # TO: updated_at <= given_date
35
+ elsif opts[:to].present?
36
+ conditions = ['updated_at <= ?', fdate(opts[:to])]
37
+ end
59
38
 
60
- def fdate date_string
61
- # YYYY-MM-DDTHH:MM:SSZ
62
- DateTime.strptime(date_string, '%Y-%m-%dT%H:%M:%SZ')
39
+ # get by status
40
+ conditions[:status] = 'active' if opts[:active_only].to_s == '1' && conditions.is_a?(Hash)
41
+ # return hash
42
+ records = where(conditions)
43
+ # get by status
44
+ records = records.where(status: 'active') if opts[:active_only].to_s == '1' && conditions.is_a?(Array)
45
+
46
+ if opts[:q] == 'count'
47
+ { count: records.count }
48
+ else
49
+ records.order(id: :asc).paginate(page: opts[:page], per_page: 50)
63
50
  end
51
+ end
52
+
53
+ private
64
54
 
65
- end
66
- extend ClassMethods
55
+ def fdate(date_string)
56
+ Date.strptime(date_string, '%Y-%m-%dT%H:%M:%SZ') # YYYY-MM-DDTHH:MM:SSZ
57
+ end
58
+ end
59
+ extend ClassMethods
67
60
  end
@@ -1,3 +1,3 @@
1
1
  module ApiQueries
2
- VERSION = "0.1.0"
2
+ VERSION = '0.1.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,15 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api_queries
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - denmarkmeralpis
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-08-08 00:00:00.000000000 Z
11
+ date: 2018-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '4.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: will_paginate
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '4.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '4.2'
13
55
  - !ruby/object:Gem::Dependency
14
56
  name: bundler
15
57
  requirement: !ruby/object:Gem::Requirement
@@ -24,6 +66,26 @@ dependencies:
24
66
  - - "~>"
25
67
  - !ruby/object:Gem::Version
26
68
  version: '1.12'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mysql2
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 0.3.13
76
+ - - "<"
77
+ - !ruby/object:Gem::Version
78
+ version: 0.4.0
79
+ type: :development
80
+ prerelease: false
81
+ version_requirements: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: 0.3.13
86
+ - - "<"
87
+ - !ruby/object:Gem::Version
88
+ version: 0.4.0
27
89
  - !ruby/object:Gem::Dependency
28
90
  name: rake
29
91
  requirement: !ruby/object:Gem::Requirement
@@ -38,6 +100,34 @@ dependencies:
38
100
  - - "~>"
39
101
  - !ruby/object:Gem::Version
40
102
  version: '10.0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: rspec
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '3.0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '3.0'
117
+ - !ruby/object:Gem::Dependency
118
+ name: rubocop
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
41
131
  description: A lightweight rails plugin that is very useful for developers.
42
132
  email:
43
133
  - denmark@nueca.net
@@ -46,8 +136,14 @@ extensions: []
46
136
  extra_rdoc_files: []
47
137
  files:
48
138
  - ".gitignore"
139
+ - ".rspec"
140
+ - ".rspec_status"
141
+ - ".rubocop.yml"
142
+ - ".rubocop_todo.yml"
143
+ - ".travis.yml"
49
144
  - CODE_OF_CONDUCT.md
50
145
  - Gemfile
146
+ - Gemfile.lock
51
147
  - LICENSE.txt
52
148
  - README.md
53
149
  - Rakefile
@@ -56,10 +152,11 @@ files:
56
152
  - bin/setup
57
153
  - lib/api_queries.rb
58
154
  - lib/api_queries/version.rb
59
- homepage: http://genmcrg.com
155
+ homepage: https://github.com/denmarkmeralpis/api_queries
60
156
  licenses:
61
157
  - MIT
62
- metadata: {}
158
+ metadata:
159
+ allowed_push_host: https://rubygems.org/gems/api_queries
63
160
  post_install_message:
64
161
  rdoc_options: []
65
162
  require_paths:
@@ -76,7 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
173
  version: '0'
77
174
  requirements: []
78
175
  rubyforge_project:
79
- rubygems_version: 2.4.8
176
+ rubygems_version: 2.7.6
80
177
  signing_key:
81
178
  specification_version: 4
82
179
  summary: This will wrap all the api methods in just a single call.