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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2d9378c422ac66a36fa04cebbdacb5f7fc4a6690
4
- data.tar.gz: ef97163dec123da5f7d9f021f46e0fb5a80ba390
3
+ metadata.gz: d9b2368e43055cca71695c86cabf7fc86a0a14a0
4
+ data.tar.gz: 7e5b02f039662717b6245af61d777d82b12a4974
5
5
  SHA512:
6
- metadata.gz: 824c7bd60007c56e64d8ad5d0f9f1ffa24b8318e28a90b79fe3bbab4639f1ae40473c4b16b01e5b93f5e8e9fef28a488bb68d3e41ccb1435ee58c5571aedb422
7
- data.tar.gz: 4dfbe1154982e42da0f0e3e76b94f286c942185e11a146bdd816af1da52b7b119c7e27bf3cd82aa16c935b5df5fce7ff451603853f6934475fda5460cbe0b980
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
- # You can add fixtures and/or initialization code here to make experimenting
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
@@ -2,6 +2,9 @@ module Ahub
2
2
  class Answer
3
3
  extend Ahub::APIHelpers
4
4
 
5
+ def initialize(attrs)
6
+ end
7
+
5
8
  def self.create(question_id:, body:, username:, password:)
6
9
  data = {body: body}
7
10
 
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
- def self.find(id=nil)
6
- url = base_url
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
- OpenStruct.new(JSON.parse(RestClient.get(url, admin_headers), symbolize_names:true))
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
- {error: nil, newQuestionURL: response.headers[:location]}
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 self.create_csv(title:, body:, topics:, user_id:, count:20, path:)
27
- ::CSV.open(path, 'w', ) do |csv|
28
- (0..count).each do |n|
29
- csv << [
30
- "question",
31
- "##{n}: #{title}",
32
- "##{n}: #{body}",
33
- 0,
34
- topics,
35
- 1443470000000,
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
- private
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 self.base_url
47
- "#{Ahub::DOMAIN}/services/v2/question"
49
+ def to_s
50
+ url
48
51
  end
49
52
  end
50
53
  end
data/lib/ahub/space.rb ADDED
@@ -0,0 +1,8 @@
1
+ module Ahub
2
+ class Space
3
+ extend Ahub::APIHelpers
4
+
5
+ def initialize(attrs)
6
+ end
7
+ end
8
+ end
data/lib/ahub/topic.rb CHANGED
@@ -1,5 +1,8 @@
1
1
  module Ahub
2
2
  class Topic
3
3
  extend Ahub::APIHelpers
4
+
5
+ def initialize(attrs)
6
+ end
4
7
  end
5
8
  end
data/lib/ahub/user.rb CHANGED
@@ -2,6 +2,9 @@ module Ahub
2
2
  class User
3
3
  extend Ahub::APIHelpers
4
4
 
5
+ def initialize(attrs)
6
+ end
7
+
5
8
  def self.find(id=nil)
6
9
  url = "#{Ahub::DOMAIN}/services/v2/user"
7
10
  url += "/#{id}" if id
data/lib/ahub/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ahub
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.7"
3
3
  end
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
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-10-05 00:00:00.000000000 Z
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