arena 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +8 -1
- data/lib/arena/api.rb +6 -1
- data/lib/arena/base.rb +3 -1
- data/lib/arena/block.rb +3 -2
- data/lib/arena/channel.rb +2 -0
- data/lib/arena/client.rb +24 -9
- data/lib/arena/configurable.rb +9 -3
- data/lib/arena/connectable.rb +30 -0
- data/lib/arena/default.rb +4 -0
- data/lib/arena/version.rb +1 -1
- metadata +3 -2
data/README.md
CHANGED
data/lib/arena/api.rb
CHANGED
@@ -51,11 +51,16 @@ module Arena
|
|
51
51
|
object_from_response(Arena::User, :get, "/users/#{id}", options)
|
52
52
|
end
|
53
53
|
|
54
|
-
# Returns a paginated list of all Channels a User has access to
|
54
|
+
# Returns a paginated list of all public Channels a User has access to
|
55
55
|
def user_channels(id, options={})
|
56
56
|
object_from_response(Arena::ChannelResults, :get, "/users/#{id}/channels", options)
|
57
57
|
end
|
58
58
|
|
59
|
+
# All of the authenticated user's Channels
|
60
|
+
def account_channels(options={})
|
61
|
+
object_from_response(Arena::ChannelResults, :get, "/accounts/channels", options)
|
62
|
+
end
|
63
|
+
|
59
64
|
# Returns a Search object with an Array for Channels, Blocks and Users
|
60
65
|
def search(query, option={})
|
61
66
|
object_from_response(Arena::SearchResults, :get, "/search?q=#{query}", options)
|
data/lib/arena/base.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
module Arena
|
2
2
|
class Base
|
3
3
|
attr_reader :attrs
|
4
|
+
|
4
5
|
alias to_hash attrs
|
5
6
|
|
6
|
-
# Define methods that retrieve the value from an initialized instance
|
7
|
+
# Define methods that retrieve the value from an initialized instance
|
8
|
+
# variable Hash, using the attribute as a key
|
7
9
|
#
|
8
10
|
# @param attrs [Array, Set, Symbol]
|
9
11
|
def self.attr_reader(*attrs)
|
data/lib/arena/block.rb
CHANGED
@@ -5,14 +5,15 @@ require 'arena/entities/image'
|
|
5
5
|
require 'arena/entities/attachment'
|
6
6
|
require 'arena/entities/embed'
|
7
7
|
require 'arena/creatable'
|
8
|
+
require 'arena/connectable'
|
8
9
|
|
9
10
|
module Arena
|
10
11
|
class Block < Arena::Base
|
11
12
|
include Arena::Creatable
|
13
|
+
include Arena::Connectable
|
12
14
|
|
13
15
|
attr_reader :id, :title, :generated_title, :state, :comment_count, :content,
|
14
|
-
:content_html, :description, :description_html, :position, :selected
|
15
|
-
:connection_id, :connected_at, :connected_by_user_id, :connected_by_username
|
16
|
+
:content_html, :description, :description_html, :position, :selected
|
16
17
|
|
17
18
|
def user
|
18
19
|
@user ||= Arena::User.new(@attrs['user'])
|
data/lib/arena/channel.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
require 'arena/base'
|
2
2
|
require 'arena/creatable'
|
3
|
+
require 'arena/connectable'
|
3
4
|
require 'arena/user'
|
4
5
|
require 'arena/block'
|
5
6
|
|
6
7
|
module Arena
|
7
8
|
class Channel < Arena::Base
|
8
9
|
include Arena::Creatable
|
10
|
+
include Arena::Connectable
|
9
11
|
|
10
12
|
attr_reader :id, :title, :published, :open, :collaboration,
|
11
13
|
:slug, :length, :kind, :status, :user_id, :total_pages,
|
data/lib/arena/client.rb
CHANGED
@@ -20,8 +20,7 @@ module Arena
|
|
20
20
|
# Performs HTTP GET POST PUT and DELETE requests
|
21
21
|
%w(get post put delete).each do |method|
|
22
22
|
define_method method do |path, options={}|
|
23
|
-
options = { query: options,
|
24
|
-
headers: { 'Authorization' => "Bearer #{@access_token}" } }
|
23
|
+
options = { query: options, headers: set_headers }
|
25
24
|
|
26
25
|
request(__method__, path, options)
|
27
26
|
end
|
@@ -29,17 +28,33 @@ module Arena
|
|
29
28
|
|
30
29
|
private
|
31
30
|
|
31
|
+
def set_headers
|
32
|
+
if !@access_token.nil?
|
33
|
+
{ 'Authorization' => "Bearer #{@access_token}" }
|
34
|
+
elsif !@auth_token.nil?
|
35
|
+
{ 'X-AUTH-TOKEN' => @auth_token }
|
36
|
+
else
|
37
|
+
{ }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def error?(response)
|
42
|
+
!response['status']['code'].nil?
|
43
|
+
end
|
44
|
+
|
45
|
+
def error_message(response)
|
46
|
+
"#{response['status']['code']}: #{response['status']['message']} - #{response['status']['description']}"
|
47
|
+
end
|
48
|
+
|
32
49
|
def request(method, path, options)
|
33
|
-
JSON.parse self.class.send(method, "http://#{@base_domain}/#{@api_version}#{path}", options).body
|
50
|
+
response = JSON.parse self.class.send(method, "http://#{@base_domain}/#{@api_version}#{path}", options).body
|
51
|
+
|
52
|
+
raise Arena::Error.new(error_message(response)) if error?(response)
|
53
|
+
|
54
|
+
return response
|
34
55
|
|
35
56
|
rescue JSON::ParserError, TypeError
|
36
57
|
nil
|
37
|
-
|
38
|
-
rescue Exception => exception
|
39
|
-
puts exception.inspect
|
40
|
-
puts exception.backtrace
|
41
|
-
|
42
|
-
raise Arena::Error
|
43
58
|
end
|
44
59
|
|
45
60
|
end
|
data/lib/arena/configurable.rb
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
module Arena
|
2
2
|
module Configurable
|
3
|
-
|
4
|
-
|
3
|
+
attr_accessor :base_domain,
|
4
|
+
:api_version
|
5
|
+
|
6
|
+
attr_writer :application_id,
|
7
|
+
:application_secret,
|
8
|
+
:access_token,
|
9
|
+
:auth_token
|
5
10
|
|
6
11
|
class << self
|
7
12
|
def keys
|
@@ -10,7 +15,8 @@ module Arena
|
|
10
15
|
:api_version,
|
11
16
|
:application_id,
|
12
17
|
:application_secret,
|
13
|
-
:access_token
|
18
|
+
:access_token,
|
19
|
+
:auth_token
|
14
20
|
]
|
15
21
|
end
|
16
22
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'time'
|
2
|
+
|
3
|
+
module Arena
|
4
|
+
module Connectable
|
5
|
+
attr_reader :connection_id
|
6
|
+
|
7
|
+
def connected_at
|
8
|
+
@connected_at ||= Time.parse(@attrs['connected_at']) if connected?
|
9
|
+
end
|
10
|
+
|
11
|
+
def connected_by_different_user?
|
12
|
+
user.id != connected_by.id
|
13
|
+
end
|
14
|
+
|
15
|
+
def connected_by
|
16
|
+
@connected_by ||= Arena::User.new({
|
17
|
+
'id' => @attrs['connected_by_user_id'],
|
18
|
+
'username' => @attrs['connected_by_username'],
|
19
|
+
'full_name' => @attrs['connected_by_username']
|
20
|
+
})
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def connected?
|
26
|
+
!@attrs['connected_at'].nil?
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
data/lib/arena/default.rb
CHANGED
data/lib/arena/version.rb
CHANGED
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.
|
4
|
+
version: 0.0.7
|
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: 2012-12-
|
12
|
+
date: 2012-12-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -79,6 +79,7 @@ files:
|
|
79
79
|
- lib/arena/channel.rb
|
80
80
|
- lib/arena/client.rb
|
81
81
|
- lib/arena/configurable.rb
|
82
|
+
- lib/arena/connectable.rb
|
82
83
|
- lib/arena/core_ext/string.rb
|
83
84
|
- lib/arena/creatable.rb
|
84
85
|
- lib/arena/default.rb
|