arena 0.2.0 → 0.3.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.
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'arena/error'
4
+
5
+ module Arena
6
+ module V3
7
+ # Raised when the v3 API returns an error, e.g. "404: Not Found - The resource you are looking for does not exist.".
8
+ class Error < Arena::Error
9
+ attr_reader :status, :body, :headers
10
+
11
+ def initialize(message = nil, status: nil, body: nil, headers: nil)
12
+ super(message)
13
+ @status = status
14
+ @body = body
15
+ @headers = headers || {}
16
+ end
17
+
18
+ def self.for(status)
19
+ ERRORS.fetch(status, self)
20
+ end
21
+ end
22
+
23
+ class BadRequestError < Error; end
24
+ class UnauthorizedError < Error; end
25
+ class ForbiddenError < Error; end
26
+ class NotFoundError < Error; end
27
+ class GoneError < Error; end
28
+
29
+ # Raised on 429 Too Many Requests, reset is the Unix timestamp when the rate limit resets.
30
+ class RateLimitError < Error
31
+ def reset
32
+ value = headers['x-ratelimit-reset']
33
+ value&.to_i
34
+ end
35
+ end
36
+
37
+ class Error
38
+ ERRORS = {
39
+ 400 => BadRequestError,
40
+ 401 => UnauthorizedError,
41
+ 403 => ForbiddenError,
42
+ 404 => NotFoundError,
43
+ 410 => GoneError,
44
+ 429 => RateLimitError
45
+ }.freeze
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Arena
4
+ module V3
5
+ # A JSON object returned by the v3 API.
6
+ #
7
+ # Attributes are readable as methods or with [], and nested objects and
8
+ # arrays of objects are wrapped as resources too.
9
+ #
10
+ # channel = Arena.v3.channel('arena-influences')
11
+ # channel.title # => "Arena Influences"
12
+ # channel.owner.slug # => "are-na-team"
13
+ # channel[:counts][:blocks] # => 126
14
+ class Resource
15
+ attr_reader :attrs
16
+
17
+ def initialize(attrs = {})
18
+ @attrs = attrs || {}
19
+ end
20
+
21
+ def [](key)
22
+ wrap(@attrs[key.to_s])
23
+ end
24
+
25
+ def key?(key)
26
+ @attrs.key?(key.to_s)
27
+ end
28
+
29
+ def to_h
30
+ @attrs
31
+ end
32
+
33
+ alias to_hash to_h
34
+
35
+ def ==(other)
36
+ other.is_a?(self.class) && attrs == other.attrs
37
+ end
38
+
39
+ def inspect
40
+ "#<#{self.class.name} #{@attrs.inspect}>"
41
+ end
42
+
43
+ private
44
+
45
+ def method_missing(name, *args)
46
+ key = name.to_s
47
+ return super unless args.empty? && @attrs.key?(key)
48
+
49
+ self[key]
50
+ end
51
+
52
+ def respond_to_missing?(name, include_private = false)
53
+ @attrs.key?(name.to_s) || super
54
+ end
55
+
56
+ def wrap(value)
57
+ case value
58
+ when Hash then Resource.new(value)
59
+ when Array then value.map { |element| wrap(element) }
60
+ else value
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
data/lib/arena/v3.rb ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'arena/v3/resource'
4
+ require 'arena/v3/collection'
5
+ require 'arena/v3/error'
6
+ require 'arena/v3/api'
7
+ require 'arena/v3/client'
data/lib/arena/version.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Arena
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.0'
5
5
 
6
6
  def self.version
7
7
  VERSION
data/lib/arena.rb CHANGED
@@ -5,6 +5,7 @@ require 'arena/version'
5
5
  require 'arena/client'
6
6
  require 'arena/default'
7
7
  require 'arena/configurable'
8
+ require 'arena/v3'
8
9
 
9
10
  module Arena
10
11
  class << self
@@ -18,6 +19,15 @@ module Arena
18
19
  @client || @client = Arena::Client.new(options)
19
20
  end
20
21
 
22
+ # Returns a client for the v3 API, using the global configuration
23
+ # unless overridden by options.
24
+ #
25
+ # @return [Arena::V3::Client]
26
+ #
27
+ def v3(options = {})
28
+ Arena::V3::Client.new(options)
29
+ end
30
+
21
31
  private
