ruby-stackoverflow 0.0.2 → 0.0.3

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 (76) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +5 -0
  3. data/CHANGELOG.md +4 -0
  4. data/Gemfile +0 -5
  5. data/README.md +5 -6
  6. data/lib/generators/ruby_stackoverflow/ruby_stackoverflow_generator.rb +2 -6
  7. data/lib/ruby-stackoverflow.rb +2 -5
  8. data/lib/ruby-stackoverflow/client/badges_helper.rb +23 -26
  9. data/lib/ruby-stackoverflow/client/comments_helper.rb +5 -7
  10. data/lib/ruby-stackoverflow/client/parse_options.rb +2 -3
  11. data/lib/ruby-stackoverflow/client/question_helper.rb +1 -3
  12. data/lib/ruby-stackoverflow/client/resource/answer.rb +0 -1
  13. data/lib/ruby-stackoverflow/client/resource/badge.rb +0 -1
  14. data/lib/ruby-stackoverflow/client/resource/comment.rb +0 -2
  15. data/lib/ruby-stackoverflow/client/resource/notification.rb +0 -2
  16. data/lib/ruby-stackoverflow/client/resource/permission.rb +0 -2
  17. data/lib/ruby-stackoverflow/client/resource/post.rb +0 -1
  18. data/lib/ruby-stackoverflow/client/resource/question.rb +5 -7
  19. data/lib/ruby-stackoverflow/client/resource/suggested_edit.rb +0 -2
  20. data/lib/ruby-stackoverflow/client/resource/tag.rb +0 -13
  21. data/lib/ruby-stackoverflow/client/resource/user.rb +4 -4
  22. data/lib/ruby-stackoverflow/client/response_data.rb +3 -3
  23. data/lib/ruby-stackoverflow/client/user_helper.rb +9 -5
  24. data/lib/ruby-stackoverflow/configuration.rb +1 -1
  25. data/lib/ruby-stackoverflow/version.rb +1 -1
  26. data/ruby-stackoverflow.gemspec +2 -1
  27. data/spec/fixtures/vcr_cassettes/badges.yml +2 -2
  28. data/spec/fixtures/vcr_cassettes/badges_by_ids.yml +2 -2
  29. data/spec/fixtures/vcr_cassettes/badges_by_name.yml +2 -2
  30. data/spec/fixtures/vcr_cassettes/badges_by_recipients.yml +2 -2
  31. data/spec/fixtures/vcr_cassettes/badges_by_recipients_by_ids.yml +2 -2
  32. data/spec/fixtures/vcr_cassettes/badges_by_tags.yml +2 -2
  33. data/spec/fixtures/vcr_cassettes/comments.yml +2 -2
  34. data/spec/fixtures/vcr_cassettes/comments_by_ids.yml +2 -2
  35. data/spec/fixtures/vcr_cassettes/error.yml +2 -2
  36. data/spec/fixtures/vcr_cassettes/featured_questions.yml +2 -2
  37. data/spec/fixtures/vcr_cassettes/linked_questions.yml +2 -2
  38. data/spec/fixtures/vcr_cassettes/noanswered_questions.yml +2 -2
  39. data/spec/fixtures/vcr_cassettes/questions.yml +2 -2
  40. data/spec/fixtures/vcr_cassettes/questions_answers.yml +2 -2
  41. data/spec/fixtures/vcr_cassettes/questions_by_ids.yml +2 -2
  42. data/spec/fixtures/vcr_cassettes/questions_comments.yml +2 -2
  43. data/spec/fixtures/vcr_cassettes/related_questions.yml +2 -2
  44. data/spec/fixtures/vcr_cassettes/timeline_questions.yml +2 -2
  45. data/spec/fixtures/vcr_cassettes/unanswered_questions.yml +2 -2
  46. data/spec/fixtures/vcr_cassettes/user_timeline.yml +2 -2
  47. data/spec/fixtures/vcr_cassettes/user_top_answers_with_given_tags.yml +2 -2
  48. data/spec/fixtures/vcr_cassettes/user_top_questions_with_given_tags.yml +2 -2
  49. data/spec/fixtures/vcr_cassettes/user_top_tags_by_answers.yml +2 -2
  50. data/spec/fixtures/vcr_cassettes/user_top_tags_by_questions.yml +2 -2
  51. data/spec/fixtures/vcr_cassettes/user_write_permissions.yml +2 -2
  52. data/spec/fixtures/vcr_cassettes/users.yml +2 -2
  53. data/spec/fixtures/vcr_cassettes/users_answers.yml +2 -2
  54. data/spec/fixtures/vcr_cassettes/users_badges.yml +2 -2
  55. data/spec/fixtures/vcr_cassettes/users_by_ids.yml +2 -2
  56. data/spec/fixtures/vcr_cassettes/users_comments.yml +2 -2
  57. data/spec/fixtures/vcr_cassettes/users_favorites_questions.yml +2 -2
  58. data/spec/fixtures/vcr_cassettes/users_featured_questions.yml +2 -2
  59. data/spec/fixtures/vcr_cassettes/users_mentioned_questions.yml +2 -2
  60. data/spec/fixtures/vcr_cassettes/users_noanswerquestions.yml +2 -2
  61. data/spec/fixtures/vcr_cassettes/users_notifications.yml +2 -2
  62. data/spec/fixtures/vcr_cassettes/users_questions.yml +2 -2
  63. data/spec/fixtures/vcr_cassettes/users_replied_comments.yml +2 -2
  64. data/spec/fixtures/vcr_cassettes/users_reputation_questions.yml +2 -2
  65. data/spec/fixtures/vcr_cassettes/users_suggested_edits.yml +2 -2
  66. data/spec/fixtures/vcr_cassettes/users_tags.yml +2 -2
  67. data/spec/fixtures/vcr_cassettes/users_unaccepted_questions.yml +2 -2
  68. data/spec/fixtures/vcr_cassettes/users_unanswered_questions.yml +2 -2
  69. data/spec/fixtures/vcr_cassettes/users_unread_notifications.yml +2 -2
  70. data/spec/helper.rb +1 -1
  71. data/spec/ruby-stackoverflow/badges_spec.rb +14 -8
  72. data/spec/ruby-stackoverflow/comments_spec.rb +4 -2
  73. data/spec/ruby-stackoverflow/question_spec.rb +24 -14
  74. data/spec/ruby-stackoverflow/user_spec.rb +51 -58
  75. data/spec/spec_helper.rb +3 -3
  76. metadata +39 -43
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cb8981bf4df204818eb1552cbba8de8571631c0d
4
+ data.tar.gz: 67b8d1ba0886d74548215f457bf33d7ef04e1e80
5
+ SHA512:
6
+ metadata.gz: 6ca616d8ac6f408d6a46aef8f8bd5439374f39913a24e79d79bf77562a43a9b809b4813d5b3996de99623ba48809adbb213ce89238de248531a3ffc0eedea064
7
+ data.tar.gz: 158e5ea960dca0786cdce59885cb4e8ca51015c51abd3a7380b36c8f954f317a916edeed18f7dc4c08c3ca776d4d61a8a4d9896ad12981bef65d37361b7b225d
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.1
4
+ notifications:
5
+ email: false
@@ -0,0 +1,4 @@
1
+ 0.0.3 - 12-03-2015
2
+
3
+ Using v2.2 Stackoverflow API (by @ondrejbartas)
4
+ Added `has_more` variable to know if there is more data in response by (@eranhirs)
data/Gemfile CHANGED
@@ -2,8 +2,3 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in ruby-stackoverflow.gemspec
4
4
  gemspec
