big_marker_client 0.1.2 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9158ca174ac5afbc0b1b0057b3e50070f65ec0573a5244b5b5214b9de19d9bbb
4
- data.tar.gz: 89a8f747bec556b71ecf3ee4ed0d7bf83d9310ea0d9682c6319402527f793c15
3
+ metadata.gz: 761022b647bdfeecdd833b29b236ff768cf2713d2d5c82a3986638d5cc67b0d5
4
+ data.tar.gz: 16707b0d879dd593066b400677c343bdfa47eed6d97e5132a5f99599b94e64e6
5
5
  SHA512:
6
- metadata.gz: cbc3d4cb06b5ee68b65bafa1390ced3f73dc9a00f2c60aa111f7d32f369b4dcabfc24f3fb96b3ecc9a9d0a6521ff37d60ad74dc628ecfc25556c2b272943a484
7
- data.tar.gz: bc6517c9c88a1f347cc27bf859a76e0b2a6b03078df0967f057e80805092c314d8ab1d0e61a3b3bc1037220b2cdf420d76e3df7d910327cdc7f7ddd23f3a50f0
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,20 @@
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
+
10
+ ## [0.1.4] - 2022-01-18
11
+
12
+ - add new properties to attendees and add handout model and factory
13
+
14
+ ## [0.1.3] - 2022-01-11
15
+
16
+ - add helper methods to iterate over all pages for paginated requests
17
+
1
18
  ## [0.1.2] - 2022-01-07
2
19
 
3
20
  - actually package the factories into the gem
@@ -24,6 +24,14 @@ module BigMarkerClient
24
24
  result
25
25
  end
26
26
 
27
+ ##
28
+ # helper method to retrieve all pages for the #list method
29
+ # @see #list
30
+ def list_all(conference_id, params = {})
31
+ path = replace_path_params(path: LIST_REGISTRANTS, replacements: { "{id}": conference_id })
32
+ loop_over(path, "registrations", ::BigMarkerClient::Models::Registrant, params)
33
+ end
34
+
27
35
  ##
28
36
  # list all registrants to a conference with custom fields.
29
37
  # @param conference_id [String] conference identifier
@@ -39,6 +47,14 @@ module BigMarkerClient
39
47
  result
40
48
  end
41
49
 
50
+ ##
51
+ # helper method to retrieve all pages for the #list_with_fields method
52
+ # @see #list_with_fields
53
+ def list_all_with_fields(conference_id, params = {})
54
+ path = replace_path_params(path: LIST_REGISTRANTS_WITH_FIELDS, replacements: { "{id}": conference_id })
55
+ loop_over(path, "registrations", ::BigMarkerClient::Models::Registrant, params)
56
+ end
57
+
42
58
  ##
43
59
  # registers a participant to a conference.
44
60
  # @param conference_id [String] conference identifier
@@ -86,8 +102,8 @@ module BigMarkerClient
86
102
 
87
103
  private
88
104
 
89
- def map_to_model_array(hash_array)
90
- hash_array.map { |hash| ::BigMarkerClient::Models::Registrant.new(hash) }
105
+ def map_to_model_array(hash_array, model_class = ::BigMarkerClient::Models::Registrant)
106
+ hash_array.map { |hash| model_class.new(hash) }
91
107
  end
92
108
  end
93
109
  end
@@ -34,6 +34,14 @@ module BigMarkerClient
34
34
  result
35
35
  end
36
36
 
37
+ ##
38
+ # helper method to retrieve all pages for the #list method
39
+ # @see #list
40
+ def list_all(params = {})
41
+ params["page_count"] ||= params["per_page"] if params["per_page"]
42
+ loop_over(LIST_CONFERENCES, "conferences", ::BigMarkerClient::Models::Conference, params)
43
+ end
44
+
37
45
  ##
38
46
  # search for conferences with specific matching criteria.
39
47
  # @param params [Hash] recognized are:
@@ -55,6 +63,13 @@ module BigMarkerClient
55
63
  result
56
64
  end
57
65
 
66
+ ##
67
+ # helper method to retrieve all pages for the #search method
68
+ # @see #search
69
+ def search_all(params = {})
70
+ loop_over(SEARCH_CONFERENCES, "conferences", ::BigMarkerClient::Models::Conference, params, :post)
71
+ end
72
+
58
73
  ##
59
74
  # get one conference based on it's ID
60
75
  # @param conference_id [String] conference identifier
@@ -81,6 +96,14 @@ module BigMarkerClient
81
96
  result
