arena 0.0.9 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -16,3 +16,4 @@ spec/reports
16
16
  test/tmp
17
17
  test/version_tmp
18
18
  tmp
19
+ _debug.rb
data/README.md CHANGED
@@ -18,9 +18,24 @@ Or install it yourself as:
18
18
 
19
19
  Register an application at http://dev.are.na
20
20
 
21
- ### Configure for personal use
21
+ ### Configure for personal use (optional; be aware this grants access to everything your account has access to)
22
22
  ```ruby
23
23
  Arena.configure do |config|
24
24
  config.access_token = 'XXXXXXXXXXXXX'
25
25
  end
26
26
  ```
27
+
28
+ ### Simple usage example
29
+
30
+ ```ruby
31
+ @channel = Arena.channel(params[:id])
32
+ ```
33
+
34
+ ```erb
35
+ <% @channel.contents.each do |connectable| %>
36
+ <%= connectable.title %>
37
+ <% if connectable.has_image? %>
38
+ <img src="<%= connectable.image.display.url %>" alt="<%= connectable.title %>" />
39
+ <% end %>
40
+ <% end %>
41
+ ```
data/lib/arena.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  require "arena/version"
2
- require_relative "./arena/client"
3
- require_relative "./arena/default"
4
- require_relative "./arena/configurable"
2
+
3
+ load "arena/client.rb"
4
+ load "arena/default.rb"
5
+ load "arena/configurable.rb"
5
6
 
6
7
  module Arena
7
8
  class << self
@@ -10,6 +11,7 @@ module Arena
10
11
  # Delegate to a Arena::Client
11
12
  #
12
13
  # @return [Arena::Client]
14
+ #
13
15
  def client
14
16
  if @client
15
17
  @client
@@ -23,8 +25,7 @@ module Arena
23
25
  def method_missing(method, *args, &block)
24
26
  self.client.send(method, *args, &block)
25
27
  end
28
+ end # self
29
+ end # Arena
26
30
 
27
- end
28
- end
29
-
30
- Arena.setup
31
+ Arena.setup
@@ -0,0 +1,26 @@
1
+ require "arena/base"
2
+ require "arena/user"
3
+
4
+ module Arena
5
+ class Account < Arena::Base
6
+ def user
7
+ @user ||= Arena::User.new(@attrs["user"])
8
+ end
9
+
10
+ def channels
11
+ @channels ||= @attrs["channels"].collect { |channel| Arena::Channel.new(channel) }
12
+ end
13
+
14
+ def help_channels
15
+ @help_channels ||= @attrs["help_channels"].collect { |channel| Arena::Channel.new(channel) }
16
+ end
17
+
18
+ def following_channel_ids
19
+ @following_channel_ids ||= @attrs["following_ids"]["channels"]
20
+ end
21
+
22
+ def following_user_ids
23
+ @following_user_ids ||= @attrs["following_ids"]["users"]
24
+ end
25
+ end
26
+ end
data/lib/arena/api.rb CHANGED
@@ -1,8 +1,11 @@
1
- require 'arena/user'
2
- require 'arena/block'
3
- require 'arena/channel'
4
- require 'arena/results'
5
- require 'arena/search_results'
1
+ require "arena/user"
2
+ require "arena/block"
3
+ require "arena/channel"
4
+ require "arena/results"
5
+ require "arena/search_results"
6
+ require "arena/account"
7
+ require "arena/comment"
8
+ require "arena/feed"
6
9
 
7
10
  module Arena
8
11
  module API
@@ -46,6 +49,11 @@ module Arena
46
49
  object_from_response(Arena::Block, :get, "/blocks/#{id}", options)
47
50
  end
48
51
 
52
+ # Returns Block comments
53
+ def block_comments(id, options={})
54
+ collection_from_response(Arena::Comment, :get, "/blocks/#{id}/comments", "comments", options)
55
+ end
56
+
49
57
  # Returns a User representation
50
58
  def user(id, options={})
51
59
  object_from_response(Arena::User, :get, "/users/#{id}", options)
@@ -56,18 +64,47 @@ module Arena
56
64
  object_from_response(Arena::ChannelResults, :get, "/users/#{id}/channels", options)
57
65
  end
58
66
 
