ahub 0.1.4 → 0.1.7
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/bin/console +2 -10
- data/lib/ahub/answer.rb +3 -0
- data/lib/ahub/group.rb +17 -0
- data/lib/ahub/modules/api_helpers.rb +19 -0
- data/lib/ahub/question.rb +34 -31
- data/lib/ahub/space.rb +8 -0
- data/lib/ahub/topic.rb +3 -0
- data/lib/ahub/user.rb +3 -0
- data/lib/ahub/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d9b2368e43055cca71695c86cabf7fc86a0a14a0
|
4
|
+
data.tar.gz: 7e5b02f039662717b6245af61d777d82b12a4974
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0407028044aef597c3b71fb0b17c8c8d436827dc06006009b481700f7ee804c62ef699ab988f6c0dd3b4c6e7cf156cc0d1c6c89f8015c7dd31bae6dbb7b96ed5
|
7
|
+
data.tar.gz: 417f5c614e1e171af792b0f107630474ca15087018a2295646172de99345ad4cf4e81f41718d410af9c50b64aebeb9cfb2c825de4d11bc79f55a6fdd6034a083
|
data/bin/console
CHANGED
@@ -2,13 +2,5 @@
|
|
2
2
|
|
3
3
|
require "bundler/setup"
|
4
4
|
require "ahub"
|
5
|
-
|
6
|
-
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require "irb"
|
14
|
-
IRB.start
|
5
|
+
require "pry"
|
6
|
+
Pry.start
|
data/lib/ahub/answer.rb
CHANGED
data/lib/ahub/group.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
module Ahub
|
2
|
+
class Group
|
3
|
+
extend Ahub::APIHelpers
|
4
|
+
|
5
|
+
def initialize(attrs)
|
6
|
+
end
|
7
|
+
|
8
|
+
def assign_user(user_id)
|
9
|
+
raise Exception("No Group Id") unless id
|
10
|
+
|
11
|
+
move_url = "#{self.class.base_url}/#{id}/move.json?space=#{space_id}"
|
12
|
+
RestClient.put("#{url}", self.class.admin_headers)
|
13
|
+
rescue => e
|
14
|
+
@error = e.message
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
module Ahub
|
2
2
|
module APIHelpers
|
3
3
|
require 'base64'
|
4
|
+
|
4
5
|
def headers(username:'answerhub', password:'answerhub')
|
5
6
|
encoded = "Basic #{::Base64.strict_encode64("#{username}:#{password}")}"
|
6
7
|
|
@@ -14,5 +15,23 @@ module Ahub
|
|
14
15
|
def admin_headers
|
15
16
|
headers(username: Ahub::ADMIN_USER, password: Ahub::ADMIN_PASS)
|
16
17
|
end
|
18
|
+
|
19
|
+
def find(id)
|
20
|
+
url = "#{base_url}/#{id}.json"
|
21
|
+
|
22
|
+
new JSON.parse(RestClient.get(url, admin_headers), symbolize_names:true)
|
23
|
+
rescue => e
|
24
|
+
new({error: e.message})
|
25
|
+
end
|
26
|
+
|
27
|
+
# def find_all(params: nil, page: 1)
|
28
|
+
# url = "#{base_url}.json?page=#{page}"
|
29
|
+
# JSON.parse(RestClient.get(url, admin_headers), symbolize_names:true)
|
30
|
+
# end
|
31
|
+
|
32
|
+
def base_url
|
33
|
+
class_name = name.gsub(/Ahub::/, '').downcase
|
34
|
+
"#{Ahub::DOMAIN}/services/v2/#{class_name}"
|
35
|
+
end
|
17
36
|
end
|
18
37
|
end
|
data/lib/ahub/question.rb
CHANGED
@@ -2,49 +2,52 @@ module Ahub
|
|
2
2
|
class Question
|
3
3
|
extend Ahub::APIHelpers
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
url +="/#{id}" if id
|
8
|
-
url +='.json'
|
5
|
+
attr_accessor :title, :body, :body_as_html, :author, :answerCount
|
6
|
+
attr_reader :id, :error, :space_id
|
9
7
|
|
10
|
-
|
11
|
-
rescue => e
|
12
|
-
{error: e.message}
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.create(title:, body:, topics:, username:, password:)
|
8
|
+
def self.create(title:, body:, topics:, space_id: nil, username:, password:)
|
16
9
|
url = "#{base_url}.json"
|
17
10
|
payload = {title: title, body: body, topics: topics}
|
11
|
+
payload[:spaceId] = space_id if space_id
|
12
|
+
|
18
13
|
user_headers = headers(username:username, password:password)
|
19
14
|
|
20
15
|
response = RestClient.post(url, payload.to_json, user_headers)
|
21
|
-
|
16
|
+
|
17
|
+
question_id = response.headers[:location].match(/(?<id>\d*)\.json/)[:id]
|
18
|
+
find(question_id)
|
22
19
|
rescue => e
|
23
|
-
{error: e.message}
|
20
|
+
new({error: e.message})
|
24
21
|
end
|
25
22
|
|
26
|
-
def
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
'',
|
38
|
-
user_id
|
39
|
-
]
|
40
|
-
end
|
41
|
-
end
|
23
|
+
def initialize(attrs)
|
24
|
+
@id = attrs[:id]
|
25
|
+
@error = attrs[:error]
|
26
|
+
|
27
|
+
@answer_ids = attrs[:answers]
|
28
|
+
@answerCount = attrs[:answerCount]
|
29
|
+
@body = attrs[:body]
|
30
|
+
@body_as_html = attrs[:bodyAsHTML]
|
31
|
+
@space_id = attrs[:primaryContainerId]
|
32
|
+
@title = attrs[:title]
|
33
|
+
@topics = attrs[:topics]
|
42
34
|
end
|
43
35
|
|
44
|
-
|
36
|
+
def move(space_id:)
|
37
|
+
raise Exception("No Question Id") unless id
|
38
|
+
|
39
|
+
move_url = "#{self.class.base_url}/#{id}/move.json?space=#{space_id}"
|
40
|
+
RestClient.put("#{url}", self.class.admin_headers)
|
41
|
+
rescue => e
|
42
|
+
@error = e.message
|
43
|
+
end
|
44
|
+
|
45
|
+
def url
|
46
|
+
"#{self.class.base_url}/#{id}.json" if id
|
47
|
+
end
|
45
48
|
|
46
|
-
def
|
47
|
-
|
49
|
+
def to_s
|
50
|
+
url
|
48
51
|
end
|
49
52
|
end
|
50
53
|
end
|
data/lib/ahub/space.rb
ADDED
data/lib/ahub/topic.rb
CHANGED
data/lib/ahub/user.rb
CHANGED
data/lib/ahub/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Abel Martin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -118,8 +118,10 @@ files:
|
|
118
118
|
- bin/setup
|
119
119
|
- lib/ahub.rb
|
120
120
|
- lib/ahub/answer.rb
|
121
|
+
- lib/ahub/group.rb
|
121
122
|
- lib/ahub/modules/api_helpers.rb
|
122
123
|
- lib/ahub/question.rb
|
124
|
+
- lib/ahub/space.rb
|
123
125
|
- lib/ahub/topic.rb
|
124
126
|
- lib/ahub/user.rb
|
125
127
|
- lib/ahub/version.rb
|