turbovax 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b7eb3cef5be33d25066c57d5f579f9adcb09f88bf4a6c220fcbee989c03dee9f
4
- data.tar.gz: 2966b37e81f69598b389baa14db55170ec357cd6f4d692a42e8df9f67d7e081a
3
+ metadata.gz: 7706debe63953e9803596d99c356d3fd1c4d794acb6122f46ad07cf26d16a4e4
4
+ data.tar.gz: 3837f1d090cf3d6f4d0991ceb26fe6dc47d1da94f3d8654b3e4ddad4de6c3cbb
5
5
  SHA512:
6
- metadata.gz: 11656203efb8765bfe4c3dbe4affabdf7e8d5213bd6c27b567a340c6c8f54c84b6f1f9ac9aa16a3c08abd75c8c39971d829ff11bb1efd29600e0a0bc23d05fe8
7
- data.tar.gz: 4d8268fc496fcae1aceb54b38509c0b572d3a7e0b230001ccc37e7ba15f16b28c154d4a86e52ea895178b1d99f4a8c118477f52531e74278da033643b2a481d8
6
+ metadata.gz: 21cd5222cd9b074d5bbf6a6e66d6fc9c40d99adcfbfd3f403b16efb84d580c46ed2a3d888becc96e9cb31c6039525b610dab5e2b791d7c302c5799412f45f402
7
+ data.tar.gz: 2fe1ef597cc87dc6fddae4ce32957174e5ff73d4fc68cb33e1f271b4eeb6f29ee87f79a70141a4a4e506aba5e664dd53112f82ccb629250250ee9854c4fbcece
data/CHANGELOG.md CHANGED
@@ -1,2 +1,11 @@
1
+ # 0.0.3
2
+ - Updated docs
3
+ - Improve how data fetcher params are provided to Portal methods
4
+
5
+ # 0.0.2
6
+ - Updated docs
7
+ - Test webhook
8
+
9
+
1
10
  # 0.0.1
2
11
  - First release
data/README.md CHANGED
@@ -7,6 +7,10 @@ Turbovax gem helps you quickly stand up bots that can:
7
7
 
8
8
  It does not provide any data storage or web server layers. You can build that functionality on top of the gem by yourself.
9
9
 
10
+ ## Disclaimer
11
+
12
+ This gem should only be used for the purposes of improving accessibility to vaccines and not for private gain.
13
+
10
14
  ## Installation
11
15
 
12
16
  Add this line to your application's Gemfile:
@@ -23,25 +27,24 @@ Or install it yourself as:
23
27
 
24
28
  $ gem install turbovax
25
29
 
30
+ ## Development
31
+
32
+ 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.
33
+
34
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
35
+
36
+
26
37
  ## Usage
27
38
 
28
- Initialize configuration (optional):
39
+ Initialize configuration:
29
40
 
30
41
  Turbovax.configure do |config|
31
- config.logger = Logger.new($stdout, level: Logger::DEBUG)
32
- config.twitter_enabled = true
33
42
  config.twitter_credentials = {
34
43
  consumer_key: "CONSUMER_KEY",
35
44
  consumer_secret: "CONSUMER_SECRET",
36
45
  access_token: "ACCESS_TOKEN",
37
46
  access_token_secret: "ACCESS_TOKEN_SECRET"
38
47
  }
39
-
40
- config.faraday_logging_config = {
41
- headers: true,
42
- bodies: true,
43
- log_level: :info
44
- }
45
48
  end
46
49
 
47
50
  Create test portal:
@@ -80,12 +83,94 @@ Execute operation:
80
83
 
81
84
  locations = Turbovax::DataFetcher.new(TestPortal, twitter_handler: Turbovax::Handlers::LocationHandler).execute!
82
85
 
83
- ## Development
86
+ ## Advanced
84
87
 
85
- 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.
88
+ ### Configuration
89
+ Specify logger:
86
90
 
