sg_delivery_slot_checker 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4bfb73d7e65d186c01a3f065c943b137d96d255d2e6d9acf82581e9195bc0e35
4
+ data.tar.gz: a54d74c0fee2d7f397b01379ffe1c12a1d2b2fe553fc8281d5b3b29221177d03
5
+ SHA512:
6
+ metadata.gz: f0efeca34f0eb247cb01ab4198d7a5ed4facebf90107f59d395f23d6abcde3afbf047bd89533daa5c85e0e579b3327e18bcac476d75cf0efe8144ea384ede11c
7
+ data.tar.gz: c580f50e76bdd43ac14a37b29c8515901bae5c1baeecb833857730e039fdba374492f85ff28073fd2231dde62865dd584f96fa00549c415de62576dadc6925ac
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ .idea
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in sg_delivery_slot_checker.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,60 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ sg_delivery_slot_checker (0.1.0)
5
+ hashie (~> 4.1.0)
6
+ httparty (~> 0.18)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ coderay (1.1.2)
12
+ diff-lcs (1.3)
13
+ hashie (4.1.0)
14
+ httparty (0.18.0)
15
+ mime-types (~> 3.0)
16
+ multi_xml (>= 0.5.2)
17
+ method_source (0.8.2)
18
+ mime-types (3.3.1)
19
+ mime-types-data (~> 3.2015)
20
+ mime-types-data (3.2020.0425)
21
+ multi_xml (0.6.0)
22
+ pry (0.10.4)
23
+ coderay (~> 1.1.0)
24
+ method_source (~> 0.8.1)
25
+ slop (~> 3.4)
26
+ pry-nav (0.3.0)
27
+ pry (>= 0.9.10, < 0.13.0)
28
+ pry-remote (0.1.8)
29
+ pry (~> 0.9)
30
+ slop (~> 3.0)
31
+ rake (12.3.3)
32
+ rspec (3.9.0)
33
+ rspec-core (~> 3.9.0)
34
+ rspec-expectations (~> 3.9.0)
35
+ rspec-mocks (~> 3.9.0)
36
+ rspec-core (3.9.1)
37
+ rspec-support (~> 3.9.1)
38
+ rspec-expectations (3.9.1)
39
+ diff-lcs (>= 1.2.0, < 2.0)
40
+ rspec-support (~> 3.9.0)
41
+ rspec-mocks (3.9.1)
42
+ diff-lcs (>= 1.2.0, < 2.0)
43
+ rspec-support (~> 3.9.0)
44
+ rspec-support (3.9.2)
45
+ slop (3.6.0)
46
+
47
+ PLATFORMS
48
+ ruby
49
+
50
+ DEPENDENCIES
51
+ bundler (~> 2.0)
52
+ pry (~> 0.10.3)
53
+ pry-nav (~> 0.3.0)
54
+ pry-remote (~> 0.1.8)
55
+ rake (~> 12.0)
56
+ rspec (~> 3.0)
57
+ sg_delivery_slot_checker!
58
+
59
+ BUNDLED WITH
60
+ 2.1.4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Vincent Paca
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # Singapore Grocery Delivery Slot Checker
2
+
3
+ Tells you if there are any available delivery slots from supported grocery stores.
4
+
5
+ Supported Grocery Stores:
6
+ - Fairprice
7
+ - Giant
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'sg_delivery_slot_checker'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle install
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install sg_delivery_slot_checker
24
+
25
+ ## Usage
26
+
27
+ ```ruby
28
+ SgDeliverySlotChecker::Checker.new(postal_code: 149555).check_availability
29
+ ```
30
+ Returns the following `Hash`
31
+ ```
32
+ => {:fairprice=>true, :giant=>false}
33
+ ```
34
+
35
+ ## Development
36
+
37
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
38
+
39
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
40
+
41
+ ## Contributing
42
+
43
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/sg_delivery_slot_checker.
44
+
45
+
46
+ ## License
47
+
48
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "sg_delivery_slot_checker"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -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,6 @@
1
+ require "sg_delivery_slot_checker/version"
2
+ require "sg_delivery_slot_checker/checker"
3
+
4
+ module SgDeliverySlotChecker
5
+ class Error < StandardError; end
6
+ end
@@ -0,0 +1,31 @@
1
+ require "sg_delivery_slot_checker/stores/fairprice"
2
+ require "sg_delivery_slot_checker/stores/giant"
3
+
4
+ module SgDeliverySlotChecker
5
+ class Checker
6
+
7
+ def initialize(postal_code:)
8
+ @postal_code = postal_code
9
+ end
10
+
11
+ def check_availability
12
+ {}.tap do |hash|
13
+ stores.each do |k, v|
14
+ hash[k] = v.new(postal_code: postal_code).available?
15
+ end
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ attr_reader :postal_code
22
+
23
+ def stores
24
+ {
25
+ fairprice: SgDeliverySlotChecker::Stores::Fairprice,
26
+ giant: SgDeliverySlotChecker::Stores::Giant
27
+ }
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,35 @@
1
+ require 'httparty'
2
+
3
+ module SgDeliverySlotChecker
4
+ module Stores
5
+ class Fairprice
6
+
7
+ def initialize(postal_code:)
8
+ @postal_code = postal_code
9
+ end
10
+
11
+ def available?
12
+ if store_id
13
+ get_availability(store: store_id)
14
+ else
15
+ false
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ attr_reader :postal_code
22
+
23
+ def store_id
24
+ response = HTTParty.get("https://website-api.omni.fairprice.com.sg/api/serviceable-area?city=Singapore&pincode=#{postal_code}")
25
+ response.parsed_response&.dig("data", "store", "id")
26
+ end
27
+
28
+ def get_availability(store:)
29
+ response = HTTParty.get("https://website-api.omni.fairprice.com.sg/api/slot-availability?address[pincode]=#{postal_code}&storeId=#{store}")
30
+ response.parsed_response&.dig("data", "available")
31
+ end
32
+
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,29 @@
1
+ require 'httparty'
2
+ require 'hashie'
3
+
4
+ module SgDeliverySlotChecker
5
+ module Stores
6
+ class Giant
7
+
8
+ def initialize(postal_code:)
9
+ @postal_code = postal_code
10
+ end
11
+
12
+ def available?
13
+ get_availability
14
+ end
15
+
16
+ private
17
+
18
+ attr_reader :postal_code
19
+
20
+ def get_availability
21
+ response = HTTParty.post("https://giant.sg/checkout/cart/checkdelivery", body: { postal_code: postal_code })
22
+ slots = response.parsed_response
23
+ slots.extend Hashie::Extensions::DeepFind
24
+ slots.deep_find_all("available").any?(true)
25
+ end
26
+
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,3 @@
1
+ module SgDeliverySlotChecker
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,37 @@
1
+ require_relative 'lib/sg_delivery_slot_checker/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "sg_delivery_slot_checker"
5
+ spec.version = SgDeliverySlotChecker::VERSION
6
+ spec.authors = ["Vincent Paca"]
7
+ spec.email = ["vincent.paca@gmail.com"]
8
+
9
+ spec.authors = ["Vincent Paca"]
10
+ spec.email = ["vincent.paca@gmail.com"]
11
+
12
+ spec.summary = "Checks for available delivery slots in Singapore grocery stores"
13
+ spec.description = "Checks for available delivery slots in Singapore grocery stores"
14
+ spec.homepage = "https://github.com/vincentpaca/sg_delivery_slot_checker"
15
+ spec.license = "MIT"
16
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
17
+
18
+ spec.metadata["homepage_uri"] = spec.homepage
19
+ spec.metadata["source_code_uri"] = "https://github.com/vincentpaca/sg_delivery_slot_checker"
20
+
21
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ end
24
+ spec.bindir = 'exe'
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ['lib']
27
+
28
+ spec.add_development_dependency 'bundler', '~> 2.0'
29
+ spec.add_development_dependency 'rake', '~> 13.0'
30
+ spec.add_development_dependency 'rspec', '~> 3.0'
31
+ spec.add_development_dependency 'pry', '~> 0.10.3'
32
+ spec.add_development_dependency 'pry-remote', '~> 0.1.8'
33
+ spec.add_development_dependency 'pry-nav', '~> 0.3.0'
34
+
35
+ spec.add_runtime_dependency 'httparty', '~> 0.18'
36
+ spec.add_runtime_dependency 'hashie', '~> 4.1.0'
37
+ end
metadata ADDED
@@ -0,0 +1,172 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sg_delivery_slot_checker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Vincent Paca
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-05-01 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: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.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: '13.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '13.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: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.10.3
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.10.3
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-remote
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.1.8
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.1.8
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry-nav
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.3.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.3.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.18'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.18'
111
+ - !ruby/object:Gem::Dependency
112
+ name: hashie
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 4.1.0
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 4.1.0
125
+ description: Checks for available delivery slots in Singapore grocery stores
126
+ email:
127
+ - vincent.paca@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - Gemfile
134
+ - Gemfile.lock
135
+ - LICENSE.txt
136
+ - README.md
137
+ - Rakefile
138
+ - bin/console
139
+ - bin/setup
140
+ - lib/sg_delivery_slot_checker.rb
141
+ - lib/sg_delivery_slot_checker/checker.rb
142
+ - lib/sg_delivery_slot_checker/stores/fairprice.rb
143
+ - lib/sg_delivery_slot_checker/stores/giant.rb
144
+ - lib/sg_delivery_slot_checker/version.rb
145
+ - sg_delivery_slot_checker.gemspec
146
+ homepage: https://github.com/vincentpaca/sg_delivery_slot_checker
147
+ licenses:
148
+ - MIT
149
+ metadata:
150
+ homepage_uri: https://github.com/vincentpaca/sg_delivery_slot_checker
151
+ source_code_uri: https://github.com/vincentpaca/sg_delivery_slot_checker
152
+ post_install_message:
153
+ rdoc_options: []
154
+ require_paths:
155
+ - lib
156
+ required_ruby_version: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: 2.3.0
161
+ required_rubygems_version: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ requirements: []
167
+ rubyforge_project:
168
+ rubygems_version: 2.7.6
169
+ signing_key:
170
+ specification_version: 4
171
+ summary: Checks for available delivery slots in Singapore grocery stores
172
+ test_files: []