Class: Yapi::JIMService

Inherits:
Object
  • Object
show all
Defined in:
lib/yapi/jim_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key) ⇒ JIMService

Returns a new instance of JIMService.



9
10
11
12
# File 'lib/yapi/jim_service.rb', line 9

def initialize(api_key)
  @client = Client.new(api_key)
  self.config = {}
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



7
8
9
# File 'lib/yapi/jim_service.rb', line 7

def config
  @config
end

Instance Method Details

#configure(options = {}) ⇒ Object



14
15
16
17
18
# File 'lib/yapi/jim_service.rb', line 14

def configure(options = {})
  options.each do |key, value|
    self.config[key] = value
  end
end

#conversion(sentence) ⇒ Object



20
21
22
23
# File 'lib/yapi/jim_service.rb', line 20

def conversion sentence
  req_url = "http://jlp.yahooapis.jp/JIMService/V1/conversion?appid=#{@client.get_api_key}#{@client.build_url(self.config)}&sentence=#{sentence}"
  return @client.xml_to_json(open(URI.encode(req_url)).read)[:ResultSet][:Result]
end