class Yiban::Base

Public Instance Methods

json() click to toggle source
# File lib/yiban/base.rb, line 33
def json
  JSON.parse(response.body)
end
response() click to toggle source
# File lib/yiban/base.rb, line 10
def response
  uri = URI.parse("https://api.yiban.io/title/search")
  request = Net::HTTP::Post.new(uri)
  request.content_type = "application/json"

  request["X-Extension-Token"] = Yiban.config[:extension_token]

  request.body = JSON.dump({
    "keyword": @text,
    "size": @size,
    "page": 1
  })


  req_options = {
    use_ssl: uri.scheme == "https",
  }

  response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
    http.request(request)
  end
end