22
32
 
23
33
  def method_missing(method, ...)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arena
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - dzuc
@@ -37,33 +37,21 @@ dependencies:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
39
  version: '0'
40
- description: Wrapper for Arena's API
40
+ description: A Ruby client for the Are.na v3 and legacy v2 APIs.
41
41
  email:
42
42
  - everyone@aredotna.com
43
43
  executables: []
44
44
  extensions: []
45
45
  extra_rdoc_files: []
46
46
  files:
47
- - ".github/workflows/lint.yml"
48
- - ".github/workflows/test.yml"
49
- - ".gitignore"
50
- - ".rubocop.yml"
51
- - ".rubocop_todo.yml"
52
- - Gemfile
47
+ - CHANGELOG.md
53
48
  - LICENSE
54
49
  - README.md
55
- - Rakefile
56
- - arena.gemspec
57
50
  - lib/arena.rb
58
51
  - lib/arena/account.rb
59
52
  - lib/arena/api.rb
60
53
  - lib/arena/base.rb
61
54
  - lib/arena/block.rb
62
- - lib/arena/cache.rb
63
- - lib/arena/cache/adaptor/generic.rb
64
- - lib/arena/cache/adaptor/null.rb
65
- - lib/arena/cache/adaptor/padrino.rb
66
- - lib/arena/cache/adaptor/rails.rb
67
55
  - lib/arena/channel.rb
68
56
  - lib/arena/channel_feed.rb
69
57
  - lib/arena/client.rb
@@ -71,7 +59,6 @@ files:
71
59
  - lib/arena/configurable.rb
72
60
  - lib/arena/connectable.rb
73
61
  - lib/arena/connection.rb
74
- - lib/arena/core_ext/string.rb
75
62
  - lib/arena/creatable.rb
76
63
  - lib/arena/default.rb
77
64
  - lib/arena/entities/attachment.rb
@@ -83,7 +70,6 @@ files:
83
70
  - lib/arena/entities/version.rb
84
71
  - lib/arena/entity.rb
85
72
  - lib/arena/error.rb
86
- - lib/arena/error/cache_error.rb
87
73
  - lib/arena/feed.rb
88
74
  - lib/arena/group.rb
89
75
  - lib/arena/results.rb
@@ -92,16 +78,20 @@ files:
92
78
  - lib/arena/summary.rb
93
79
  - lib/arena/user.rb
94
80
  - lib/arena/user_feed.rb
81
+ - lib/arena/v3.rb
82
+ - lib/arena/v3/api.rb
83
+ - lib/arena/v3/client.rb
84
+ - lib/arena/v3/collection.rb
85
+ - lib/arena/v3/error.rb
86
+ - lib/arena/v3/resource.rb
95
87
  - lib/arena/version.rb
96
- - test/cassettes/Arena/channel/handles_a_400_error_that_returns_JSON.yml
97
- - test/cassettes/Arena/channel/handles_a_403_error.yml
98
- - test/cassettes/Arena/channel/returns_a_channel.yml
99
- - test/lib/arena/api_test.rb
100
- - test/lib/arena/version_test.rb
101
- - test/test_helper.rb
102
- homepage: https://www.are.na/
103
- licenses: []
88
+ homepage: https://github.com/aredotna/arena-rb
89
+ licenses:
90
+ - MIT
104
91
  metadata:
92
+ bug_tracker_uri: https://github.com/aredotna/arena-rb/issues
93
+ changelog_uri: https://github.com/aredotna/arena-rb/blob/master/CHANGELOG.md
94
+ documentation_uri: https://www.are.na/developers
105
95
  rubygems_mfa_required: 'true'
106
96
  rdoc_options: []
107
97
  require_paths:
@@ -117,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
107
  - !ruby/object:Gem::Version
118
108
  version: '0'
119
109
  requirements: []
120
- rubygems_version: 3.6.9
110
+ rubygems_version: 4.0.20
121
111
  specification_version: 4
122
- summary: Wrapper for Arena's API
112
+ summary: Ruby client for the Are.na API.
123
113
  test_files: []
