itis 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in itis.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Oto Brglez
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,4 @@
1
+ # Itis - Ruby API for Telefonski Imenik Slovenije
2
+
3
+ This API uses search suggestion/opensearch and XML to do lookups.
4
+ GEM also installs simple command line tool.
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # Itis - Ruby API for Telefonski Imenik Slovenije
2
+
3
+ This API uses search suggestion/opensearch and XML to do lookups.
4
+ GEM also installs simple command line tool.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'itis'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install itis
19
+
20
+ ## Usade in the code
21
+
22
+ results = Itis.search("Oto Brglez")
23
+
24
+ phones = Itis.search("Oto Brglez").first.phones
25
+
26
+ ## Comand line usage
27
+
28
+ itis "Oto Brglez"
29
+
30
+
31
+ ## Contributing
32
+
33
+ 1. Fork it
34
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
35
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
36
+ 4. Push to the branch (`git push origin my-new-feature`)
37
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # #!/usr/bin/env rake
2
+ # require "bundler/gem_tasks"
3
+
4
+ #require 'rake/testtask'
5
+ #Rake::TestTask.new do |t|
6
+ # t.libs << 'test'
7
+ #end
8
+ #desc "Run tests"
9
+ #task :default => :test
10
+
11
+ require 'bundler'
12
+ Bundler::GemHelper.install_tasks
data/bin/itis ADDED
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'itis'
4
+
5
+ if ARGV[0].nil?
6
+ puts("Missing search attribute...")
7
+ exit(1)
8
+ end
9
+
10
+ results = Itis.search(ARGV[0])
11
+
12
+ unless results.empty?
13
+ results.each do |result|
14
+ if result.person?
15
+ puts "#{result.text} - #{result.description} - #{result.phones.join(",")}"
16
+ else
17
+ puts "#{result.text} - #{result.description}"
18
+ end
19
+ end
20
+ else
21
+ puts "No results."
22
+ end
data/itis.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/itis/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Oto Brglez"]
6
+ gem.email = ["otobrglez@gmail.com"]
7
+ gem.description = %q{Ruby API for TIS}
8
+ gem.summary = %q{Ruby API and console client for Telefonski Imenik Slovenije}
9
+ gem.homepage = "https://github.com/otobrglez/itis"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "itis"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = '0.0.1'
17
+
18
+ gem.has_rdoc = false
19
+ gem.bindir = 'bin'
20
+
21
+ # gem.add_development_dependency 'mechanize'
22
+ gem.add_dependency "httparty"
23
+ gem.add_dependency "nokogiri"
24
+ gem.add_development_dependency 'rspec'
25
+ gem.add_development_dependency 'rake'
26
+ end
@@ -0,0 +1,3 @@
1
+ class Itis
2
+ VERSION="0.0.1"
3
+ end
data/lib/itis.rb ADDED
@@ -0,0 +1,65 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ # By Oto Brglez - <oto.brglez@opalab.com>
4
+ require "httparty"
5
+ require "nokogiri"
6
+
7
+ class ItisItem
8
+ attr_accessor :text, :description, :url
9
+
10
+ def initialize element
11
+ @text = element.at("Text").content.strip
12
+ @url = element.at("Url").content.strip
13
+ @description = element.at("Description").content.strip
14
+ self
15
+ end
16
+
17
+ def to_s; @text end
18
+ def person?; (@url =~ /Person/i)? true: false end
19
+
20
+ def id
21
+ Regexp.last_match[0] if @url.match(/\d+/) and person?
22
+ end
23
+
24
+ def phones
25
+ out = HTTParty.get("http://www.itis.si/AAA-AAA?#{id}").parsed_response if person?
26
+ end
27
+
28
+ class HTTParty::Parser
29
+ def noko
30
+ doc = Nokogiri::HTML(body)
31
+ doc.remove_namespaces!
32
+ results = doc.css("p.nums span.phone").to_a
33
+ return results.map!{|phone| phone.content } unless results.empty?
34
+ []
35
+ end
36
+ end
37
+ end
38
+
39
+ class SearchSuggestionParser < HTTParty::Parser
40
+ SupportedFormats.merge!('text/html' => :noko) # Service retursn HTML!
41
+ SupportedFormats.merge!('text/xml' => :noko)
42
+
43
+ def noko
44
+ doc = Nokogiri::XML(body)
45
+ doc.remove_namespaces!
46
+ results = doc.xpath("//Item").to_a
47
+ return results.map!{|element| ItisItem.new(element)} unless results.empty?
48
+ []
49
+ end
50
+ end
51
+
52
+ class Itis
53
+
54
+ include HTTParty
55
+ base_uri 'www.itis.si'
56
+ parser SearchSuggestionParser
57
+
58
+ def search(q)
59
+ self.class.get('/Page_VisualSearch.aspx',:query => {q: q}).parsed_response
60
+ end
61
+
62
+ def self.search(q)
63
+ Itis.new.search(q)
64
+ end
65
+ end
data/spec/itis_spec.rb ADDED
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe Itis do
4
+
5
+ it "should return some results if you do query" do
6
+ out = Itis.new.search("Oto Brglez")
7
+ out.should_not be_nil
8
+ out.should be_an_instance_of(Array)
9
+ out.size.should == 1
10
+
11
+ out.first.to_s.should =~ /Oto/i
12
+ out.first.url.should =~ /person/i
13
+ out.first.should be_person
14
+ end
15
+
16
+ it "should do some searches with more results" do
17
+ out = Itis.search("Janez Novak")
18
+ out.size.should_not == 0
19
+ out.first.should_not be_person
20
+ end
21
+
22
+ it "has the ability to do contact lookup" do
23
+ out = Itis.new.search("Oto Brglez").first
24
+ out.should_not be_nil
25
+ out.phones.size.should == 2
26
+ end
27
+
28
+ end
@@ -0,0 +1,7 @@
1
+ Dir[File.dirname(__FILE__) + '/../lib/**/*.rb'].each {|file| require file }
2
+
3
+ RSpec.configure do |config|
4
+ config.treat_symbols_as_metadata_keys_with_true_values = true
5
+ config.run_all_when_everything_filtered = true
6
+ config.filter_run :focus
7
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: itis
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Oto Brglez
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2012-06-06 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: httparty
17
+ requirement: &id001 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "0"
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: nokogiri
28
+ requirement: &id002 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
38
+ name: rspec
39
+ requirement: &id003 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: "0"
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *id003
48
+ - !ruby/object:Gem::Dependency
49
+ name: rake
50
+ requirement: &id004 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: *id004
59
+ description: Ruby API for TIS
60
+ email:
61
+ - otobrglez@gmail.com
62
+ executables:
63
+ - itis
64
+ extensions: []
65
+
66
+ extra_rdoc_files: []
67
+
68
+ files:
69
+ - .gitignore
70
+ - .rspec
71
+ - Gemfile
72
+ - LICENSE
73
+ - README
74
+ - README.md
75
+ - Rakefile
76
+ - bin/itis
77
+ - itis.gemspec
78
+ - lib/itis.rb
79
+ - lib/itis/version.rb
80
+ - spec/itis_spec.rb
81
+ - spec/spec_helper.rb
82
+ homepage: https://github.com/otobrglez/itis
83
+ licenses: []
84
+
85
+ post_install_message:
86
+ rdoc_options: []
87
+
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ hash: -1227818931761413211
96
+ segments:
97
+ - 0
98
+ version: "0"
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ hash: -1227818931761413211
105
+ segments:
106
+ - 0
107
+ version: "0"
108
+ requirements: []
109
+
110
+ rubyforge_project:
111
+ rubygems_version: 1.8.15
112
+ signing_key:
113
+ specification_version: 3
114
+ summary: Ruby API and console client for Telefonski Imenik Slovenije
115
+ test_files:
116
+ - spec/itis_spec.rb
117
+ - spec/spec_helper.rb