Class: WebService::Aboutme::API
- Inherits:
-
Object
- Object
- WebService::Aboutme::API
- Defined in:
- lib/webservice/aboutme/api.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
Instance Method Summary collapse
-
#initialize(args = {}, &block) ⇒ API
constructor
Takes initialization parameters or a block to override default setttings.
-
#search_answer(params) ⇒ Object
Looks up and returns a list of answers.
-
#search_question(params) ⇒ Object
Looks up and returns a list of questions.
-
#search_user(params = {}) ⇒ Object
Looks up and returns a list of users.
-
#show_answer(id) ⇒ Object
Takes numeric id and returns information of the answer.
-
#show_answer_digest(id) ⇒ Object
Takes numeric question id and returns summary of answers for the question.
-
#show_question(id) ⇒ Object
Takes numeric id and returns information of the question.
-
#show_user(id) ⇒ Object
Takes numeric id and returns information of the user.
Constructor Details
#initialize(args = {}, &block) ⇒ API
Takes initialization parameters or a block to override default setttings. You can pass parameters like this,
client = WebService::Aboutme::API.new(
:open_timeout => 5,
:read_timeout => 7,
)
or, override default parameters with a block,
client = WebService::Aboutme::API.new do |c|
c.open_timeout = 5
c.read_timeout = 7
end
Or, just call new with no argument to create default instance.
client = WebService::Aboutme::API.new
See Config class for further information.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/webservice/aboutme/api.rb', line 38 def initialize(args = {}, &block) uri = REQUEST_URI_BASE @config = Config.new do |c| c.request_path_base = uri.path c.request_domain = args[:request_domain] || REQUEST_URI_BASE.host c.request_port = args[:request_port] || REQUEST_URI_BASE.port c.open_timeout = args[:open_timeout] || DEFAULT_OPEN_TIMEOUT c.read_timeout = args[:read_timeout] || DEFAULT_READ_TIMEOUT c.user_agent = "Aboutme API client for Ruby ver-#{Version.to_version}" end if block_given? block.call @config end end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
19 20 21 |
# File 'lib/webservice/aboutme/api.rb', line 19 def config @config end |
Instance Method Details
#search_answer(params) ⇒ Object
Looks up and returns a list of answers. Lookup key should be one of :user, :text, :gender, or :age, and :question is required.
response = client.search_answer(:question => 987,
:age => '30s',
:order => 'new_to_old',
:hits => 20,
:page => 1)
response.answers.each {|ans| do_something }
126 127 128 |
# File 'lib/webservice/aboutme/api.rb', line 126 def search_answer(params) request(SearchAnswerRequest, SearchAnswerResponse, params) end |
#search_question(params) ⇒ Object
Looks up and returns a list of questions. Lookup key should be one of :owenr, :answerer, or :text.
response = client.search_question(:owner => 'aboutme-user',
:order => 'hot',
:hits => 20,
:page => 1)
response.questions.each {|q| do_something }
102 103 104 |
# File 'lib/webservice/aboutme/api.rb', line 102 def search_question(params) request(SearchQuestionRequest, SearchQuestionResponse, params) end |
#search_user(params = {}) ⇒ Object
Looks up and returns a list of users. Lookup key should be one of :nickname, :interest, :followers, or :contacts.
response = client.search_user(:nickname => 'aboutme-user',
:order => 'now_to_old,
:hits => 20,
:page => 1)
response.users.each {|user| do_something }
80 81 82 |
# File 'lib/webservice/aboutme/api.rb', line 80 def search_user(params = {}) request(SearchUserRequest, SearchUserResponse, params) end |
#show_answer(id) ⇒ Object
Takes numeric id and returns information of the answer.
response = client.show_question(987) # => #<ShowAnswerResponse>
answer = response.answer
111 112 113 |
# File 'lib/webservice/aboutme/api.rb', line 111 def show_answer(id) request(ShowAnswerRequest, ShowAnswerResponse, :id => id) end |
#show_answer_digest(id) ⇒ Object
Takes numeric question id and returns summary of answers for the question.
response = client.show_answer_digest(987) # => #<ShowAnswerDigestResponse>
response.digest.each {|d| do_something }
135 136 137 |
# File 'lib/webservice/aboutme/api.rb', line 135 def show_answer_digest(id) request(ShowAnswerDigestRequest, ShowAnswerDigestResponse, :id => id) end |
#show_question(id) ⇒ Object
Takes numeric id and returns information of the question.
response = client.show_question(123) # => #<ShowQuestionResponse>
question = response.question
89 90 91 |
# File 'lib/webservice/aboutme/api.rb', line 89 def show_question(id) request(ShowQuestionRequest, ShowQuestionResponse, :id => id) end |
#show_user(id) ⇒ Object
Takes numeric id and returns information of the user.
response = client.show_user(1) # => #<ShowUserResponse>
user = response.user
67 68 69 |
# File 'lib/webservice/aboutme/api.rb', line 67 def show_user(id) request(ShowUserRequest, ShowUserResponse, :id => id) end |