Module: Juhe::Express

Defined in:
lib/juhe_ruby/express.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.companiesObject

Returns the value of attribute companies.



8
9
10
# File 'lib/juhe_ruby/express.rb', line 8

def companies
  @companies
end

Class Method Details

.company_code_of(company_name, options = nil) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/juhe_ruby/express.rb', line 25

def self.company_code_of(company_name, options = nil)
  refresh_companies(options) if @companies.nil?

  @companies.each do |company|
    return company["no"] if company["com"] == company_name
  end
end

.refresh_companies(options) ⇒ Object



34
35
36
37
38
39
# File 'lib/juhe_ruby/express.rb', line 34

def self.refresh_companies(options)
  app_key = (options[:app_key] if options) || Juhe::Express.app_key
  result = JSON.parse(open(BASE_URL+"/com?key="+app_key).read)
  raise result["reason"] if result["resultcode"] != "200"
  @companies = result["result"]
end

.search(company_name, number, options = nil) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/juhe_ruby/express.rb', line 12

def self.search(company_name, number, options = nil)
  app_key = (options[:app_key] if options) || Juhe::Express.app_key
  url = BASE_URL \
        + "/index?key=" + app_key \
        + "&no=" + number \
        + "&com=" + company_code_of(company_name, options)

  result = JSON.parse(open(url).read)
  raise result["reason"] if result["resultcode"] != "200"
  result["result"]
end