big_marker_client 0.1.4 → 0.1.6
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 +4 -4
- data/.rubocop.yml +1 -5
- data/CHANGELOG.md +9 -0
- data/lib/big_marker_client/api/v1/conference.rb +2 -2
- data/lib/big_marker_client/base.rb +46 -30
- data/lib/big_marker_client/http_client.rb +30 -0
- data/lib/big_marker_client/version.rb +1 -1
- data/lib/big_marker_client.rb +1 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 761022b647bdfeecdd833b29b236ff768cf2713d2d5c82a3986638d5cc67b0d5
|
4
|
+
data.tar.gz: 16707b0d879dd593066b400677c343bdfa47eed6d97e5132a5f99599b94e64e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c18cf2836336c335143e01690ccbc3acdfaf96f39bc86d415270fc9e8bf8b97c5069f35d508e664a65dab94bd97cba7d191acada60fd242a710b56828229e948
|
7
|
+
data.tar.gz: 12d4ca8e8394a012f395dbd910c3a9835c9a072b20e88a39167f25adecf1b77d1483cbb42a303f05774b39405fc06bcda4fc806a8056b932003c9533935b36b7
|
data/.rubocop.yml
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
AllCops:
|
2
|
-
TargetRubyVersion:
|
2
|
+
TargetRubyVersion: 2.6
|
3
3
|
NewCops: enable
|
4
4
|
Exclude:
|
5
5
|
- "vendor/**/*"
|
@@ -18,10 +18,6 @@ Metrics/BlockLength:
|
|
18
18
|
- "spec/**/*"
|
19
19
|
- "big_marker_client.gemspec"
|
20
20
|
|
21
|
-
Performance/StringIdentifierArgument:
|
22
|
-
Exclude:
|
23
|
-
- "lib/big_marker_client/base.rb"
|
24
|
-
|
25
21
|
Style/Documentation:
|
26
22
|
Enabled: false
|
27
23
|
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
## [0.1.6] - 2022-01-19
|
2
|
+
|
3
|
+
- fix recurring method to return "child_conferences"
|
4
|
+
|
5
|
+
## [0.1.5] - 2022-01-19 (broken, don't use!)
|
6
|
+
|
7
|
+
- refactor HTTP client into a separate class
|
8
|
+
- fix looping if no meta-data is returned
|
9
|
+
|
1
10
|
## [0.1.4] - 2022-01-18
|
2
11
|
|
3
12
|
- add new properties to attendees and add handout model and factory
|
@@ -116,7 +116,7 @@ module BigMarkerClient
|
|
116
116
|
def recurring(conference_id, params = {})
|
117
117
|
result = get(replace_path_params(path: RECURRING_CONFERENCES,
|
118
118
|
replacements: { "{id}": conference_id }), params)
|
119
|
-
return map_to_model_array(result["
|
119
|
+
return map_to_model_array(result["child_conferences"]) if result["child_conferences"]
|
120
120
|
|
121
121
|
result
|
122
122
|
end
|
@@ -126,7 +126,7 @@ module BigMarkerClient
|
|
126
126
|
# @see #recurring
|
127
127
|
def recurring_all(conference_id, params = {})
|
128
128
|
path = replace_path_params(path: RECURRING_CONFERENCES, replacements: { "{id}": conference_id })
|
129
|
-
loop_over(path, "
|
129
|
+
loop_over(path, "child_conferences", ::BigMarkerClient::Models::Conference, params)
|
130
130
|
end
|
131
131
|
|
132
132
|
##
|
@@ -3,6 +3,8 @@ require "typhoeus/adapters/faraday"
|
|
3
3
|
|
4
4
|
module BigMarkerClient
|
5
5
|
class Base
|
6
|
+
DEFAULT_PER_PAGE_SIZE = 25
|
7
|
+
|
6
8
|
class << self
|
7
9
|
def post(path, body = {})
|
8
10
|
request(verb: :post, path: path, params: body)
|
@@ -36,10 +38,10 @@ module BigMarkerClient
|
|
36
38
|
page = 1
|
37
39
|
results = []
|
38
40
|
loop do
|
39
|
-
params[
|
41
|
+
params["page"] = page
|
40
42
|
result = send(method, path, params)
|
41
43
|
results += map_to_model_array(result[field], model_class) if result[field]
|
42
|
-
break if
|
44
|
+
break if break?(results: results, result: result, page: page, page_size: page_size(params))
|
43
45
|
|
44
46
|
page += 1
|
45
47
|
end
|
@@ -50,55 +52,69 @@ module BigMarkerClient
|
|
50
52
|
|
51
53
|
def request(path:, verb: :get, params: {})
|
52
54
|
check_preconditions(verb, path)
|
55
|
+
params = stringify_keys(params)
|
53
56
|
|
54
57
|
params = params.to_json unless %w[get delete].include?(verb.to_s)
|
55
|
-
|
58
|
+
@http_client ||= HttpClient.new
|
59
|
+
response = @http_client.connection.send(verb.to_s, base_url(path), params)
|
56
60
|
parse_body(response.body)
|
57
61
|
end
|
58
62
|
|
59
63
|
def check_preconditions(verb, path)
|
60
|
-
if verb.nil? || path.nil? ||
|
61
|
-
raise ArgumentError, "http_method, path or api key is missing"
|
62
|
-
end
|
64
|
+
raise ArgumentError, "http_method, path or api key is missing" if verb.nil? || path.nil? || Config.api_key.nil?
|
63
65
|
raise ArgumentError, "unsupported http_method: #{verb}" unless %w[post put patch delete get].include?(verb.to_s)
|
64
66
|
end
|
65
67
|
|
66
|
-
def
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
conn.adapter :typhoeus
|
72
|
-
conn
|
73
|
-
end
|
74
|
-
|
75
|
-
def headers(adapter)
|
76
|
-
adapter.headers["Content-Type"] = "application/json"
|
77
|
-
adapter.headers["API-KEY"] = BigMarkerClient::Config.api_key unless BigMarkerClient::Config.api_key.nil?
|
78
|
-
adapter
|
79
|
-
end
|
80
|
-
|
81
|
-
def configure_logging(adapter)
|
82
|
-
adapter.response :logger do |logger|
|
83
|
-
logger.instance_variable_get("@options")[:log_level] = :debug if BigMarkerClient::Config.debug
|
84
|
-
logger.filter(/password=([^&]+)/, "password=[FILTERED]")
|
85
|
-
logger.filter(/API-KEY: "(\w*)"/, "API-KEY: [FILTERED]")
|
68
|
+
def stringify_keys(hash)
|
69
|
+
hash_symbol_keys = hash.keys.select { |key| key.is_a?(Symbol) }
|
70
|
+
hash_symbol_keys.each do |key|
|
71
|
+
hash[key.to_s] = hash[key]
|
72
|
+
hash.delete(key)
|
86
73
|
end
|
87
|
-
|
74
|
+
hash
|
88
75
|
end
|
89
76
|
|
90
77
|
def base_url(path)
|
91
|
-
|
78
|
+
Config.base_url + (path.start_with?("/") ? path : "/#{path}")
|
92
79
|
end
|
93
80
|
|
94
81
|
def parse_body(body)
|
95
82
|
return nil if body.strip == ""
|
96
83
|
|
97
84
|
json = JSON.parse(body)
|
98
|
-
|
85
|
+
Config.logger.debug(json) if Config.debug
|
99
86
|
json
|
100
87
|
rescue JSON::ParserError
|
101
|
-
raise
|
88
|
+
raise ResponseError, "invalid response"
|
89
|
+
end
|
90
|
+
|
91
|
+
def page_size(params)
|
92
|
+
params["page_count"] || params.fetch("per_page", DEFAULT_PER_PAGE_SIZE)
|
93
|
+
end
|
94
|
+
|
95
|
+
##
|
96
|
+
# BigMarker API is a total mess that won't return total_pages or total_entries on all request types so we have to
|
97
|
+
# get creative
|
98
|
+
def break?(results:, result:, page:, page_size:)
|
99
|
+
return true if break_on_full_metadata?(results: results, result: result, page: page) ||
|
100
|
+
break_on_partial_metadata?(results: results, result: result, page: page)
|
101
|
+
|
102
|
+
results.length.zero? || (results.length % page_size) != 0 || (results.length.to_f / page_size) < page
|
103
|
+
end
|
104
|
+
|
105
|
+
def break_on_full_metadata?(results:, result:, page:)
|
106
|
+
if !result["total_pages"].nil? && !total_count(result).nil?
|
107
|
+
return ((page >= result["total_pages"].to_i) || (results.length >= total_count(result).to_i))
|
108
|
+
end
|
109
|
+
|
110
|
+
false
|
111
|
+
end
|
112
|
+
|
113
|
+
def break_on_partial_metadata?(results:, result:, page:)
|
114
|
+
return page >= result["total_pages"].to_i unless result["total_pages"].nil?
|
115
|
+
return results.length >= total_count(result).to_i unless total_count(result).nil?
|
116
|
+
|
117
|
+
false
|
102
118
|
end
|
103
119
|
|
104
120
|
##
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module BigMarkerClient
|
2
|
+
class HttpClient
|
3
|
+
attr_reader :connection
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@connection = Faraday.new(url: Config.base_url) do |faraday|
|
7
|
+
faraday = headers(faraday)
|
8
|
+
configure_logging(faraday) if Config.log
|
9
|
+
end
|
10
|
+
@connection.adapter :typhoeus
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def headers(adapter)
|
16
|
+
adapter.headers["Content-Type"] = "application/json"
|
17
|
+
adapter.headers["API-KEY"] = Config.api_key unless Config.api_key.nil?
|
18
|
+
adapter
|
19
|
+
end
|
20
|
+
|
21
|
+
def configure_logging(adapter)
|
22
|
+
adapter.response :logger do |logger|
|
23
|
+
logger.instance_variable_get(:@options)[:log_level] = :debug if Config.debug
|
24
|
+
logger.filter(/password=([^&]+)/, "password=[FILTERED]")
|
25
|
+
logger.filter(/API-KEY: "(\w*)"/, "API-KEY: [FILTERED]")
|
26
|
+
end
|
27
|
+
adapter
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/big_marker_client.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: big_marker_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Burkhard Vogel-Kreykenbohm
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-01-
|
11
|
+
date: 2022-01-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -92,6 +92,7 @@ files:
|
|
92
92
|
- lib/big_marker_client/api/v1/presenter.rb
|
93
93
|
- lib/big_marker_client/base.rb
|
94
94
|
- lib/big_marker_client/config.rb
|
95
|
+
- lib/big_marker_client/http_client.rb
|
95
96
|
- lib/big_marker_client/models/attendee.rb
|
96
97
|
- lib/big_marker_client/models/base.rb
|
97
98
|
- lib/big_marker_client/models/conference.rb
|
@@ -124,7 +125,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
124
125
|
requirements:
|
125
126
|
- - ">="
|
126
127
|
- !ruby/object:Gem::Version
|
127
|
-
version: '
|
128
|
+
version: '2.6'
|
128
129
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
130
|
requirements:
|
130
131
|
- - ">="
|