67
+ # Full representation of the account endpoint
68
+ def account(options={})
69
+ require_authentication!
70
+
71
+ object_from_response(Arena::Account, :get, "/accounts", options)
72
+ end
73
+
59
74
  # All of the authenticated user's Channels
60
75
  def account_channels(options={})
76
+ require_authentication!
77
+
61
78
  object_from_response(Arena::ChannelResults, :get, "/accounts/channels", options)
62
79
  end
63
80
 
81
+ # Returns the authenticated user's settings
82
+ def settings(options={})
83
+ require_authentication!
84
+
85
+ object_from_response(Arena::User, :get, "/accounts/settings", options)
86
+ end
87
+
64
88
  # Returns a Search object with an Array for Channels, Blocks and Users
65
- def search(query, option={})
66
- object_from_response(Arena::SearchResults, :get, "/search?q=#{query}", options)
89
+ def search(query, options={})
90
+ path = options[:kind].nil? ? "/search/?q=#{query}" : "/search/#{options[:kind]}/?q=#{query}"
91
+
92
+ object_from_response(Arena::SearchResults, :get, path, options)
93
+ end
94
+
95
+ # Returns a Feed object with an arry of Stories
96
+ def feed(options={})
97
+ require_authentication!
98
+
99
+ object_from_response(Arena::Feed, :get, "/feed", options)
67
100
  end
68
101
 
69
102
  private
70
103
 
104
+ def require_authentication!
105
+ # todo: Raise error if key missing
106
+ end
107
+
71
108
  def object_from_response(klass, request_method, url, options={})
72
109
  response = send(request_method.to_sym, url, options)
73
110
  klass.new(response)
@@ -77,9 +114,8 @@ module Arena
77
114
  array.collect { |element| klass.new(element) }
78
115
  end
79
116
 
80
- def collection_from_response(klass, request_method, url, options={}, selector)
117
+ def collection_from_response(klass, request_method, url, selector, options={})
81
118
  collection_from_array(klass, send(request_method.to_sym, url, options)[selector])
82
119
  end
83
-
84
- end
85
- end
120
+ end # API
121
+ end # Arena
data/lib/arena/block.rb CHANGED
@@ -1,11 +1,11 @@
1
1
  require 'arena/base'
2
+ require 'arena/creatable'
3
+ require 'arena/connectable'
2
4
  require 'arena/entity'
3
5
  require 'arena/entities/source'
4
6
  require 'arena/entities/image'
5
7
  require 'arena/entities/attachment'
6
8
  require 'arena/entities/embed'
7
- require 'arena/creatable'
8
- require 'arena/connectable'
9
9
 
10
10
  module Arena
11
11
  class Block < Arena::Base
@@ -15,10 +15,6 @@ module Arena
15
15
  attr_reader :id, :title, :generated_title, :state, :comment_count, :content,
16
16
  :content_html, :description, :description_html
17
17
 
18
- def user
19
- @user ||= Arena::User.new(@attrs['user'])
20
- end
21
-
22
18
  def _class
23
19
  @_class ||= @attrs['class']
24
20
  end
@@ -28,7 +24,7 @@ module Arena
28
24
  end
29
25
 
30
26
  def source
31
- @source ||= Arena::Entity::Source.new(@attrs['source'])
27
+ @source ||= Arena::Entity::Source.new(@attrs['source']) if !@attrs['source'].nil?
32
28
  end
33
29
 
34
30
  def image
@@ -42,18 +38,6 @@ module Arena
42
38
  def embed
43
39
  @embed ||= Arena::Entity::Embed.new(@attrs['embed']) if has_embed?
44
40
  end
45
-
46
- def connections
47
- @connections ||= @attrs['connections'].collect { |channel| Arena::Channel.new(channel) }
48
- end
49
-
50
- # Detect optional portions of the response
51
- [:image, :attachment, :embed].each do |kind|
52
- define_method "has_#{kind}?" do
53
- !@attrs[kind.to_s].nil?
54
- end
55
- end
56
-
57
41
  end
58
42
 
59
43
  class Text < Block; end
@@ -61,4 +45,4 @@ module Arena
61
45
  class Link < Block; end
62
46
  class Media < Block; end
63
47
  class Attachment < Block; end
