Module: AsiaSearch::Base::InstanceMethods

Defined in:
lib/asiasearch.rb

Constant Summary collapse

KE =
"http://asia.search.yahooapis.com/cas/v1/ke"
WS =
"http://asia.search.yahooapis.com/cas/v1/ws"

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#maxnumObject (readonly)

Returns the value of attribute maxnum.



27
28
29
# File 'lib/asiasearch.rb', line 27

def maxnum
  @maxnum
end

#thresholdObject (readonly)

Returns the value of attribute threshold.



27
28
29
# File 'lib/asiasearch.rb', line 27

def threshold
  @threshold
end

Instance Method Details

#ke(maxnum = 5, threshold = 30) ⇒ Object



41
42
43
44
45
46
47
48
49
# File 'lib/asiasearch.rb', line 41

def ke(maxnum=5,threshold=30)
  params = {
    :content => keyword_content,
    :threshold => threshold,
    :maxnum => maxnum,
  }
  result = request(KE, params)
  return result
end

#request(path, params) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/asiasearch.rb', line 51

def request(path, params)
  agent = Mechanize.new
  appid = AsiaSearch.config["appid"]
  
  params.merge!({:appid => appid, :format => "json" })
  
  agent.post(path,params)
  data = agent.current_page.body
  result = JSON.parse(data)
  return result
end

#wsObject



33
34
35
36
37
38
39
# File 'lib/asiasearch.rb', line 33

def ws
  params = {
    :content => keyword_content,
  }
  result = request(WS, params)
  return result
end