jekyll-action-network 0.4.0 → 0.4.1

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: 65a9afd8b2fcbcc33e2f1f45ea6d25a07acc6bcc28e5b7ac3900443a5c4078dc
4
- data.tar.gz: ba9411be015b223ded854fec35a3fb2f39c9cdaa60ce9271b0cddb4c80511ed7
3
+ metadata.gz: 2947b846e07427841ccd8923055f0bcda8f01f80fc38291fd0b9bf077af007c6
4
+ data.tar.gz: 9ff2f727a3da1e2c31015b3d9fc90f4c94ab1666db54a939473c02f2a1a81aa3
5
5
  SHA512:
6
- metadata.gz: e00cde2d4c9d533931f046f11b7272bfa33dfedebd94b26141d721d7990ffb6d8be48be770ccac1ff378504a8856b958987c25ddd0d7e26c2607c76fa6709399
7
- data.tar.gz: 4b0c39e1b928efce610feb7ba9733853c022a33d4a20eba190d6518f465777324152c6eba58a4294da562f2931ce39298bf4a524d1a4f7c948822f526a44ba1b
6
+ metadata.gz: 685c03c3b844d8fdd9cbfe373db626a492175958e3624f2dd1ec685057f05bceb652ec6179d7d6f348f934eb1a88b963601a08a5c0097167635f0bf5bfaca914
7
+ data.tar.gz: d6cc9aaa7040eb21d42458b4f09c2fa27f3668aa959f0196be2eed55ae69d455c510722601df65a3fc0126886e93171f376706e3091eb79090edcf0b9661c126
@@ -8,8 +8,9 @@ module Jekyll
8
8
  class Collection
9
9
  UTILS = Jekyll::ActionNetwork::Utils.new
10
10
 
11
- def initialize(site, client, config_init, settings)
11
+ def initialize(site, generator, client, config_init, settings)
12
12
  @site = site
13
+ @generator = generator
13
14
  @settings = settings
14
15
  @client = client
15
16
  @config_init = config_init
@@ -44,7 +45,7 @@ module Jekyll
44
45
  end
45
46
 
46
47
  def actions
47
- @actions ||= UTILS.get_full_list(@client, @name)
48
+ @actions ||= @generator.get_full_list(@name)
48
49
  end
49
50
 
50
51
  def filters
@@ -29,19 +29,26 @@ module Jekyll
29
29
 
30
30
  def make_collections
31
31
  @config["import"].each do |config|
32
- name = config["name"] if config.is_a? Hash
33
- name ||= config if config.is_a? String
34
- next unless name
32
+ col_config = make_collection_config(config)
33
+ name = col_config["name"]
34
+ next unless col_config["name"]
35
35
 
36
- make_collection(name, config)
36
+ make_collection(name, col_config)
37
37
  end
38
38
  @site.collections["actions"] = actions if @config["actions"]
39
39
  end
40
40
 
41
+ def make_collection_config(col_config_init)
42
+ return col_config_init if col_config_init.is_a? Hash
43
+ return { "name" => col_config_init } if col_config_init.is_a? String
44
+
45
+ Jekyll.logger.warn LOG_NAME, "Config format #{col_config_init} not recognised"
46
+ end
47
+
41
48
  def make_collection(name, config)
42
49
  return unless defaults[name]
43
50
 
44
- collection = Jekyll::ActionNetwork::Collection.new(@site, @client, config, settings)
51
+ collection = Jekyll::ActionNetwork::Collection.new(@site, self, @client, config, settings)
45
52
  @site.collections[collection.config["collection"]] = collection.populate
46
53
  actions.docs.concat(collection.collection.docs)
47
54
  end
@@ -50,7 +57,7 @@ module Jekyll
50
57
  return @actions if @actions
51
58
 
52
59
  actions_config = @config["actions"] if @config["actions"].is_a? Hash
53
- actions_settings = @settings["actions"].merge(actions_config || {})
60
+ actions_settings = settings["actions"].merge(actions_config || {})
54
61
  @actions ||= Jekyll::Collection.new(@site, actions_settings["collection"])
55
62
  end
56
63
 
@@ -67,10 +74,8 @@ module Jekyll
67
74
  @defaults ||= settings["defaults"]
68
75
  end
69
76
 
70
- private
71
-
72
77
  def api_key
73
- key = @config["key"] || @settings["key"]
78
+ key = @config["key"] || settings["key"]
74
79
  return ENV.fetch(key[4..key.length - 1], nil) if key[0..3] == "ENV_"
75
80
 
76
81
  key
@@ -82,13 +87,37 @@ module Jekyll
82
87
  return
83
88
  end
84
89
 
85
- @client = ActionNetworkRest.new(api_key: api_key)
86
- unless @client.entry_point.authenticated_successfully?
90
+ unless entry_point.dig("_links", "osdi:tags").present?
87
91
  Jekyll.logger.warn "Action Network Authentication Unsucessful"
88
92
  return
89
93
  end
90
94
  true
91
95
  end
96
+
97
+ def client
98
+ @client ||= ActionNetworkRest.new(api_key: api_key)
99
+ end
100
+
101
+ def entry_point
102
+ @entry_point ||= client.entry_point.get
103
+ end
104
+
105
+ def page_size
106
+ @page_size ||= @entry_point["max_page_size"]
107
+ end
108
+
109
+ def get_full_list(name)
110
+ page = 1
111
+ actions = []
112
+ loop do
113
+ action_page = @client.send(name).list(page: page)
114
+ actions.concat(action_page)
115
+ break if action_page.size < page_size
116
+
117
+ page += 1
118
+ end
119
+ actions
120
+ end
92
121
  end
93
122
  end
94
123
  end
@@ -26,19 +26,6 @@ module Jekyll
26
26
  "#{css}<script src='https://actionnetwork.org/widgets/v5/#{resource}/#{slug}?format=js&source=widget'></script>
27
27
  <div id='can-#{resource}-area-#{slug}' style='width: 100%'></div>"
28
28
  end
29
-
30
- def get_full_list(client, name)
31
- page = 1
32
- actions = []
33
- loop do
34
- action_page = client.send(name).list(page: page)
35
- break if action_page.empty?
36
-
37
- actions.concat(action_page)
38
- page += 1
39
- end
40
- actions
41
- end
42
29
  end
43
30
  end
44
31
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  module ActionNetwork
5
- VERSION = "0.4.0"
5
+ VERSION = "0.4.1"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-action-network
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Irving