Class: Kashflow::Api
- Inherits:
-
Object
- Object
- Kashflow::Api
- Defined in:
- lib/kashflow/api.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
Class Method Summary collapse
Instance Method Summary collapse
- #api_page ⇒ Object
- #import ⇒ Object
-
#initialize(name, page) ⇒ Api
constructor
A new instance of Api.
Constructor Details
#initialize(name, page) ⇒ Api
Returns a new instance of Api.
44 45 46 47 |
# File 'lib/kashflow/api.rb', line 44 def initialize(name, page) @name = name @page = page end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
43 44 45 |
# File 'lib/kashflow/api.rb', line 43 def name @name end |
#page ⇒ Object (readonly)
Returns the value of attribute page.
43 44 45 |
# File 'lib/kashflow/api.rb', line 43 def page @page end |
Class Method Details
.api_page(path) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/kashflow/api.rb', line 13 def api_page(path) cache_path = File.join(Kashflow.root, 'tmp', 'kf_api_pages', path) unless File.exists?(cache_path) File.open(cache_path, 'w'){ |f| f << open("http://accountingapi.com/#{path}").read } end Nokogiri::HTML(open(cache_path)) end |
.apis_from_web ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/kashflow/api.rb', line 23 def apis_from_web main_page = api_page('manual_class_customer.asp') main_page.search('#mr_manual_inner a').select do |node| node['href'] =~ /manual_methods/ and node['href'] != 'manual_methods_overview.asp' end.map{|n| new(n.content, n['href']) } end |
Instance Method Details
#api_page ⇒ Object
49 50 51 |
# File 'lib/kashflow/api.rb', line 49 def api_page @api_page ||= self.class.api_page(page) end |
#import ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/kashflow/api.rb', line 53 def import @fields ||= api_page.search('.mnl_tbl1 tr').map do |row| { :name => row.search('span.mnl_varName').first.try(:content), :type => row.search('span.mnl_varType').first.try(:content), :direction => row.search('td strong').first.try(:content), :desc => row.search('td').last.try(:content) } end end |