quandora 0.1.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.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Hamid
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,178 @@
1
+ # Quandora
2
+
3
+ a simple gem to connect to the [quandora](https://www.quandora.com/).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'quandora'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install quandora
20
+
21
+
22
+ ## Configuration
23
+
24
+ Add this to your `config/application.rb`.
25
+
26
+ ```ruby
27
+ Quandora.configure do |config|
28
+ config.url = 'https://example.quandora.com/m/json'
29
+ config.username = 'example@example.com'
30
+ config.password = 'password'
31
+ end
32
+
33
+ # Alternative way to configure
34
+
35
+ config = Quandora::Configuration.new
36
+ config.url = 'https://example.quandora.com/m/json'
37
+ config.username = 'example@example.com'
38
+ config.password = 'password'
39
+ ```
40
+
41
+ ## Usage
42
+
43
+ ```ruby
44
+ activity apis:
45
+ index: Quandora.activity.index
46
+
47
+ ------------------------------------------------------
48
+
49
+ badges apis:
50
+ index: Quandora.badges.index
51
+
52
+ ------------------------------------------------------
53
+
54
+ end points apis:
55
+ index: Quandora.end_points.index
56
+
57
+ ------------------------------------------------------
58
+
59
+ users apis:
60
+ index: Quandora.end_points.index
61
+ show: Quandora.end_points.show(user_id)
62
+ me: Quandora.end_points.me
63
+ create: Quandora.end_points.create(args)
64
+ the args it must be:
65
+ {
66
+ "email": "email",
67
+ "password": "password",
68
+ "firstName": "first_name",
69
+ "lastName": "last_name",
70
+ "title": "title",
71
+ "isManager": "is_manager",
72
+ "aliases": "aliases",
73
+ "groups": "groups"
74
+ }
75
+
76
+ ------------------------------------------------------
77
+
78
+ bases apis:
79
+ index: Quandora.bases.index
80
+ questions: Quandora.bases.questions('base_id')
81
+ show: Quandora.bases.show('base_id')
82
+ ask: Quandora.bases.ask('base_id', args)
83
+ the args it must be:
84
+ {
85
+ "title": "title",
86
+ "content": "content",
87
+ "content_type": "default is markdown"
88
+ }
89
+
90
+ follow: Quandora.bases.follow('base_id')
91
+ mlt: Quandora.bases.mlt('base_id')
92
+
93
+ bases tags apis:
94
+ index: Quandora.bases.tag('base_id').list
95
+ show: Quandora.bases.tag('base_id').show('tag_name')
96
+
97
+ create: Quandora.bases.tag('base_id').create(args)
98
+ the args it must be:
99
+ {
100
+ "name": "name",
101
+ "url": "url",
102
+ "content": "content"
103
+ }
104
+
105
+ udpate: Quandora.bases.tag('base_id').udpate(args)
106
+ the args it must be:
107
+ {
108
+ "uid": "uid",
109
+ "content": "content"
110
+ }
111
+
112
+ delete: Quandora.bases.tag('base_id').delete('tag_name')
113
+
114
+ bases reports apis:
115
+ asked: Quandora.bases.report('base_id').asked
116
+ users_reputation_change: Quandora.bases.report('base_id').users_reputation_change
117
+ most_voted_question: Quandora.bases.report('base_id').most_voted_question
118
+
119
+ ------------------------------------------------------
120
+
121
+ question apis:
122
+ detail: Quandora.question.detail('question_id')
123
+ view: Quandora.question.view('question_id')
124
+ mlt: Quandora.question.mlt('question_id')
125
+
126
+ answer: Quandora.question.answer('question_id', args)
127
+ the args it must be:
128
+ {
129
+ "content_type": "default is markdown",
130
+ "content": "content"
131
+ }
132
+
133
+ vote: Quandora.question.vote('question_id', args)
134
+ the args it must be:
135
+ {
136
+ "data": "true or false"
137
+ }
138
+
139
+ question tag apis:
140
+ set: Quandora.question.tag('question_id').set('tag1,tag2,tag3')
141
+ add: Quandora.question.tag('question_id').add('tag1,tag2,tag3')
142
+
143
+ question comments apis:
144
+ create: Quandora.question.comment('question_id').create(args)
145
+ the args it must be:
146
+ {
147
+ 'comment': 'comment'
148
+ }
149
+
150
+ update: Quandora.question.comment('question_id').update(args)
151
+ the args it must be:
152
+ {
153
+ 'comment': 'comment',
154
+ 'hash': 'hash',
155
+ }
156
+
157
+ delete: Quandora.question.comment('question_id').delete('hash')
158
+ ```
159
+
160
+ For more information please go to the [quandora api document](https://www.quandora.com/quandora-rest-api-documentation/)
161
+
162
+ ## Development
163
+
164
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
165
+
166
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
167
+
168
+ ## Contributing
169
+
170
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/quandora. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
171
+
172
+ ## License
173
+
174
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
175
+
176
+ ## Code of Conduct
177
+
178
+ Everyone interacting in the Quandora project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/quandora/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "quandora"
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(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/quandora.rb ADDED
@@ -0,0 +1,52 @@
1
+ require 'json'
2
+ require 'faraday'
3
+ require "quandora/version"
4
+ require "quandora/configuration"
5
+
6
+ # api calls
7
+ require "quandora/request"
8
+ require "quandora/activity"
9
+ require "quandora/answer"
10
+ require "quandora/badges"
11
+ require "quandora/bases"
12
+ require "quandora/comment"
13
+ require "quandora/end_points"
14
+ require "quandora/question"
15
+ require "quandora/report"
16
+ require "quandora/tag"
17
+ require "quandora/users"
18
+
19
+ module Quandora
20
+ class Error < StandardError; end
21
+
22
+ class << self
23
+ attr_accessor :configuration
24
+
25
+ def configuration
26
+ @configuration ||= Configuration.new
27
+ end
28
+
29
+ def configure
30
+ yield(configuration)
31
+ end
32
+
33
+ [
34
+ :activity, :question, :badges, :bases,
35
+ :end_points, :report, :users
36
+ ].each do |api|
37
+ define_method :"#{api}" do |args = {}|
38
+ @conn = Faraday.new(url: configuration.url) do |conn|
39
+ conn.adapter Faraday.default_adapter # make requests with Net::HTTP
40
+ conn.basic_auth(configuration.username, configuration.password)
41
+ end
42
+
43
+ find_api(api).new(@conn, api, args)
44
+ end
45
+ end
46
+
47
+ def find_api(api)
48
+ class_name = api.to_s.split('_').collect(&:capitalize).join
49
+ Object.const_get("Quandora::#{class_name}")
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,8 @@
1
+ # index
2
+
3
+ class Quandora::Activity < Quandora::Request
4
+ def index(args = {})
5
+ @params.merge!("userId": args["user_id"]) unless args.fetch('user_id', nil).nil?
6
+ super
7
+ end
8
+ end
@@ -0,0 +1,29 @@
1
+ class Quandora::Answer < Quandora::Request
2
+ def vote(answer_id, args)
3
+ body = {
4
+ "type": "boolean",
5
+ "data": args["vote"]
6
+ }
7
+
8
+ resp = @conn.post("a/#{id}/vote") do |req|
9
+ req.body = body.to_s
10
+ req.headers['Content-Type'] = 'application/json'
11
+ end
12
+ end
13
+
14
+ def accept(answer_id, args)
15
+ body = {
16
+ "type": "boolean",
17
+ "data": args["accept"]
18
+ }
19
+
20
+ resp = @conn.post("a/#{id}/accept") do |req|
21
+ req.body = body.to_json
22
+ req.headers['Content-Type'] = 'application/json'
23
+ end
24
+ end
25
+
26
+ def comment(answer_id)
27
+ Comment.new(@conn, "a", answer_id)
28
+ end
29
+ end
@@ -0,0 +1,2 @@
1
+ class Quandora::Badges < Quandora::Request
2
+ end
@@ -0,0 +1,51 @@
1
+ class Quandora::Bases < Quandora::Request
2
+ def list
3
+ @api = "kb/"
4
+ index
5
+ end
6
+
7
+ def questions(base_id, args = {})
8
+ @api = "kb/#{base_id}/list"
9
+ @params.merge!("o": args["o"]) unless args.fetch('o', nil).nil?
10
+ @params.merge!("l": args["l"]) unless args.fetch('l', nil).nil?
11
+ @params.merge!("q": args["q"]) unless args.fetch('q', nil).nil?
12
+ @params.merge!("tag": args["tag"]) unless args.fetch('tag', nil).nil?
13
+ @params.merge!("s": args["s"]) unless args.fetch('s', nil).nil?
14
+ index
15
+ end
16
+
17
+ def mlt(base_id, args = {})
18
+ @api = "kb/#{base_id}/mlt"
19
+ @params.merge!("q": args["q"]) unless args.fetch('q', nil).nil?
20
+ index
21
+ end
22
+
23
+ def ask(base_id, args = {})
24
+ body = {
25
+ "type": "post-question",
26
+ "data": {
27
+ "title": args["title"],
28
+ "content": args["content"],
29
+ "contentType": args["content_type"] || "markdown"
30
+ }
31
+ }
32
+
33
+ resp = @conn.post("kb/#{base_id}/ask") do |req|
34
+ req.body = body.to_json
35
+ req.headers['Content-Type'] = 'application/json'
36
+ end
37
+ end
38
+
39
+ def follow(base_id, args = {})
40
+ @api = "kb/#{base_id}/follow"
41
+ index
42
+ end
43
+
44
+ def tag(kb_id)
45
+ Quandora::Tag.new(@conn, "kb", kb_id)
46
+ end
47
+
48
+ def report(kb_id)
49
+ Quandora::Report.new(@conn, "kb", kb_id)
50
+ end
51
+ end
@@ -0,0 +1,40 @@
1
+ class Quandora::Comment
2
+ def initialize(conn, api, id)
3
+ @conn = conn
4
+ @api = api
5
+ @id = id
6
+ end
7
+
8
+ def create(args)
9
+ body = {
10
+ "type": "post-comment",
11
+ "data": {
12
+ "content": args["comment"]
13
+ }
14
+ }
15
+
16
+ resp = @conn.post("#{@api}/#{@id}/comment") do |req|
17
+ req.body = body.to_s
18
+ req.headers['Content-Type'] = 'application/json'
19
+ end
20
+ end
21
+
22
+ def update(args)
23
+ body = {
24
+ "type": "post-comment",
25
+ "data": {
26
+ "content": args["comment"],
27
+ "hash": args["hash"]
28
+ }
29
+ }
30
+
31
+ resp = @conn.put("#{@api}/#{@id}/comment") do |req|
32
+ req.body = body.to_s
33
+ req.headers['Content-Type'] = 'application/json'
34
+ end
35
+ end
36
+
37
+ def delete(hash)
38
+ resp = @conn.delete("#{@api}/#{@id}/comment/#{hash}")
39
+ end
40
+ end
@@ -0,0 +1,11 @@
1
+ module Quandora
2
+ class Configuration
3
+ attr_accessor :url, :username, :password
4
+
5
+ def initialize
6
+ @url = ''
7
+ @username = ''
8
+ @password = ''
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,6 @@
1
+ class Quandora::EndPoints < Quandora::Request
2
+ def index(args = {})
3
+ @api = ""
4
+ super
5
+ end
6
+ end