64
- end
48
+ end
@@ -0,0 +1,25 @@
1
+ require "arena/cache/adaptor/rails"
2
+ require "arena/cache/adaptor/padrino"
3
+ require "arena/cache/adaptor/null"
4
+
5
+ module Arena
6
+ module Cache
7
+ class << self
8
+ def adapt_to
9
+ if defined?(Rails)
10
+ "Rails"
11
+ elsif defined?(Padrino)
12
+ "Padrino"
13
+ else
14
+ "Null"
15
+ end
16
+ end
17
+
18
+ # Delegate to the appropriate cache engine
19
+ #
20
+ def method_missing(method, *args, &block)
21
+ "Arena::Cache::Adaptor::#{adapt_to}".constantize.send(method, *args, &block)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,11 @@
1
+ require "arena/configurable"
2
+
3
+ module Arena
4
+ module Cache
5
+ module Adaptor
6
+ class Generic
7
+ include Arena::Configurable
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ require "arena/error/cache_error"
2
+
3
+ module Arena
4
+ module Cache
5
+ module Adaptor
6
+ class Null
7
+ def self.method_missing(method, *args, &block)
8
+ raise Arena::Error::CacheError
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ require "arena/cache/adaptor/generic"
2
+
3
+ module Arena
4
+ module Cache
5
+ module Adaptor
6
+ class Padrino < Arena::Cache::Adaptor::Generic
7
+ def self.method_missing(method, *args, &block)
8
+ # todo
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,26 @@
1
+ require "arena/cache/adaptor/generic"
2
+
3
+ module Arena
4
+ module Cache
5
+ module Adaptor
6
+ class Rails < Arena::Cache::Adaptor::Generic
7
+ def self.method_missing(method, *args, &block)
8
+ # Brittle/ugly but works for the time being
9
+ #
10
+ key = args.present? ? "arena_#{method}_#{args.first}" : "arena_#{method}"
11
+ cache = Rails.cache.read(key)
12
+
13
+ if cache.nil?
14
+ object = args.present? ? Arena.send(method, args.first) : Arena.send(method)
15
+
16
+ Rails.cache.write(key, object, expires_in: Arena.expires_in)
17
+
18
+ cache = Rails.cache.read(key)
19
+ end
20
+
21
+ cache
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
data/lib/arena/channel.rb CHANGED
@@ -13,10 +13,6 @@ module Arena
13
13
  :slug, :length, :kind, :status, :user_id, :total_pages,
14
14
  :current_page, :per, :follower_count
15
15
 
16
- def user
17
- @user ||= Arena::User.new(@attrs['user'])
18
- end
19
-
20
16
  def _class
21
17
  @attrs['class']
22
18
  end
@@ -29,15 +25,34 @@ module Arena
29
25
  @contents ||= @attrs['contents'].collect { |object| "Arena::#{object['class']}".constantize.new(object) }
30
26
  end
31
27
 
28
+ def contents_updated_at
29
+ # todo
30
+ end
31
+
32
+ def connection_count
33
+ @connection_count ||= contents.collect(&:connections).flatten.size
34
+ end
35
+
32
36
  def collaborators
33
37
  @collaborators ||= @attrs['collaborators'].collect { |user| Arena::User.new(user) }
34
38
  end
35
39
 
40
+ def contributors
41
+ @contributors ||= contents.collect(&:user).uniq(&:id)
42
+ end
43
+
44
+ def flat_connections
45
+ @flat_connections ||= contents.collect(&:connections).flatten.compact.uniq(&:id)
46
+ end
47
+
36
48
  %w(image text link media attachment channel).each do |kind|
37
49
  define_method "#{kind}s" do
38
50
  contents.select { |connectable| connectable._class.downcase == kind }
39
51
  end
40
52
  end
41
-
42
- end
43
- end
53
+
54
+ def blocks
55
+ contents.select { |connectable| connectable._base_class == "Block" }
56
+ end
57
+ end # Channel < Arena::Base
58
+ end # Arena
data/lib/arena/client.rb CHANGED
@@ -1,11 +1,10 @@
1
- require 'arena/configurable'
2
- require 'arena/error'
3
- require 'arena/api'
4
- require 'httparty'
5
- require 'json'
1
+ require "arena/configurable"
2
+ require "arena/error"
3
+ require "arena/api"
4
+ require "httparty"
5
+ require "json"
6
6
 