87
- 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
91
+ Turbovax.configure do |config|
92
+ config.logger = Logger.new($stdout, level: Logger::DEBUG)
93
+ end
94
+
95
+ Change Faraday (HTTP request library) logging:
96
+
97
+ Turbovax.configure do |config|
98
+ config.faraday_logging_config = {
99
+ headers: true,
100
+ bodies: true,
101
+ log_level: :info
102
+ }
103
+ end
104
+
105
+ Disable tweets:
106
+
107
+ Turbovax.configure do |config|
108
+ config.twitter_enabled = false
109
+ end
110
+
111
+ ### DataFetcher
112
+
113
+ Provide extra parameters:
114
+
115
+ Turbovax::DataFetcher.new(
116
+ TestPortal,
117
+ twitter_handler: Turbovax::Handlers::LocationHandler,
118
+ # will be passed to Portal methods
119
+ extra_params: {
120
+ site_id: 123,
121
+ date: "2021-08-08",
122
+ }
123
+ ).execute!
124
+
125
+
126
+ ### Portal
127
+
128
+ Custom HTTP headers ([curl-to-ruby](https://jhawthorn.github.io/curl-to-ruby/) is helpful here):
129
+
130
+ class TestPortal < Turbovax::Portal
131
+ request_headers do
132
+ headers = {}
133
+ headers["Connection"] = "keep-alive"
134
+ headers["Pragma"] = "no-cache"
135
+ headers["Cache-Control"] = "no-cache"
136
+ headers["Sec-Ch-Ua"] = "\"Google Chrome\";v=\"89\", \"Chromium\";v=\"89\", \";Not A Brand\";v=\"99\""
137
+ headers
138
+ end
139
+ end
140
+
141
+ Use extra params provided by data fetcher:
142
+
143
+ class TestPortal < Turbovax::Portal
144
+ request_body do
145
+ {
146
+ site_id: data_fetcher_params[:site_id],
147
+ }
148
+ end
149
+ end
150
+
151
+ Interpolate variables into URL:
152
+
153
+ # resulting URL https://www.example-site.info/abc/2021-08-08
154
+ class TestPortal < Turbovax::Portal
155
+ api_url "https://www.example-site.info/%{site_id}/${date}"
156
+ api_url_variables do
157
+ {
158
+ site_id: data_fetcher_params[:site_id],
159
+ date: data_fetcher_params[:date].strftime("%F"),
160
+ }
161
+ end
162
+ end
163
+
164
+ Use HTTP POST:
165
+
166
+ class TestPortal < Turbovax::Portal
167
+ request_http_method Turbovax::Constants::POST_REQUEST_METHOD
168
+ end
169
+
170
+ ## License
171
+
172
+ This gem is licensed according to [GNU General Public License v3.0](https://github.com/hugem/turbovax-gem/blob/main/LICENSE).
88
173
 
89
174
  ## Contributing
90
175
 
91
- Bug reports and pull requests are welcome on GitHub at https://github.com/hugem/turbovax-gem.
176
+ Bug reports and pull requests are welcome on GitHub at [https://github.com/hugem/turbovax-gem](https://github.com/hugem/turbovax-gem).
@@ -13,8 +13,8 @@ module Turbovax
13
13
  # @param [TurboVax::Twitter::Handler] twitter_handler a class handles if appointments are found
14
14
  # @param [Hash] extra_params other info that can be provided to portal when executing blocks
15
15
  def initialize(portal, twitter_handler: nil, extra_params: {})
16
+ portal.data_fetcher_params = { date: DateTime.now }.merge(extra_params)
16
17
  @portal = portal
17
- @extra_params = { date: DateTime.now }.merge(extra_params)
18
18
  @conn = create_request_connection
19
19
  @twitter_handler = twitter_handler
20
20
  end
@@ -23,7 +23,7 @@ module Turbovax
23
23
  def execute!
24
24
  response = make_request
25
25
  log("make request [DONE]")
26
- locations = @portal.parse_response_with_portal(response.body, @extra_params)
26
+ locations = @portal.parse_response_with_portal(response.body)
27
27
  log("parse response [DONE]")
28
28
 
29
29
  send_to_twitter_handler(locations)
@@ -59,7 +59,7 @@ module Turbovax
59
59
  def make_request
60
60
  request_type = @portal.request_http_method
61
61
  path = @portal.api_path
62
- query_params = @portal.api_query_params(@extra_params)
62
+ query_params = @portal.api_query_params
63
63
 
64
64
  case request_type
65
65
  when Turbovax::Constants::GET_REQUEST_METHOD
@@ -84,7 +84,7 @@ module Turbovax
84
84
  # only set params if they are present, otherwise this will overwrite any string query
85
85
  # param values that are existing in the url path
86
86
  req.params = query_params if query_params.nil? || query_params != {}
87
- req.body = @portal.request_body(@extra_params)
87
+ req.body = @portal.request_body
88
88
  end
89
89
  end
90
90
 
@@ -6,13 +6,13 @@ module Turbovax
6
6
  # Captures configuration required to fetch and process data from a specific vaccine website
7
7
  class Portal
8
8
  class << self
9
- # @!macro [attach] definte_parameter
9
+ # @!macro [attach] define_parameter
10
10
  # @method $1
11
11
  # $3
12
12
  # @return [$2]
13
13
  # @example $4
14
14
  # $5
15
- def self.definte_parameter(
15
+ def self.define_parameter(
16
16
  attribute, _doc_return_type, _explanation = nil, _explanation = nil,
17
17
  _example = nil
18
18
  )
@@ -39,25 +39,25 @@ module Turbovax
39
39
  end
40
40
  end
41
41
 
42
- definte_parameter :name, String, "Full name of portal", "Name",
43
- "'New York City Vaccine Website'"
44
- definte_parameter :key, String, "Unique identifier for portal", "Key", "'nyc_vax'"
45
- definte_parameter :public_url,
46
- String,
47
- "Link to public facing website", "Full URL",
48
- "'https://www.turbovax.info/'"
42
+ define_parameter :name, String, "Full name of portal", "Name",
43
+ "'New York City Vaccine Website'"
44
+ define_parameter :key, String, "Unique identifier for portal", "Key", "'nyc_vax'"
45
+ define_parameter :public_url,
46
+ String,
47
+ "Link to public facing website", "Full URL",
48
+ "'https://www.turbovax.info/'"
49
49
 
50
- definte_parameter :request_headers, Hash, "Key:value mapping of HTTP request headers",
51
- "Specify user agent and cookies", "{ 'user-agent': 'Mozilla/5.0', " \
50
+ define_parameter :request_headers, Hash, "Key:value mapping of HTTP request headers",
51
+ "Specify user agent and cookies", "{ 'user-agent': 'Mozilla/5.0', " \
52
52
  "'cookies': 'ABC' }"
53
- definte_parameter :request_http_method, Symbol,
54
- "Turbovax::Constants::GET_REQUEST_METHOD or " \
55
- "Turbovax::Constants::POST_REQUEST_METHOD"
56
- definte_parameter :api_url, String, "Full API URL", "Example Turbovax endpoint",
57
- "'https://api.turbovax.info/v1/dashboard'"
58
- definte_parameter :api_url_variables, Hash,
59
- "Hash or block that is interpolated ",
60
- '
53
+ define_parameter :request_http_method, Symbol,
54
+ "Turbovax::Constants::GET_REQUEST_METHOD or " \
55
+ "Turbovax::Constants::POST_REQUEST_METHOD"
56
+ define_parameter :api_url, String, "Full API URL", "Example Turbovax endpoint",
57
+ "'https://api.turbovax.info/v1/dashboard'"
58
+ define_parameter :api_url_variables, Hash,
59
+ "Hash or block that is interpolated ",
60
+ '
61
61
  api_url_variables do |extra_params|
62
62
  {
63
63
  site_id: NAME_TO_ID_MAPPING[extra_params[:name]],
@@ -71,16 +71,11 @@ module Turbovax
71
71
  # after api_url_variables interpolation
72
72
  api_url "https://api.turbovax.info/v1/sites/8888/2021-08-08"
73
73
  '
74
- # definte_parameter :request_body, Hash,
75
- # "Hash (or block evaluates to a hash) that is used to in a POST request",
76
- # '
77
- # request_body do |extra_params|
78
- # {
79
- # site_id: NAME_TO_ID_MAPPING[extra_params[:name]],
80
- # date: extra_params.strftime("%F"),
81
- # }
82
- # end
83
- # '
74
+ define_parameter :data_fetcher_params, Hash,
75
+ "Extra params that are set by [Turbovax::DataFetcher]",
76
+ "{ date: DateTime.now }"
77
+
78
+ attr_writer :data_fetcher_params
84
79
 
85
80
  # Block that will called after raw data is fetched from API. Must return list of Location
86
81
  # instances
@@ -161,8 +156,8 @@ module Turbovax
161
156
 
162
157
  # Calls parse_response and assigns portal to each location so user doesn't need to do
163
158
  # this by themselves
164
- def parse_response_with_portal(response, extra_params)
165
- parse_response(response, extra_params).map do |location|
159
+ def parse_response_with_portal(response)
160
+ parse_response(response).map do |location|
166
161
  location.portal ||= self
167
162
  location
168
163
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Turbovax
4
- VERSION = "0.0.2"
4
+ VERSION = "0.0.3"
5
5
  end
data/turbovax.gemspec CHANGED
@@ -11,10 +11,9 @@ Gem::Specification.new do |spec|
11
11
 
12
12
  spec.summary = "Quickly build vaccine twitter bots"
13
13
  spec.description = spec.summary
14
- spec.homepage = "https://github.com/hugem/turbovax-gem"
14
+ spec.homepage = "https://www.turbovax.info/"
15
15
  spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
16
16
 
17
-
18
17
  spec.metadata["homepage_uri"] = spec.homepage
19
18
  spec.metadata["source_code_uri"] = "https://github.com/hugem/turbovax-gem"
20
19
  spec.metadata["changelog_uri"] = "https://github.com/hugem/turbovax-gem/blob/main/CHANGELOG.md"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turbovax
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Huge Ma
@@ -87,11 +87,11 @@ files:
87
87
  - lib/turbovax/twitter_client.rb
88
88
  - lib/turbovax/version.rb
89
89
  - turbovax.gemspec
90
- homepage: https://github.com/hugem/turbovax-gem
90
+ homepage: https://www.turbovax.info/
91
91
  licenses:
92
92
  - AGPLv3
93
93
  metadata:
94
- homepage_uri: https://github.com/hugem/turbovax-gem
94
+ homepage_uri: https://www.turbovax.info/
95
95
  source_code_uri: https://github.com/hugem/turbovax-gem
96
96
  changelog_uri: https://github.com/hugem/turbovax-gem/blob/main/CHANGELOG.md
97
97
  documentation_uri: https://rubydoc.info/gems/turbovax