82
97
  end
83
98
 
99
+ ##
100
+ # helper method to retrieve all pages for the #associated_series method
101
+ # @see #associated_series
102
+ def associated_series_all(conference_id, params = {})
103
+ path = replace_path_params(path: ASSOCIATED_SERIES_CONFERENCES, replacements: { "{id}": conference_id })
104
+ loop_over(path, "conferences", ::BigMarkerClient::Models::Conference, params)
105
+ end
106
+
84
107
  ##
85
108
  # get child conferences of a parent recurring conference.
86
109
  # @param conference_id [String] conference identifier
@@ -93,11 +116,19 @@ module BigMarkerClient
93
116
  def recurring(conference_id, params = {})
94
117
  result = get(replace_path_params(path: RECURRING_CONFERENCES,
95
118
  replacements: { "{id}": conference_id }), params)
96
- return map_to_model_array(result["conferences"]) if result["conferences"]
119
+ return map_to_model_array(result["child_conferences"]) if result["child_conferences"]
97
120
 
98
121
  result
99
122
  end
100
123
 
124
+ ##
125
+ # helper method to retrieve all pages for the #recurring method
126
+ # @see #recurring
127
+ def recurring_all(conference_id, params = {})
128
+ path = replace_path_params(path: RECURRING_CONFERENCES, replacements: { "{id}": conference_id })
129
+ loop_over(path, "child_conferences", ::BigMarkerClient::Models::Conference, params)
130
+ end
131
+
101
132
  ##
102
133
  # update a conference either with a Models::Conference object or single properties as hash
103
134
  # @param conference_id [String] conference identifier
@@ -176,6 +207,14 @@ module BigMarkerClient
176
207
  result
177
208
  end
178
209
 
210
+ ##
211
+ # helper method to retrieve all pages for the #attendees method
212
+ # @see #attendees
213
+ def attendees_all(conference_id, params = {})
214
+ path = replace_path_params(path: GET_CONFERENCE_ATTENDEES, replacements: { "{id}": conference_id })
215
+ loop_over(path, "attendees", ::BigMarkerClient::Models::Attendee, params)
216
+ end
217
+
179
218
  private
180
219
 
181
220
  def map_to_model_array(hash_array, model_class = ::BigMarkerClient::Models::Conference)
@@ -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)
@@ -32,59 +34,94 @@ module BigMarkerClient
32
34
  new_path
33
35
  end
34
36
 
37
+ def loop_over(path, field, model_class, params = {}, method = :get)
38
+ page = 1
39
+ results = []
40
+ loop do
41
+ params["page"] = page
42
+ result = send(method, path, params)
43
+ results += map_to_model_array(result[field], model_class) if result[field]
44
+ break if break?(results: results, result: result, page: page, page_size: page_size(params))
45
+
46
+ page += 1
47
+ end
48
+ results
49
+ end
50
+
35
51
  private
36
52
 
37
53
  def request(path:, verb: :get, params: {})
38
54
  check_preconditions(verb, path)
55
+ params = stringify_keys(params)
39
56
 
40
57
  params = params.to_json unless %w[get delete].include?(verb.to_s)
41
- 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)
42
60
  parse_body(response.body)
43
61
  end
44
62
 
45
63
  def check_preconditions(verb, path)
46
- if verb.nil? || path.nil? || BigMarkerClient::Config.api_key.nil?
47
- raise ArgumentError, "http_method, path or api key is missing"
48
- end
64
+ raise ArgumentError, "http_method, path or api key is missing" if verb.nil? || path.nil? || Config.api_key.nil?
49
65
  raise ArgumentError, "unsupported http_method: #{verb}" unless %w[post put patch delete get].include?(verb.to_s)
50
66
  end
51
67
 
52
- def http_client
53
- conn ||= Faraday.new(url: BigMarkerClient::Config.base_url) do |faraday|
54
- faraday = headers(faraday)
55
- configure_logging(faraday) if BigMarkerClient::Config.log
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)
56
73
  end
57
- conn.adapter :typhoeus
58
- conn
59
- end
60
-
61
- def headers(adapter)
62
- adapter.headers["Content-Type"] = "application/json"
63
- adapter.headers["API-KEY"] = BigMarkerClient::Config.api_key unless BigMarkerClient::Config.api_key.nil?
64
- adapter
65
- end
66
-
67
- def configure_logging(adapter)
68
- adapter.response :logger do |logger|
69
- logger.instance_variable_get("@options")[:log_level] = :debug if BigMarkerClient::Config.debug
70
- logger.filter(/password=([^&]+)/, "password=[FILTERED]")
71
- logger.filter(/API-KEY: "(\w*)"/, "API-KEY: [FILTERED]")
72
- end
73
- adapter
74
+ hash
74
75
  end