7
7
  module Arena
8
-
9
8
  class Client
10
9
  include HTTParty
11
10
  include Arena::Configurable
@@ -18,6 +17,7 @@ module Arena
18
17
  end
19
18
 
20
19
  # Performs HTTP GET POST PUT and DELETE requests
20
+ #
21
21
  %w(get post put delete).each do |method|
22
22
  define_method method do |path, options={}|
23
23
  options = { query: options, headers: set_headers }
@@ -30,9 +30,9 @@ module Arena
30
30
 
31
31
  def set_headers
32
32
  if !@access_token.nil?
33
- { 'Authorization' => "Bearer #{@access_token}" }
33
+ { "Authorization" => "Bearer #{@access_token}" }
34
34
  elsif !@auth_token.nil?
35
- { 'X-AUTH-TOKEN' => @auth_token }
35
+ { "X-AUTH-TOKEN" => @auth_token }
36
36
  else
37
37
  { }
38
38
  end
@@ -52,12 +52,9 @@ module Arena
52
52
 
53
53
  raise Arena::Error.new(error_message(parsed)) if error?(response)
54
54
 
55
- return parsed
56
-
55
+ parsed
57
56
  rescue JSON::ParserError, TypeError
58
57
  nil
59
58
  end
60
-
61
59
  end
62
-
63
60
  end
@@ -0,0 +1,19 @@
1
+ require "arena/base"
2
+ require "arena/user"
3
+ require "arena/creatable"
4
+
5
+ module Arena
6
+ class Comment < Arena::Base
7
+ include Arena::Creatable
8
+
9
+ attr_reader :id, :commentable_id, :commentable_type, :body
10
+
11
+ def _class
12
+ @_class ||= @attrs["class"]
13
+ end
14
+
15
+ def user
16
+ @user ||= Arena::User.new(@attrs["user"])
17
+ end
18
+ end
19
+ end
@@ -1,7 +1,9 @@
1
1
  module Arena
2
2
  module Configurable
3
3
  attr_accessor :base_domain,
4
- :api_version
4
+ :api_version,
5
+ :use_caching,
6
+ :expires_in
5
7
 
6
8
  attr_writer :application_id,
7
9
  :application_secret,
@@ -16,15 +18,18 @@ module Arena
16
18
  :application_id,
17
19
  :application_secret,
18
20
  :access_token,
19
- :auth_token
21
+ :auth_token,
22
+ :use_caching,
23
+ :expires_in
20
24
  ]
21
25
  end
22
26
  end
23
27
 
24
- # Allows configuration options
25
- # to be set in a block
28
+ # Allows configuration options to be set in a block
29
+ #
26
30
  def configure
27
31
  yield self
32
+
28
33
  self
29
34
  end
30
35
 
@@ -32,6 +37,7 @@ module Arena
32
37
  Arena::Configurable.keys.each do |key|
33
38
  instance_variable_set(:"@#{key}", Arena::Default.options[key])
34
39
  end
40
+
35
41
  self
36
42
  end
37
43
 
@@ -39,10 +45,8 @@ module Arena
39
45
 
40
46
  private
41
47
 
42
- # @return [Hash]
43
48
  def options
44
49
  Hash[Arena::Configurable.keys.map{|key| [key, instance_variable_get(:"@#{key}")]}]
45
50
  end
46
-
47
51
  end
48
52
  end
@@ -2,6 +2,9 @@ require 'time'
2
2
 
3
3
  module Arena
4
4
  module Connectable
5
+ def user
6
+ @user ||= Arena::User.new(@attrs['user']) if !@attrs['user'].nil?
7
+ end
5
8
 
6
9
  %w(position selected connection_id).each do |method|
7
10
  define_method method do
@@ -16,6 +19,21 @@ module Arena
16
19
  end
17
20
  end
18
21
 
