arena 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/arena.rb +13 -1
- data/lib/arena/client.rb +23 -21
- data/lib/arena/configurable.rb +37 -4
- data/lib/arena/default.rb +21 -0
- data/lib/arena/version.rb +1 -1
- metadata +3 -2
data/lib/arena.rb
CHANGED
@@ -1,11 +1,23 @@
|
|
1
1
|
require "arena/version"
|
2
2
|
require_relative "./arena/client"
|
3
|
+
require_relative "./arena/default"
|
3
4
|
require_relative "./arena/configurable"
|
4
5
|
|
5
6
|
module Arena
|
6
7
|
class << self
|
8
|
+
include Arena::Configurable
|
9
|
+
|
10
|
+
# Delegate to a Arena::Client
|
11
|
+
#
|
12
|
+
# @return [Arena::Client]
|
7
13
|
def client
|
8
|
-
|
14
|
+
if @client
|
15
|
+
@client
|
16
|
+
else
|
17
|
+
@client = Arena::Client.new(options)
|
18
|
+
end
|
9
19
|
end
|
10
20
|
end
|
11
21
|
end
|
22
|
+
|
23
|
+
Arena.setup
|
data/lib/arena/client.rb
CHANGED
@@ -7,35 +7,37 @@ module Arena
|
|
7
7
|
class Client
|
8
8
|
include HTTParty
|
9
9
|
include Arena::Configurable
|
10
|
-
|
11
|
-
class << self
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
def users_channels(id, options={})
|
18
|
-
get_json "/channels?user=#{id}", options
|
11
|
+
def initialize(options={})
|
12
|
+
Arena::Configurable.keys.each do |key|
|
13
|
+
instance_variable_set(:"@#{key}", options[key] || Arena.instance_variable_get(:"@#{key}"))
|
19
14
|
end
|
15
|
+
end
|
20
16
|
|
21
|
-
|
22
|
-
|
23
|
-
|
17
|
+
# Wrapper for v1
|
18
|
+
def channel(identifier, options={})
|
19
|
+
get_json "/channels/#{identifier}", options
|
20
|
+
end
|
24
21
|
|
25
|
-
|
26
|
-
|
27
|
-
|
22
|
+
def users_channels(id, options={})
|
23
|
+
get_json "/channels?user=#{id}", options
|
24
|
+
end
|
28
25
|
|
29
|
-
|
26
|
+
def block(id, options={})
|
27
|
+
get_json "/blocks/#{id}", options
|
28
|
+
end
|
30
29
|
|
31
|
-
|
32
|
-
|
33
|
-
JSON.parse(
|
34
|
-
(get "#{Arena::Configurable::BASE_URL}#{path}", options).body
|
35
|
-
)
|
36
|
-
end
|
30
|
+
def blocks(identifier, options={})
|
31
|
+
get_json "/blocks?channel=#{identifier}", options
|
37
32
|
end
|
38
33
|
|
34
|
+
private
|
35
|
+
|
36
|
+
def get_json(path, options)
|
37
|
+
JSON.parse(
|
38
|
+
(self.class.get "http://#{@base_domain}/api/#{@api_version}#{path}", options).body
|
39
|
+
)
|
40
|
+
end
|
39
41
|
end
|
40
42
|
|
41
43
|
end
|
data/lib/arena/configurable.rb
CHANGED
@@ -1,8 +1,41 @@
|
|
1
1
|
module Arena
|
2
|
-
|
3
2
|
module Configurable
|
4
|
-
API_VERSION = "v1"
|
5
|
-
BASE_URL = "http://are.na/api/#{API_VERSION}"
|
6
|
-
end
|
7
3
|
|
4
|
+
CONFIG_KEYS = [
|
5
|
+
:base_domain,
|
6
|
+
:api_version,
|
7
|
+
] unless defined? CONFIG_KEYS
|
8
|
+
|
9
|
+
attr_accessor *CONFIG_KEYS
|
10
|
+
|
11
|
+
class << self
|
12
|
+
def keys
|
13
|
+
@keys ||= CONFIG_KEYS
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Allows configuration options
|
18
|
+
# to be set in a block
|
19
|
+
def configure
|
20
|
+
yield self
|
21
|
+
self
|
22
|
+
end
|
23
|
+
|
24
|
+
def reset!
|
25
|
+
Arena::Configurable.keys.each do |key|
|
26
|
+
instance_variable_set(:"@#{key}", Arena::Default.options[key])
|
27
|
+
end
|
28
|
+
self
|
29
|
+
end
|
30
|
+
|
31
|
+
alias setup reset!
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
# @return [Hash]
|
36
|
+
def options
|
37
|
+
Hash[Arena::Configurable.keys.map{|key| [key, instance_variable_get(:"@#{key}")]}]
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
8
41
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Arena
|
2
|
+
module Default
|
3
|
+
BASE_DOMAIN = "are.na" unless defined? BASE_DOMAIN
|
4
|
+
API_VERSION = "v1" unless defined? API_VERSION
|
5
|
+
|
6
|
+
class << self
|
7
|
+
# @return [Hash]
|
8
|
+
def options
|
9
|
+
Hash[Arena::Configurable.keys.map{|key| [key, send(key)]}]
|
10
|
+
end
|
11
|
+
|
12
|
+
def api_version
|
13
|
+
API_VERSION
|
14
|
+
end
|
15
|
+
|
16
|
+
def base_domain
|
17
|
+
BASE_DOMAIN
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
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.2
|
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-07
|
12
|
+
date: 2012-08-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -75,6 +75,7 @@ files:
|
|
75
75
|
- lib/arena.rb
|
76
76
|
- lib/arena/client.rb
|
77
77
|
- lib/arena/configurable.rb
|
78
|
+
- lib/arena/default.rb
|
78
79
|
- lib/arena/version.rb
|
79
80
|
- test/lib/arena/version_test.rb
|
80
81
|
- test/test_helper.rb
|