ruby-stackoverflow 0.0.2

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.
Files changed (90) hide show
  1. data/.gitignore +17 -0
  2. data/.rake_tasks +4 -0
  3. data/Gemfile +9 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +50 -0
  6. data/Rakefile +6 -0
  7. data/lib/generators/ruby_stackoverflow/ruby_stackoverflow_generator.rb +31 -0
  8. data/lib/generators/ruby_stackoverflow/templates/ruby_stackoverflow.rb +1 -0
  9. data/lib/ruby-stackoverflow.rb +29 -0
  10. data/lib/ruby-stackoverflow/client.rb +68 -0
  11. data/lib/ruby-stackoverflow/client/.DS_Store +0 -0
  12. data/lib/ruby-stackoverflow/client/badges_helper.rb +50 -0
  13. data/lib/ruby-stackoverflow/client/comments_helper.rb +23 -0
  14. data/lib/ruby-stackoverflow/client/parse_options.rb +25 -0
  15. data/lib/ruby-stackoverflow/client/question_helper.rb +61 -0
  16. data/lib/ruby-stackoverflow/client/resource/answer.rb +7 -0
  17. data/lib/ruby-stackoverflow/client/resource/badge.rb +7 -0
  18. data/lib/ruby-stackoverflow/client/resource/comment.rb +8 -0
  19. data/lib/ruby-stackoverflow/client/resource/notification.rb +8 -0
  20. data/lib/ruby-stackoverflow/client/resource/permission.rb +8 -0
  21. data/lib/ruby-stackoverflow/client/resource/post.rb +7 -0
  22. data/lib/ruby-stackoverflow/client/resource/question.rb +66 -0
  23. data/lib/ruby-stackoverflow/client/resource/reputation.rb +8 -0
  24. data/lib/ruby-stackoverflow/client/resource/resource.rb +28 -0
  25. data/lib/ruby-stackoverflow/client/resource/stackoverflow_error.rb +13 -0
  26. data/lib/ruby-stackoverflow/client/resource/suggested_edit.rb +8 -0
  27. data/lib/ruby-stackoverflow/client/resource/tag.rb +19 -0
  28. data/lib/ruby-stackoverflow/client/resource/user.rb +125 -0
  29. data/lib/ruby-stackoverflow/client/response_data.rb +20 -0
  30. data/lib/ruby-stackoverflow/client/user_helper.rb +152 -0
  31. data/lib/ruby-stackoverflow/configuration.rb +10 -0
  32. data/lib/ruby-stackoverflow/ruby-stackoverflow_generator.rb +29 -0
  33. data/lib/ruby-stackoverflow/version.rb +4 -0
  34. data/ruby-stackoverflow.gemspec +28 -0
  35. data/spec/fixtures/error.json +5 -0
  36. data/spec/fixtures/questions.json +28 -0
  37. data/spec/fixtures/questions_answers.json +23 -0
  38. data/spec/fixtures/questions_comments.json +39 -0
  39. data/spec/fixtures/questions_timeline.json +200 -0
  40. data/spec/fixtures/users.json +32 -0
  41. data/spec/fixtures/vcr_cassettes/badges.yml +67 -0
  42. data/spec/fixtures/vcr_cassettes/badges_by_ids.yml +56 -0
  43. data/spec/fixtures/vcr_cassettes/badges_by_name.yml +55 -0
  44. data/spec/fixtures/vcr_cassettes/badges_by_recipients.yml +73 -0
  45. data/spec/fixtures/vcr_cassettes/badges_by_recipients_by_ids.yml +70 -0
  46. data/spec/fixtures/vcr_cassettes/badges_by_tags.yml +58 -0
  47. data/spec/fixtures/vcr_cassettes/comments.yml +104 -0
  48. data/spec/fixtures/vcr_cassettes/comments_by_ids.yml +60 -0
  49. data/spec/fixtures/vcr_cassettes/error.yml +53 -0
  50. data/spec/fixtures/vcr_cassettes/featured_questions.yml +62 -0
  51. data/spec/fixtures/vcr_cassettes/linked_questions.yml +53 -0
  52. data/spec/fixtures/vcr_cassettes/noanswered_questions.yml +62 -0
  53. data/spec/fixtures/vcr_cassettes/questions.yml +165 -0
  54. data/spec/fixtures/vcr_cassettes/questions_answers.yml +63 -0
  55. data/spec/fixtures/vcr_cassettes/questions_by_ids.yml +62 -0
  56. data/spec/fixtures/vcr_cassettes/questions_comments.yml +60 -0
  57. data/spec/fixtures/vcr_cassettes/related_questions.yml +94 -0
  58. data/spec/fixtures/vcr_cassettes/timeline_questions.yml +68 -0
  59. data/spec/fixtures/vcr_cassettes/unanswered_questions.yml +62 -0
  60. data/spec/fixtures/vcr_cassettes/user_timeline.yml +73 -0
  61. data/spec/fixtures/vcr_cassettes/user_top_answers_with_given_tags.yml +64 -0
  62. data/spec/fixtures/vcr_cassettes/user_top_questions_with_given_tags.yml +66 -0
  63. data/spec/fixtures/vcr_cassettes/user_top_tags_by_answers.yml +62 -0
  64. data/spec/fixtures/vcr_cassettes/user_top_tags_by_questions.yml +58 -0
  65. data/spec/fixtures/vcr_cassettes/user_write_permissions.yml +56 -0
  66. data/spec/fixtures/vcr_cassettes/users.yml +61 -0
  67. data/spec/fixtures/vcr_cassettes/users_answers.yml +65 -0
  68. data/spec/fixtures/vcr_cassettes/users_badges.yml +60 -0
  69. data/spec/fixtures/vcr_cassettes/users_by_ids.yml +61 -0
  70. data/spec/fixtures/vcr_cassettes/users_comments.yml +74 -0
  71. data/spec/fixtures/vcr_cassettes/users_favorites_questions.yml +74 -0
  72. data/spec/fixtures/vcr_cassettes/users_featured_questions.yml +53 -0
  73. data/spec/fixtures/vcr_cassettes/users_mentioned_questions.yml +97 -0
  74. data/spec/fixtures/vcr_cassettes/users_noanswerquestions.yml +60 -0
  75. data/spec/fixtures/vcr_cassettes/users_notifications.yml +80 -0
  76. data/spec/fixtures/vcr_cassettes/users_questions.yml +67 -0
  77. data/spec/fixtures/vcr_cassettes/users_replied_comments.yml +60 -0
  78. data/spec/fixtures/vcr_cassettes/users_reputation_questions.yml +59 -0
  79. data/spec/fixtures/vcr_cassettes/users_suggested_edits.yml +72 -0
  80. data/spec/fixtures/vcr_cassettes/users_tags.yml +60 -0
  81. data/spec/fixtures/vcr_cassettes/users_unaccepted_questions.yml +65 -0
  82. data/spec/fixtures/vcr_cassettes/users_unanswered_questions.yml +77 -0
  83. data/spec/fixtures/vcr_cassettes/users_unread_notifications.yml +53 -0
  84. data/spec/helper.rb +45 -0
  85. data/spec/ruby-stackoverflow/badges_spec.rb +63 -0
  86. data/spec/ruby-stackoverflow/comments_spec.rb +31 -0
  87. data/spec/ruby-stackoverflow/question_spec.rb +90 -0
  88. data/spec/ruby-stackoverflow/user_spec.rb +289 -0
  89. data/spec/spec_helper.rb +16 -0
  90. metadata +292 -0
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rake_tasks ADDED
@@ -0,0 +1,4 @@
1
+ build
2
+ install
3
+ release
4
+ spec
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ruby-stackoverflow.gemspec
4
+ gemspec
5
+
6
+ group :test do
7
+ gem 'rspec'
8
+ end
9
+
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,6 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -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
@@ -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
@@ -0,0 +1,7 @@
1
+ module RubyStackoverflow
2
+ class Client
3
+ class Answer < Resource
4
+ end
5
+ end
6
+ end
7
+
@@ -0,0 +1,7 @@
1
+ module RubyStackoverflow
2
+ class Client
3
+ class Badge < Resource
4
+ end
5
+ end
6
+ end
7
+
@@ -0,0 +1,8 @@
1
+ module RubyStackoverflow
2
+ class Client
3
+ class Comment < Resource
4
+ end
5
+ end
6
+ end
7
+
8
+