75
76
 
76
77
  def base_url(path)
77
- BigMarkerClient::Config.base_url + (path.start_with?("/") ? path : "/#{path}")
78
+ Config.base_url + (path.start_with?("/") ? path : "/#{path}")
78
79
  end
79
80
 
80
81
  def parse_body(body)
81
82
  return nil if body.strip == ""
82
83
 
83
84
  json = JSON.parse(body)
84
- BigMarkerClient::Config.logger.debug(json) if BigMarkerClient::Config.debug
85
+ Config.logger.debug(json) if Config.debug
85
86
  json
86
87
  rescue JSON::ParserError
87
- 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
118
+ end
119
+
120
+ ##
121
+ # conferences#list is a total mess as requests require `page_count` instead of `per_page` as everywhere else and
122
+ # ti will return `total_count` instead of `total_entries` compared to the rest
123
+ def total_count(response)
124
+ response["total_entries"] || response["total_count"]
88
125
  end
89
126
  end
90
127
  end
@@ -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,9 +1,28 @@
1
1
  module BigMarkerClient
2
2
  module Models
3
3
  class Attendee < Base
4
- attr_accessor :email, :first_name, :last_name, :entered_at, :leaved_at, :total_duration, :engaged_duration,
4
+ attr_accessor :id, :bmid, :conference_id, :email, :first_name, :last_name, :edited_in_room_display_name,
5
+ :custom_fields, :entered_at, :leaved_at, :total_duration, :engaged_duration, :attendance_monitor,
6
+ :survey_results, :time_zone, :country,
5
7
  :chats_count, :qas_count, :polls_count, :polls, :questions, :handouts, :browser_name,
6
8
  :browser_version, :device_name
9
+ attr_reader :view_handout, :download_handout
10
+
11
+ def download_handout=(handout_array)
12
+ @download_handout = if handout_array.nil? || !handout_array.is_a?(Array) || handout_array.empty?
13
+ []
14
+ else
15
+ handout_array.map { |handout_hash| Handout.new(handout_hash) }
16
+ end
17
+ end
18
+
19
+ def view_handout=(handout_array)
20
+ @view_handout = if handout_array.nil? || !handout_array.is_a?(Array) || handout_array.empty?
21
+ []
22
+ else
23
+ handout_array.map { |handout_hash| Handout.new(handout_hash) }
24
+ end
25
+ end
7
26
  end
8
27
  end
9
28
  end
@@ -0,0 +1,12 @@
1
+ module BigMarkerClient
2
+ module Models
3
+ class Handout < Base
4
+ attr_accessor :type, :email, :content, :source_from
5
+ attr_reader :timestamp
6
+
7
+ def timestamp=(timestamp)
8
+ @timestamp = DateTime.strptime(timestamp, "%m/%d/%Y %H:%M:%S %z") unless timestamp.nil? || timestamp == ""
9
+ end
10
+ end
11
+ end
12
+ end
@@ -1,3 +1,3 @@
1
1
  module BigMarkerClient
2
- VERSION = "0.1.2".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
@@ -27,6 +28,7 @@ module BigMarkerClient
27
28
  autoload :Base, "big_marker_client/models/base"
28
29
  autoload :Conference, "big_marker_client/models/conference"
29
30
  autoload :DialInInformation, "big_marker_client/models/dial_in_information"
31
+ autoload :Handout, "big_marker_client/models/handout"
30
32
  autoload :PreloadFile, "big_marker_client/models/preload_file"
31
33
  autoload :Presenter, "big_marker_client/models/presenter"
32
34
  autoload :Registrant, "big_marker_client/models/registrant"
@@ -1,12 +1,21 @@
1
1
  FactoryBot.define do
2
2
  factory :big_marker_attendee, class: "BigMarkerClient::Models::Attendee" do
3
+ sequence(:id)
4
+ sequence(:bmid) { SecureRandom.hex(6) }
5
+ sequence(:conference_id) { SecureRandom.hex(6) }
3
6
  sequence(:email) { |n| "attendee#{n}@example.com" }
4
7
  first_name { "Attendee first name" }
5
8
  last_name { "Attendee last name" }