5
-
6
- group :test do
7
- gem 'rspec'
8
- end
9
-
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Ruby::Stackoverflow
1
+ # Ruby::Stackoverflow [![Code Climate](https://codeclimate.com/github/raysrashmi/ruby-stackoverflow.png)](https://codeclimate.com/github/raysrashmi/ruby-stackoverflow)
2
2
 
3
3
  Ruby toolkit to Stackoverflow API
4
4
 
@@ -20,11 +20,11 @@ Or install it yourself as:
20
20
 
21
21
  <a href='https://github.com/raysrashmi/ruby-stackoverflow/wiki/Users-calls'>User Calls</a>
22
22
  <br/>
23
- <a href='https://github.com/raysrashmi/ruby-stackoverflow/wiki/Users-calls'>Questions Calls</a>
23
+ <a href='https://github.com/raysrashmi/ruby-stackoverflow/wiki/Questions-Calls'>Questions Calls</a>
24
24
  <br/>
25
- <a href='https://github.com/raysrashmi/ruby-stackoverflow/wiki/Users-calls'>Badges Calls</a>
25
+ <a href='https://github.com/raysrashmi/ruby-stackoverflow/wiki/Badges-calls'>Badges Calls</a>
26
26
  <br/>
27
- <a href='https://github.com/raysrashmi/ruby-stackoverflow/wiki/Users-calls'>Badges Calls</a>
27
+ <a href='https://github.com/raysrashmi/ruby-stackoverflow/wiki/Comments-calls'>Comments Calls</a>
28
28
  <br/>
