apple_store_inventory_checker 0.1.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.circleci/config.yml +101 -0
- data/.circleci/setup-rubygems.sh +3 -0
- data/.codeclimate.yml +7 -0
- data/.devcontainer/Dockerfile +11 -0
- data/.devcontainer/devcontainer.json +30 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.rubocop.yml +90 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +116 -0
- data/LICENSE.txt +21 -0
- data/README.md +89 -0
- data/Rakefile +6 -0
- data/apple_store_inventory_checker.gemspec +46 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/apple_store_inventory_checker/api_client.rb +19 -0
- data/lib/apple_store_inventory_checker/api_request.rb +19 -0
- data/lib/apple_store_inventory_checker/result.rb +23 -0
- data/lib/apple_store_inventory_checker/results_list.rb +47 -0
- data/lib/apple_store_inventory_checker/version.rb +3 -0
- data/lib/apple_store_inventory_checker.rb +33 -0
- metadata +225 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f6c6dd692f60a5a5b7c8db6d7c8944bfd966f82ac2f4b296b1f4eb27409a16f0
|
4
|
+
data.tar.gz: efd3288f76fb85fa7275796d8ea8fa5414bc3b563ab8dd7566cf8bac700ea348
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f7485acd1945fa2e0b2836ac9f8de2a23988b574b7edca0469f937302d96e350477aab6c30af18a0fe86d4a614c315e03d65d58061e6bd8058a02854a21049db
|
7
|
+
data.tar.gz: 63dba997a087cd0bed4b47b4ef31a7ca3fe758135a333c9046838f3548fd6320b3b9e0e432c7b1ff936cc502640f15754eb7842026367596152f8fb12fa21e0b
|
@@ -0,0 +1,101 @@
|
|
1
|
+
# Ruby CircleCI 2.0 configuration file
|
2
|
+
#
|
3
|
+
# Check https://circleci.com/docs/2.0/language-ruby/ for more details
|
4
|
+
#
|
5
|
+
version: 2
|
6
|
+
jobs:
|
7
|
+
build:
|
8
|
+
environment:
|
9
|
+
CC_TEST_REPORTER_ID: c295d1731b36a91f463f605831f39750dddaa5c6fd65fab2be78405b5a00c226
|
10
|
+
docker:
|
11
|
+
# specify the version you desire here
|
12
|
+
- image: circleci/ruby:2.4.6
|
13
|
+
|
14
|
+
# Specify service dependencies here if necessary
|
15
|
+
# CircleCI maintains a library of pre-built images
|
16
|
+
# documented at https://circleci.com/docs/2.0/circleci-images/
|
17
|
+
# - image: circleci/postgres:9.4
|
18
|
+
|
19
|
+
working_directory: ~/repo
|
20
|
+
|
21
|
+
steps:
|
22
|
+
- checkout
|
23
|
+
|
24
|
+
# Download and cache dependencies
|
25
|
+
- restore_cache:
|
26
|
+
keys:
|
27
|
+
- v1-dependencies-{{ checksum "Gemfile.lock" }}
|
28
|
+
# fallback to using the latest cache if no exact match is found
|
29
|
+
- v1-dependencies-
|
30
|
+
|
31
|
+
- run:
|
32
|
+
name: install dependencies
|
33
|
+
command: |
|
34
|
+
bundle install --jobs=4 --retry=3 --path vendor/bundle
|
35
|
+
|
36
|
+
- save_cache:
|
37
|
+
paths:
|
38
|
+
- ./vendor/bundle
|
39
|
+
key: v1-dependencies-{{ checksum "Gemfile.lock" }}
|
40
|
+
|
41
|
+
# run tests!
|
42
|
+
- run:
|
43
|
+
name: Install Code Climate Test Reporter
|
44
|
+
command: |
|
45
|
+
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
46
|
+
chmod +x ./cc-test-reporter
|
47
|
+
- run:
|
48
|
+
name: run tests
|
49
|
+
command: |
|
50
|
+
mkdir /tmp/test-results
|
51
|
+
./cc-test-reporter before-build
|
52
|
+
TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | \
|
53
|
+
circleci tests split --split-by=timings)"
|
54
|
+
|
55
|
+
bundle exec rspec \
|
56
|
+
--format RspecJunitFormatter \
|
57
|
+
--out /tmp/test-results/rspec.xml \
|
58
|
+
$TEST_FILES
|
59
|
+
- run:
|
60
|
+
name: Code Climate Test Coverage
|
61
|
+
command: |
|
62
|
+
./cc-test-reporter format-coverage -t simplecov -o "coverage/codeclimate.$CIRCLE_NODE_INDEX.json"
|
63
|
+
|
64
|
+
# collect reports
|
65
|
+
- store_test_results:
|
66
|
+
path: /tmp/test-results
|
67
|
+
- store_artifacts:
|
68
|
+
path: /tmp/test-results
|
69
|
+
destination: test-results
|
70
|
+
- deploy:
|
71
|
+
command: |
|
72
|
+
./cc-test-reporter sum-coverage --output - --parts $CIRCLE_NODE_TOTAL coverage/codeclimate.*.json | ./cc-test-reporter upload-coverage --debug --input -
|
73
|
+
deploy:
|
74
|
+
docker:
|
75
|
+
- image: circleci/ruby:2.4.6
|
76
|
+
|
77
|
+
working_directory: ~/repo
|
78
|
+
|
79
|
+
steps:
|
80
|
+
- checkout
|
81
|
+
- run:
|
82
|
+
name: Setup Rubygems
|
83
|
+
command: bash .circleci/setup-rubygems.sh
|
84
|
+
|
85
|
+
- run:
|
86
|
+
name: Publish to Rubygems
|
87
|
+
command: |
|
88
|
+
gem build apple_store_inventory_checker.gemspec
|
89
|
+
gem push "apple_store_inventory_checker-$(git describe --tags).gem"
|
90
|
+
|
91
|
+
workflows:
|
92
|
+
version: 2
|
93
|
+
test-deploy:
|
94
|
+
jobs:
|
95
|
+
- build
|
96
|
+
- deploy:
|
97
|
+
filters:
|
98
|
+
tags:
|
99
|
+
only: /.*/
|
100
|
+
branches:
|
101
|
+
ignore: /.*/
|
data/.codeclimate.yml
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
FROM ruby:2.4
|
2
|
+
RUN apt-get update && apt-get -y install git procps
|
3
|
+
RUN apt-get autoremove -y \
|
4
|
+
&& apt-get clean -y \
|
5
|
+
&& rm -rf /var/lib/apt/lists/*
|
6
|
+
COPY lib/apple_store_inventory_checker/version.rb ./lib/apple_store_inventory_checker/
|
7
|
+
COPY Gemfile* ./
|
8
|
+
COPY apple_store_inventory_checker.gemspec ./
|
9
|
+
RUN bundle
|
10
|
+
RUN bundle exec yard gems
|
11
|
+
ENV SHELL /bin/bash
|
@@ -0,0 +1,30 @@
|
|
1
|
+
{
|
2
|
+
"name": "Apple Store Inventory Checker",
|
3
|
+
"dockerFile": "Dockerfile",
|
4
|
+
"context": "..",
|
5
|
+
"settings": {
|
6
|
+
"[json]": {
|
7
|
+
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
8
|
+
},
|
9
|
+
"[ruby]": {
|
10
|
+
"editor.formatOnSave": true
|
11
|
+
},
|
12
|
+
"ruby.format": "rubocop",
|
13
|
+
"editor.formatOnSaveTimeout": 2500,
|
14
|
+
"ruby.codeCompletion": false,
|
15
|
+
"ruby.intellisense": "rubyLocate",
|
16
|
+
"ruby.lint": {
|
17
|
+
"rubocop": true
|
18
|
+
},
|
19
|
+
"ruby.useBundler": true,
|
20
|
+
"solargraph.useBundler": true
|
21
|
+
},
|
22
|
+
"extensions": [
|
23
|
+
"castwide.solargraph",
|
24
|
+
"eamodio.gitlens",
|
25
|
+
"esbenp.prettier-vscode",
|
26
|
+
"kaiwood.endwise",
|
27
|
+
"noku.rails-run-spec-vscode",
|
28
|
+
"rebornix.Ruby"
|
29
|
+
],
|
30
|
+
}
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
require: rubocop-performance
|
2
|
+
|
3
|
+
AllCops:
|
4
|
+
Exclude:
|
5
|
+
- db/schema.rb
|
6
|
+
- vendor/**/*
|
7
|
+
TargetRubyVersion: 2.4.6
|
8
|
+
|
9
|
+
Documentation:
|
10
|
+
Enabled: false
|
11
|
+
|
12
|
+
Layout/AccessModifierIndentation:
|
13
|
+
EnforcedStyle: outdent
|
14
|
+
|
15
|
+
Metrics/AbcSize:
|
16
|
+
Exclude:
|
17
|
+
- spec/**/*
|
18
|
+
- test/**/*
|
19
|
+
|
20
|
+
Metrics/BlockLength:
|
21
|
+
Exclude:
|
22
|
+
- config/initializers/*
|
23
|
+
- config/routes.rb
|
24
|
+
- Gemfile
|
25
|
+
- spec/**/*
|
26
|
+
- test/**/*
|
27
|
+
- "*.gemspec"
|
28
|
+
- "**/*.rake"
|
29
|
+
|
30
|
+
Metrics/BlockNesting:
|
31
|
+
Exclude:
|
32
|
+
- spec/**/*
|
33
|
+
- test/**/*
|
34
|
+
|
35
|
+
Metrics/CyclomaticComplexity:
|
36
|
+
Exclude:
|
37
|
+
- spec/**/*
|
38
|
+
- test/**/*
|
39
|
+
|
40
|
+
Metrics/LineLength:
|
41
|
+
Max: 120
|
42
|
+
Exclude:
|
43
|
+
- config/routes.rb
|
44
|
+
- config/routes/*
|
45
|
+
- db/migrate/*
|
46
|
+
|
47
|
+
Metrics/MethodLength:
|
48
|
+
Exclude:
|
49
|
+
- db/migrate/*
|
50
|
+
- spec/**/*
|
51
|
+
- test/**/*
|
52
|
+
|
53
|
+
Metrics/ModuleLength:
|
54
|
+
Exclude:
|
55
|
+
- spec/**/*
|
56
|
+
- test/**/*
|
57
|
+
|
58
|
+
Style/Alias:
|
59
|
+
EnforcedStyle: prefer_alias_method
|
60
|
+
|
61
|
+
Style/AndOr:
|
62
|
+
EnforcedStyle: conditionals
|
63
|
+
|
64
|
+
Style/DateTime:
|
65
|
+
Enabled: false
|
66
|
+
|
67
|
+
Style/FrozenStringLiteralComment:
|
68
|
+
Enabled: false
|
69
|
+
|
70
|
+
Style/Lambda:
|
71
|
+
Enabled: false
|
72
|
+
|
73
|
+
Style/NumericLiterals:
|
74
|
+
Enabled: false
|
75
|
+
|
76
|
+
Style/PercentLiteralDelimiters:
|
77
|
+
PreferredDelimiters:
|
78
|
+
'%i': ()
|
79
|
+
'%I': ()
|
80
|
+
'%q': ()
|
81
|
+
'%Q': ()
|
82
|
+
'%r': '{}'
|
83
|
+
'%s': ()
|
84
|
+
'%w': ()
|
85
|
+
'%W': ()
|
86
|
+
'%x': ()
|
87
|
+
|
88
|
+
Style/StringLiterals:
|
89
|
+
EnforcedStyle: double_quotes
|
90
|
+
Enabled: true
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
apple_store_inventory_checker (0.1.0.pre)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
addressable (2.6.0)
|
10
|
+
public_suffix (>= 2.0.2, < 4.0)
|
11
|
+
ast (2.4.0)
|
12
|
+
backport (1.1.1)
|
13
|
+
coderay (1.1.2)
|
14
|
+
crack (0.4.3)
|
15
|
+
safe_yaml (~> 1.0.0)
|
16
|
+
debase (0.2.2)
|
17
|
+
debase-ruby_core_source (>= 0.10.2)
|
18
|
+
debase-ruby_core_source (0.10.5)
|
19
|
+
diff-lcs (1.3)
|
20
|
+
docile (1.3.2)
|
21
|
+
hashdiff (0.4.0)
|
22
|
+
htmlentities (4.3.4)
|
23
|
+
jaro_winkler (1.5.3)
|
24
|
+
json (2.2.0)
|
25
|
+
kramdown (1.17.0)
|
26
|
+
method_source (0.9.2)
|
27
|
+
mini_portile2 (2.4.0)
|
28
|
+
nokogiri (1.10.3)
|
29
|
+
mini_portile2 (~> 2.4.0)
|
30
|
+
parallel (1.17.0)
|
31
|
+
parser (2.6.3.0)
|
32
|
+
ast (~> 2.4.0)
|
33
|
+
pry (0.12.2)
|
34
|
+
coderay (~> 1.1.0)
|
35
|
+
method_source (~> 0.9.0)
|
36
|
+
public_suffix (3.1.1)
|
37
|
+
rainbow (3.0.0)
|
38
|
+
rake (10.5.0)
|
39
|
+
ramsey_cop (0.14.0)
|
40
|
+
rubocop (~> 0.62)
|
41
|
+
rubocop-performance
|
42
|
+
reverse_markdown (1.1.0)
|
43
|
+
nokogiri
|
44
|
+
rspec (3.8.0)
|
45
|
+
rspec-core (~> 3.8.0)
|
46
|
+
rspec-expectations (~> 3.8.0)
|
47
|
+
rspec-mocks (~> 3.8.0)
|
48
|
+
rspec-core (3.8.2)
|
49
|
+
rspec-support (~> 3.8.0)
|
50
|
+
rspec-expectations (3.8.4)
|
51
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
52
|
+
rspec-support (~> 3.8.0)
|
53
|
+
rspec-mocks (3.8.1)
|
54
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
55
|
+
rspec-support (~> 3.8.0)
|
56
|
+
rspec-support (3.8.2)
|
57
|
+
rspec_junit_formatter (0.4.1)
|
58
|
+
rspec-core (>= 2, < 4, != 2.12.0)
|
59
|
+
rubocop (0.72.0)
|
60
|
+
jaro_winkler (~> 1.5.1)
|
61
|
+
parallel (~> 1.10)
|
62
|
+
parser (>= 2.6)
|
63
|
+
rainbow (>= 2.2.2, < 4.0)
|
64
|
+
ruby-progressbar (~> 1.7)
|
65
|
+
unicode-display_width (>= 1.4.0, < 1.7)
|
66
|
+
rubocop-performance (1.4.0)
|
67
|
+
rubocop (>= 0.71.0)
|
68
|
+
ruby-debug-ide (0.7.0)
|
69
|
+
rake (>= 0.8.1)
|
70
|
+
ruby-progressbar (1.10.1)
|
71
|
+
safe_yaml (1.0.5)
|
72
|
+
simplecov (0.16.1)
|
73
|
+
docile (~> 1.1)
|
74
|
+
json (>= 1.8, < 3)
|
75
|
+
simplecov-html (~> 0.10.0)
|
76
|
+
simplecov-html (0.10.2)
|
77
|
+
solargraph (0.34.1)
|
78
|
+
backport (~> 1.1)
|
79
|
+
bundler (>= 1.17.2)
|
80
|
+
htmlentities (~> 4.3, >= 4.3.4)
|
81
|
+
jaro_winkler (~> 1.5)
|
82
|
+
kramdown (~> 1.16)
|
83
|
+
parser (~> 2.3)
|
84
|
+
reverse_markdown (~> 1.0, >= 1.0.5)
|
85
|
+
rubocop (~> 0.52)
|
86
|
+
thor (~> 0.19, >= 0.19.4)
|
87
|
+
tilt (~> 2.0)
|
88
|
+
yard (~> 0.9)
|
89
|
+
thor (0.20.3)
|
90
|
+
tilt (2.0.9)
|
91
|
+
unicode-display_width (1.6.0)
|
92
|
+
webmock (3.6.0)
|
93
|
+
addressable (>= 2.3.6)
|
94
|
+
crack (>= 0.3.2)
|
95
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
96
|
+
yard (0.9.20)
|
97
|
+
|
98
|
+
PLATFORMS
|
99
|
+
ruby
|
100
|
+
|
101
|
+
DEPENDENCIES
|
102
|
+
apple_store_inventory_checker!
|
103
|
+
bundler (~> 1.17)
|
104
|
+
debase
|
105
|
+
pry
|
106
|
+
rake (~> 10.0)
|
107
|
+
ramsey_cop
|
108
|
+
rspec (~> 3.0)
|
109
|
+
rspec_junit_formatter
|
110
|
+
ruby-debug-ide
|
111
|
+
simplecov
|
112
|
+
solargraph
|
113
|
+
webmock
|
114
|
+
|
115
|
+
BUNDLED WITH
|
116
|
+
1.17.3
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Rick Peyton
|
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,89 @@
|
|
1
|
+
# Apple Store Inventory Checker
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/apple_store_inventory_checker.svg)](https://badge.fury.io/rb/apple_store_inventory_checker)
|
4
|
+
[![CircleCI](https://circleci.com/gh/rickpeyton/apple-store-inventory-checker.svg?style=svg)](https://circleci.com/gh/rickpeyton/apple-store-inventory-checker)
|
5
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/df6fd8e126fe44f99348/maintainability)](https://codeclimate.com/github/rickpeyton/apple-store-inventory-checker/maintainability)
|
6
|
+
[![Test Coverage](https://api.codeclimate.com/v1/badges/df6fd8e126fe44f99348/test_coverage)](https://codeclimate.com/github/rickpeyton/apple-store-inventory-checker/test_coverage)
|
7
|
+
[![Dependabot Status](https://api.dependabot.com/badges/status?host=github&identifier=77203066)](https://dependabot.com)
|
8
|
+
|
9
|
+
## Description
|
10
|
+
|
11
|
+
Apple has a habit of failing to provide enough supply to meet demand early in a product's lifecycle.
|
12
|
+
|
13
|
+
When a new product comes out I want to check the inventory at my local stores so that I will know when I can walk in and buy it.
|
14
|
+
|
15
|
+
### How I use this
|
16
|
+
|
17
|
+
I intend to setup a Ruby Lambda on AWS that will be triggered a few times a day by a Cloudwatch event.
|
18
|
+
|
19
|
+
If the item I am looking for is in stock I will receive an text message.
|
20
|
+
|
21
|
+
## Installation
|
22
|
+
|
23
|
+
Add this line to your application's Gemfile
|
24
|
+
|
25
|
+
```
|
26
|
+
gem 'apple_store_inventory_checker'
|
27
|
+
```
|
28
|
+
|
29
|
+
And then execute:
|
30
|
+
|
31
|
+
```
|
32
|
+
$ bundle
|
33
|
+
```
|
34
|
+
|
35
|
+
Or install it yourself as:
|
36
|
+
|
37
|
+
```
|
38
|
+
$ gem install apple_store_inventory_checker
|
39
|
+
```
|
40
|
+
|
41
|
+
## Usage
|
42
|
+
|
43
|
+
The first argument is the item number. You might be able to pull this out of the URL, but the best way to be sure is to pull it off of the XHR request Apple makes to their "pickup-message" endpoint when you load the product Apple Store page.
|
44
|
+
|
45
|
+
Max Distance is optional and is an integer representation of the miles you want to search for Apple Stores from your zip code. The default is 15.
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
retrieve_results = AppleStoreInventoryChecker.retrieve("MV6Y2LL/A", zip: "37064", max_distance: 160)
|
49
|
+
|
50
|
+
first_result = retrieve_results.first # AppleStoreInventoryChecker::Result
|
51
|
+
|
52
|
+
first_result.product # Powerbeats Pro - Totally Wireless Earphones - Black
|
53
|
+
first_result.in_stock? # false
|
54
|
+
first_result.distance # 4.76
|
55
|
+
first_result.store # CoolSprings Galleria
|
56
|
+
first_result.city # Franklin
|
57
|
+
first_result.state # TN
|
58
|
+
first_result.phone # 615-435 0620
|
59
|
+
first_result.url # http://www.apple.com/retail/coolspringsgalleria
|
60
|
+
|
61
|
+
in_stock_results = retrieve_results.select { |result| result.in_stock? }
|
62
|
+
|
63
|
+
in_stock_results.first.product # Powerbeats Pro - Totally Wireless Earphones - Black
|
64
|
+
in_stock_results.first.in_stock? # true
|
65
|
+
in_stock_results.first.distance # 158.76
|
66
|
+
in_stock_results.first.store # West Town Mall
|
67
|
+
in_stock_results.first.city # Knoxville
|
68
|
+
in_stock_results.first.state # TN
|
69
|
+
in_stock_results.first.phone # 865-824 2507
|
70
|
+
in_stock_results.first.url # http://www.apple.com/retail/westtownmall
|
71
|
+
```
|
72
|
+
|
73
|
+
## Releases
|
74
|
+
|
75
|
+
CircleCi is used to push releases to rubygems.org
|
76
|
+
|
77
|
+
To release
|
78
|
+
|
79
|
+
* Edit the version.rb file
|
80
|
+
* `bundle`
|
81
|
+
* Commit that to your master branch
|
82
|
+
* Create and push a git tag with the same name as your version
|
83
|
+
|
84
|
+
Example
|
85
|
+
|
86
|
+
```
|
87
|
+
git tag -a 0.1.0
|
88
|
+
git push origin 0.1.0
|
89
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "apple_store_inventory_checker/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "apple_store_inventory_checker"
|
7
|
+
spec.version = AppleStoreInventoryChecker::VERSION
|
8
|
+
spec.authors = ["Rick Peyton"]
|
9
|
+
spec.email = ["peytorb@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "Check inventory status at the Apple Store"
|
12
|
+
spec.description = <<~DESCRIPTION
|
13
|
+
Apple has a habit of failing to provide enough supply to meet demand early in a product's lifecycle.
|
14
|
+
|
15
|
+
When a new product comes out I want to check the inventory at my local stores so that I will know when I can walk in and buy it.
|
16
|
+
DESCRIPTION
|
17
|
+
spec.homepage = "https://github.com/rickpeyton/apple-store-inventory-checker"
|
18
|
+
spec.metadata = {
|
19
|
+
"changelog_uri" => "https://github.com/rickpeyton/apple-store-inventory-checker/releases",
|
20
|
+
"homepage_uri" => "https://github.com/rickpeyton/apple-store-inventory-checker",
|
21
|
+
"source_code_uri" => "https://github.com/rickpeyton/apple-store-inventory-checker"
|
22
|
+
}
|
23
|
+
spec.license = "MIT"
|
24
|
+
spec.required_ruby_version = ">= 2.4.6"
|
25
|
+
|
26
|
+
# Specify which files should be added to the gem when it is released.
|
27
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
28
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
29
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
30
|
+
end
|
31
|
+
spec.bindir = "exe"
|
32
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
33
|
+
spec.require_paths = ["lib"]
|
34
|
+
|
35
|
+
spec.add_development_dependency "bundler", "~> 1.17"
|
36
|
+
spec.add_development_dependency "debase"
|
37
|
+
spec.add_development_dependency "pry"
|
38
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
39
|
+
spec.add_development_dependency "ramsey_cop"
|
40
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
41
|
+
spec.add_development_dependency "rspec_junit_formatter"
|
42
|
+
spec.add_development_dependency "ruby-debug-ide"
|
43
|
+
spec.add_development_dependency "simplecov"
|
44
|
+
spec.add_development_dependency "solargraph"
|
45
|
+
spec.add_development_dependency "webmock"
|
46
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "apple_store_inventory_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,19 @@
|
|
1
|
+
module AppleStoreInventoryChecker
|
2
|
+
class APIClient
|
3
|
+
class << self
|
4
|
+
def get(uri)
|
5
|
+
http = setup_http(uri)
|
6
|
+
req = Net::HTTP::Get.new(uri)
|
7
|
+
req.add_field "Accept", "application/json"
|
8
|
+
http.request(req)
|
9
|
+
end
|
10
|
+
|
11
|
+
def setup_http(uri)
|
12
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
13
|
+
http.use_ssl = true
|
14
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
15
|
+
http
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module AppleStoreInventoryChecker
|
2
|
+
class APIRequest
|
3
|
+
class << self; end
|
4
|
+
|
5
|
+
private
|
6
|
+
|
7
|
+
def request(_method, query: {})
|
8
|
+
url_params = to_url_params(query)
|
9
|
+
uri = URI("#{AppleStoreInventoryChecker.base_url}?#{url_params}")
|
10
|
+
response = AppleStoreInventoryChecker.client.get(uri)
|
11
|
+
|
12
|
+
JSON.parse(response.body, symbolize_names: true)
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_url_params(query)
|
16
|
+
URI.encode_www_form(query)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module AppleStoreInventoryChecker
|
2
|
+
class Result
|
3
|
+
attr_accessor :city
|
4
|
+
attr_accessor :distance
|
5
|
+
attr_accessor :phone
|
6
|
+
attr_accessor :product
|
7
|
+
attr_accessor :state
|
8
|
+
attr_accessor :store
|
9
|
+
attr_accessor :url
|
10
|
+
|
11
|
+
attr_reader :product_id
|
12
|
+
|
13
|
+
attr_writer :in_stock
|
14
|
+
|
15
|
+
def initialize(product_id:)
|
16
|
+
@product_id = product_id
|
17
|
+
end
|
18
|
+
|
19
|
+
def in_stock?
|
20
|
+
@in_stock
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module AppleStoreInventoryChecker
|
2
|
+
class ResultsList < APIRequest
|
3
|
+
include Enumerable
|
4
|
+
|
5
|
+
attr_accessor :max_distance
|
6
|
+
attr_accessor :product_id
|
7
|
+
attr_accessor :results
|
8
|
+
attr_accessor :zip
|
9
|
+
|
10
|
+
def initialize(product_id, zip:, max_distance: 15.0)
|
11
|
+
@product_id = product_id
|
12
|
+
@zip = zip
|
13
|
+
@max_distance = max_distance
|
14
|
+
end
|
15
|
+
|
16
|
+
def refresh
|
17
|
+
response = request(:get, query: { "parts.0" => @product_id, location: @zip })
|
18
|
+
raw_results = response.dig(:body, :stores)
|
19
|
+
self.results = refresh_list_objects(raw_results, max_distance: @max_distance)
|
20
|
+
self
|
21
|
+
end
|
22
|
+
|
23
|
+
def each
|
24
|
+
results.each do |result|
|
25
|
+
yield(result)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def refresh_list_objects(raw_results, max_distance:) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
32
|
+
objects = raw_results.map do |raw_result|
|
33
|
+
result = Result.new(product_id: product_id)
|
34
|
+
result.product = raw_result.dig(:partsAvailability, product_id.to_sym, :storePickupProductTitle)
|
35
|
+
result.in_stock = raw_result.dig(:partsAvailability, product_id.to_sym, :storePickupQuote).include?("Today")
|
36
|
+
result.distance = raw_result.dig(:storedistance).to_f
|
37
|
+
result.store = raw_result.dig(:storeName)
|
38
|
+
result.city = raw_result.dig(:city)
|
39
|
+
result.state = raw_result.dig(:state)
|
40
|
+
result.phone = raw_result.dig(:phoneNumber)
|
41
|
+
result.url = raw_result.dig(:directionsUrl)
|
42
|
+
result
|
43
|
+
end
|
44
|
+
objects.select { |result| result&.distance && (result.distance < max_distance) }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
begin
|
2
|
+
require "pry"
|
3
|
+
rescue StandardError; end # rubocop:disable Lint/HandleExceptions
|
4
|
+
require "json"
|
5
|
+
|
6
|
+
require_relative "apple_store_inventory_checker/api_client"
|
7
|
+
require_relative "apple_store_inventory_checker/api_request"
|
8
|
+
require_relative "apple_store_inventory_checker/result"
|
9
|
+
require_relative "apple_store_inventory_checker/results_list"
|
10
|
+
require_relative "apple_store_inventory_checker/version"
|
11
|
+
|
12
|
+
module AppleStoreInventoryChecker
|
13
|
+
class << self
|
14
|
+
attr_writer :client
|
15
|
+
|
16
|
+
BASE_URL = "https://www.apple.com/shop/retail/pickup-message".freeze
|
17
|
+
|
18
|
+
def base_url
|
19
|
+
BASE_URL
|
20
|
+
end
|
21
|
+
|
22
|
+
def client
|
23
|
+
@client ||= AppleStoreInventoryChecker::APIClient
|
24
|
+
end
|
25
|
+
|
26
|
+
def retrieve(product_id, zip:, max_distance: 15.0)
|
27
|
+
instance = ResultsList.new(product_id, zip: zip, max_distance: max_distance)
|
28
|
+
instance.refresh
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class Error < StandardError; end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,225 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: apple_store_inventory_checker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0.pre
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rick Peyton
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-06-29 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: '1.17'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.17'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: debase
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
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
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: ramsey_cop
|
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: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '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: '3.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec_junit_formatter
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
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: ruby-debug-ide
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
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: simplecov
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: solargraph
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: webmock
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
description: |
|
168
|
+
Apple has a habit of failing to provide enough supply to meet demand early in a product's lifecycle.
|
169
|
+
|
170
|
+
When a new product comes out I want to check the inventory at my local stores so that I will know when I can walk in and buy it.
|
171
|
+
email:
|
172
|
+
- peytorb@gmail.com
|
173
|
+
executables: []
|
174
|
+
extensions: []
|
175
|
+
extra_rdoc_files: []
|
176
|
+
files:
|
177
|
+
- ".circleci/config.yml"
|
178
|
+
- ".circleci/setup-rubygems.sh"
|
179
|
+
- ".codeclimate.yml"
|
180
|
+
- ".devcontainer/Dockerfile"
|
181
|
+
- ".devcontainer/devcontainer.json"
|
182
|
+
- ".gitignore"
|
183
|
+
- ".rspec"
|
184
|
+
- ".rubocop.yml"
|
185
|
+
- Gemfile
|
186
|
+
- Gemfile.lock
|
187
|
+
- LICENSE.txt
|
188
|
+
- README.md
|
189
|
+
- Rakefile
|
190
|
+
- apple_store_inventory_checker.gemspec
|
191
|
+
- bin/console
|
192
|
+
- bin/setup
|
193
|
+
- lib/apple_store_inventory_checker.rb
|
194
|
+
- lib/apple_store_inventory_checker/api_client.rb
|
195
|
+
- lib/apple_store_inventory_checker/api_request.rb
|
196
|
+
- lib/apple_store_inventory_checker/result.rb
|
197
|
+
- lib/apple_store_inventory_checker/results_list.rb
|
198
|
+
- lib/apple_store_inventory_checker/version.rb
|
199
|
+
homepage: https://github.com/rickpeyton/apple-store-inventory-checker
|
200
|
+
licenses:
|
201
|
+
- MIT
|
202
|
+
metadata:
|
203
|
+
changelog_uri: https://github.com/rickpeyton/apple-store-inventory-checker/releases
|
204
|
+
homepage_uri: https://github.com/rickpeyton/apple-store-inventory-checker
|
205
|
+
source_code_uri: https://github.com/rickpeyton/apple-store-inventory-checker
|
206
|
+
post_install_message:
|
207
|
+
rdoc_options: []
|
208
|
+
require_paths:
|
209
|
+
- lib
|
210
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
211
|
+
requirements:
|
212
|
+
- - ">="
|
213
|
+
- !ruby/object:Gem::Version
|
214
|
+
version: 2.4.6
|
215
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
216
|
+
requirements:
|
217
|
+
- - ">"
|
218
|
+
- !ruby/object:Gem::Version
|
219
|
+
version: 1.3.1
|
220
|
+
requirements: []
|
221
|
+
rubygems_version: 3.0.3
|
222
|
+
signing_key:
|
223
|
+
specification_version: 4
|
224
|
+
summary: Check inventory status at the Apple Store
|
225
|
+
test_files: []
|