22
+ # Detect optional portions of the response
23
+ %w(image attachment embed).each do |kind|
24
+ define_method "has_#{kind}?" do
25
+ !@attrs[kind.to_s].nil?
26
+ end
27
+ end
28
+
29
+ def is_block?
30
+ _base_class == "Block"
31
+ end
32
+
33
+ def connections
34
+ @connections ||= @attrs['connections'].collect { |channel| Arena::Channel.new(channel) } if !@attrs['connections'].nil?
35
+ end
36
+
19
37
  def connected_at
20
38
  @connected_at ||= Time.parse(@attrs['connected_at']) if connected?
21
39
  end
@@ -29,7 +47,7 @@ module Arena
29
47
  'id' => @attrs['connected_by_user_id'],
30
48
  'username' => @attrs['connected_by_username'],
31
49
  'full_name' => @attrs['connected_by_username']
32
- })
50
+ }) if connected?
33
51
  end
34
52
 
35
53
  private
@@ -37,6 +55,5 @@ module Arena
37
55
  def connected?
38
56
  !@attrs['connected_at'].nil?
39
57
  end
40
-
41
- end
42
- end
58
+ end # Connectable
59
+ end # Arena
@@ -0,0 +1,10 @@
1
+ require "arena/base"
2
+
3
+ module Arena
4
+ class Connection < Arena::Base
5
+ include Arena::Creatable
6
+
7
+ attr_reader :id, :position, :selected, :user_id,
8
+ :connectable_id, :connectable_type, :channel_id
9
+ end # Connection
10
+ end # Arena
@@ -1,7 +1,5 @@
1
1
  class String
2
-
3
2
  def constantize
4
3
  self.split("::").inject(Module) {|acc, val| acc.const_get(val)}
5
4
  end unless method_defined?(:constantize)
6
-
7
- end
5
+ end
data/lib/arena/default.rb CHANGED
@@ -2,9 +2,10 @@ module Arena
2
2
  module Default
3
3
  BASE_DOMAIN = "api.are.na" unless defined? BASE_DOMAIN
4
4
  API_VERSION = "v2" unless defined? API_VERSION
5
+ USE_CACHING = false unless defined? USE_CACHING
6
+ EXPIRES_IN = 600 unless defined? EXPIRES_IN # 10 minutes
5
7
 
6
8
  class << self
7
- # @return [Hash]
8
9
  def options
9
10
  Hash[Arena::Configurable.keys.map{|key| [key, send(key)]}]
10
11
  end
@@ -18,20 +19,28 @@ module Arena
18
19
  end
19
20
 
20
21
  def application_id
21
- ENV['APPLICATION_ID']
22
+ ENV["APPLICATION_ID"]
22
23
  end
23
24
 
24
25
  def application_secret
25
- ENV['APPLICATION_SECRET']
26
+ ENV["APPLICATION_SECRET"]
26
27
  end
27
28
 
28
29
  def access_token
29
- ENV['APPLICATION_SECRET']
30
+ ENV["APPLICATION_SECRET"]
30
31
  end
31
32
 
32
33
  def auth_token
33
- ENV['AUTH_TOKEN']
34
+ ENV["AUTH_TOKEN"]
35
+ end
36
+
37
+ def use_caching
38
+ USE_CACHING
39
+ end
40
+
41
+ def expires_in
42
+ EXPIRES_IN
34
43
  end
35
44
  end
36
45
  end
37
- end
46
+ end
@@ -0,0 +1,13 @@
1
+ require "arena/entity"
2
+
3
+ module Arena
4
+ class Entity
5
+ class Avatar < Arena::Entity
6
+ attr_reader :thumb, :display
7
+
8
+ def custom(size=40)
9
+ thumb.gsub("s=40", "s=#{size}")
10
+ end
11
+ end # Avatar
12
+ end # Entity
13
+ end # Arena
@@ -1,11 +1,10 @@
1
- require 'arena/entity'
2
- require 'arena/entities/version'
1
+ require "arena/entity"
3
2
 
4
3
  module Arena
5
4
  class Entity
6
5
  class Embed < Arena::Entity
7
6
  attr_reader :embed, :url, :type, :title, :author_name, :author_url,
8
7
  :source_url, :thumbnail_url, :width, :height, :html
9
- end
10
- end
11
- end
8
+ end # Embed
9
+ end # Entity
10
+ end # Arena
@@ -9,7 +9,7 @@ module Arena
9
9
 
10
10
  attr_reader :filename, :content_type
