fitnesspark_api 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.rubocop.yml +20 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.md +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +18 -0
- data/Gemfile.lock +77 -0
- data/LICENSE +7 -0
- data/README.md +54 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/data/config.yml +17 -0
- data/fitnesspark_api.gemspec +31 -0
- data/lib/fitnesspark_api.rb +71 -0
- data/lib/fitnesspark_api/http_client.rb +77 -0
- data/lib/fitnesspark_api/version.rb +5 -0
- metadata +92 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: bbf543f83acc35e82b3ea019cc871012623426af34e65c2fd4227e6685dc2180
|
4
|
+
data.tar.gz: 31770634d91fbe7dd45b5d07eee8310605be31c535d93f4d4d32481ef0032cca
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 950491a3572d6cbf93daa4fe3b8c1dfc008495f0785d3ce99f55814f1a9f4b0c93d1282c468df040eb28aace3b4832ca72d8c8f8bf5bf29475965270dec2513e
|
7
|
+
data.tar.gz: f9ab1c1be3d6ecc595e503e1aecad4e6aa1c94fc6c4c804d7cc751657136ab83d23d0ccca6e95890c72afebf2060cf1b1c6199effd58e89221740db049413a55
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.6
|
3
|
+
|
4
|
+
Style/Documentation:
|
5
|
+
Enabled: false
|
6
|
+
|
7
|
+
Metrics/AbcSize:
|
8
|
+
Max: 28
|
9
|
+
|
10
|
+
Metrics/BlockLength:
|
11
|
+
Max: 30
|
12
|
+
|
13
|
+
Metrics/CyclomaticComplexity:
|
14
|
+
Max: 11
|
15
|
+
|
16
|
+
Metrics/MethodLength:
|
17
|
+
Max: 20
|
18
|
+
|
19
|
+
Metrics/PerceivedComplexity:
|
20
|
+
Max: 11
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at alexander.adam@vade.io. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in fitnesspark_api.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
gem 'rake'
|
9
|
+
|
10
|
+
group :development, :test do
|
11
|
+
gem 'rubocop'
|
12
|
+
end
|
13
|
+
|
14
|
+
group :test do
|
15
|
+
gem 'rspec'
|
16
|
+
gem 'vcr'
|
17
|
+
gem 'webmock'
|
18
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
fitnesspark_api (0.1.1)
|
5
|
+
oga
|
6
|
+
oj
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
addressable (2.7.0)
|
12
|
+
public_suffix (>= 2.0.2, < 5.0)
|
13
|
+
ansi (1.5.0)
|
14
|
+
ast (2.4.1)
|
15
|
+
crack (0.4.4)
|
16
|
+
diff-lcs (1.4.4)
|
17
|
+
hashdiff (1.0.1)
|
18
|
+
oga (3.3)
|
19
|
+
ast
|
20
|
+
ruby-ll (~> 2.1)
|
21
|
+
oj (3.10.15)
|
22
|
+
parallel (1.19.2)
|
23
|
+
parser (2.7.2.0)
|
24
|
+
ast (~> 2.4.1)
|
25
|
+
public_suffix (4.0.6)
|
26
|
+
rainbow (3.0.0)
|
27
|
+
rake (13.0.1)
|
28
|
+
regexp_parser (1.8.2)
|
29
|
+
rexml (3.2.4)
|
30
|
+
rspec (3.9.0)
|
31
|
+
rspec-core (~> 3.9.0)
|
32
|
+
rspec-expectations (~> 3.9.0)
|
33
|
+
rspec-mocks (~> 3.9.0)
|
34
|
+
rspec-core (3.9.3)
|
35
|
+
rspec-support (~> 3.9.3)
|
36
|
+
rspec-expectations (3.9.3)
|
37
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
38
|
+
rspec-support (~> 3.9.0)
|
39
|
+
rspec-mocks (3.9.1)
|
40
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
41
|
+
rspec-support (~> 3.9.0)
|
42
|
+
rspec-support (3.9.4)
|
43
|
+
rubocop (1.0.0)
|
44
|
+
parallel (~> 1.10)
|
45
|
+
parser (>= 2.7.1.5)
|
46
|
+
rainbow (>= 2.2.2, < 4.0)
|
47
|
+
regexp_parser (>= 1.8)
|
48
|
+
rexml
|
49
|
+
rubocop-ast (>= 0.6.0)
|
50
|
+
ruby-progressbar (~> 1.7)
|
51
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
52
|
+
rubocop-ast (1.0.1)
|
53
|
+
parser (>= 2.7.1.5)
|
54
|
+
ruby-ll (2.1.2)
|
55
|
+
ansi
|
56
|
+
ast
|
57
|
+
ruby-progressbar (1.10.1)
|
58
|
+
unicode-display_width (1.7.0)
|
59
|
+
vcr (6.0.0)
|
60
|
+
webmock (3.9.3)
|
61
|
+
addressable (>= 2.3.6)
|
62
|
+
crack (>= 0.3.2)
|
63
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
64
|
+
|
65
|
+
PLATFORMS
|
66
|
+
ruby
|
67
|
+
|
68
|
+
DEPENDENCIES
|
69
|
+
fitnesspark_api!
|
70
|
+
rake
|
71
|
+
rspec
|
72
|
+
rubocop
|
73
|
+
vcr
|
74
|
+
webmock
|
75
|
+
|
76
|
+
BUNDLED WITH
|
77
|
+
2.1.4
|
data/LICENSE
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright 2020 Alexander Adam
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# FitnessparkApi
|
2
|
+
|
3
|
+
You can use this Gem to get data from the [Fitnesspark API](https://www.fitnesspark.ch/).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'fitnesspark_api'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
```bash
|
16
|
+
$ bundle install
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
```bash
|
22
|
+
$ gem install fitnesspark_api
|
23
|
+
```
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
require 'fitnesspark_api'
|
30
|
+
|
31
|
+
FitnessparkApi.stores # returns a hash with base data of all centers
|
32
|
+
# => {"stores"=>[{"localized_slugs"=>{"de"=>"activ-fitness-acacias", "it"…
|
33
|
+
|
34
|
+
FitnessparkApi.store('fitnesspark-eichstaette') # returns a hash with detailed data of a center
|
35
|
+
# => {"markets"=>[{"closing_date"=>nil, "media"=>…
|
36
|
+
|
37
|
+
FitnessparkApi.visitors('fitnesspark-eichstaette') # returns a hash with visitor data
|
38
|
+
# => {"centerId"=>12, "centerIdTac"=>45, "currentVisitors"=>169, "maxVisitors"=>300}
|
39
|
+
```
|
40
|
+
|
41
|
+
## Development
|
42
|
+
|
43
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
44
|
+
|
45
|
+
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).
|
46
|
+
|
47
|
+
## Contributing
|
48
|
+
|
49
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/alexanderadam/fitnesspark_api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/alexanderadam/fitnesspark_api/blob/master/CODE_OF_CONDUCT.md).
|
50
|
+
|
51
|
+
|
52
|
+
## Code of Conduct
|
53
|
+
|
54
|
+
Everyone interacting in the FitnessparkApi project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/alexanderadam/fitnesspark_api/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'fitnesspark_api'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/data/config.yml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
user_agent: "FitnessparkAPI %{version}"
|
2
|
+
stores:
|
3
|
+
default_params:
|
4
|
+
verbosity: store
|
5
|
+
limit: '5000'
|
6
|
+
aggregation_options[empty_buckets]: 'true'
|
7
|
+
filters[markets][0][]:
|
8
|
+
- fitnesspark
|
9
|
+
- activ_fitness
|
10
|
+
- flowerpower
|
11
|
+
- migros_fitnessclub
|
12
|
+
- one_training_center
|
13
|
+
- mfit
|
14
|
+
- migros_fitnesscenter
|
15
|
+
- aquaparks
|
16
|
+
- elements
|
17
|
+
- only_fitness
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/fitnesspark_api/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'fitnesspark_api'
|
7
|
+
spec.version = FitnessparkApi::VERSION
|
8
|
+
spec.licenses = ['MIT']
|
9
|
+
spec.authors = ['Alexander Adam']
|
10
|
+
spec.email = ['alexander.adam@vade.io']
|
11
|
+
|
12
|
+
spec.summary = 'Access Migros Fitnesspark data via Ruby'
|
13
|
+
spec.description = 'Access Migros Fitnesspark data via Ruby'
|
14
|
+
spec.homepage = 'https://github.com/alexanderadam/fitnesspark_api'
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.6.0')
|
16
|
+
|
17
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
18
|
+
spec.metadata['source_code_uri'] = 'https://github.com/alexanderadam/fitnesspark_api'
|
19
|
+
spec.metadata['changelog_uri'] = 'https://github.com/alexanderadam/fitnesspark_api/blob/main/CHANGELOG.md'
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
24
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
end
|
26
|
+
spec.bindir = 'exe'
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ['lib']
|
29
|
+
spec.add_dependency 'oga'
|
30
|
+
spec.add_dependency 'oj'
|
31
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
require_relative 'fitnesspark_api/version'
|
5
|
+
require_relative 'fitnesspark_api/http_client'
|
6
|
+
|
7
|
+
module FitnessparkApi
|
8
|
+
ResponseError = Class.new(IOError)
|
9
|
+
STORES_URL = 'https://web-api.migros.ch/widgets/stores'
|
10
|
+
VISITORS_URL = 'https://blfa-api.migros.ch/fp/api/center/%<center_id>s/currentuser'
|
11
|
+
|
12
|
+
module_function
|
13
|
+
|
14
|
+
def stores(get_params = nil)
|
15
|
+
get_params ||= config.dig('stores', 'default_params')
|
16
|
+
get_params['key'] ||= api_key
|
17
|
+
|
18
|
+
uri = URI(STORES_URL)
|
19
|
+
uri.query = URI.encode_www_form(get_params)
|
20
|
+
HttpClient.get_json(uri)
|
21
|
+
end
|
22
|
+
|
23
|
+
def store(center_id)
|
24
|
+
get_params = { 'key' => api_key }
|
25
|
+
uri = URI(File.join(STORES_URL, center_id))
|
26
|
+
uri.query = URI.encode_www_form(get_params)
|
27
|
+
HttpClient.get_json(uri)
|
28
|
+
end
|
29
|
+
|
30
|
+
def visitors(center_id)
|
31
|
+
center_id = center_volume_id(center_id) if center_id.is_a?(String) && !center_id.match(/\A\d+\z/)
|
32
|
+
uri = URI(format(VISITORS_URL, center_id: center_id))
|
33
|
+
HttpClient.get_json(uri)
|
34
|
+
end
|
35
|
+
|
36
|
+
def config
|
37
|
+
YAML.load_file(File.join(File.dirname(__FILE__), '..', 'data', 'config.yml'))
|
38
|
+
end
|
39
|
+
|
40
|
+
def center_volume_id(slug)
|
41
|
+
base_data = base_data_by_name(slug)
|
42
|
+
detail_data = store(base_data['id'])
|
43
|
+
markets = detail_data['markets']
|
44
|
+
raise(ArgumentError, "Found more than one center for slug #{slug}") unless markets.one?
|
45
|
+
|
46
|
+
HttpClient.get_center_volume_id(markets.first['weblink']['url'])
|
47
|
+
end
|
48
|
+
|
49
|
+
def base_data_by_name(slug)
|
50
|
+
all_base_data = stores
|
51
|
+
result = all_base_data['stores'].find do |store_hash|
|
52
|
+
store_hash['name'] == slug ||
|
53
|
+
store_hash['id'] == slug ||
|
54
|
+
store_hash['slug'] == slug ||
|
55
|
+
store_hash.dig('localized_slugs', 'de') == slug ||
|
56
|
+
store_hash.dig('localized_slugs', 'it') == slug ||
|
57
|
+
store_hash.dig('localized_slugs', 'fr') == slug ||
|
58
|
+
store_hash['additional_slugs'].include?(slug) ||
|
59
|
+
store_hash['additional_ids'].include?(slug)
|
60
|
+
end
|
61
|
+
|
62
|
+
return result if result
|
63
|
+
|
64
|
+
all_slugs = stores['stores'].map { |s| s['slug'] }.uniq.sort
|
65
|
+
raise(ArgumentError, "Unable to find #{slug.inspect}. Did you mean one of these: #{all_slugs.inspect}")
|
66
|
+
end
|
67
|
+
|
68
|
+
def api_key
|
69
|
+
ENV['FITNESSPARK_SESSION_KEY'] || HttpClient.api_key
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'net/http'
|
4
|
+
require 'oj'
|
5
|
+
require 'oga'
|
6
|
+
|
7
|
+
module FitnessparkApi
|
8
|
+
module HttpClient
|
9
|
+
module_function
|
10
|
+
|
11
|
+
def get_json(uri, headers: {})
|
12
|
+
response = get(uri, headers: headers)
|
13
|
+
|
14
|
+
Oj.load(response.body)
|
15
|
+
end
|
16
|
+
|
17
|
+
def get_html(uri, headers: {})
|
18
|
+
response = get(uri, headers: headers)
|
19
|
+
|
20
|
+
Oga.parse_html(response.body.force_encoding('UTF-8'))
|
21
|
+
end
|
22
|
+
|
23
|
+
def get_center_volume_id(url)
|
24
|
+
html = get_html(url)
|
25
|
+
html.css('.centerVolume').first.attribute('centerId').value.to_i
|
26
|
+
end
|
27
|
+
|
28
|
+
def get(uri, headers: {}, max_redirect_count: 10)
|
29
|
+
uri = URI(uri) if uri.is_a?(String)
|
30
|
+
|
31
|
+
request = Net::HTTP::Get.new(uri)
|
32
|
+
headers.merge!('User-Agent' => user_agent, 'Origin' => 'https://www.migros-fitness.ch')
|
33
|
+
headers.each { |name, value| request[name] = value }
|
34
|
+
|
35
|
+
http = Net::HTTP.new(uri.hostname, uri.port)
|
36
|
+
http.use_ssl = uri.scheme == 'https'
|
37
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
38
|
+
response = http.request(request)
|
39
|
+
if response.is_a?(Net::HTTPRedirection) && response['location'] && max_redirect_count.positive?
|
40
|
+
return get(response['location'], headers: headers, max_redirect_count: max_redirect_count - 1)
|
41
|
+
end
|
42
|
+
|
43
|
+
ensure_successful_response(response)
|
44
|
+
response
|
45
|
+
end
|
46
|
+
|
47
|
+
def user_agent
|
48
|
+
format(FitnessparkApi.config['user_agent'], version: VERSION)
|
49
|
+
end
|
50
|
+
|
51
|
+
def ensure_successful_response(response)
|
52
|
+
return if response.code == '200'
|
53
|
+
|
54
|
+
if response.body.to_s.strip.start_with?('{')
|
55
|
+
error_json = Oj.load(response.body)
|
56
|
+
if error_json.key?('error')
|
57
|
+
msg = error_json['error']
|
58
|
+
msg << ": #{error_json['message']}" if error_json.key?('message')
|
59
|
+
else
|
60
|
+
msg = error_json.to_s
|
61
|
+
end
|
62
|
+
else
|
63
|
+
msg = "Unsuccessful response #{response.code}"
|
64
|
+
end
|
65
|
+
|
66
|
+
raise ResponseError, msg
|
67
|
+
end
|
68
|
+
|
69
|
+
def api_key
|
70
|
+
return @api_key if @api_key
|
71
|
+
|
72
|
+
html = get_html('https://www.migros-fitness.ch/karte')
|
73
|
+
json = Oj.load(html.css('html').first.attribute('data-setup').value.gsub("'", '"'))
|
74
|
+
@api_key = json['sessionKey']
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fitnesspark_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alexander Adam
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-10-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: oga
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
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: oj
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Access Migros Fitnesspark data via Ruby
|
42
|
+
email:
|
43
|
+
- alexander.adam@vade.io
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- ".rspec"
|
50
|
+
- ".rubocop.yml"
|
51
|
+
- ".travis.yml"
|
52
|
+
- CHANGELOG.md
|
53
|
+
- CODE_OF_CONDUCT.md
|
54
|
+
- Gemfile
|
55
|
+
- Gemfile.lock
|
56
|
+
- LICENSE
|
57
|
+
- README.md
|
58
|
+
- Rakefile
|
59
|
+
- bin/console
|
60
|
+
- bin/setup
|
61
|
+
- data/config.yml
|
62
|
+
- fitnesspark_api.gemspec
|
63
|
+
- lib/fitnesspark_api.rb
|
64
|
+
- lib/fitnesspark_api/http_client.rb
|
65
|
+
- lib/fitnesspark_api/version.rb
|
66
|
+
homepage: https://github.com/alexanderadam/fitnesspark_api
|
67
|
+
licenses:
|
68
|
+
- MIT
|
69
|
+
metadata:
|
70
|
+
homepage_uri: https://github.com/alexanderadam/fitnesspark_api
|
71
|
+
source_code_uri: https://github.com/alexanderadam/fitnesspark_api
|
72
|
+
changelog_uri: https://github.com/alexanderadam/fitnesspark_api/blob/main/CHANGELOG.md
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: 2.6.0
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
requirements: []
|
88
|
+
rubygems_version: 3.1.2
|
89
|
+
signing_key:
|
90
|
+
specification_version: 4
|
91
|
+
summary: Access Migros Fitnesspark data via Ruby
|
92
|
+
test_files: []
|