EskomSePush 0.0.3 → 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: 986e9ba3c964e53d5dec933e4a94748a10637754f88832ed6c4218be75ac03f5
4
- data.tar.gz: 32267164c397c93246fe311870e063fea8100738c999ef8d26dc15711ea76128
3
+ metadata.gz: 3c195b94cb2b0a32e7ca57ea9c6eedd71ce35595bd3064e989c20b442e29e27f
4
+ data.tar.gz: 47b507de0e2f9c99a2a217dacf7f38cb97f4872e58ceffed9ea821122c4b8915
5
5
  SHA512:
6
- metadata.gz: 811f693b184dfbb801b9c31d3c04c31bf9c7c3aa8001dd9afd7f0c50de729073e119fc954da95b1daa9e4c3ace9059f92347d5e954be7b574e6ddea66b5c6ca5
7
- data.tar.gz: e22302a84ea0401f3b963962ad59742c5f67561a94d7716bac085bb5dfbe22dc639f6d3dc8b9a2fc1e344c68bed1966961fda7dae9926e4734d543508dcda413
6
+ metadata.gz: 0dff6e1db9a1bda6d5a31c29791f871045341e8ab345d65dd3b952ca99a71acd708ff9476a5132e7a1b0bc715568fb35079eca635c94c780672e63aee2a0f7e0
7
+ data.tar.gz: '03036719db6bceb98e9970d4bfdf88b295f6510fcc1b62758cb740df0ca9369554cfd5c43b68c6524316497bc9c3dc5b0e4ab06b83fbbfc82d8e456a9c5c748d'
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- EskomSePush (0.0.3)
5
- api_pattern (~> 0.0.1)
4
+ EskomSePush (0.0.4)
5
+ api_pattern (~> 0.0.4)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
@@ -34,7 +34,7 @@ GEM
34
34
  addressable (2.8.4)
35
35
  public_suffix (>= 2.0.2, < 6.0)
36
36
  ansi (1.5.0)
37
- api_pattern (0.0.1)
37
+ api_pattern (0.0.4)
38
38
  active_attr (~> 0.15.4)
39
39
  httparty (~> 0.21.0)
40
40
  nokogiri (~> 1.14.3)
data/README.md CHANGED
@@ -35,6 +35,10 @@ Or install it yourself as:
35
35
  client.areas_search(text: "fourways")
36
36
  client.topics_nearby(latitude: "-26.0269658", longitude: "28.0137339") # Can submit as a Float too
37
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
38
42
  ```
39
43
 
40
44
  ### Endpoints
@@ -44,6 +48,7 @@ Or install it yourself as:
44
48
  - Areas Search (Text)
45
49
  - Topics Nearby
46
50
  - Check Allowance
51
+ - Historic Data (Google Sheet returned as CSV)
47
52
  - Constants
48
53
 
49
54
  ## Development
@@ -22,7 +22,7 @@ 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 "api_pattern", "~> 0.0.1"
25
+ spec.add_dependency "api_pattern", "~> 0.0.4"
26
26
 
27
27
  # Development dependancies
28
28
  spec.add_development_dependency "rake", "~> 13.0.6"
@@ -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.3"
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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: EskomSePush
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
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-24 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
14
  name: api_pattern
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.0.1
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.0.1
26
+ version: 0.0.4
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement