Skip to content

Commit 64cbd7b

Browse files
committed
added search resource with single helper to find similar questions
1 parent 7a4d8b9 commit 64cbd7b

File tree

5 files changed

+32
-6
lines changed

5 files changed

+32
-6
lines changed

lib/ruby-stackoverflow/client.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313
require 'ruby-stackoverflow/client/resource/post'
1414
require 'ruby-stackoverflow/client/resource/permission'
1515
require 'ruby-stackoverflow/client/resource/stackoverflow_error'
16+
require 'ruby-stackoverflow/client/resource/search'
1617
require 'ruby-stackoverflow/client/user_helper'
1718
require 'ruby-stackoverflow/client/question_helper'
1819
require 'ruby-stackoverflow/client/badges_helper'
1920
require 'ruby-stackoverflow/client/comments_helper'
21+
require 'ruby-stackoverflow/client/search_helper'
2022
require 'ruby-stackoverflow/client/parse_options'
2123

2224
module RubyStackoverflow
@@ -26,6 +28,7 @@ class Client
2628
include RubyStackoverflow::Client::QuestionHelper
2729
include RubyStackoverflow::Client::BadgesHelper
2830
include RubyStackoverflow::Client::CommentsHelper
31+
include RubyStackoverflow::Client::SearchHelper
2932

3033
attr_accessor :configuration
3134

lib/ruby-stackoverflow/client/resource/question.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,25 @@ def parse_data(data)
3131

3232
def data_has_answer?(data)
3333
data.first.include?(:answer_id)
34-
end
34+
end
3535

3636
def data_has_comment?(data)
3737
data.first.include?(:comment_id) && !data.first.include?(:timeline_type)
38-
end
38+
end
3939

4040
def data_has_timeline?(data)
4141
data.first.include?(:timeline_type)
42-
end
42+
end
4343

4444
def find_or_create_question(questions, qid)
4545
question_array = questions.select{|q|q.question_id == qid}
4646
!question_array.empty? ? question_array.first : new({question_id: qid})
4747
end
4848

4949

50-
def create_question(attr_hash, questions, hash_key)
50+
def create_question(attr_hash, questions, hash_key)
5151
qid = attr_hash.delete(hash_key)
52-
question = find_or_create_question(questions, qid)
52+
question = find_or_create_question(questions, qid)
5353
questions << question unless question_exists?(questions,qid)
5454
question
5555
end
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module RubyStackoverflow
2+
class Client
3+
class Search < Resource
4+
end
5+
end
6+
end
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module RubyStackoverflow
2+
class Client
3+
module SearchHelper
4+
5+
def similar(title, options={})
6+
similar_response(title, options)
7+
end
8+
9+
private
10+
11+
def similar_response(title, options={})
12+
getr 'similar', 'question', options.merge(title: title)
13+
end
14+
15+
end
16+
end
17+
end

lib/ruby-stackoverflow/client/user_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def users_unread_notifications(id, options = {})
4343
url = id + '/notifications/unread'
4444
user_response(options, url)
4545
end
46-
46+
4747
def users_with_favorites_questions(ids, options = {})
4848
ids = join_ids(ids)
4949
url = ids + '/favorites'

0 commit comments

Comments
 (0)