big_marker_client 0.1.4 → 0.1.6

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: d6fb91b5a5354ae4629ec265e53476357d78dbd65da6996cf24de3c7866a3402
4
- data.tar.gz: cadac9e803e07b4836b3a6008a825f976884877196852b9573fbc33c59f35386
3
+ metadata.gz: 761022b647bdfeecdd833b29b236ff768cf2713d2d5c82a3986638d5cc67b0d5
4
+ data.tar.gz: 16707b0d879dd593066b400677c343bdfa47eed6d97e5132a5f99599b94e64e6
5
5
  SHA512:
6
- metadata.gz: 62a7c90fe1839b181dfe1f3103933de22053e7330a9e17044d17c5323a67929bd23bf9c1f81d8741807d56018c1c40c4b9a8765ecc6ed9137bd9ff4496cf5628
7
- data.tar.gz: c08e7e125dc6fd43a8174f40d0c52d300431704030436b36f6afe942c379b081b9a1106b9aaf3a9254bd801ad6810a86dce4e12edc2ba5d78dd62ba76021911a
6
+ metadata.gz: c18cf2836336c335143e01690ccbc3acdfaf96f39bc86d415270fc9e8bf8b97c5069f35d508e664a65dab94bd97cba7d191acada60fd242a710b56828229e948
7
+ data.tar.gz: 12d4ca8e8394a012f395dbd910c3a9835c9a072b20e88a39167f25adecf1b77d1483cbb42a303f05774b39405fc06bcda4fc806a8056b932003c9533935b36b7
data/.rubocop.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  AllCops:
2
- TargetRubyVersion: 3.0
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["conferences"]) if result["conferences"]
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, "conferences", ::BigMarkerClient::Models::Conference, params)
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[:page] = page
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 page >= result["total_pages"].to_i || results.length >= total_count(result).to_i
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
- response = http_client.send(verb.to_s, base_url(path), params)
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? || BigMarkerClient::Config.api_key.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 http_client
67
- conn ||= Faraday.new(url: BigMarkerClient::Config.base_url) do |faraday|
68
- faraday = headers(faraday)
69
- configure_logging(faraday) if BigMarkerClient::Config.log
70
- end
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
- adapter
74
+ hash
88
75
  end
89
76
 
90
77
  def base_url(path)
91
- BigMarkerClient::Config.base_url + (path.start_with?("/") ? path : "/#{path}")
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
- BigMarkerClient::Config.logger.debug(json) if BigMarkerClient::Config.debug
85
+ Config.logger.debug(json) if Config.debug
99
86
  json
100
87
  rescue JSON::ParserError
101
- raise BigMarkerClient::ResponseError, "invalid response"
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
@@ -1,3 +1,3 @@
1
1
  module BigMarkerClient
2
- VERSION = "0.1.4".freeze
2
+ VERSION = "0.1.6".freeze
3
3
  end
@@ -10,6 +10,7 @@ module BigMarkerClient
10
10
 
11
11
  autoload :Base, "big_marker_client/base"
12
12
  autoload :Config, "big_marker_client/config"
13
+ autoload :HttpClient, "big_marker_client/http_client"
13
14
  autoload :Version, "big_marker_client/version"
14
15
 
15
16
  module Api
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
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-18 00:00:00.000000000 Z
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: '3.0'
128
+ version: '2.6'
128
129
  required_rubygems_version: !ruby/object:Gem::Requirement
129
130
  requirements:
130
131
  - - ">="