11
11
 
12
- %w(thumb display original).each do |method|
12
+ %w(thumb square display large original).each do |method|
13
13
  define_method method do
14
14
  instance_variable_set("@#{method}", Arena::Entity::Version.new(@attrs[method])) unless instance_variable_get "@#{method}"
15
15
  instance_variable_get "@#{method}"
@@ -0,0 +1,10 @@
1
+ require "arena/error"
2
+
3
+ module Arena
4
+ class Error
5
+ # Raised when Cache engine is unavailable
6
+ #
7
+ class CacheError < Arena::Error
8
+ end
9
+ end
10
+ end
data/lib/arena/feed.rb ADDED
@@ -0,0 +1,36 @@
1
+ require "arena/base"
2
+ require "arena/story"
3
+ require "arena/group"
4
+
5
+ module Arena
6
+ class Feed < Arena::Base
7
+ attr_reader :type, :limit, :total, :offset, :range_start, :range_end
8
+
9
+ def stories
10
+ @stories ||= @attrs["items"].collect { |item| Arena::Story.new(item) } if stories?
11
+ end
12
+
13
+ alias items stories
14
+
15
+ def groups
16
+ if stories?
17
+ groups = items.group_by do |item|
18
+ target = "#{item.target.id}_" if !item.target.nil?
19
+
20
+ "#{item.user.id}_#{target}#{item.action.gsub(' ', '_')}"
21
+ end
22
+
23
+ @groups ||=
24
+ groups.collect { |key, stories| Arena::Group.new(key, stories) }.
25
+ sort_by { |group| group.summary.indicative.created_at }.reverse!
26
+ end
27
+ end
28
+
29
+ private
30
+
31
+ def stories?
32
+ !@attrs["items"].nil?
33
+ end
34
+
35
+ end # Feed
36
+ end # Arena
@@ -0,0 +1,21 @@
1
+ require "arena/story"
2
+ require "arena/summary"
3
+
4
+ module Arena
5
+ class Group
6
+ attr_reader :id, :stories
7
+
8
+ def initialize(id, stories)
9
+ @id = id
10
+ @stories = stories
11
+ end
12
+
13
+ def created_at
14
+ @created_at ||= stories.first.created_at
15
+ end
16
+
17
+ def summary
18
+ @summary ||= Arena::Summary.new(stories)
19
+ end
20
+ end # Group
21
+ end # Arena
@@ -1,14 +1,17 @@
1
- require 'arena/core_ext/string'
2
- require 'arena/base'
3
- require 'arena/channel'
4
- require 'arena/user'
5
- require 'arena/block'
1
+ require "arena/core_ext/string"
2
+ require "arena/base"
3
+ require "arena/channel"
4
+ require "arena/user"
5
+ require "arena/block"
6
6
 
7
7
  module Arena
8
8
  class SearchResults < Arena::Base
9
- def term
10
- @attrs['term'] unless @attrs['term'].nil?
11
- end
9
+ attr_reader :term,
10
+ :per,
11
+ :current_page,
12
+ :total_pages,
13
+ :length,
14
+ :authenticated
12
15
 
13
16
  %w(user channel block).each do |method|
14
17
  define_method "#{method}s" do
@@ -18,5 +21,5 @@ module Arena
18
21
  instance_variable_get "@#{method}s"
19
22
  end
20
23
  end