29
29
 
30
30
  ##Configuration
@@ -33,7 +33,7 @@ You can add your key and access-token for higher rate limit.
33
33
  To get Key and Access Token you have to register your app to http://stackapps.com/
34
34
  Run command in your application dir.
35
35
 
36
- $ rails generate ruby-stackoverflow --client_key=<key> --access_token=<access token>
36
+ $ rails generate ruby_stackoverflow --client_key=<key> --access_token=<access token>
37
37
 
38
38
  This command will create a ruby_stackoverflow.rb file in config/initializers.
39
39
 
@@ -47,4 +47,3 @@ This command will create a ruby_stackoverflow.rb file in config/initializers.
47
47
 
48
48
  ##LICENSE
49
49
 
50
-
@@ -14,7 +14,7 @@ class RubyStackoverflowGenerator < Rails::Generators::Base
14
14
  end
15
15
 
16
16
  private
17
-
17
+
18
18
  def configuration_output
19
19
  output = <<-eos
20
20
  RubyStackoverflow.configure do|config|
@@ -24,8 +24,4 @@ end
24
24
  eos
25
25
  output
26
26
  end
27
-
28
-
29
- end
30
-
31
-
27
+ end
@@ -8,8 +8,7 @@ module RubyStackoverflow
8
8
 
9
9
  class << self
10
10
  def client
11
- @client = RubyStackoverflow::Client.new unless defined?(@client)
12
- @client
11
+ @client ||= RubyStackoverflow::Client.new
13
12
  end
14
13
 
15
14
  # @private
@@ -17,13 +16,11 @@ module RubyStackoverflow
17
16
  # @private
18
17
  def respond_to?(method_name, include_private=false); client.respond_to?(method_name, include_private) || super; end if RUBY_VERSION < "1.9"
19
18
 
20
- private
19
+ private
21
20
 
22
21
  def method_missing(method_name, *args, &block)
23
22
  return super unless client.respond_to?(method_name)
24
23
  client.send(method_name, *args, &block)
25
24
  end
26
-
27
25
  end
28
26
  end
29
-
@@ -1,49 +1,46 @@
1
1
  module RubyStackoverflow
2
2
  class Client
3
3
  module BadgesHelper
4
-
5
- def badges(options={})
4
+ def badges(options = {})
6
5
  badges_response(options)
7
- end
6
+ end
8
7
 
9
- def badges_by_ids(ids, options={})
10
- ids = join_ids(ids)
11
- url = ids
8
+ def badges_by_ids(ids, options = {})
9
+ url = join_ids(ids)
12
10
  badges_response(options, url)
13
- end
11
+ end
14
12
 
15
- def badges_by_ids(ids, options={})
16
- ids = join_ids(ids)
17
- url = ids
13
+ def badges_by_ids(ids, options = {})
14
+ url = join_ids(ids)
18
15
  badges_response(options, url)
19
- end
16
+ end
20
17
 
21
- def badges_by_name(options={})
22
- url ='/name'
18
+ def badges_by_name(options = {})
19
+ url = "/name"
23
20
  badges_response(options, url)
24
- end
21
+ end
25
22
 
26
- def badges_between_dates(options={})
27
- url ='/recipients'
23
+ def badges_between_dates(options = {})
24
+ url = "/recipients"
28
25
  badges_response(options, url)
29
- end
26
+ end
30
27
 
31
- def badges_between_dates_by_ids(ids,options={})
28
+ def badges_between_dates_by_ids(ids, options = {})
32
29
  ids = join_ids(ids)
33
- url = ids + '/recipients'
30
+ url = ids + "/recipients"
34
31
  badges_response(options, url)
35
- end
32
+ end
36
33
 
