ahub 0.1.8 → 0.1.12
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 +4 -4
- data/lib/ahub/answer.rb +15 -7
- data/lib/ahub/group.rb +18 -4
- data/lib/ahub/modules/api_helpers.rb +8 -0
- data/lib/ahub/modules/class_helpers.rb +15 -0
- data/lib/ahub/question.rb +3 -3
- data/lib/ahub/space.rb +2 -0
- data/lib/ahub/topic.rb +3 -0
- data/lib/ahub/user.rb +28 -17
- data/lib/ahub/version.rb +1 -1
- data/lib/ahub.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 371152a9dddd73396e1608c4f51fd1271bff7f6d
|
4
|
+
data.tar.gz: 2000a920adcc97a0db540dd4402d97fc730ad359
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b203c7a7f54e6a9614f14c543fe7fb21e28e638f0e22a7eab81ae3de4e15bd3fd3e21e39678b8b2db6a86758768bce96bd4bd4cd8a5ac227cddab1264ff2ebc2
|
7
|
+
data.tar.gz: 9eb00d0e34711c4bcfcd2cd86e6df9a7a318bf45bac02e912d69859b5040ca526d1994b9c4e664d96e895e48caef7cb70b869a65773bb1780ab624f816ae43c1
|
data/lib/ahub/answer.rb
CHANGED
@@ -1,8 +1,21 @@
|
|
1
1
|
module Ahub
|
2
2
|
class Answer
|
3
3
|
extend Ahub::APIHelpers
|
4
|
+
include Ahub::ClassHelpers
|
5
|
+
|
6
|
+
attr_accessor :body, :author
|
4
7
|
|
5
8
|
def initialize(attrs)
|
9
|
+
@id = attrs[:id]
|
10
|
+
@error = attrs[:error]
|
11
|
+
|
12
|
+
@body = attrs[:body]
|
13
|
+
@body = attrs[:bodyAsHTML]
|
14
|
+
# @author = Ahub::User.new(attrs[:author]) # this is an incomplete user object.
|
15
|
+
end
|
16
|
+
|
17
|
+
def user
|
18
|
+
@author
|
6
19
|
end
|
7
20
|
|
8
21
|
def self.create(question_id:, body:, username:, password:)
|
@@ -12,14 +25,9 @@ module Ahub
|
|
12
25
|
|
13
26
|
auth_headers = headers(username: username, password: password)
|
14
27
|
|
15
|
-
|
16
|
-
JSON.parse(
|
17
|
-
RestClient.post(url, data.to_json, auth_headers),
|
18
|
-
symbolize_names: true
|
19
|
-
)
|
20
|
-
)
|
28
|
+
new JSON.parse(RestClient.post(url, data.to_json, auth_headers), symbolize_names: true)
|
21
29
|
rescue => e
|
22
|
-
{error: e.message}
|
30
|
+
new({error: e.message})
|
23
31
|
end
|
24
32
|
|
25
33
|
end
|
data/lib/ahub/group.rb
CHANGED
@@ -1,17 +1,31 @@
|
|
1
1
|
module Ahub
|
2
2
|
class Group
|
3
3
|
extend Ahub::APIHelpers
|
4
|
+
include Ahub::ClassHelpers
|
4
5
|
|
6
|
+
attr_reader :name
|
5
7
|
def initialize(attrs)
|
8
|
+
@id = attrs[:id]
|
9
|
+
@name = attrs[:name]
|
6
10
|
end
|
7
11
|
|
8
|
-
def
|
12
|
+
def add(user_id)
|
13
|
+
add_user(user_id)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.find_by_name(group_name)
|
17
|
+
matches = find_all
|
18
|
+
matches.find{|group| group.name.downcase.strip == group_name.downcase.strip}
|
19
|
+
end
|
20
|
+
|
21
|
+
def add_user(user_id)
|
9
22
|
raise Exception("No Group Id") unless id
|
10
23
|
|
11
|
-
move_url = "#{self.class.base_url}/#{id}/
|
12
|
-
RestClient.put("#{
|
24
|
+
move_url = "#{self.class.base_url}/#{id}/add.json?users=#{user_id}"
|
25
|
+
RestClient.put("#{move_url}", self.class.admin_headers)
|
26
|
+
true
|
13
27
|
rescue => e
|
14
|
-
|
28
|
+
false
|
15
29
|
end
|
16
30
|
end
|
17
31
|
end
|
@@ -27,6 +27,10 @@ module Ahub
|
|
27
27
|
def find_all(params: nil, page: 1, pageSize: 30)
|
28
28
|
url = "#{base_url}.json?page=#{page}&pageSize=#{pageSize}"
|
29
29
|
|
30
|
+
if params
|
31
|
+
params.each{|k,v| url << "&#{k}=#{URI.encode(v)}"}
|
32
|
+
end
|
33
|
+
|
30
34
|
JSON.parse(RestClient.get(url, admin_headers), symbolize_names:true)[:list].map do |node|
|
31
35
|
new(node)
|
32
36
|
end
|
@@ -36,5 +40,9 @@ module Ahub
|
|
36
40
|
class_name = name.gsub(/Ahub::/, '').downcase
|
37
41
|
"#{Ahub::DOMAIN}/services/v2/#{class_name}"
|
38
42
|
end
|
43
|
+
|
44
|
+
def object_id_from_response(response)
|
45
|
+
response.headers[:location].match(/(?<id>\d*)\.json/)[:id].to_i
|
46
|
+
end
|
39
47
|
end
|
40
48
|
end
|
data/lib/ahub/question.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
module Ahub
|
2
2
|
class Question
|
3
3
|
extend Ahub::APIHelpers
|
4
|
+
include Ahub::ClassHelpers
|
4
5
|
|
5
6
|
attr_accessor :title, :body, :body_as_html, :author, :answerCount
|
6
|
-
attr_reader :
|
7
|
+
attr_reader :space_id
|
7
8
|
|
8
9
|
def self.create(title:, body:, topics:, space_id: nil, username:, password:)
|
9
10
|
url = "#{base_url}.json"
|
@@ -14,8 +15,7 @@ module Ahub
|
|
14
15
|
|
15
16
|
response = RestClient.post(url, payload.to_json, user_headers)
|
16
17
|
|
17
|
-
|
18
|
-
find(question_id)
|
18
|
+
find(object_id_from_response(response))
|
19
19
|
rescue => e
|
20
20
|
new({error: e.message})
|
21
21
|
end
|
data/lib/ahub/space.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
module Ahub
|
2
2
|
class Space
|
3
3
|
extend Ahub::APIHelpers
|
4
|
+
include Ahub::ClassHelpers
|
4
5
|
|
5
6
|
attr_accessor :id, :error, :name, :active, :parent_id
|
6
7
|
def initialize(attrs)
|
7
8
|
@id = attrs[:id]
|
8
9
|
@error = attrs[:error]
|
10
|
+
|
9
11
|
@name = attrs[:name]
|
10
12
|
@active = attrs[:active]
|
11
13
|
@parent_id = attrs[:parentId]
|
data/lib/ahub/topic.rb
CHANGED
data/lib/ahub/user.rb
CHANGED
@@ -1,31 +1,42 @@
|
|
1
1
|
module Ahub
|
2
2
|
class User
|
3
3
|
extend Ahub::APIHelpers
|
4
|
-
|
5
|
-
def initialize(attrs)
|
6
|
-
end
|
7
|
-
|
8
|
-
def self.find(id=nil)
|
9
|
-
url = "#{Ahub::DOMAIN}/services/v2/user"
|
10
|
-
url += "/#{id}" if id
|
11
|
-
url += '.json'
|
12
|
-
OpenStruct.new(JSON.parse(RestClient.get(url, admin_headers), symbolize_names:true))
|
13
|
-
rescue => e
|
14
|
-
{error: e.message}
|
15
|
-
end
|
4
|
+
include Ahub::ClassHelpers
|
16
5
|
|
17
6
|
def self.create(username:, email:, password:nil)
|
18
|
-
url = "#{
|
19
|
-
|
7
|
+
url = "#{base_url}.json"
|
8
|
+
|
9
|
+
payload = {
|
20
10
|
email: email,
|
21
11
|
username: username,
|
22
12
|
password: password || Ahub::DEFAULT_PASSWORD,
|
23
13
|
}
|
24
14
|
|
25
|
-
response = RestClient.post(url,
|
26
|
-
|
15
|
+
response = RestClient.post(url, payload.to_json, admin_headers)
|
16
|
+
find(object_id_from_response(response))
|
27
17
|
rescue => e
|
28
|
-
{error: e.message}
|
18
|
+
new({error: e.message})
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.find_by_username(username)
|
22
|
+
matches = find_all(params: {q: username})
|
23
|
+
matches.find{|user| user.username.downcase.strip == username.downcase.strip}
|
24
|
+
end
|
25
|
+
|
26
|
+
attr_reader :username, :realname, :avatar_url, :post_count, :follow_count, :follower_count, :active, :suspended, :deactivated
|
27
|
+
def initialize(attrs)
|
28
|
+
@id = attrs[:id]
|
29
|
+
@error = attrs[:error]
|
30
|
+
|
31
|
+
@username = attrs[:username]
|
32
|
+
@realname = attrs[:realname]
|
33
|
+
@avatar_url = attrs[:avatar]
|
34
|
+
@post_count = attrs[:postCount]
|
35
|
+
@follow_count = attrs[:followCount]
|
36
|
+
@follower_count = attrs[:followerCount]
|
37
|
+
@active = attrs[:active]
|
38
|
+
@suspended = attrs[:suspended]
|
39
|
+
@deactivated =attrs[:deactivated]
|
29
40
|
end
|
30
41
|
end
|
31
42
|
end
|
data/lib/ahub/version.rb
CHANGED
data/lib/ahub.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ahub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Abel Martin
|
@@ -120,6 +120,7 @@ files:
|
|
120
120
|
- lib/ahub/answer.rb
|
121
121
|
- lib/ahub/group.rb
|
122
122
|
- lib/ahub/modules/api_helpers.rb
|
123
|
+
- lib/ahub/modules/class_helpers.rb
|
123
124
|
- lib/ahub/question.rb
|
124
125
|
- lib/ahub/space.rb
|
125
126
|
- lib/ahub/topic.rb
|