vodacom 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +69 -0
- data/.ruby-version +1 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +113 -0
- data/LICENSE +21 -0
- data/LICENSE.txt +21 -0
- data/README.md +54 -0
- data/Rakefile +10 -0
- data/bin/console +11 -0
- data/bin/setup +8 -0
- data/lib/vodacom.rb +10 -0
- data/lib/vodacom/client.rb +191 -0
- data/lib/vodacom/version.rb +3 -0
- data/vodacom.gemspec +40 -0
- metadata +226 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 616e8f37264023776722f3257b0a3f2f0fb81c44ac7be438e4b1696944e55bbf
|
4
|
+
data.tar.gz: 622956d5c44f8212bad1e9f8c9e082708373e9b45884701403c39bdfa4c754ff
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 937f6afefe92045f0483fa7a678a8f53ae9033cf3a9da1e25991a6cab361ff619e5cb0224f0758a426889406926f52fd86f2107741db9c3624581096cafd17a8
|
7
|
+
data.tar.gz: 0a6bff1375032eb927764f2907e184ff9a3545d677c7628a219dde7957b0e0156b2ff59e474226f6e54a0073a4912f9966a01930bf4e3f5f153a026513e80bd5
|
data/.gitignore
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
*.rbc
|
2
|
+
capybara-*.html
|
3
|
+
.rspec
|
4
|
+
/db/*.sqlite3
|
5
|
+
/db/*.sqlite3-journal
|
6
|
+
/db/*.sqlite3-[0-9]*
|
7
|
+
/public/system
|
8
|
+
/coverage/
|
9
|
+
/spec/tmp
|
10
|
+
*.orig
|
11
|
+
rerun.txt
|
12
|
+
pickle-email-*.html
|
13
|
+
|
14
|
+
# Ignore all logfiles and tempfiles.
|
15
|
+
/log/*
|
16
|
+
/tmp/*
|
17
|
+
!/log/.keep
|
18
|
+
!/tmp/.keep
|
19
|
+
|
20
|
+
# TODO Comment out this rule if you are OK with secrets being uploaded to the repo
|
21
|
+
config/initializers/secret_token.rb
|
22
|
+
config/master.key
|
23
|
+
|
24
|
+
# Only include if you have production secrets in this file, which is no longer a Rails default
|
25
|
+
# config/secrets.yml
|
26
|
+
|
27
|
+
# dotenv
|
28
|
+
# TODO Comment out this rule if environment variables can be committed
|
29
|
+
.env
|
30
|
+
|
31
|
+
## Environment normalization:
|
32
|
+
/.bundle
|
33
|
+
/vendor/bundle
|
34
|
+
|
35
|
+
# these should all be checked in to normalize the environment:
|
36
|
+
# Gemfile.lock, .ruby-version, .ruby-gemset
|
37
|
+
|
38
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
39
|
+
.rvmrc
|
40
|
+
|
41
|
+
# if using bower-rails ignore default bower_components path bower.json files
|
42
|
+
/vendor/assets/bower_components
|
43
|
+
*.bowerrc
|
44
|
+
bower.json
|
45
|
+
|
46
|
+
# Ignore pow environment settings
|
47
|
+
.powenv
|
48
|
+
|
49
|
+
# Ignore Byebug command history file.
|
50
|
+
.byebug_history
|
51
|
+
|
52
|
+
# Ignore node_modules
|
53
|
+
node_modules/
|
54
|
+
|
55
|
+
# Ignore precompiled javascript packs
|
56
|
+
/public/packs
|
57
|
+
/public/packs-test
|
58
|
+
/public/assets
|
59
|
+
|
60
|
+
# Ignore yarn files
|
61
|
+
/yarn-error.log
|
62
|
+
yarn-debug.log*
|
63
|
+
.yarn-integrity
|
64
|
+
|
65
|
+
# Ignore uploaded files in development
|
66
|
+
/storage/*
|
67
|
+
!/storage/.keep
|
68
|
+
|
69
|
+
*.gem
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.6.3
|
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 contact@jasonchalom.com. 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 [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
vodacom (0.0.1)
|
5
|
+
active_attr (~> 0.15)
|
6
|
+
httparty (~> 0.18)
|
7
|
+
nokogiri (~> 1.11.2)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
actionpack (6.1.3)
|
13
|
+
actionview (= 6.1.3)
|
14
|
+
activesupport (= 6.1.3)
|
15
|
+
rack (~> 2.0, >= 2.0.9)
|
16
|
+
rack-test (>= 0.6.3)
|
17
|
+
rails-dom-testing (~> 2.0)
|
18
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
19
|
+
actionview (6.1.3)
|
20
|
+
activesupport (= 6.1.3)
|
21
|
+
builder (~> 3.1)
|
22
|
+
erubi (~> 1.4)
|
23
|
+
rails-dom-testing (~> 2.0)
|
24
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
25
|
+
active_attr (0.15.2)
|
26
|
+
actionpack (>= 3.0.2, < 7.0)
|
27
|
+
activemodel (>= 3.0.2, < 7.0)
|
28
|
+
activesupport (>= 3.0.2, < 7.0)
|
29
|
+
activemodel (6.1.3)
|
30
|
+
activesupport (= 6.1.3)
|
31
|
+
activesupport (6.1.3)
|
32
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
33
|
+
i18n (>= 1.6, < 2)
|
34
|
+
minitest (>= 5.1)
|
35
|
+
tzinfo (~> 2.0)
|
36
|
+
zeitwerk (~> 2.3)
|
37
|
+
addressable (2.7.0)
|
38
|
+
public_suffix (>= 2.0.2, < 5.0)
|
39
|
+
ansi (1.5.0)
|
40
|
+
builder (3.2.4)
|
41
|
+
coderay (1.1.3)
|
42
|
+
concurrent-ruby (1.1.8)
|
43
|
+
crack (0.4.5)
|
44
|
+
rexml
|
45
|
+
crass (1.0.6)
|
46
|
+
erubi (1.10.0)
|
47
|
+
hashdiff (1.0.1)
|
48
|
+
httparty (0.18.1)
|
49
|
+
mime-types (~> 3.0)
|
50
|
+
multi_xml (>= 0.5.2)
|
51
|
+
i18n (1.8.9)
|
52
|
+
concurrent-ruby (~> 1.0)
|
53
|
+
loofah (2.9.0)
|
54
|
+
crass (~> 1.0.2)
|
55
|
+
nokogiri (>= 1.5.9)
|
56
|
+
method_source (1.0.0)
|
57
|
+
mime-types (3.3.1)
|
58
|
+
mime-types-data (~> 3.2015)
|
59
|
+
mime-types-data (3.2021.0225)
|
60
|
+
minitest (5.14.4)
|
61
|
+
minitest-focus (1.1.2)
|
62
|
+
minitest (>= 4, < 6)
|
63
|
+
minitest-reporters (1.4.3)
|
64
|
+
ansi
|
65
|
+
builder
|
66
|
+
minitest (>= 5.0)
|
67
|
+
ruby-progressbar
|
68
|
+
mocha (1.11.2)
|
69
|
+
multi_xml (0.6.0)
|
70
|
+
nokogiri (1.11.2-x86_64-linux)
|
71
|
+
racc (~> 1.4)
|
72
|
+
pry (0.14.0)
|
73
|
+
coderay (~> 1.1)
|
74
|
+
method_source (~> 1.0)
|
75
|
+
public_suffix (4.0.6)
|
76
|
+
racc (1.5.2)
|
77
|
+
rack (2.2.3)
|
78
|
+
rack-test (1.1.0)
|
79
|
+
rack (>= 1.0, < 3)
|
80
|
+
rails-dom-testing (2.0.3)
|
81
|
+
activesupport (>= 4.2.0)
|
82
|
+
nokogiri (>= 1.6)
|
83
|
+
rails-html-sanitizer (1.3.0)
|
84
|
+
loofah (~> 2.3)
|
85
|
+
rake (13.0.3)
|
86
|
+
rexml (3.2.4)
|
87
|
+
ruby-progressbar (1.11.0)
|
88
|
+
timecop (0.9.4)
|
89
|
+
tzinfo (2.0.4)
|
90
|
+
concurrent-ruby (~> 1.0)
|
91
|
+
webmock (3.8.3)
|
92
|
+
addressable (>= 2.3.6)
|
93
|
+
crack (>= 0.3.2)
|
94
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
95
|
+
zeitwerk (2.4.2)
|
96
|
+
|
97
|
+
PLATFORMS
|
98
|
+
x86_64-linux
|
99
|
+
|
100
|
+
DEPENDENCIES
|
101
|
+
bundler (~> 2.2.14)
|
102
|
+
minitest (~> 5.0)
|
103
|
+
minitest-focus (~> 1.1.2)
|
104
|
+
minitest-reporters (~> 1.4.2)
|
105
|
+
mocha (~> 1.11.2)
|
106
|
+
pry (~> 0.13)
|
107
|
+
rake (~> 13.0)
|
108
|
+
timecop (~> 0.9.1)
|
109
|
+
vodacom!
|
110
|
+
webmock (~> 3.8.3)
|
111
|
+
|
112
|
+
BUNDLED WITH
|
113
|
+
2.2.14
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2021 Jason Chalom
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 trex22
|
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,54 @@
|
|
1
|
+
# Vodacom-Client
|
2
|
+
A client for the Vodacom-Client API.
|
3
|
+
|
4
|
+
This is an unofficial project and still a work in progress (WIP) ... more to come soon.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'vodacom'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install vodacom
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
require 'vodacom'
|
26
|
+
client = Vodacom::Client.new(key: 'your key', secret: 'your secret')
|
27
|
+
```
|
28
|
+
|
29
|
+
### Endpoints
|
30
|
+
- Login
|
31
|
+
- Balance
|
32
|
+
|
33
|
+
## Development
|
34
|
+
|
35
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
36
|
+
|
37
|
+
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).
|
38
|
+
|
39
|
+
### Tests
|
40
|
+
To run tests execute:
|
41
|
+
|
42
|
+
$ rake test
|
43
|
+
|
44
|
+
## Contributing
|
45
|
+
|
46
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/trex22/vodacom-client. 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.
|
47
|
+
|
48
|
+
## License
|
49
|
+
|
50
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
51
|
+
|
52
|
+
## Code of Conduct
|
53
|
+
|
54
|
+
Everyone interacting in the vodacom-client: project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/trex22/vodacom-client/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "vodacom"
|
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
|
data/bin/setup
ADDED
data/lib/vodacom.rb
ADDED
@@ -0,0 +1,191 @@
|
|
1
|
+
module Vodacom
|
2
|
+
class Client
|
3
|
+
# include HTTParty_with_cookies
|
4
|
+
|
5
|
+
LOGIN_PATH = 'https://www.vodacom.co.za/cloud/login/v3/login'
|
6
|
+
BALANCE_PATH = 'https://www.vodacom.co.za/cloud/rest/balances/v3/bundle/balances/'
|
7
|
+
|
8
|
+
attr_reader :username,
|
9
|
+
:password,
|
10
|
+
:base_path,
|
11
|
+
:port,
|
12
|
+
:login_response,
|
13
|
+
# :gateway_session,
|
14
|
+
# :gateway_session_expiry,
|
15
|
+
# :vopToken,
|
16
|
+
# :vopToken_expiry,
|
17
|
+
# :vod_web_auth_token,
|
18
|
+
# :vod_web_auth_token_expiry,
|
19
|
+
# :jsessionid,
|
20
|
+
# :jsessionid_expiry,
|
21
|
+
# :oauth2_apps_token_db,
|
22
|
+
# :oauth2_apps_token_db_expiry,
|
23
|
+
:raw_cookie
|
24
|
+
|
25
|
+
def initialize(username:, password:, base_path: 'https://www.vodacom.co.za/cloud', port: 80)
|
26
|
+
@username = username
|
27
|
+
@password = password
|
28
|
+
@base_path = base_path
|
29
|
+
@port = port
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.compatible_api_version
|
33
|
+
'v3'
|
34
|
+
end
|
35
|
+
|
36
|
+
# This is the version of the API docs this client was built off-of
|
37
|
+
def self.api_version
|
38
|
+
'v3 2021-03-13'
|
39
|
+
end
|
40
|
+
|
41
|
+
def balance(phone_number)
|
42
|
+
start_time = get_micro_second_time
|
43
|
+
|
44
|
+
login unless raw_cookie
|
45
|
+
response = HTTParty.send(
|
46
|
+
:get,
|
47
|
+
"#{BALANCE_PATH}#{phone_number}",
|
48
|
+
headers: {
|
49
|
+
'Content-Type': 'application/json',
|
50
|
+
'Accept': '*/*',
|
51
|
+
'Cookie': process_cookies
|
52
|
+
},
|
53
|
+
port: port
|
54
|
+
)
|
55
|
+
|
56
|
+
end_time = get_micro_second_time
|
57
|
+
construct_response_object(response, BALANCE_PATH, start_time, end_time)
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def login
|
63
|
+
start_time = get_micro_second_time
|
64
|
+
|
65
|
+
response = HTTParty.send(
|
66
|
+
:post,
|
67
|
+
LOGIN_PATH,
|
68
|
+
body: { username: username, password: password }.to_json,
|
69
|
+
headers: {
|
70
|
+
'Content-Type': 'application/json',
|
71
|
+
'Authority': 'www.vodacom.co.za',
|
72
|
+
'x-application-context': 'vod-ms-zuul-gateway-crd:prodcluster:8091',
|
73
|
+
'Accept': '*/*'
|
74
|
+
},
|
75
|
+
port: port
|
76
|
+
)
|
77
|
+
|
78
|
+
end_time = get_micro_second_time
|
79
|
+
|
80
|
+
@login_response = construct_response_object(response, LOGIN_PATH, start_time, end_time)
|
81
|
+
|
82
|
+
@raw_cookie = @login_response.dig("headers").dig("set-cookie")
|
83
|
+
# @gateway_session, _ = parse_cookie(raw_cookie, 'gatewaysession')
|
84
|
+
# @vopToken, @vopToken_expiry = parse_cookie(raw_cookie, 'vopToken')
|
85
|
+
# @vod_web_auth_token, @vod_web_auth_token_expiry = parse_cookie(raw_cookie, 'vod-web-auth-token')
|
86
|
+
# @jsessionid, @jsessionid_expiry = parse_cookie(raw_cookie, 'JSESSIONID')
|
87
|
+
# @oauth2_apps_token_db, @oauth2_apps_token_db_expiry = parse_cookie(raw_cookie, 'OAuth2AppsTokenDB')
|
88
|
+
end
|
89
|
+
|
90
|
+
# def authorise_and_send(http_method:, path:, payload: {}, params: {})
|
91
|
+
# auth = {username: username, password: password}
|
92
|
+
|
93
|
+
# start_time = get_micro_second_time
|
94
|
+
|
95
|
+
# response = HTTParty.send(
|
96
|
+
# http_method.to_sym,
|
97
|
+
# construct_base_path(path, params),
|
98
|
+
# body: payload,
|
99
|
+
# headers: { 'Content-Type': 'application/json' },
|
100
|
+
# port: port,
|
101
|
+
# basic_auth: auth,
|
102
|
+
# format: :json
|
103
|
+
# )
|
104
|
+
|
105
|
+
# end_time = get_micro_second_time
|
106
|
+
# construct_response_object(response, path, start_time, end_time)
|
107
|
+
# end
|
108
|
+
|
109
|
+
def construct_response_object(response, path, start_time, end_time)
|
110
|
+
{
|
111
|
+
'body' => parse_body(response, path),
|
112
|
+
'headers' => response.headers,
|
113
|
+
'metadata' => construct_metadata(response, start_time, end_time)
|
114
|
+
}
|
115
|
+
end
|
116
|
+
|
117
|
+
def construct_metadata(response, start_time, end_time)
|
118
|
+
total_time = end_time - start_time
|
119
|
+
|
120
|
+
{
|
121
|
+
'start_time' => start_time,
|
122
|
+
'end_time' => end_time,
|
123
|
+
'total_time' => total_time
|
124
|
+
}
|
125
|
+
end
|
126
|
+
|
127
|
+
def body_is_present?(response)
|
128
|
+
!body_is_missing?(response)
|
129
|
+
end
|
130
|
+
|
131
|
+
def body_is_missing?(response)
|
132
|
+
response.body.nil? || response.body.empty?
|
133
|
+
end
|
134
|
+
|
135
|
+
def parse_body(response, path)
|
136
|
+
parsed_response = JSON.parse(response.body) # Purposely not using HTTParty
|
137
|
+
|
138
|
+
if parsed_response.dig(path.to_s)
|
139
|
+
parsed_response.dig(path.to_s)
|
140
|
+
else
|
141
|
+
parsed_response
|
142
|
+
end
|
143
|
+
rescue JSON::ParserError => _e
|
144
|
+
response.body
|
145
|
+
end
|
146
|
+
|
147
|
+
def parse_cookie(set_cookie_str, key)
|
148
|
+
value = nil
|
149
|
+
expiry = nil
|
150
|
+
|
151
|
+
set_cookie_str.each do |item|
|
152
|
+
if item.include?(key)
|
153
|
+
value = item.split('; ').first.split('=').last
|
154
|
+
|
155
|
+
if item.include?('Expires') || item.include?('expires')
|
156
|
+
item.split('; ').each do |sub_item|
|
157
|
+
if sub_item.include?('Expires') || sub_item.include?('expires')
|
158
|
+
expiry = Time.parse(sub_item.gsub('expires=', '').gsub('Expires=', ''))
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
[value, expiry]
|
166
|
+
end
|
167
|
+
|
168
|
+
def process_cookies
|
169
|
+
# Cookies are always a single string separated by spaces
|
170
|
+
raw_cookie.map { |item| item.split('; ').first }.join('; ')
|
171
|
+
end
|
172
|
+
|
173
|
+
def get_micro_second_time
|
174
|
+
(Time.now.to_f * 1000000).to_i
|
175
|
+
end
|
176
|
+
|
177
|
+
def construct_base_path(path, params)
|
178
|
+
constructed_path = "#{base_path}/#{path}"
|
179
|
+
|
180
|
+
if params == {}
|
181
|
+
constructed_path
|
182
|
+
else
|
183
|
+
"#{constructed_path}?#{process_params(params)}"
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
def process_params(params)
|
188
|
+
params.keys.map { |key| "#{key}=#{params[key]}" }.join('&')
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
data/vodacom.gemspec
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "vodacom/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "vodacom"
|
7
|
+
spec.version = Vodacom::VERSION
|
8
|
+
spec.authors = ["trex22"]
|
9
|
+
spec.email = ["contact@jasonchalom.com"]
|
10
|
+
|
11
|
+
spec.summary = "A client for using the Vodacom API in Ruby."
|
12
|
+
spec.description = "A client for using the Vodacom API in Ruby. This is an unofficial project."
|
13
|
+
spec.homepage = "https://github.com/TRex22/vodacom-client"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
# Specify which files should be added to the gem when it is released.
|
17
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
18
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
19
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
|
+
end
|
21
|
+
spec.bindir = "exe"
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
|
25
|
+
spec.add_dependency "httparty", "~> 0.18"
|
26
|
+
# spec.add_dependency "httparty_with_cookies", "~> 0.2.2"
|
27
|
+
spec.add_dependency "active_attr", "~> 0.15"
|
28
|
+
spec.add_dependency "nokogiri", "~> 1.11.2"
|
29
|
+
|
30
|
+
# Development dependancies
|
31
|
+
spec.add_development_dependency "bundler", "~> 2.2.14"
|
32
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
33
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
34
|
+
spec.add_development_dependency "minitest-focus", "~> 1.1.2"
|
35
|
+
spec.add_development_dependency "minitest-reporters", "~> 1.4.2"
|
36
|
+
spec.add_development_dependency "timecop", "~> 0.9.1"
|
37
|
+
spec.add_development_dependency "mocha", "~> 1.11.2"
|
38
|
+
spec.add_development_dependency "pry", "~> 0.13"
|
39
|
+
spec.add_development_dependency "webmock", "~> 3.8.3"
|
40
|
+
end
|
metadata
ADDED
@@ -0,0 +1,226 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vodacom
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- trex22
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-03-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.18'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.18'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: active_attr
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.15'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.15'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: nokogiri
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.11.2
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.11.2
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.2.14
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.2.14
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '13.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '13.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: minitest
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '5.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '5.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: minitest-focus
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 1.1.2
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 1.1.2
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: minitest-reporters
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 1.4.2
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 1.4.2
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: timecop
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 0.9.1
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 0.9.1
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: mocha
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 1.11.2
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 1.11.2
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: pry
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0.13'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0.13'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: webmock
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - "~>"
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: 3.8.3
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - "~>"
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: 3.8.3
|
181
|
+
description: A client for using the Vodacom API in Ruby. This is an unofficial project.
|
182
|
+
email:
|
183
|
+
- contact@jasonchalom.com
|
184
|
+
executables: []
|
185
|
+
extensions: []
|
186
|
+
extra_rdoc_files: []
|
187
|
+
files:
|
188
|
+
- ".gitignore"
|
189
|
+
- ".ruby-version"
|
190
|
+
- CODE_OF_CONDUCT.md
|
191
|
+
- Gemfile
|
192
|
+
- Gemfile.lock
|
193
|
+
- LICENSE
|
194
|
+
- LICENSE.txt
|
195
|
+
- README.md
|
196
|
+
- Rakefile
|
197
|
+
- bin/console
|
198
|
+
- bin/setup
|
199
|
+
- lib/vodacom.rb
|
200
|
+
- lib/vodacom/client.rb
|
201
|
+
- lib/vodacom/version.rb
|
202
|
+
- vodacom.gemspec
|
203
|
+
homepage: https://github.com/TRex22/vodacom-client
|
204
|
+
licenses:
|
205
|
+
- MIT
|
206
|
+
metadata: {}
|
207
|
+
post_install_message:
|
208
|
+
rdoc_options: []
|
209
|
+
require_paths:
|
210
|
+
- lib
|
211
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
212
|
+
requirements:
|
213
|
+
- - ">="
|
214
|
+
- !ruby/object:Gem::Version
|
215
|
+
version: '0'
|
216
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
217
|
+
requirements:
|
218
|
+
- - ">="
|
219
|
+
- !ruby/object:Gem::Version
|
220
|
+
version: '0'
|
221
|
+
requirements: []
|
222
|
+
rubygems_version: 3.0.6
|
223
|
+
signing_key:
|
224
|
+
specification_version: 4
|
225
|
+
summary: A client for using the Vodacom API in Ruby.
|
226
|
+
test_files: []
|