9
+ edited_in_room_display_name { nil }
10
+ custom_fields { [] }
6
11
  entered_at { (Time.now - (60 * BigMarkerClient::TestSupport::MINUTES)).strftime("%FT%T%:z") }
7
12
  leaved_at { Time.now.strftime("%FT%T%:z") }
8
13
  total_duration { "3600" }
9
14
  engaged_duration { "240" }
15
+ attendance_monitor { { "show_popup" => 0, "click_popup" => 0 } }
16
+ survey_results { [] }
17
+ time_zone { "Europe/Berlin" }
18
+ country { "Germany" }
10
19
  chats_count { 1 }
11
20
  qas_count { 0 }
12
21
  polls_count { 2 }
@@ -16,12 +25,26 @@ FactoryBot.define do
16
25
  browser_name { "Google Chrome" }
17
26
  browser_version { 96 }
18
27
  device_name { "desktop" }
28
+ download_handout { [] }
29
+ view_handout { [] }
19
30
 
20
31
  initialize_with do
21
- new(email: email, first_name: first_name, last_name: last_name, entered_at: entered_at, leaved_at: leaved_at,
22
- total_duration: total_duration, engaged_duration: engaged_duration, chats_count: chats_count,
23
- qas_count: qas_count, polls_count: polls_count, polls: polls, questions: questions, handouts: handouts,
24
- browser_name: browser_name, browser_version: browser_version, device_name: device_name)
32
+ new(id: id, bmid: bmid, conference_id: conference_id, email: email, first_name: first_name, last_name: last_name,
33
+ edited_in_room_display_name: edited_in_room_display_name, custom_fields: custom_fields,
34
+ entered_at: entered_at, leaved_at: leaved_at, total_duration: total_duration,
35
+ engaged_duration: engaged_duration, attendance_monitor: attendance_monitor, survey_results: survey_results,
36
+ time_zone: time_zone, country: country, chats_count: chats_count, qas_count: qas_count,
37
+ polls_count: polls_count, polls: polls, questions: questions, handouts: handouts, browser_name: browser_name,
38
+ browser_version: browser_version, device_name: device_name, download_handout: download_handout,
39
+ view_handout: view_handout)
40
+ end
41
+
42
+ trait :with_view_handouts do
43
+ view_handout { build_list(:big_marker_handout, 1, :view_handout) }
44
+ end
45
+
46
+ trait :with_download_handouts do
47
+ download_handout { build_list(:big_marker_handout, 1, :download_handout) }
25
48
  end
26
49
  end
27
50
  end
@@ -0,0 +1,21 @@
1
+ FactoryBot.define do
2
+ factory :big_marker_handout, class: "BigMarkerClient::Models::Handout" do
3
+ type { "handout" }
4
+ sequence(:email) { |n| "attendee-email#{n}@example.com" }
5
+ sequence(:content) { |n| "some_file_name#{n}.pdf" }
6
+ timestamp { Time.now.strftime("%m/%d/%Y %H:%M:%S %z") }
7
+ source_from { "Live Webinar" }
8
+
9
+ trait :view_handout do
10
+ type { "view_handout" }
11
+ end
12
+
13
+ trait :download_handout do
14
+ type { "download_handout" }
15
+ end
16
+
17
+ initialize_with do
18
+ new(type: type, email: email, content: content, timestamp: timestamp, source_from: source_from)
19
+ end
20
+ end
21
+ end
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.2
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-07 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,10 +92,12 @@ 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
98
99
  - lib/big_marker_client/models/dial_in_information.rb
100
+ - lib/big_marker_client/models/handout.rb
99
101
  - lib/big_marker_client/models/preload_file.rb
100
102
  - lib/big_marker_client/models/presenter.rb
101
103
  - lib/big_marker_client/models/registrant.rb
@@ -105,6 +107,7 @@ files:
105
107
  - spec/factories/big_marker/attendee.rb
106
108
  - spec/factories/big_marker/conference.rb
107
109
  - spec/factories/big_marker/dial_in_infromation.rb
110
+ - spec/factories/big_marker/handout.rb
108
111
  - spec/factories/big_marker/preload_file.rb
109
112
  - spec/factories/big_marker/presenter.rb
110
113
  - spec/factories/big_marker/registrant.rb
@@ -122,7 +125,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
122
125
  requirements:
123
126
  - - ">="
124
127
  - !ruby/object:Gem::Version
125
- version: '3.0'
128
+ version: '2.6'
126
129
  required_rubygems_version: !ruby/object:Gem::Requirement
127
130
  requirements:
128
131
  - - ">="