21
- end
22
- end
24
+ end # SearchResults
25
+ end # Arena
@@ -0,0 +1,31 @@
1
+ require "arena/base"
2
+ require "arena/creatable"
3
+ require "arena/user"
4
+ require "arena/block"
5
+ require "arena/channel"
6
+ require "arena/connection"
7
+
8
+ module Arena
9
+ class Story < Arena::Base
10
+ include Arena::Creatable
11
+
12
+ attr_reader :id, :action, :bulletin_id, :connector, :created_at
13
+
14
+ def user
15
+ @user ||= Arena::User.new(@attrs["user"])
16
+ end
17
+
18
+ %w(item target parent).each do |method|
19
+ define_method method do
20
+ if !@attrs[method].nil?
21
+ type = "#{method}_type"
22
+
23
+ instance_variable_set("@#{method}",
24
+ "Arena::#{@attrs[type]}".constantize.new(@attrs[method])
25
+ ) unless instance_variable_get "@#{method}"
26
+ instance_variable_get "@#{method}"
27
+ end
28
+ end
29
+ end
30
+ end # Story
31
+ end # Arena
@@ -0,0 +1,11 @@
1
+ module Arena
2
+ class Summary
3
+ attr_reader :indicative, :kinds, :size
4
+
5
+ def initialize(stories)
6
+ @indicative = stories.first
7
+ @kinds = stories.collect { |story| story.item._class }.uniq
8
+ @size = stories.size
9
+ end
10
+ end # Summary
11
+ end # Arena
data/lib/arena/user.rb CHANGED
@@ -1,16 +1,22 @@
1
- require 'arena/base'
2
- require 'arena/creatable'
1
+ require "arena/base"
2
+ require "arena/creatable"
3
+ require "arena/entity"
4
+ require "arena/entities/avatar"
3
5
 
4
6
  module Arena
5
7
  class User < Arena::Base
6
8
  include Arena::Creatable
7
9
 
8
10
  attr_reader :id, :slug, :username, :first_name, :last_name,
9
- :full_name, :avatar, :email, :channel_count, :following_count,
10
- :profile_id, :follower_count, :initials
11
+ :full_name, :avatar, :email, :channel_count, :following_count,
12
+ :profile_id, :follower_count, :initials
11
13
 
12
14
  def _class
13
- @attrs['class']
15
+ @attrs["class"]
14
16
  end
15
- end
16
- end
17
+
18
+ def avatar_image
19
+ Arena::Entity::Avatar.new(@attrs["avatar_image"]) if !@attrs["avatar_image"].nil?
20
+ end
21
+ end # User
22
+ end # Arena
data/lib/arena/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Arena
2
- VERSION = "0.0.9"
2
+ VERSION = "0.1.0"
3
3
 
4
4
  def self.version
5
5
  VERSION
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.0.9
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-06 00:00:00.000000000 Z
12
+ date: 2013-05-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -73,17 +73,26 @@ files:
73
73
  - Rakefile
74
74
  - arena.gemspec
75
75
  - lib/arena.rb
76
+ - lib/arena/account.rb
76
77
  - lib/arena/api.rb
77
78
  - lib/arena/base.rb
78
79
  - lib/arena/block.rb
80
+ - lib/arena/cache.rb
81
+ - lib/arena/cache/adaptor/generic.rb
82
+ - lib/arena/cache/adaptor/null.rb
83
+ - lib/arena/cache/adaptor/padrino.rb
84
+ - lib/arena/cache/adaptor/rails.rb
79
85
  - lib/arena/channel.rb
80
86
  - lib/arena/client.rb
87
+ - lib/arena/comment.rb
81
88
  - lib/arena/configurable.rb
82
89
  - lib/arena/connectable.rb
90
+ - lib/arena/connection.rb
83
91
  - lib/arena/core_ext/string.rb
84
92
  - lib/arena/creatable.rb
85
93
  - lib/arena/default.rb
86
94
  - lib/arena/entities/attachment.rb
95
+ - lib/arena/entities/avatar.rb
87
96
  - lib/arena/entities/embed.rb
88
97
  - lib/arena/entities/image.rb
89
98
  - lib/arena/entities/provider.rb
@@ -91,8 +100,13 @@ files:
91
100
  - lib/arena/entities/version.rb
92
101
  - lib/arena/entity.rb
93
102
  - lib/arena/error.rb
103
+ - lib/arena/error/cache_error.rb
104
+ - lib/arena/feed.rb
105
+ - lib/arena/group.rb
94
106
  - lib/arena/results.rb
95
107
  - lib/arena/search_results.rb
108
+ - lib/arena/story.rb
109
+ - lib/arena/summary.rb
96
110
  - lib/arena/user.rb
97
111
  - lib/arena/version.rb
98
112
  - test/lib/arena/version_test.rb
@@ -117,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
131
  version: '0'
118
132
  requirements: []
119
133
  rubyforge_project:
120
- rubygems_version: 1.8.24
134
+ rubygems_version: 1.8.25
121
135
  signing_key:
122
136
  specification_version: 3
123
137
  summary: Wrapper for Arena's API