37
- def badges_by_tags(options={})
38
- url = '/tags'
34
+ def badges_by_tags(options = {})
35
+ url = "/tags"
39
36
  badges_response(options, url)
40
- end
37
+ end
41
38
 
42
39
  private
43
40
 
44
- def badges_response(options={}, url='')
45
- url = 'badges/'+ url
46
- getr(url,'badge',options)
41
+ def badges_response(options = {}, url= "")
42
+ url = "badges/" + url
43
+ getr(url, "badge", options)
47
44
  end
48
45
  end
49
46
  end
@@ -1,22 +1,20 @@
1
1
  module RubyStackoverflow
2
2
  class Client
3
3
  module CommentsHelper
4
-
5
4
  def comments(options = {})
6
- comments_response(options)
5
+ comments_response(options)
7
6
  end
8
-
7
+
9
8
  def comments_by_ids(ids, options = {})
10
- ids = join_ids(ids)
11
- url = ids
12
- comments_response(options, url)
9
+ url = join_ids(ids)
10
+ comments_response(options, url)
13
11
  end
14
12
 
15
13
  private
16
14
 
17
15
  def comments_response(options={}, url='')
18
16
  url = 'comments/' + url
19
- getr(url,'comment',options)
17
+ getr(url, 'comment', options)
20
18
  end
21
19
  end
22
20
  end
@@ -1,20 +1,19 @@
1
1
  module RubyStackoverflow
2
2
  class Client
3
3
  module ParseOptions
4
-
5
4
  def parse_options(options = {})
6
5
  options.each do|k,v|
7
6
  case k
8
7
  when :fromdate , :todate, :min, :max
9
8
  begin
10
- options[k] = Date.parse(v).to_time.to_i
9
+ options[k] = Time.parse(v).to_i
11
10
  rescue
12
11
  options[k] = v
13
12
  end
14
13
  else
15
14
  options[k] = v
16
15
  end
17
- end
16
+ end
18
17
  end
19
18
 
20
19
  def join_ids(ids)
@@ -1,7 +1,6 @@
1
1
  module RubyStackoverflow
2
2
  class Client
3
3
  module QuestionHelper
4
-
5
4
  def questions(options = {})
6
5
  question_response(options)
7
6
  end
@@ -51,10 +50,9 @@ module RubyStackoverflow
51
50
 
52
51
  private
53
52
 
54
-
55
53
  def question_response(options={}, url='')
56
54
  url = 'questions/' + url
57
- getr(url,'question',options)
55
+ getr(url, 'question', options)
58
56
  end
59
57
  end
60
58
  end
@@ -4,4 +4,3 @@ module RubyStackoverflow
4
4
  end
5
5
  end
6
6
  end
7
-
@@ -4,4 +4,3 @@ module RubyStackoverflow
4
4
  end
5
5
  end
6
6
  end
7
-
@@ -4,5 +4,3 @@ module RubyStackoverflow
4
4
  end
5
5
  end
6
6
  end
7
-
8
-
@@ -4,5 +4,3 @@ module RubyStackoverflow
4
4
  end
5
5
  end
6
6
  end
7
-
8
-
@@ -4,5 +4,3 @@ module RubyStackoverflow
4
4
  end
5
5
  end
6
6
  end
7
-
8
-
@@ -1,4 +1,3 @@
1
-
2
1
  module RubyStackoverflow
3
2
  class Client
4
3
  class Post < Resource
@@ -31,15 +31,15 @@ module RubyStackoverflow
31
31
 
32
32
  def data_has_answer?(data)
33
33
  data.first.include?(:answer_id)
34
- end
34
+ end
35
35
 
36
36
  def data_has_comment?(data)
37
37
  data.first.include?(:comment_id) && !data.first.include?(:timeline_type)
38
- end
38
+ end
39
39
 
40
40
  def data_has_timeline?(data)
41
41
  data.first.include?(:timeline_type)
42
- end
42
+ end
43
43
 
44
44
  def find_or_create_question(questions, qid)
45
45
  question_array = questions.select{|q|q.question_id == qid}
@@ -47,9 +47,9 @@ module RubyStackoverflow
47
47
  end
48
48
 
49
49
 
50
- def create_question(attr_hash, questions, hash_key)
50
+ def create_question(attr_hash, questions, hash_key)
51
51
  qid = attr_hash.delete(hash_key)
