EskomSePush 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d496294815ae03ca8bc0dbd3740e512f650ff0a181630b82098cc4b2b65550c6
4
- data.tar.gz: 0cb33efbb037b89804ca6e0cd98bb8f461696ef52bd4cb8fca9e2e509343dd59
3
+ metadata.gz: 3c195b94cb2b0a32e7ca57ea9c6eedd71ce35595bd3064e989c20b442e29e27f
4
+ data.tar.gz: 47b507de0e2f9c99a2a217dacf7f38cb97f4872e58ceffed9ea821122c4b8915
5
5
  SHA512:
6
- metadata.gz: fea2a7feb5f5600d0cc84069ce2c412ada5423b4d2bb726fdbd52cae26b01ffc73599a8d463c641fc200da4cceae16d59ff4bf167802ec911c4c28168c6dfafb
7
- data.tar.gz: 39c751ffc8c754ad4ede5e96dc9ff281a1ab70aca3181ab611cf92d3d0580078f286d97c581955539974e857265d682c467f94cb860a063cb5ba2acb4b21b475
6
+ metadata.gz: 0dff6e1db9a1bda6d5a31c29791f871045341e8ab345d65dd3b952ca99a71acd708ff9476a5132e7a1b0bc715568fb35079eca635c94c780672e63aee2a0f7e0
7
+ data.tar.gz: '03036719db6bceb98e9970d4bfdf88b295f6510fcc1b62758cb740df0ca9369554cfd5c43b68c6524316497bc9c3dc5b0e4ab06b83fbbfc82d8e456a9c5c748d'
@@ -0,0 +1,24 @@
1
+ name: Ruby Tests
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ test:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v2
10
+ - name: Set up Ruby
11
+ uses: ruby/setup-ruby@v1
12
+ with:
13
+ ruby-version: 3.2.2
14
+ - name: Cache dependencies
15
+ uses: actions/cache@v2
16
+ with:
17
+ path: vendor/bundle
18
+ key: v1-${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
19
+ restore-keys: |
20
+ v1-${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
21
+ - name: Install dependencies
22
+ run: bundle install
23
+ - name: Run tests
24
+ run: bundle exec rake test
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.2.2
data/Gemfile.lock CHANGED
@@ -1,9 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- EskomSePush (0.0.2)
5
- active_attr (~> 0.15.4)
6
- httparty (~> 0.21.0)
4
+ EskomSePush (0.0.4)
5
+ api_pattern (~> 0.0.4)
7
6
 
8
7
  GEM
9
8
  remote: https://rubygems.org/
@@ -35,6 +34,10 @@ GEM
35
34
  addressable (2.8.4)
36
35
  public_suffix (>= 2.0.2, < 6.0)
37
36
  ansi (1.5.0)
37
+ api_pattern (0.0.4)
38
+ active_attr (~> 0.15.4)
39
+ httparty (~> 0.21.0)
40
+ nokogiri (~> 1.14.3)
38
41
  builder (3.2.4)
39
42
  coderay (1.1.3)
40
43
  concurrent-ruby (1.2.2)
@@ -53,15 +56,16 @@ GEM
53
56
  nokogiri (>= 1.5.9)
54
57
  method_source (1.0.0)
55
58
  mini_mime (1.1.2)
56
- minitest (5.15.0)
59
+ minitest (5.18.0)
57
60
  minitest-focus (1.3.1)
58
61
  minitest (>= 4, < 6)
59
- minitest-reporters (1.5.0)
62
+ minitest-reporters (1.6.0)
60
63
  ansi
61
64
  builder
62
65
  minitest (>= 5.0)
63
66
  ruby-progressbar
64
- mocha (1.13.0)
67
+ mocha (2.0.2)
68
+ ruby2_keywords (>= 0.0.5)
65
69
  multi_xml (0.6.0)
66
70
  nokogiri (1.14.3-arm64-darwin)
67
71
  racc (~> 1.4)
@@ -81,27 +85,28 @@ GEM
81
85
  rake (13.0.6)
82
86
  rexml (3.2.5)
83
87
  ruby-progressbar (1.13.0)
88
+ ruby2_keywords (0.0.5)
84
89
  timecop (0.9.6)
85
90
  tzinfo (2.0.6)
86
91
  concurrent-ruby (~> 1.0)
87
- webmock (3.14.0)
92
+ webmock (3.18.1)
88
93
  addressable (>= 2.8.0)
89
94
  crack (>= 0.3.2)
90
95
  hashdiff (>= 0.4.0, < 2.0.0)
91
96
 
92
97
  PLATFORMS
93
- arm64-darwin-20
98
+ arm64-darwin-22
94
99
 
95
100
  DEPENDENCIES
96
101
  EskomSePush!
97
- minitest (~> 5.15.0)
102
+ minitest (~> 5.18.0)
98
103
  minitest-focus (~> 1.3.1)
99
- minitest-reporters (~> 1.5.0)
100
- mocha (~> 1.13.0)
101
- pry (~> 0.14.1)
104
+ minitest-reporters (~> 1.6.0)
105
+ mocha (~> 2.0.2)
106
+ pry (~> 0.14.2)
102
107
  rake (~> 13.0.6)
103
- timecop (~> 0.9.1)
104
- webmock (~> 3.14.0)
108
+ timecop (~> 0.9.6)
109
+ webmock (~> 3.18.1)
105
110
 
106
111
  BUNDLED WITH
107
- 2.3.16
112
+ 2.4.12
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2020 Jason Chalom
3
+ Copyright (c) 2023 Jason Chalom
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -23,6 +23,8 @@ Or install it yourself as:
23
23
 
24
24
  ## Usage
25
25
 
26
+ `id` is found using `areas_search` or `areas_nearby`.
27
+
26
28
  ```ruby
27
29
  require 'eskom_se_push'
28
30
  client = EskomSePush::Client.new(token: 'Your token here')
@@ -33,6 +35,10 @@ Or install it yourself as:
33
35
  client.areas_search(text: "fourways")
34
36
  client.topics_nearby(latitude: "-26.0269658", longitude: "28.0137339") # Can submit as a Float too
35
37
  client.check_allowance
38
+
39
+ # Historic data polls the EskomSePush Google sheet
40
+ # Does not need authorisation but Google does throttle calls to their servers
41
+ client.historic_data
36
42
  ```
37
43
 
38
44
  ### Endpoints
@@ -42,6 +48,7 @@ Or install it yourself as:
42
48
  - Areas Search (Text)
43
49
  - Topics Nearby
44
50
  - Check Allowance
51
+ - Historic Data (Google Sheet returned as CSV)
45
52
  - Constants
46
53
 
47
54
  ## Development
@@ -22,16 +22,15 @@ Gem::Specification.new do |spec|
22
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
23
  spec.require_paths = ["lib"]
24
24
 
25
- spec.add_dependency "httparty", "~> 0.21.0"
26
- spec.add_dependency "active_attr", "~> 0.15.4"
25
+ spec.add_dependency "api_pattern", "~> 0.0.4"
27
26
 
28
27
  # Development dependancies
29
28
  spec.add_development_dependency "rake", "~> 13.0.6"
30
- spec.add_development_dependency "minitest", "~> 5.15.0"
29
+ spec.add_development_dependency "minitest", "~> 5.18.0"
31
30
  spec.add_development_dependency "minitest-focus", "~> 1.3.1"
32
- spec.add_development_dependency "minitest-reporters", "~> 1.5.0"
33
- spec.add_development_dependency "timecop", "~> 0.9.1"
34
- spec.add_development_dependency "mocha", "~> 1.13.0"
35
- spec.add_development_dependency "pry", "~> 0.14.1"
36
- spec.add_development_dependency "webmock", "~> 3.14.0"
31
+ spec.add_development_dependency "minitest-reporters", "~> 1.6.0"
32
+ spec.add_development_dependency "timecop", "~> 0.9.6"
33
+ spec.add_development_dependency "mocha", "~> 2.0.2"
34
+ spec.add_development_dependency "pry", "~> 0.14.2"
35
+ spec.add_development_dependency "webmock", "~> 3.18.1"
37
36
  end
@@ -1,13 +1,11 @@
1
1
  module EskomSePush
2
- class Client
2
+ class Client < ApiPattern::Client
3
3
  include ::EskomSePush::Constants
4
4
 
5
5
  attr_reader :token, :base_path, :port
6
6
 
7
- def initialize(token:, base_path: BASE_URI, port: BASE_PORT)
8
- @token = token
9
- @base_path = base_path
10
- @port = port
7
+ def initialize(token:, base_path: BASE_URI, port: BASE_PORT, content_type: CONTENT_TYPE)
8
+ super(token: token, base_path: base_path, port: port, content_type: content_type)
11
9
  end
12
10
 
13
11
  def self.compatible_api_version
@@ -49,94 +47,11 @@ module EskomSePush
49
47
  authorise_and_send(http_method: :get, path: 'api_allowance')
50
48
  end
51
49
 
52
- private
50
+ def historic_data(process: true)
51
+ response = unauthorised_and_send(http_method: :get, path: "", custom_url: HISTORY_URL, format: :csv)
52
+ return response unless process
53
53
 
54
- def unauthorised_and_send(http_method:, path:, payload: {}, params: {})
55
- start_time = get_micro_second_time
56
-
57
- response = HTTParty.send(
58
- http_method.to_sym,
59
- construct_base_path(path, params),
60
- body: payload,
61
- headers: { 'Content-Type': 'application/json' },
62
- port: port,
63
- format: :json
64
- )
65
-
66
- end_time = get_micro_second_time
67
- construct_response_object(response, path, start_time, end_time)
68
- end
69
-
70
- def authorise_and_send(http_method:, path:, payload: {}, params: {})
71
- start_time = get_micro_second_time
72
-
73
- response = HTTParty.send(
74
- http_method.to_sym,
75
- construct_base_path(path, params),
76
- body: payload,
77
- headers: { 'Content-Type': 'application/json', Token: token },
78
- port: port,
79
- format: :json
80
- )
81
-
82
- end_time = get_micro_second_time
83
- construct_response_object(response, path, start_time, end_time)
84
- end
85
-
86
- def construct_response_object(response, path, start_time, end_time)
87
- {
88
- 'body' => parse_body(response, path),
89
- 'headers' => response.headers,
90
- 'metadata' => construct_metadata(response, start_time, end_time)
91
- }
92
- end
93
-
94
- def construct_metadata(response, start_time, end_time)
95
- total_time = end_time - start_time
96
-
97
- {
98
- 'start_time' => start_time,
99
- 'end_time' => end_time,
100
- 'total_time' => total_time
101
- }
102
- end
103
-
104
- def body_is_present?(response)
105
- !body_is_missing?(response)
106
- end
107
-
108
- def body_is_missing?(response)
109
- response.body.nil? || response.body.empty?
110
- end
111
-
112
- def parse_body(response, path)
113
- parsed_response = JSON.parse(response.body) # Purposely not using HTTParty
114
-
115
- if parsed_response.dig(path.to_s)
116
- parsed_response.dig(path.to_s)
117
- else
118
- parsed_response
119
- end
120
- rescue JSON::ParserError => _e
121
- response.body
122
- end
123
-
124
- def get_micro_second_time
125
- (Time.now.to_f * 1000000).to_i
126
- end
127
-
128
- def construct_base_path(path, params)
129
- constructed_path = "#{base_path}/#{path}"
130
-
131
- if params == {}
132
- constructed_path
133
- else
134
- "#{constructed_path}?#{process_params(params)}"
135
- end
136
- end
137
-
138
- def process_params(params)
139
- params.keys.map { |key| "#{key}=#{params[key]}" }.join('&')
54
+ response["body"].split("\r\n")
140
55
  end
141
56
  end
142
57
  end
@@ -1,7 +1,9 @@
1
1
  module EskomSePush
2
2
  module Constants
3
3
  BASE_URI = "https://developer.sepush.co.za/business/2.0/"
4
+ HISTORY_URL = "https://docs.google.com/spreadsheets/d/1ZpX_twP8sFBOAU6t--Vvh1pWMYSvs60UXINuD5n-K08/export?usp=sharing&format=csv"
4
5
  BASE_PORT = 80
6
+ CONTENT_TYPE = 'application/json'
5
7
 
6
8
  FREE_LIMIT = 50
7
9
  AREAS_SEARCH_FREE_COST = 5
@@ -1,3 +1,3 @@
1
1
  module EskomSePush
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/eskom_se_push.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  require 'httparty'
2
2
  require 'nokogiri'
3
3
 
4
+ require 'api-pattern'
5
+
4
6
  require 'eskom_se_push/version'
5
7
  require 'eskom_se_push/constants'
6
8
 
metadata CHANGED
@@ -1,43 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: EskomSePush
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - trex22
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-04-12 00:00:00.000000000 Z
11
+ date: 2023-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: httparty
14
+ name: api_pattern
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.21.0
19
+ version: 0.0.4
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.21.0
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.4
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.4
26
+ version: 0.0.4
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: rake
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -58,14 +44,14 @@ dependencies:
58
44
  requirements:
59
45
  - - "~>"
60
46
  - !ruby/object:Gem::Version
61
- version: 5.15.0
47
+ version: 5.18.0
62
48
  type: :development
63
49
  prerelease: false
64
50
  version_requirements: !ruby/object:Gem::Requirement
65
51
  requirements:
66
52
  - - "~>"
67
53
  - !ruby/object:Gem::Version
68
- version: 5.15.0
54
+ version: 5.18.0
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: minitest-focus
71
57
  requirement: !ruby/object:Gem::Requirement
@@ -86,70 +72,70 @@ dependencies:
86
72
  requirements:
87
73
  - - "~>"
88
74
  - !ruby/object:Gem::Version
89
- version: 1.5.0
75
+ version: 1.6.0
90
76
  type: :development
91
77
  prerelease: false
92
78
  version_requirements: !ruby/object:Gem::Requirement
93
79
  requirements:
94
80
  - - "~>"
95
81
  - !ruby/object:Gem::Version
96
- version: 1.5.0
82
+ version: 1.6.0
97
83
  - !ruby/object:Gem::Dependency
98
84
  name: timecop
99
85
  requirement: !ruby/object:Gem::Requirement
100
86
  requirements:
101
87
  - - "~>"
102
88
  - !ruby/object:Gem::Version
103
- version: 0.9.1
89
+ version: 0.9.6
104
90
  type: :development
105
91
  prerelease: false
106
92
  version_requirements: !ruby/object:Gem::Requirement
107
93
  requirements:
108
94
  - - "~>"
109
95
  - !ruby/object:Gem::Version
110
- version: 0.9.1
96
+ version: 0.9.6
111
97
  - !ruby/object:Gem::Dependency
112
98
  name: mocha
113
99
  requirement: !ruby/object:Gem::Requirement
114
100
  requirements:
115
101
  - - "~>"
116
102
  - !ruby/object:Gem::Version
117
- version: 1.13.0
103
+ version: 2.0.2
118
104
  type: :development
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
107
  requirements:
122
108
  - - "~>"
123
109
  - !ruby/object:Gem::Version
124
- version: 1.13.0
110
+ version: 2.0.2
125
111
  - !ruby/object:Gem::Dependency
126
112
  name: pry
127
113
  requirement: !ruby/object:Gem::Requirement
128
114
  requirements:
129
115
  - - "~>"
130
116
  - !ruby/object:Gem::Version
131
- version: 0.14.1
117
+ version: 0.14.2
132
118
  type: :development
133
119
  prerelease: false
134
120
  version_requirements: !ruby/object:Gem::Requirement
135
121
  requirements:
136
122
  - - "~>"
137
123
  - !ruby/object:Gem::Version
138
- version: 0.14.1
124
+ version: 0.14.2
139
125
  - !ruby/object:Gem::Dependency
140
126
  name: webmock
141
127
  requirement: !ruby/object:Gem::Requirement
142
128
  requirements:
143
129
  - - "~>"
144
130
  - !ruby/object:Gem::Version
145
- version: 3.14.0
131
+ version: 3.18.1
146
132
  type: :development
147
133
  prerelease: false
148
134
  version_requirements: !ruby/object:Gem::Requirement
149
135
  requirements:
150
136
  - - "~>"
151
137
  - !ruby/object:Gem::Version
152
- version: 3.14.0
138
+ version: 3.18.1
153
139
  description: A client for using the EskomSePush API in Ruby. Built from their api
154
140
  documentation. This is an unofficial project.
155
141
  email:
@@ -158,12 +144,13 @@ executables: []
158
144
  extensions: []
159
145
  extra_rdoc_files: []
160
146
  files:
147
+ - ".github/workflows/ruby-ci.yml"
161
148
  - ".gitignore"
149
+ - ".ruby-version"
162
150
  - CODE_OF_CONDUCT.md
163
151
  - Gemfile
164
152
  - Gemfile.lock
165
153
  - LICENSE
166
- - LICENSE.txt
167
154
  - README.md
168
155
  - Rakefile
169
156
  - bin/console
@@ -192,7 +179,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
192
179
  - !ruby/object:Gem::Version
193
180
  version: '0'
194
181
  requirements: []
195
- rubygems_version: 3.3.4
182
+ rubygems_version: 3.4.10
196
183
  signing_key:
197
184
  specification_version: 4
198
185
  summary: A client for using the EskomSePush API in Ruby.
data/LICENSE.txt DELETED
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2020 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.