@@ -1,14 +0,0 @@
1
- name: lint
2
-
3
- on: [push, pull_request]
4
-
5
- jobs:
6
- rubocop:
7
- runs-on: ubuntu-latest
8
- steps:
9
- - uses: actions/checkout@v4
10
- - uses: ruby/setup-ruby@v1
11
- with:
12
- ruby-version: '3.4.6'
13
- bundler-cache: true
14
- - run: bundle exec rubocop
@@ -1,14 +0,0 @@
1
- name: test
2
-
3
- on: [push, pull_request]
4
-
5
- jobs:
6
- test:
7
- runs-on: ubuntu-latest
8
- steps:
9
- - uses: actions/checkout@v4
10
- - uses: ruby/setup-ruby@v1
11
- with:
12
- ruby-version: '3.4.6'
13
- bundler-cache: true
14
- - run: bundle exec rake test
data/.gitignore DELETED
@@ -1,19 +0,0 @@
1
- .DS_Store
2
- *.gem
3
- *.rbc
4
- .bundle
5
- .config
6
- .yardoc
7
- Gemfile.lock
8
- InstalledFiles
9
- _yardoc
10
- coverage
11
- doc/
12
- lib/bundler/man
13
- pkg
14
- rdoc
15
- spec/reports
16
- test/tmp
17
- test/version_tmp
18
- tmp
19
- _debug.rb
data/.rubocop.yml DELETED
@@ -1,12 +0,0 @@
1
- AllCops:
2
- TargetRubyVersion: 3.0
3
- NewCops: enable
4
-
5
- Metrics:
6
- Enabled: false
7
-
8
- inherit_from: .rubocop_todo.yml
9
-
10
- plugins:
11
- - rubocop-rake
12
- - rubocop-minitest
data/.rubocop_todo.yml DELETED
@@ -1,49 +0,0 @@
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 DELETED
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source 'https://rubygems.org'
4
-
5
- gemspec
6
-
7
- group :development, :test do
8
- gem 'minitest'
9
- gem 'minitest-vcr'
10
- gem 'rake'
11
- gem 'rubocop'
12
- gem 'rubocop-minitest'
13
- gem 'rubocop-rake'
14
- gem 'webmock'
15
- end
data/Rakefile DELETED
@@ -1,22 +0,0 @@
1
- #!/usr/bin/env rake
2
- # frozen_string_literal: true
3
-
4
- require 'bundler/gem_tasks'
5
-
6
- desc 'Open an irb session preloaded with this library.'
7
- task :console do
8
- sh 'irb -rubygems -I lib -r arena.rb'
9
- end
10
-
11
- require 'rake/testtask'
12
-
13
- Rake::TestTask.new do |t|
14
- t.libs << 'lib/arena'
15
- t.test_files = FileList['test/lib/arena/*_test.rb']
16
- t.verbose = true
17
- end
18
-
19
- require 'rubocop/rake_task'
20
- RuboCop::RakeTask.new
21
-
22
- task default: %i[rubocop test]
data/arena.gemspec DELETED
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'English'
4
- require File.expand_path('lib/arena/version', __dir__)
5
-
6
- Gem::Specification.new do |gem|
7
- gem.authors = ['dzuc']
8
- gem.email = ['everyone@aredotna.com']
9
- gem.description = "Wrapper for Arena's API"
10
- gem.summary = "Wrapper for Arena's API"
11
- gem.homepage = 'https://www.are.na/'
12
-
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'
18
-
19
- gem.version = Arena::VERSION
20
-
21
- gem.add_dependency 'httparty'
22
- gem.add_dependency 'json'
23
- gem.metadata['rubygems_mfa_required'] = 'true'
24
- end
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'arena/configurable'
4
-
5
- module Arena
6
- module Cache
7
- module Adaptor
8
- class Generic
9
- include Arena::Configurable
10
- end
11
- end
12
- end
13
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'arena/error/cache_error'
4
-
5
- module Arena
6
- module Cache
7
- module Adaptor
8
- class Null
9
- def self.method_missing(_method, *_args)
10
- raise Arena::Error::CacheError
11
- end
12
- end
13
- end
14
- end
15
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'arena/cache/adaptor/generic'
4
-
5
- module Arena
6
- module Cache
7
- module Adaptor
8
- class Padrino < Arena::Cache::Adaptor::Generic
9
- def self.method_missing(method, *args, &block)
10
- # todo
11
- end
12
- end
13
- end
14
- end
15
- end
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'arena/cache/adaptor/generic'
4
-
5
- module Arena
6
- module Cache
7
- module Adaptor
8
- class Rails < Arena::Cache::Adaptor::Generic
9
- def self.method_missing(method, *args)
10
- # Brittle/ugly but works for the time being
11
- #
12
- key = args.present? ? "arena_#{method}_#{args.first}" : "arena_#{method}"
13
- cache = Rails.cache.read(key)
14
-
15
- if cache.nil?
16
- object = args.present? ? Arena.send(method, args.first) : Arena.send(method)
17
-
18
- Rails.cache.write(key, object, expires_in: Arena.expires_in)
19
-
20
- cache = Rails.cache.read(key)
21
- end
22
-
23
- cache
24
- end
25
- end
26
- end
27
- end
28
- end
data/lib/arena/cache.rb DELETED
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'arena/cache/adaptor/rails'
4
- require 'arena/cache/adaptor/padrino'
5
- require 'arena/cache/adaptor/null'
6
-
7
- module Arena
8
- module Cache
9
- class << self
10
- def adapt_to
11
- if defined?(Rails)
12
- 'Rails'
13
- elsif defined?(Padrino)
14
- 'Padrino'
15
- else
16
- 'Null'
17
- end
18
- end
19
-
20
- # Delegate to the appropriate cache engine
21
- #
22
- def method_missing(method, ...)
23
- "Arena::Cache::Adaptor::#{adapt_to}".constantize.send(method, ...)
24
- end
25
- end
26
- end
27
- end
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class String
4
- unless method_defined?(:constantize)
5
- def constantize
6
- split('::').inject(Module) { |acc, val| acc.const_get(val) }
7
- end
8
- end
9
- end
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'arena/error'
4
-
5
- module Arena
6
- class Error
7
- # Raised when Cache engine is unavailable
8
- #
9
- class CacheError < Arena::Error
10
- end
11
- end
12
- end
@@ -1,39 +0,0 @@
1
- ---
2
- http_interactions:
3
- - request:
4
- method: get
5
- uri: https://api.are.na/v2/channels/delightfully-absurd
6
- body:
7
- encoding: US-ASCII
8
- string: ''
9
- headers:
10
- Accept-Encoding:
11
- - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
- Accept:
13
- - "*/*"
14
- User-Agent:
15
- - Ruby
16
- response:
17
- status:
18
- code: 403
19
- message: OK
20
- headers:
21
- Date:
22
- - Sat, 11 Oct 2025 20:29:37 GMT
23
- Content-Type:
24
- - application/json; charset=utf-8
25
- Transfer-Encoding:
26
- - chunked
27
- Cache-Control:
28
- - max-age=604800, private
29
- Server:
30
- - cloudflare
31
- Vary:
32
- - Origin
33
- Via:
34
- - 2.0 heroku-router
35
- body:
36
- encoding: UTF-8
37
- string: '{"code":400,"message":"Internal Server Error","description":"Something went wrong."}'
38
- recorded_at: Sat, 11 Oct 2025 20:29:37 GMT
39
- recorded_with: VCR 6.3.1
@@ -1,39 +0,0 @@
1
- ---
2
- http_interactions:
3
- - request:
4
- method: get
5
- uri: https://api.are.na/v2/channels/delightfully-absurd
6
- body:
7
- encoding: US-ASCII
8
- string: ''
9
- headers:
10
- Accept-Encoding:
11
- - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
- Accept:
13
- - "*/*"
14
- User-Agent:
15
- - Ruby
16
- response:
17
- status:
18
- code: 403
19
- message: OK
20
- headers:
21
- Date:
22
- - Sat, 11 Oct 2025 20:29:37 GMT
23
- Content-Type:
24
- - text/plain; charset=utf-8
25
- Transfer-Encoding:
26
- - chunked
27
- Cache-Control:
28
- - max-age=604800, private
29
- Server:
30
- - cloudflare
31
- Vary:
32
- - Origin
33
- Via:
34
- - 2.0 heroku-router
35
- body:
36
- encoding: UTF-8
37
- string: 'Forbidden'
38
- recorded_at: Sat, 11 Oct 2025 20:29:37 GMT
39
- recorded_with: VCR 6.3.1