ahub 0.1.17 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 51dec395f4122427774250b499935ffa9767a752
4
- data.tar.gz: 6c246f6620f11f7d69295750e9cb368c0d2e51ea
3
+ metadata.gz: 1ea4fc5534f83930d5fc06d6555c4d7e71be49e4
4
+ data.tar.gz: f194dee02fedc6a3d1ffaf296b4b7871820713cd
5
5
  SHA512:
6
- metadata.gz: 82ca7eba872c110c1048f44c2753ff41277b024e972f8219af51b63eae6650c849fb29025c8bdfd79407191d1ad65ac8d1e74af9f609e27805c9176fed7bd98a
7
- data.tar.gz: 166d305ed495919e899ac1036b048ea0f96a868d8927cf0f45d5702aff1fe888018b8bf9f03d5037ef79128abd0345d3695c85006b9b9900b679608193a7a255
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
  [![Build Status](https://travis-ci.org/abelmartin/ahub.svg?branch=master)](https://travis-ci.org/abelmartin/ahub)
6
6
 
7
- Gem v0.1.16
8
- [![Build Status](https://travis-ci.org/abelmartin/ahub.svg?branch=v0.1.16)](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
- make_post_call(url: url, payload: {body: body}, headers: headers(username: username, password: password))
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 JSON.parse(RestClient.get(url, admin_headers), symbolize_names:true)
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
- JSON.parse(RestClient.get(url, admin_headers), symbolize_names:true)[:list].map do |node|
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 make_post_call(url:, payload:, headers:)
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
- make_post_call(url: url, payload: payload, headers: user_headers)
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
- make_post_call(url: url, payload: payload, headers: admin_headers)
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
@@ -1,3 +1,3 @@
1
1
  module Ahub
2
- VERSION = "0.1.17"
2
+ VERSION = "0.2.0"
3
3
  end
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.17
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abel Martin