52
- question = find_or_create_question(questions, qid)
52
+ question = find_or_create_question(questions, qid)
53
53
  questions << question unless question_exists?(questions,qid)
54
54
  question
55
55
  end
@@ -58,9 +58,7 @@ module RubyStackoverflow
58
58
  question_array = questions.select{|q|q.question_id == question_id }
59
59
  !question_array.empty?
60
60
  end
61
-
62
61
  end
63
-
64
62
  end
65
63
  end
66
64
  end
@@ -4,5 +4,3 @@ module RubyStackoverflow
4
4
  end
5
5
  end
6
6
  end
7
-
8
-
@@ -1,19 +1,6 @@
1
1
  module RubyStackoverflow
2
2
  class Client
3
3
  class Tag < Resource
4
- #def initialize(attributes_hash)
5
- #Tag.define_atribute_methods(attributes_hash)
6
- #end
7
-
8
- #class << self
9
- #def define_atribute_methods(attributes_hash)
10
- #attributes_hash.each do|k,v|
11
- #define_method(k) do v; end
12
- #end
13
- #end
14
- #end
15
4
  end
16
5
  end
17
6
  end
18
-
19
-
@@ -1,7 +1,7 @@
1
1
  module RubyStackoverflow
2
2
  class Client
3
3
  class User < Resource
4
- attr_reader :badges, :answers, :comments,
4
+ attr_reader :badges, :answers, :comments,
5
5
  :questions, :reputations,
6
6
  :suggested_edits, :tags, :posts, :permissions
7
7
 
@@ -65,10 +65,10 @@ module RubyStackoverflow
65
65
  !user_array.empty? ? user_array.first : new(user_attr)
66
66
  end
67
67
 
68
- def create_user(attr_hash, users, hash_key=:owner)
68
+ def create_user(attr_hash, users, hash_key=:owner)
69
69
  user_attr = attr_hash.delete(hash_key)
70
- user_attr = user_attr.is_a?(Hash) ? user_attr : {user_id: user_attr }
71
- user = find_or_create_user(users, user_attr)
70
+ user_attr = user_attr.is_a?(Hash) ? user_attr : {user_id: user_attr }
71
+ user = find_or_create_user(users, user_attr)
72
72
  users << user unless user_exists?(users, user_attr[:user_id])
73
73
  user
74
74
  end
@@ -1,14 +1,14 @@
1
-
2
1
  module RubyStackoverflow
3
2
  class Client
4
3
  class ResponseData
5
- attr_reader :data, :error
4
+ attr_reader :data, :has_more, :error
6
5
 
7
6
  def initialize(response, klass)
8
7
  if response[:items].nil?
9
- @error = StackoverflowError.new(response)
8
+ @error = StackoverflowError.new(response)
10
9
  else
11
10
  @data = format_data(response[:items], klass)
11
+ @has_more = response[:has_more]
12
12
  end
13
13
  end
14
14
 
@@ -34,16 +34,16 @@ module RubyStackoverflow
34
34
  user_response(options, url)
35
35
  end
36
36
 
37
- def users_notifications(id, options = {})
37
+ def users_notifications(id, options = {})
38
38
  url = id + '/notifications'
39
39
  user_response(options, url)
40
40
  end
41
41
 
42
- def users_unread_notifications(id, options = {})
42
+ def users_unread_notifications(id, options = {})
43
43
  url = id + '/notifications/unread'
44
44
  user_response(options, url)
45
45
  end
46
-
46
+
47
47
  def users_with_favorites_questions(ids, options = {})
48
48
  ids = join_ids(ids)
49
49
  url = ids + '/favorites'
@@ -114,6 +114,11 @@ module RubyStackoverflow
114
114
  user_response(options, url)
115
115
  end
116
116
 
117
+ def user_top_tags(id, options ={})
118
+ url = id + '/top-tags'
119
+ user_response(options, url)
120
+ end
121
+
117
122
  def user_top_tags_by_answers(id, options ={})
118
123
  url = id + '/top-answer-tags'
119
124
  user_response(options, url)
@@ -142,10 +147,9 @@ module RubyStackoverflow
142
147
 
143
148
  private
144
149
 
145
-
146
150
  def user_response(options={}, url='')
147
151
  url = 'users/'+ url
148
- getr(url,'user',options)
152
+ getr(url, 'user', options)
149
153
  end
150
154
  end
151
155
  end