arena 0.1.3 → 0.2.0
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 +5 -5
- data/.github/workflows/lint.yml +14 -0
- data/.github/workflows/test.yml +14 -0
- data/.rubocop.yml +12 -0
- data/.rubocop_todo.yml +49 -0
- data/Gemfile +12 -0
- data/README.md +1 -1
- data/Rakefile +9 -4
- data/arena.gemspec +16 -18
- data/lib/arena/account.rb +9 -7
- data/lib/arena/api.rb +42 -40
- data/lib/arena/base.rb +6 -5
- data/lib/arena/block.rb +5 -3
- data/lib/arena/cache/adaptor/generic.rb +3 -1
- data/lib/arena/cache/adaptor/null.rb +4 -2
- data/lib/arena/cache/adaptor/padrino.rb +3 -1
- data/lib/arena/cache/adaptor/rails.rb +7 -5
- data/lib/arena/cache.rb +11 -9
- data/lib/arena/channel.rb +8 -6
- data/lib/arena/channel_feed.rb +9 -8
- data/lib/arena/client.rb +25 -16
- data/lib/arena/comment.rb +7 -5
- data/lib/arena/configurable.rb +15 -13
- data/lib/arena/connectable.rb +21 -13
- data/lib/arena/connection.rb +6 -4
- data/lib/arena/core_ext/string.rb +7 -3
- data/lib/arena/creatable.rb +3 -3
- data/lib/arena/default.rb +9 -7
- data/lib/arena/entities/attachment.rb +4 -2
- data/lib/arena/entities/avatar.rb +8 -6
- data/lib/arena/entities/embed.rb +7 -5
- data/lib/arena/entities/image.rb +7 -2
- data/lib/arena/entities/provider.rb +2 -0
- data/lib/arena/entities/source.rb +2 -0
- data/lib/arena/entities/version.rb +2 -0
- data/lib/arena/entity.rb +2 -0
- data/lib/arena/error/cache_error.rb +4 -2
- data/lib/arena/error.rb +2 -0
- data/lib/arena/feed.rb +19 -18
- data/lib/arena/group.rb +6 -4
- data/lib/arena/results.rb +3 -1
- data/lib/arena/search_results.rb +16 -11
- data/lib/arena/story.rb +18 -15
- data/lib/arena/summary.rb +4 -2
- data/lib/arena/user.rb +12 -10
- data/lib/arena/user_feed.rb +9 -8
- data/lib/arena/version.rb +3 -1
- data/lib/arena.rb +12 -14
- data/test/cassettes/Arena/channel/handles_a_400_error_that_returns_JSON.yml +39 -0
- data/test/cassettes/Arena/channel/handles_a_403_error.yml +39 -0
- data/test/lib/arena/api_test.rb +15 -0
- data/test/lib/arena/version_test.rb +4 -4
- data/test/test_helper.rb +5 -1
- metadata +15 -73
- data/.travis.yml +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f3371aa0176ae4b8281424c96411818c2148a94577064b82028d74d2c0b3a25b
|
4
|
+
data.tar.gz: 95896b4182c13238e273aea03e07d4268672d62b2769886f16d03bf989d2bc72
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 51ada54286c9ecc23b53cb0d585c287785373770a37eefce33708d8593ee953985c8e9e4721389cb94442499bee56f4fcfa494f5335a342ccd19e892bd9f4989
|
7
|
+
data.tar.gz: 1bec6fc4a24221ab8a9e4a7fda5e20db5ebafb2e49f226f136e682620f65964548612dc6a0a10ea26a6a79546fbcc704af277754bd0fbf71a2406b6747bcf5a4
|
data/.rubocop.yml
ADDED
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2025-10-12 15:57:16 UTC using RuboCop version 1.81.1.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 2
|
10
|
+
# Configuration parameters: Mode, AllowedMethods, AllowedPatterns, AllowBangMethods, WaywardPredicates.
|
11
|
+
# AllowedMethods: call
|
12
|
+
# WaywardPredicates: nonzero?
|
13
|
+
Naming/PredicateMethod:
|
14
|
+
Exclude:
|
15
|
+
- 'lib/arena/base.rb'
|
16
|
+
|
17
|
+
# Offense count: 1
|
18
|
+
# Configuration parameters: NamePrefix, ForbiddenPrefixes, AllowedMethods, MethodDefinitionMacros, UseSorbetSigs.
|
19
|
+
# NamePrefix: is_, has_, have_, does_
|
20
|
+
# ForbiddenPrefixes: is_, has_, have_, does_
|
21
|
+
# AllowedMethods: is_a?
|
22
|
+
# MethodDefinitionMacros: define_method, define_singleton_method
|
23
|
+
Naming/PredicatePrefix:
|
24
|
+
Exclude:
|
25
|
+
- 'spec/**/*'
|
26
|
+
- 'lib/arena/connectable.rb'
|
27
|
+
|
28
|
+
# Offense count: 36
|
29
|
+
# Configuration parameters: AllowedConstants.
|
30
|
+
Style/Documentation:
|
31
|
+
Enabled: false
|
32
|
+
|
33
|
+
# Offense count: 2
|
34
|
+
# This cop supports unsafe autocorrection (--autocorrect-all).
|
35
|
+
# Configuration parameters: AllowedReceivers.
|
36
|
+
# AllowedReceivers: Thread.current
|
37
|
+
Style/HashEachMethods:
|
38
|
+
Exclude:
|
39
|
+
- 'lib/arena/client.rb'
|
40
|
+
- 'lib/arena/configurable.rb'
|
41
|
+
|
42
|
+
# Offense count: 5
|
43
|
+
Style/MissingRespondToMissing:
|
44
|
+
Exclude:
|
45
|
+
- 'lib/arena.rb'
|
46
|
+
- 'lib/arena/cache.rb'
|
47
|
+
- 'lib/arena/cache/adaptor/null.rb'
|
48
|
+
- 'lib/arena/cache/adaptor/padrino.rb'
|
49
|
+
- 'lib/arena/cache/adaptor/rails.rb'
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
[](https://github.com/aredotna/arena-rb/actions/workflows/test.yml)
|
2
2
|
|
3
3
|
# Arena
|
4
4
|
|
data/Rakefile
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
#!/usr/bin/env rake
|
2
|
-
|
2
|
+
# frozen_string_literal: true
|
3
3
|
|
4
|
-
|
4
|
+
require 'bundler/gem_tasks'
|
5
|
+
|
6
|
+
desc 'Open an irb session preloaded with this library.'
|
5
7
|
task :console do
|
6
|
-
sh
|
8
|
+
sh 'irb -rubygems -I lib -r arena.rb'
|
7
9
|
end
|
8
10
|
|
9
11
|
require 'rake/testtask'
|
@@ -14,4 +16,7 @@ Rake::TestTask.new do |t|
|
|
14
16
|
t.verbose = true
|
15
17
|
end
|
16
18
|
|
17
|
-
|
19
|
+
require 'rubocop/rake_task'
|
20
|
+
RuboCop::RakeTask.new
|
21
|
+
|
22
|
+
task default: %i[rubocop test]
|
data/arena.gemspec
CHANGED
@@ -1,26 +1,24 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'English'
|
4
|
+
require File.expand_path('lib/arena/version', __dir__)
|
3
5
|
|
4
6
|
Gem::Specification.new do |gem|
|
5
|
-
gem.authors = [
|
6
|
-
gem.email = [
|
7
|
+
gem.authors = ['dzuc']
|
8
|
+
gem.email = ['everyone@aredotna.com']
|
7
9
|
gem.description = "Wrapper for Arena's API"
|
8
10
|
gem.summary = "Wrapper for Arena's API"
|
9
|
-
gem.homepage =
|
10
|
-
|
11
|
-
gem.files = `git ls-files`.split($\)
|
12
|
-
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
-
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
-
gem.name = "arena"
|
15
|
-
gem.require_paths = ["lib"]
|
16
|
-
gem.version = Arena::VERSION
|
11
|
+
gem.homepage = 'https://www.are.na/'
|
17
12
|
|
18
|
-
gem.
|
19
|
-
gem.
|
20
|
-
gem.
|
21
|
-
gem.
|
13
|
+
gem.files = `git ls-files`.split($OUTPUT_RECORD_SEPARATOR)
|
14
|
+
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
15
|
+
gem.name = 'arena'
|
16
|
+
gem.require_paths = ['lib']
|
17
|
+
gem.required_ruby_version = '>= 3.0'
|
22
18
|
|
23
|
-
gem.
|
24
|
-
gem.add_runtime_dependency 'httparty'
|
19
|
+
gem.version = Arena::VERSION
|
25
20
|
|
21
|
+
gem.add_dependency 'httparty'
|
22
|
+
gem.add_dependency 'json'
|
23
|
+
gem.metadata['rubygems_mfa_required'] = 'true'
|
26
24
|
end
|
data/lib/arena/account.rb
CHANGED
@@ -1,26 +1,28 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'arena/base'
|
4
|
+
require 'arena/user'
|
3
5
|
|
4
6
|
module Arena
|
5
7
|
class Account < Arena::Base
|
6
8
|
def user
|
7
|
-
@user ||= Arena::User.new(@attrs[
|
9
|
+
@user ||= Arena::User.new(@attrs['user'])
|
8
10
|
end
|
9
11
|
|
10
12
|
def channels
|
11
|
-
@channels ||= @attrs[
|
13
|
+
@channels ||= @attrs['channels'].collect { |channel| Arena::Channel.new(channel) }
|
12
14
|
end
|
13
15
|
|
14
16
|
def help_channels
|
15
|
-
@help_channels ||= @attrs[
|
17
|
+
@help_channels ||= @attrs['help_channels'].collect { |channel| Arena::Channel.new(channel) }
|
16
18
|
end
|
17
19
|
|
18
20
|
def following_channel_ids
|
19
|
-
@following_channel_ids ||= @attrs[
|
21
|
+
@following_channel_ids ||= @attrs['following_ids']['channels']
|
20
22
|
end
|
21
23
|
|
22
24
|
def following_user_ids
|
23
|
-
@following_user_ids ||= @attrs[
|
25
|
+
@following_user_ids ||= @attrs['following_ids']['users']
|
24
26
|
end
|
25
27
|
end
|
26
28
|
end
|
data/lib/arena/api.rb
CHANGED
@@ -1,123 +1,125 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'arena/user'
|
4
|
+
require 'arena/block'
|
5
|
+
require 'arena/channel'
|
6
|
+
require 'arena/results'
|
7
|
+
require 'arena/search_results'
|
8
|
+
require 'arena/account'
|
9
|
+
require 'arena/comment'
|
10
|
+
require 'arena/feed'
|
11
|
+
require 'arena/channel_feed'
|
12
|
+
require 'arena/user_feed'
|
11
13
|
|
12
14
|
module Arena
|
13
15
|
module API
|
14
16
|
# Returns paginated global list of Channels
|
15
|
-
def channels(options={})
|
16
|
-
object_from_response(Arena::ChannelResults, :get,
|
17
|
+
def channels(options = {})
|
18
|
+
object_from_response(Arena::ChannelResults, :get, '/channels', options)
|
17
19
|
end
|
18
20
|
|
19
21
|
# Returns a full Channel representation
|
20
|
-
def channel(id, options={})
|
22
|
+
def channel(id, options = {})
|
21
23
|
object_from_response(Arena::Channel, :get, "/channels/#{id}", options)
|
22
24
|
end
|
23
25
|
|
24
26
|
# Posts a block to a channel
|
25
|
-
def channel_add_block(id, options={})
|
27
|
+
def channel_add_block(id, options = {})
|
26
28
|
object_from_response(Arena::Block, :post, "/channels/#{id}/blocks", options)
|
27
29
|
end
|
28
30
|
|
29
31
|
# Remove a block from channel (destroy connection)
|
30
|
-
def channel_remove_block(channel_id, id, options={})
|
32
|
+
def channel_remove_block(channel_id, id, options = {})
|
31
33
|
send(:delete, "/channels/#{channel_id}/blocks/#{id}", options)
|
32
34
|
end
|
33
35
|
|
34
36
|
# Select a block within the context of a channel
|
35
|
-
def channel_toggle_block_selection(id, options={})
|
37
|
+
def channel_toggle_block_selection(id, options = {})
|
36
38
|
send(:put, "/connections/#{id}/selection", options)
|
37
39
|
end
|
38
40
|
|
39
41
|
# Returns thumbnail representation (first 9 Blocks) for the given Channel
|
40
|
-
def channel_thumb(id, options={})
|
42
|
+
def channel_thumb(id, options = {})
|
41
43
|
object_from_response(Arena::Channel, :get, "/channels/#{id}/thumb", options)
|
42
44
|
end
|
43
45
|
|
44
46
|
# Returns a paginated list of all Channels connected to the given Channel
|
45
|
-
def channel_channels(id, options={})
|
47
|
+
def channel_channels(id, options = {})
|
46
48
|
object_from_response(Arena::ChannelResults, :get, "/channels/#{id}/channels", options)
|
47
49
|
end
|
48
50
|
|
49
51
|
# Returns a paginated feed for a given Channel
|
50
|
-
def channel_feed(id, options={})
|
52
|
+
def channel_feed(id, options = {})
|
51
53
|
object_from_response(Arena::ChannelFeed, :get, "/channel/#{id}/feed", options)
|
52
54
|
end
|
53
55
|
|
54
56
|
# Returns a paginated feed for a given User
|
55
|
-
def user_feed(id, options={})
|
57
|
+
def user_feed(id, options = {})
|
56
58
|
object_from_response(Arena::UserFeed, :get, "/user/#{id}/feed", options)
|
57
59
|
end
|
58
60
|
|
59
61
|
# Returns a full Block representation
|
60
|
-
def block(id, options={})
|
62
|
+
def block(id, options = {})
|
61
63
|
object_from_response(Arena::Block, :get, "/blocks/#{id}", options)
|
62
64
|
end
|
63
65
|
|
64
66
|
# Returns Block comments
|
65
|
-
def block_comments(id, options={})
|
66
|
-
collection_from_response(Arena::Comment, :get, "/blocks/#{id}/comments",
|
67
|
+
def block_comments(id, options = {})
|
68
|
+
collection_from_response(Arena::Comment, :get, "/blocks/#{id}/comments", 'comments', options)
|
67
69
|
end
|
68
70
|
|
69
71
|
# Returns a User representation
|
70
|
-
def user(id, options={})
|
72
|
+
def user(id, options = {})
|
71
73
|
object_from_response(Arena::User, :get, "/users/#{id}", options)
|
72
74
|
end
|
73
75
|
|
74
76
|
# Returns a paginated list of all public Channels a User has access to
|
75
|
-
def user_channels(id, options={})
|
77
|
+
def user_channels(id, options = {})
|
76
78
|
object_from_response(Arena::ChannelResults, :get, "/users/#{id}/channels", options)
|
77
79
|
end
|
78
80
|
|
79
81
|
# Full representation of the account endpoint
|
80
|
-
def account(options={})
|
82
|
+
def account(options = {})
|
81
83
|
require_authentication!
|
82
84
|
|
83
|
-
object_from_response(Arena::Account, :get,
|
85
|
+
object_from_response(Arena::Account, :get, '/accounts', options)
|
84
86
|
end
|
85
87
|
|
86
88
|
# All of the authenticated user's Channels
|
87
|
-
def account_channels(options={})
|
89
|
+
def account_channels(options = {})
|
88
90
|
require_authentication!
|
89
91
|
|
90
|
-
object_from_response(Arena::ChannelResults, :get,
|
92
|
+
object_from_response(Arena::ChannelResults, :get, '/accounts/channels', options)
|
91
93
|
end
|
92
94
|
|
93
95
|
# Returns the authenticated user's settings
|
94
|
-
def settings(options={})
|
96
|
+
def settings(options = {})
|
95
97
|
require_authentication!
|
96
98
|
|
97
|
-
object_from_response(Arena::User, :get,
|
99
|
+
object_from_response(Arena::User, :get, '/accounts/settings', options)
|
98
100
|
end
|
99
101
|
|
100
102
|
# Returns a Search object with an Array for Channels, Blocks and Users
|
101
|
-
def search(query, options={})
|
103
|
+
def search(query, options = {})
|
102
104
|
path = options[:kind].nil? ? "/search/?q=#{query}" : "/search/#{options[:kind]}/?q=#{query}"
|
103
105
|
|
104
106
|
object_from_response(Arena::SearchResults, :get, path, options)
|
105
107
|
end
|
106
108
|
|
107
109
|
# Returns a Feed object with an arry of Stories
|
108
|
-
def feed(options={})
|
110
|
+
def feed(options = {})
|
109
111
|
require_authentication!
|
110
112
|
|
111
|
-
object_from_response(Arena::Feed, :get,
|
113
|
+
object_from_response(Arena::Feed, :get, '/feed', options)
|
112
114
|
end
|
113
115
|
|
114
|
-
|
116
|
+
private
|
115
117
|
|
116
118
|
def require_authentication!
|
117
|
-
#
|
119
|
+
# TODO: Raise error if key missing
|
118
120
|
end
|
119
121
|
|
120
|
-
def object_from_response(klass, request_method, url, options={})
|
122
|
+
def object_from_response(klass, request_method, url, options = {})
|
121
123
|
response = send(request_method.to_sym, url, options)
|
122
124
|
klass.new(response)
|
123
125
|
end
|
@@ -126,8 +128,8 @@ module Arena
|
|
126
128
|
array.collect { |element| klass.new(element) }
|
127
129
|
end
|
128
130
|
|
129
|
-
def collection_from_response(klass, request_method, url, selector, options={})
|
131
|
+
def collection_from_response(klass, request_method, url, selector, options = {})
|
130
132
|
collection_from_array(klass, send(request_method.to_sym, url, options)[selector])
|
131
133
|
end
|
132
|
-
end
|
133
|
-
end
|
134
|
+
end
|
135
|
+
end
|
data/lib/arena/base.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Arena
|
2
4
|
class Base
|
3
5
|
attr_reader :attrs
|
@@ -22,7 +24,7 @@ module Arena
|
|
22
24
|
#
|
23
25
|
# @param attrs [Hash]
|
24
26
|
# @return [Arena::Base]
|
25
|
-
def initialize(attrs={})
|
27
|
+
def initialize(attrs = {})
|
26
28
|
@attrs = attrs
|
27
29
|
end
|
28
30
|
|
@@ -35,20 +37,19 @@ module Arena
|
|
35
37
|
# self
|
36
38
|
# end
|
37
39
|
|
38
|
-
|
40
|
+
protected
|
39
41
|
|
40
42
|
# @param attr [Symbol]
|
41
43
|
# @param other [Arena::Base]
|
42
44
|
# @return [Boolean]
|
43
45
|
def attr_equal(attr, other)
|
44
|
-
|
46
|
+
instance_of?(other.class) && !other.send(attr).nil? && send(attr) == other.send(attr)
|
45
47
|
end
|
46
48
|
|
47
49
|
# @param other [Arena::Base]
|
48
50
|
# @return [Boolean]
|
49
51
|
def attrs_equal(other)
|
50
|
-
|
52
|
+
instance_of?(other.class) && !other.attrs.empty? && attrs == other.attrs
|
51
53
|
end
|
52
|
-
|
53
54
|
end
|
54
55
|
end
|
data/lib/arena/block.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'arena/base'
|
2
4
|
require 'arena/creatable'
|
3
5
|
require 'arena/connectable'
|
@@ -13,7 +15,7 @@ module Arena
|
|
13
15
|
include Arena::Connectable
|
14
16
|
|
15
17
|
attr_reader :id, :title, :generated_title, :state, :comment_count, :content,
|
16
|
-
|
18
|
+
:content_html, :description, :description_html
|
17
19
|
|
18
20
|
def _class
|
19
21
|
@_class ||= @attrs['class']
|
@@ -24,13 +26,13 @@ module Arena
|
|
24
26
|
end
|
25
27
|
|
26
28
|
def source
|
27
|
-
@source ||= Arena::Entity::Source.new(@attrs['source'])
|
29
|
+
@source ||= Arena::Entity::Source.new(@attrs['source']) unless @attrs['source'].nil?
|
28
30
|
end
|
29
31
|
|
30
32
|
def image
|
31
33
|
@image ||= Arena::Entity::Image.new(@attrs['image']) if has_image?
|
32
34
|
end
|
33
|
-
|
35
|
+
|
34
36
|
def attachment
|
35
37
|
@attachment ||= Arena::Entity::Attachment.new(@attrs['attachment']) if has_attachment?
|
36
38
|
end
|
@@ -1,10 +1,12 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'arena/error/cache_error'
|
2
4
|
|
3
5
|
module Arena
|
4
6
|
module Cache
|
5
7
|
module Adaptor
|
6
8
|
class Null
|
7
|
-
def self.method_missing(
|
9
|
+
def self.method_missing(_method, *_args)
|
8
10
|
raise Arena::Error::CacheError
|
9
11
|
end
|
10
12
|
end
|
@@ -1,20 +1,22 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'arena/cache/adaptor/generic'
|
2
4
|
|
3
5
|
module Arena
|
4
6
|
module Cache
|
5
7
|
module Adaptor
|
6
8
|
class Rails < Arena::Cache::Adaptor::Generic
|
7
|
-
def self.method_missing(method, *args
|
9
|
+
def self.method_missing(method, *args)
|
8
10
|
# Brittle/ugly but works for the time being
|
9
|
-
#
|
11
|
+
#
|
10
12
|
key = args.present? ? "arena_#{method}_#{args.first}" : "arena_#{method}"
|
11
13
|
cache = Rails.cache.read(key)
|
12
14
|
|
13
15
|
if cache.nil?
|
14
16
|
object = args.present? ? Arena.send(method, args.first) : Arena.send(method)
|
15
|
-
|
17
|
+
|
16
18
|
Rails.cache.write(key, object, expires_in: Arena.expires_in)
|
17
|
-
|
19
|
+
|
18
20
|
cache = Rails.cache.read(key)
|
19
21
|
end
|
20
22
|
|
data/lib/arena/cache.rb
CHANGED
@@ -1,24 +1,26 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'arena/cache/adaptor/rails'
|
4
|
+
require 'arena/cache/adaptor/padrino'
|
5
|
+
require 'arena/cache/adaptor/null'
|
4
6
|
|
5
7
|
module Arena
|
6
8
|
module Cache
|
7
9
|
class << self
|
8
10
|
def adapt_to
|
9
11
|
if defined?(Rails)
|
10
|
-
|
12
|
+
'Rails'
|
11
13
|
elsif defined?(Padrino)
|
12
|
-
|
14
|
+
'Padrino'
|
13
15
|
else
|
14
|
-
|
16
|
+
'Null'
|
15
17
|
end
|
16
18
|
end
|
17
19
|
|
18
20
|
# Delegate to the appropriate cache engine
|
19
|
-
#
|
20
|
-
def method_missing(method,
|
21
|
-
"Arena::Cache::Adaptor::#{adapt_to}".constantize.send(method,
|
21
|
+
#
|
22
|
+
def method_missing(method, ...)
|
23
|
+
"Arena::Cache::Adaptor::#{adapt_to}".constantize.send(method, ...)
|
22
24
|
end
|
23
25
|
end
|
24
26
|
end
|
data/lib/arena/channel.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'arena/base'
|
2
4
|
require 'arena/creatable'
|
3
5
|
require 'arena/connectable'
|
@@ -10,8 +12,8 @@ module Arena
|
|
10
12
|
include Arena::Connectable
|
11
13
|
|
12
14
|
attr_reader :id, :title, :published, :open, :collaboration,
|
13
|
-
|
14
|
-
|
15
|
+
:slug, :length, :kind, :status, :user_id, :total_pages,
|
16
|
+
:current_page, :per, :follower_count
|
15
17
|
|
16
18
|
def _class
|
17
19
|
@attrs['class']
|
@@ -45,14 +47,14 @@ module Arena
|
|
45
47
|
@flat_connections ||= contents.collect(&:connections).flatten.compact.uniq(&:id)
|
46
48
|
end
|
47
49
|
|
48
|
-
%w
|
50
|
+
%w[image text link media attachment channel].each do |kind|
|
49
51
|
define_method "#{kind}s" do
|
50
52
|
contents.select { |connectable| connectable._class.downcase == kind }
|
51
53
|
end
|
52
54
|
end
|
53
55
|
|
54
56
|
def blocks
|
55
|
-
contents.select { |connectable| connectable._base_class ==
|
57
|
+
contents.select { |connectable| connectable._base_class == 'Block' }
|
56
58
|
end
|
57
|
-
end
|
58
|
-
end
|
59
|
+
end
|
60
|
+
end
|
data/lib/arena/channel_feed.rb
CHANGED
@@ -1,21 +1,22 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'arena/base'
|
4
|
+
require 'arena/story'
|
3
5
|
|
4
6
|
module Arena
|
5
7
|
class ChannelFeed < Arena::Base
|
6
8
|
attr_reader :type, :limit, :total, :offset, :range_start, :range_end
|
7
9
|
|
8
10
|
def stories
|
9
|
-
@stories ||= @attrs[
|
11
|
+
@stories ||= @attrs['items'].collect { |item| Arena::Story.new(item) } if stories?
|
10
12
|
end
|
11
13
|
|
12
14
|
alias items stories
|
13
15
|
|
14
|
-
|
16
|
+
private
|
15
17
|
|
16
18
|
def stories?
|
17
|
-
!@attrs[
|
19
|
+
!@attrs['items'].nil?
|
18
20
|
end
|
19
|
-
|
20
|
-
|
21
|
-
end # Arena
|
21
|
+
end
|
22
|
+
end
|