ruby-stackoverflow 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.rake_tasks +4 -0
- data/Gemfile +9 -0
- data/LICENSE.txt +22 -0
- data/README.md +50 -0
- data/Rakefile +6 -0
- data/lib/generators/ruby_stackoverflow/ruby_stackoverflow_generator.rb +31 -0
- data/lib/generators/ruby_stackoverflow/templates/ruby_stackoverflow.rb +1 -0
- data/lib/ruby-stackoverflow.rb +29 -0
- data/lib/ruby-stackoverflow/client.rb +68 -0
- data/lib/ruby-stackoverflow/client/.DS_Store +0 -0
- data/lib/ruby-stackoverflow/client/badges_helper.rb +50 -0
- data/lib/ruby-stackoverflow/client/comments_helper.rb +23 -0
- data/lib/ruby-stackoverflow/client/parse_options.rb +25 -0
- data/lib/ruby-stackoverflow/client/question_helper.rb +61 -0
- data/lib/ruby-stackoverflow/client/resource/answer.rb +7 -0
- data/lib/ruby-stackoverflow/client/resource/badge.rb +7 -0
- data/lib/ruby-stackoverflow/client/resource/comment.rb +8 -0
- data/lib/ruby-stackoverflow/client/resource/notification.rb +8 -0
- data/lib/ruby-stackoverflow/client/resource/permission.rb +8 -0
- data/lib/ruby-stackoverflow/client/resource/post.rb +7 -0
- data/lib/ruby-stackoverflow/client/resource/question.rb +66 -0
- data/lib/ruby-stackoverflow/client/resource/reputation.rb +8 -0
- data/lib/ruby-stackoverflow/client/resource/resource.rb +28 -0
- data/lib/ruby-stackoverflow/client/resource/stackoverflow_error.rb +13 -0
- data/lib/ruby-stackoverflow/client/resource/suggested_edit.rb +8 -0
- data/lib/ruby-stackoverflow/client/resource/tag.rb +19 -0
- data/lib/ruby-stackoverflow/client/resource/user.rb +125 -0
- data/lib/ruby-stackoverflow/client/response_data.rb +20 -0
- data/lib/ruby-stackoverflow/client/user_helper.rb +152 -0
- data/lib/ruby-stackoverflow/configuration.rb +10 -0
- data/lib/ruby-stackoverflow/ruby-stackoverflow_generator.rb +29 -0
- data/lib/ruby-stackoverflow/version.rb +4 -0
- data/ruby-stackoverflow.gemspec +28 -0
- data/spec/fixtures/error.json +5 -0
- data/spec/fixtures/questions.json +28 -0
- data/spec/fixtures/questions_answers.json +23 -0
- data/spec/fixtures/questions_comments.json +39 -0
- data/spec/fixtures/questions_timeline.json +200 -0
- data/spec/fixtures/users.json +32 -0
- data/spec/fixtures/vcr_cassettes/badges.yml +67 -0
- data/spec/fixtures/vcr_cassettes/badges_by_ids.yml +56 -0
- data/spec/fixtures/vcr_cassettes/badges_by_name.yml +55 -0
- data/spec/fixtures/vcr_cassettes/badges_by_recipients.yml +73 -0
- data/spec/fixtures/vcr_cassettes/badges_by_recipients_by_ids.yml +70 -0
- data/spec/fixtures/vcr_cassettes/badges_by_tags.yml +58 -0
- data/spec/fixtures/vcr_cassettes/comments.yml +104 -0
- data/spec/fixtures/vcr_cassettes/comments_by_ids.yml +60 -0
- data/spec/fixtures/vcr_cassettes/error.yml +53 -0
- data/spec/fixtures/vcr_cassettes/featured_questions.yml +62 -0
- data/spec/fixtures/vcr_cassettes/linked_questions.yml +53 -0
- data/spec/fixtures/vcr_cassettes/noanswered_questions.yml +62 -0
- data/spec/fixtures/vcr_cassettes/questions.yml +165 -0
- data/spec/fixtures/vcr_cassettes/questions_answers.yml +63 -0
- data/spec/fixtures/vcr_cassettes/questions_by_ids.yml +62 -0
- data/spec/fixtures/vcr_cassettes/questions_comments.yml +60 -0
- data/spec/fixtures/vcr_cassettes/related_questions.yml +94 -0
- data/spec/fixtures/vcr_cassettes/timeline_questions.yml +68 -0
- data/spec/fixtures/vcr_cassettes/unanswered_questions.yml +62 -0
- data/spec/fixtures/vcr_cassettes/user_timeline.yml +73 -0
- data/spec/fixtures/vcr_cassettes/user_top_answers_with_given_tags.yml +64 -0
- data/spec/fixtures/vcr_cassettes/user_top_questions_with_given_tags.yml +66 -0
- data/spec/fixtures/vcr_cassettes/user_top_tags_by_answers.yml +62 -0
- data/spec/fixtures/vcr_cassettes/user_top_tags_by_questions.yml +58 -0
- data/spec/fixtures/vcr_cassettes/user_write_permissions.yml +56 -0
- data/spec/fixtures/vcr_cassettes/users.yml +61 -0
- data/spec/fixtures/vcr_cassettes/users_answers.yml +65 -0
- data/spec/fixtures/vcr_cassettes/users_badges.yml +60 -0
- data/spec/fixtures/vcr_cassettes/users_by_ids.yml +61 -0
- data/spec/fixtures/vcr_cassettes/users_comments.yml +74 -0
- data/spec/fixtures/vcr_cassettes/users_favorites_questions.yml +74 -0
- data/spec/fixtures/vcr_cassettes/users_featured_questions.yml +53 -0
- data/spec/fixtures/vcr_cassettes/users_mentioned_questions.yml +97 -0
- data/spec/fixtures/vcr_cassettes/users_noanswerquestions.yml +60 -0
- data/spec/fixtures/vcr_cassettes/users_notifications.yml +80 -0
- data/spec/fixtures/vcr_cassettes/users_questions.yml +67 -0
- data/spec/fixtures/vcr_cassettes/users_replied_comments.yml +60 -0
- data/spec/fixtures/vcr_cassettes/users_reputation_questions.yml +59 -0
- data/spec/fixtures/vcr_cassettes/users_suggested_edits.yml +72 -0
- data/spec/fixtures/vcr_cassettes/users_tags.yml +60 -0
- data/spec/fixtures/vcr_cassettes/users_unaccepted_questions.yml +65 -0
- data/spec/fixtures/vcr_cassettes/users_unanswered_questions.yml +77 -0
- data/spec/fixtures/vcr_cassettes/users_unread_notifications.yml +53 -0
- data/spec/helper.rb +45 -0
- data/spec/ruby-stackoverflow/badges_spec.rb +63 -0
- data/spec/ruby-stackoverflow/comments_spec.rb +31 -0
- data/spec/ruby-stackoverflow/question_spec.rb +90 -0
- data/spec/ruby-stackoverflow/user_spec.rb +289 -0
- data/spec/spec_helper.rb +16 -0
- metadata +292 -0
data/.gitignore
ADDED
data/.rake_tasks
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Rashmi Yadav
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# Ruby::Stackoverflow
|
2
|
+
|
3
|
+
Ruby toolkit to Stackoverflow API
|
4
|
+
|
5
|
+
## Install
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'ruby-stackoverflow'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install ruby-stackoverflow
|
18
|
+
|
19
|
+
###Documentation
|
20
|
+
|
21
|
+
<a href='https://github.com/raysrashmi/ruby-stackoverflow/wiki/Users-calls'>User Calls</a>
|
22
|
+
<br/>
|
23
|
+
<a href='https://github.com/raysrashmi/ruby-stackoverflow/wiki/Users-calls'>Questions Calls</a>
|
24
|
+
<br/>
|
25
|
+
<a href='https://github.com/raysrashmi/ruby-stackoverflow/wiki/Users-calls'>Badges Calls</a>
|
26
|
+
<br/>
|
27
|
+
<a href='https://github.com/raysrashmi/ruby-stackoverflow/wiki/Users-calls'>Badges Calls</a>
|
28
|
+
<br/>
|
29
|
+
|
30
|
+
##Configuration
|
31
|
+
|
32
|
+
You can add your key and access-token for higher rate limit.
|
33
|
+
To get Key and Access Token you have to register your app to http://stackapps.com/
|
34
|
+
Run command in your application dir.
|
35
|
+
|
36
|
+
$ rails generate ruby-stackoverflow --client_key=<key> --access_token=<access token>
|
37
|
+
|
38
|
+
This command will create a ruby_stackoverflow.rb file in config/initializers.
|
39
|
+
|
40
|
+
## Contributing
|
41
|
+
|
42
|
+
1. Fork it
|
43
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
44
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
45
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
46
|
+
5. Create new Pull Request
|
47
|
+
|
48
|
+
##LICENSE
|
49
|
+
|
50
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
class RubyStackoverflowGenerator < Rails::Generators::Base
|
4
|
+
desc "Creates the ruby-stackoverflow initializer file at config/initialize/ruby-stackoverflow.rb"
|
5
|
+
class_option :client_key, :aliases => "-k", :type => :string, :desc => "Your Stackoverflow Client key"
|
6
|
+
class_option :access_token, :aliases => "-k", :type => :string, :desc => "Your STackoverflow access token"
|
7
|
+
|
8
|
+
def self.source_root
|
9
|
+
@_ruby_stackoverflow_root ||= File.expand_path("../templates", __FILE__)
|
10
|
+
end
|
11
|
+
|
12
|
+
def install
|
13
|
+
template 'ruby_stackoverflow.rb', 'config/initializers/ruby_stackoverflow.rb'
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def configuration_output
|
19
|
+
output = <<-eos
|
20
|
+
RubyStackoverflow.configure do|config|
|
21
|
+
config.client_key = '#{options[:client_key]}'
|
22
|
+
config.access_token = '#{options[:access_token]}'
|
23
|
+
end
|
24
|
+
eos
|
25
|
+
output
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= configuration_output %>
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'ruby-stackoverflow/version'
|
3
|
+
require 'ruby-stackoverflow/client'
|
4
|
+
require 'ruby-stackoverflow/configuration'
|
5
|
+
|
6
|
+
module RubyStackoverflow
|
7
|
+
include HTTParty
|
8
|
+
|
9
|
+
class << self
|
10
|
+
def client
|
11
|
+
@client = RubyStackoverflow::Client.new unless defined?(@client)
|
12
|
+
@client
|
13
|
+
end
|
14
|
+
|
15
|
+
# @private
|
16
|
+
def respond_to_missing?(method_name, include_private=false); client.respond_to?(method_name, include_private); end if RUBY_VERSION >= "1.9"
|
17
|
+
# @private
|
18
|
+
def respond_to?(method_name, include_private=false); client.respond_to?(method_name, include_private) || super; end if RUBY_VERSION < "1.9"
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def method_missing(method_name, *args, &block)
|
23
|
+
return super unless client.respond_to?(method_name)
|
24
|
+
client.send(method_name, *args, &block)
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'ruby-stackoverflow/client/response_data'
|
3
|
+
require 'ruby-stackoverflow/client/resource/resource'
|
4
|
+
require 'ruby-stackoverflow/client/resource/user'
|
5
|
+
require 'ruby-stackoverflow/client/resource/question'
|
6
|
+
require 'ruby-stackoverflow/client/resource/answer'
|
7
|
+
require 'ruby-stackoverflow/client/resource/notification'
|
8
|
+
require 'ruby-stackoverflow/client/resource/badge'
|
9
|
+
require 'ruby-stackoverflow/client/resource/reputation'
|
10
|
+
require 'ruby-stackoverflow/client/resource/suggested_edit'
|
11
|
+
require 'ruby-stackoverflow/client/resource/comment'
|
12
|
+
require 'ruby-stackoverflow/client/resource/tag'
|
13
|
+
require 'ruby-stackoverflow/client/resource/post'
|
14
|
+
require 'ruby-stackoverflow/client/resource/permission'
|
15
|
+
require 'ruby-stackoverflow/client/resource/stackoverflow_error'
|
16
|
+
require 'ruby-stackoverflow/client/user_helper'
|
17
|
+
require 'ruby-stackoverflow/client/question_helper'
|
18
|
+
require 'ruby-stackoverflow/client/badges_helper'
|
19
|
+
require 'ruby-stackoverflow/client/comments_helper'
|
20
|
+
require 'ruby-stackoverflow/client/parse_options'
|
21
|
+
|
22
|
+
module RubyStackoverflow
|
23
|
+
class Client
|
24
|
+
include RubyStackoverflow::Client::ParseOptions
|
25
|
+
include RubyStackoverflow::Client::UserHelper
|
26
|
+
include RubyStackoverflow::Client::QuestionHelper
|
27
|
+
include RubyStackoverflow::Client::BadgesHelper
|
28
|
+
include RubyStackoverflow::Client::CommentsHelper
|
29
|
+
|
30
|
+
attr_accessor :configuration
|
31
|
+
|
32
|
+
def getr(url,klass, options={})
|
33
|
+
request :get, url,klass ,options
|
34
|
+
end
|
35
|
+
|
36
|
+
def configure
|
37
|
+
yield(configuration)
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def request(method, url, klass, options={})
|
43
|
+
url = append_params_to_url(url, parse_options(options))
|
44
|
+
response = HTTParty.send(method,url)
|
45
|
+
parse_response(response, klass)
|
46
|
+
end
|
47
|
+
|
48
|
+
def parse_response(data, klass)
|
49
|
+
data = JSON.parse(data.body, symbolize_names: true)
|
50
|
+
ResponseData.new(data, klass)
|
51
|
+
end
|
52
|
+
|
53
|
+
def append_params_to_url(url, options)
|
54
|
+
url = Configuration.api_url + url
|
55
|
+
options.merge!(key_params)
|
56
|
+
options = options.to_a.map{|k,v|"#{k}=#{v}"}
|
57
|
+
url+'?'+options.join('&')
|
58
|
+
end
|
59
|
+
|
60
|
+
def key_params
|
61
|
+
{key: configuration.client_key, site: 'stackoverflow', access_token: configuration.access_token}
|
62
|
+
end
|
63
|
+
|
64
|
+
def configuration
|
65
|
+
@configuration||= Configuration.new
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
Binary file
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module RubyStackoverflow
|
2
|
+
class Client
|
3
|
+
module BadgesHelper
|
4
|
+
|
5
|
+
def badges(options={})
|
6
|
+
badges_response(options)
|
7
|
+
end
|
8
|
+
|
9
|
+
def badges_by_ids(ids, options={})
|
10
|
+
ids = join_ids(ids)
|
11
|
+
url = ids
|
12
|
+
badges_response(options, url)
|
13
|
+
end
|
14
|
+
|
15
|
+
def badges_by_ids(ids, options={})
|
16
|
+
ids = join_ids(ids)
|
17
|
+
url = ids
|
18
|
+
badges_response(options, url)
|
19
|
+
end
|
20
|
+
|
21
|
+
def badges_by_name(options={})
|
22
|
+
url ='/name'
|
23
|
+
badges_response(options, url)
|
24
|
+
end
|
25
|
+
|
26
|
+
def badges_between_dates(options={})
|
27
|
+
url ='/recipients'
|
28
|
+
badges_response(options, url)
|
29
|
+
end
|
30
|
+
|
31
|
+
def badges_between_dates_by_ids(ids,options={})
|
32
|
+
ids = join_ids(ids)
|
33
|
+
url = ids + '/recipients'
|
34
|
+
badges_response(options, url)
|
35
|
+
end
|
36
|
+
|
37
|
+
def badges_by_tags(options={})
|
38
|
+
url = '/tags'
|
39
|
+
badges_response(options, url)
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def badges_response(options={}, url='')
|
45
|
+
url = 'badges/'+ url
|
46
|
+
getr(url,'badge',options)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module RubyStackoverflow
|
2
|
+
class Client
|
3
|
+
module CommentsHelper
|
4
|
+
|
5
|
+
def comments(options = {})
|
6
|
+
comments_response(options)
|
7
|
+
end
|
8
|
+
|
9
|
+
def comments_by_ids(ids, options = {})
|
10
|
+
ids = join_ids(ids)
|
11
|
+
url = ids
|
12
|
+
comments_response(options, url)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def comments_response(options={}, url='')
|
18
|
+
url = 'comments/' + url
|
19
|
+
getr(url,'comment',options)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module RubyStackoverflow
|
2
|
+
class Client
|
3
|
+
module ParseOptions
|
4
|
+
|
5
|
+
def parse_options(options = {})
|
6
|
+
options.each do|k,v|
|
7
|
+
case k
|
8
|
+
when :fromdate , :todate, :min, :max
|
9
|
+
begin
|
10
|
+
options[k] = Date.parse(v).to_time.to_i
|
11
|
+
rescue
|
12
|
+
options[k] = v
|
13
|
+
end
|
14
|
+
else
|
15
|
+
options[k] = v
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def join_ids(ids)
|
21
|
+
ids.join(';')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module RubyStackoverflow
|
2
|
+
class Client
|
3
|
+
module QuestionHelper
|
4
|
+
|
5
|
+
def questions(options = {})
|
6
|
+
question_response(options)
|
7
|
+
end
|
8
|
+
|
9
|
+
def questions_by_ids(ids , options = {})
|
10
|
+
url = join_ids(ids)
|
11
|
+
question_response(options, url)
|
12
|
+
end
|
13
|
+
|
14
|
+
def answers_of_questions(ids, options={})
|
15
|
+
url = join_ids(ids) + '/answers'
|
16
|
+
question_response(options, url)
|
17
|
+
end
|
18
|
+
|
19
|
+
def comments_of_questions(ids, options={})
|
20
|
+
url = join_ids(ids) + '/comments'
|
21
|
+
question_response(options, url)
|
22
|
+
end
|
23
|
+
|
24
|
+
def linked_questions(ids, options={})
|
25
|
+
url = join_ids(ids)+'/linked'
|
26
|
+
question_response(options, url)
|
27
|
+
end
|
28
|
+
|
29
|
+
def related_questions(ids, options={})
|
30
|
+
url= join_ids(ids) + '/related'
|
31
|
+
question_response(options, url)
|
32
|
+
end
|
33
|
+
|
34
|
+
def timeline_of_questions(ids, options={})
|
35
|
+
url = join_ids(ids) + '/timeline'
|
36
|
+
question_response(options, url)
|
37
|
+
end
|
38
|
+
|
39
|
+
def featured_questions(options={})
|
40
|
+
url = 'featured'
|
41
|
+
question_response(options, url)
|
42
|
+
end
|
43
|
+
|
44
|
+
def unanswered_questions(options={})
|
45
|
+
question_response(options, 'unanswered')
|
46
|
+
end
|
47
|
+
|
48
|
+
def noanswered_questions(options={})
|
49
|
+
question_response(options, 'no-answers')
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
|
55
|
+
def question_response(options={}, url='')
|
56
|
+
url = 'questions/' + url
|
57
|
+
getr(url,'question',options)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|