ahub 0.1.17 → 0.2.0
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/README.md +0 -3
- data/lib/ahub/answer.rb +1 -1
- data/lib/ahub/modules/api_helpers.rb +8 -3
- data/lib/ahub/question.rb +1 -1
- data/lib/ahub/user.rb +11 -2
- data/lib/ahub/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1ea4fc5534f83930d5fc06d6555c4d7e71be49e4
|
|
4
|
+
data.tar.gz: f194dee02fedc6a3d1ffaf296b4b7871820713cd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: df35600d963fcc5e9fcc0863539d4e3a922cea0d83bf1e9e3d94ceacaad79b15e19b6dd8a63504697fe387e04ac1ccaed8d6df8fcabe868201d606e7b7896ea2
|
|
7
|
+
data.tar.gz: 123d634b044ad2395cd31fda2ac884065a015f072a35037d970c4f03c06e832aaf87ae19a9dbd21175ec90474105ac542a609fb2677862ff566ca42893b4822f
|
data/README.md
CHANGED
|
@@ -4,9 +4,6 @@ A gem to interact with the [Answer Hub API](docs.answerhubapiv2.apiary.io)
|
|
|
4
4
|
Master
|
|
5
5
|
[](https://travis-ci.org/abelmartin/ahub)
|
|
6
6
|
|
|
7
|
-
Gem v0.1.16
|
|
8
|
-
[](https://github.com/abelmartin/ahub/tree/v0.1.16)
|
|
9
|
-
|
|
10
7
|
## Installation
|
|
11
8
|
|
|
12
9
|
Add this line to your application's Gemfile:
|
data/lib/ahub/answer.rb
CHANGED
|
@@ -6,7 +6,7 @@ module Ahub
|
|
|
6
6
|
def self.create(question_id:, body:, username:, password:)
|
|
7
7
|
url = "#{Ahub::DOMAIN}/services/v2/question/#{question_id}/answer.json"
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
create_resource(url: url, payload: {body: body}, headers: headers(username: username, password: password))
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
attr_reader :body, :body_as_html, :author
|
|
@@ -19,7 +19,7 @@ module Ahub
|
|
|
19
19
|
def find(id)
|
|
20
20
|
url = "#{base_url}/#{id}.json"
|
|
21
21
|
|
|
22
|
-
new
|
|
22
|
+
new get_resource(url: url, headers:admin_headers)
|
|
23
23
|
rescue RestClient::ResourceNotFound => e
|
|
24
24
|
nil
|
|
25
25
|
end
|
|
@@ -31,7 +31,7 @@ module Ahub
|
|
|
31
31
|
params.each{|k,v| url << "&#{k}=#{URI.encode(v)}"}
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
get_resource(url: url, headers: admin_headers)[:list].map do |node|
|
|
35
35
|
new(node)
|
|
36
36
|
end
|
|
37
37
|
end
|
|
@@ -45,11 +45,16 @@ module Ahub
|
|
|
45
45
|
response.headers[:location].match(/(?<id>\d*)\.json/)[:id].to_i
|
|
46
46
|
end
|
|
47
47
|
|
|
48
|
+
def get_resource(url:, headers:)
|
|
49
|
+
JSON.parse(RestClient.get(url, admin_headers), symbolize_names:true)
|
|
50
|
+
end
|
|
51
|
+
|
|
48
52
|
private
|
|
49
53
|
|
|
50
|
-
def
|
|
54
|
+
def create_resource(url:, payload:, headers:)
|
|
51
55
|
response = RestClient.post(url, payload.to_json, headers)
|
|
52
56
|
find(object_id_from_response(response))
|
|
53
57
|
end
|
|
58
|
+
|
|
54
59
|
end
|
|
55
60
|
end
|
data/lib/ahub/question.rb
CHANGED
|
@@ -11,7 +11,7 @@ module Ahub
|
|
|
11
11
|
|
|
12
12
|
user_headers = headers(username:username, password:password)
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
create_resource(url: url, payload: payload, headers: user_headers)
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
attr_accessor :title, :body, :body_as_html, :author
|
data/lib/ahub/user.rb
CHANGED
|
@@ -12,7 +12,7 @@ module Ahub
|
|
|
12
12
|
password: password || Ahub::DEFAULT_PASSWORD,
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
create_resource(url: url, payload: payload, headers: admin_headers)
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
def self.find_by_username(username)
|
|
@@ -22,7 +22,7 @@ module Ahub
|
|
|
22
22
|
|
|
23
23
|
attr_reader :username, :realname, :avatar_url,
|
|
24
24
|
:post_count, :follow_count, :follower_count,
|
|
25
|
-
:active, :suspended, :deactivated
|
|
25
|
+
:active, :suspended, :deactivated, :answers
|
|
26
26
|
|
|
27
27
|
def initialize(attrs)
|
|
28
28
|
@id = attrs[:id]
|
|
@@ -41,5 +41,14 @@ module Ahub
|
|
|
41
41
|
def is_complete?
|
|
42
42
|
!!@complete
|
|
43
43
|
end
|
|
44
|
+
|
|
45
|
+
def answers
|
|
46
|
+
unless @answers
|
|
47
|
+
response = self.class.get_resource(url: "#{self.class.base_url}/#{id}/answer.json", headers: self.class.admin_headers)
|
|
48
|
+
@answers = response[:list].map{ |answer| Ahub::Answer.new(answer) }
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
@answers
|
|
52
|
+
end
|
|
44
53
|
end
|
|
45
54
|
end
|
data/lib/ahub/version.rb
CHANGED