hh 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NjI2ZTZhMDUyOWU3MjRjNDNhOWYwYTBhMTkyMjQ3MmYyYjM0NGVkYg==
5
+ data.tar.gz: !binary |-
6
+ NTg2MmMzYmFmMzJlNmM5YTQyODYyNjdkNDg5MGVjZjljZGU1NDkwZg==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ ZjBhNGFmOGU2ODk3Y2ExOGU4NmU1NjdlNWFhMWZlZjU1NjM3YWJjMTQwN2Q1
10
+ MGU5ODg3NTIwMTk2OTU5ZTQ2ZmRhMDQyMmE2MWRlM2VhM2RjMGI3NmEyNzFl
11
+ Y2M3MDdlMDVhOTEwZjIzYWY0ZTM3YjUyMzJmYWM0NjU3NWIwZTQ=
12
+ data.tar.gz: !binary |-
13
+ YmUyZjcwYzMxMDhlYWMxZWIzNjA0NWU3MGQxMTY0YjE5ODc1MTVmZTA1NTQ2
14
+ YzY1ODc4Nzg1Mzk4MDRmYjQxMmZhNDIwNWFmNzhiODgyOGVjNGIwY2NjOGZi
15
+ Mjc5YjdmOWI4NjgzMzZjOGUwMTQ1MjI3MDBjNWFkNmYzMjQ1NmQ=
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,3 @@
1
+ --color
2
+ --fail-fast
3
+ --order random
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'yard'
4
+
5
+ group :development do
6
+ gem 'pry'
7
+ gem 'pry-debugger', :platforms => :mri_19
8
+ end
9
+
10
+ group :test do
11
+ gem 'coveralls', :require => false
12
+ gem 'rspec', '>= 2.13'
13
+ gem 'simplecov', :require => false
14
+ gem 'webmock'
15
+ end
16
+
17
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Igor Varavko
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,25 @@
1
+ # Hh
2
+
3
+ A Ruby interface to the HeadHanter
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'hh'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install hh
18
+
19
+ ## Contributing
20
+
21
+ 1. Fork it
22
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
23
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
24
+ 4. Push to the branch (`git push origin my-new-feature`)
25
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :test => :spec
8
+ task :default => :spec
9
+
10
+ require 'yard'
11
+ YARD::Rake::YardocTask.new
data/hh.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'hh/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'hh'
8
+ spec.version = HH::VERSION
9
+ spec.authors = ['Igor Varavko']
10
+ spec.email = ['ivaravko@me.com']
11
+ spec.description = %q{A Ruby interface to the HeadHanter.}
12
+ spec.summary = spec.description
13
+ spec.homepage = 'http://ivaravko.github.com/hh/'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files += `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.3'
22
+ spec.add_development_dependency 'rake'
23
+ spec.add_development_dependency 'rspec', '~> 2.13'
24
+ spec.add_dependency 'faraday', ['~> 0.8', '< 0.10']
25
+ spec.add_dependency 'faraday_middleware', ['~>0.9', '< 0.11']
26
+ end
@@ -0,0 +1,20 @@
1
+ module HH
2
+ module API
3
+ module Metro
4
+ def metro
5
+ response = connection.get("metro")
6
+ response.body
7
+ end
8
+
9
+ def metro_line(line_id)
10
+ response = connection.get("metro/#{line_id}")
11
+ response.body
12
+ end
13
+
14
+ def metro_station(station_id, line_id)
15
+ response = connection.get("metro/#{station_id},#{line_id}")
16
+ response.body
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,15 @@
1
+ module HH
2
+ module API
3
+ module Specialization
4
+ def specializations
5
+ response = connection.get("specialization/all/")
6
+ response.body
7
+ end
8
+
9
+ def specialization(specialization_id)
10
+ response = connection.get("specialization/#{specialization_id}")
11
+ response.body
12
+ end
13
+ end
14
+ end
15
+ end
data/lib/hh/api.rb ADDED
@@ -0,0 +1,9 @@
1
+ module HH
2
+ module API
3
+
4
+ API_URL = "https://api.hh.ru/1/json/"
5
+
6
+ include Specialization
7
+ include Metro
8
+ end
9
+ end
data/lib/hh/client.rb ADDED
@@ -0,0 +1,24 @@
1
+ module HH
2
+ class Client
3
+ include API
4
+
5
+ DEFAULT_MIDDLEWARE = Proc.new do |conn|
6
+ conn.request :json
7
+ conn.response :json
8
+ conn.adapter Faraday.default_adapter
9
+ end
10
+
11
+ def connection
12
+ @connection ||= Faraday::Connection.new(:url => API_URL, :headers => default_headers, &DEFAULT_MIDDLEWARE)
13
+ end
14
+
15
+ private
16
+
17
+ def default_headers
18
+ headers = {
19
+ :accept => 'application/json',
20
+ :user_agent => "Ruby gem HH version #{HH::VERSION}"
21
+ }
22
+ end
23
+ end
24
+ end
data/lib/hh/version.rb ADDED
@@ -0,0 +1,3 @@
1
+ module HH
2
+ VERSION = "0.0.1"
3
+ end
data/lib/hh.rb ADDED
@@ -0,0 +1,21 @@
1
+ require 'hh/version'
2
+ require 'faraday'
3
+ require 'faraday_middleware'
4
+
5
+ module HH
6
+ class << self
7
+
8
+ # Alias for Hh::Client.new
9
+ #
10
+ # @return [Hh::Client]
11
+
12
+ def client
13
+ HH::Client.new
14
+ end
15
+ end
16
+ end
17
+
18
+ require 'hh/API/specialization'
19
+ require 'hh/API/metro'
20
+ require 'hh/api'
21
+ require 'hh/client'
@@ -0,0 +1 @@
1
+ [{"id":"8","name":"Калининская","shortname":"КЛ","color":"#d5b400","stations":[{"id":"189","name":"Новокосино","lng":"37.864052","lat":"55.745113"},{"id":"88","name":"Новогиреево","lng":"37.814587","lat":"55.752237"},{"id":"107","name":"Перово","lng":"37.784220","lat":"55.750980"},{"id":"158","name":"Шоссе энтузиастов","lng":"37.751703","lat":"55.758090"},{"id":"1","name":"Авиамоторная","lng":"37.717444","lat":"55.751933"},{"id":"112","name":"Площадь Ильича","lng":"37.680726","lat":"55.747115"},{"id":"78","name":"Марксистская","lng":"37.656040","lat":"55.740746"},{"id":"91","name":"Третьяковская","lng":"37.629102","lat":"55.741193"}]}]
@@ -0,0 +1 @@
1
+ {"id":"6","name":"Калужско-Рижская","shortname":"КРЛ","color":"#F60","stations":[{"id":"81","name":"Медведково","lng":"37.661562","lat":"55.888103"},{"id":"144","name":"Тургеневская","lng":"37.636732","lat":"55.765371"},{"id":"50","name":"Китай-город","lng":"37.635003","lat":"55.754065"},{"id":"90","name":"Третьяковская","lng":"37.625624","lat":"55.740730"},{"id":"94","name":"Октябрьская","lng":"37.612851","lat":"55.731232"},{"id":"157","name":"Шаболовская","lng":"37.607892","lat":"55.718828"},{"id":"74","name":"Ленинский проспект","lng":"37.584990","lat":"55.706780"},{"id":"3","name":"Академическая","lng":"37.572300","lat":"55.687147"},{"id":"121","name":"Профсоюзная","lng":"37.563383","lat":"55.678822"},{"id":"92","name":"Новые Черемушки","lng":"37.555732","lat":"55.670952"},{"id":"41","name":"Калужская","lng":"37.540957","lat":"55.658147"},{"id":"13","name":"Бабушкинская","lng":"37.664341","lat":"55.870641"},{"id":"21","name":"Беляево","lng":"37.526585","lat":"55.643689"},{"id":"56","name":"Коньково","lng":"37.519156","lat":"55.631857"},{"id":"140","name":"Теплый Стан","lng":"37.508010","lat":"55.617381"},{"id":"164","name":"Ясенево","lng":"37.534815","lat":"55.605448"},{"id":"23","name":"Новоясеневская","lng":"37.553017","lat":"55.601947"},{"id":"129","name":"Свиблово","lng":"37.654418","lat":"55.855737"},{"id":"24","name":"Ботанический сад","lng":"37.640317","lat":"55.846073"},{"id":"27","name":"ВДНХ","lng":"37.640751","lat":"55.819626"},{"id":"8","name":"Алексеевская","lng":"37.638699","lat":"55.807794"},{"id":"126","name":"Рижская","lng":"37.636114","lat":"55.792494"},{"id":"120","name":"Проспект Мира","lng":"37.633199","lat":"55.781827"},{"id":"137","name":"Сухаревская","lng":"37.632850","lat":"55.772315"}]}
@@ -0,0 +1 @@
1
+ {"id":"6","name":"Калужско-Рижская","shortname":"КРЛ","color":"#F60","station":{"id":"8","name":"Алексеевская","lng":"37.638699","lat":"55.807794"}}
@@ -0,0 +1,53 @@
1
+ #encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe HH::API::Metro do
5
+
6
+ let(:client) { HH::Client.new }
7
+
8
+ describe "#metro" do
9
+ before do
10
+ stub_get("metro").to_return(body: fixture("metro.json"), headers: {content_type: "application/json; charset=utf-8"})
11
+ end
12
+ it "requests the correct resource" do
13
+ client.metro
14
+ expect(a_get("metro")).to have_been_made
15
+ end
16
+ it "returns the requested metro list" do
17
+ metro = client.metro
18
+ expect(metro).to be_an Array
19
+ expect(metro.first).to be_an Hash
20
+ expect(metro.first["name"]).to eq "Калининская"
21
+ end
22
+ end
23
+
24
+ describe "metro_line" do
25
+ before do
26
+ stub_get("metro/6").to_return(body: fixture("metro_line.json"), headers: {content_type: "application/json; charset=utf-8"})
27
+ end
28
+ it "requested line the correct resource" do
29
+ client.metro_line(6)
30
+ expect(a_get("metro/6")).to have_been_made
31
+ end
32
+ it "returns the requested metro line" do
33
+ metro_line = client.metro_line(6)
34
+ expect(metro_line).to be_an Hash
35
+ expect(metro_line["id"]) == 6
36
+ end
37
+ end
38
+
39
+ describe "metro_station" do
40
+ before do
41
+ stub_get("metro/6,8").to_return(body: fixture("metro_station.json"), headers: {content_type: "application/json; charset=utf-8"})
42
+ end
43
+ it "requested station the correct resource" do
44
+ client.metro_station(6, 8)
45
+ expect(a_get("metro/6,8")).to have_been_made
46
+ end
47
+ it "returns the requested metro station" do
48
+ metro_station = client.metro_station(6, 8)
49
+ expect(metro_station).to be_an Hash
50
+ expect(metro_station["name"]).to eq "Калужско-Рижская"
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe HH::Client do
4
+ let(:connection) { HH::Client.new.connection }
5
+
6
+ describe "DEFAULT_MIDDLEWARE" do
7
+ it "connection use FaradayMiddleware::EncodeJson" do
8
+ expect(connection.inspect).to include('FaradayMiddleware::EncodeJson')
9
+ end
10
+ it "response parse by ParseJson" do
11
+ expect(connection.inspect).to include('FaradayMiddleware::ParseJson')
12
+ end
13
+ it "default adapter is NetHttp" do
14
+ expect(connection.inspect).to include('Faraday::Adapter::NetHttp')
15
+ end
16
+ end
17
+ end
data/spec/hh_spec.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe HH do
4
+ describe ".client" do
5
+ it "returns a HH::Client" do
6
+ expect(HH.client).to be_a HH::Client
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,38 @@
1
+ #encoding: utf-8
2
+ require 'simplecov'
3
+ require 'coveralls'
4
+
5
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
6
+ SimpleCov::Formatter::HTMLFormatter,
7
+ Coveralls::SimpleCov::Formatter
8
+ ]
9
+
10
+ SimpleCov.start
11
+
12
+ require 'hh'
13
+ require 'rspec'
14
+ require 'webmock/rspec'
15
+
16
+ WebMock.disable_net_connect!(:allow => 'coveralls.io')
17
+
18
+ RSpec.configure do |config|
19
+ config.expect_with :rspec do |c|
20
+ c.syntax = :expect
21
+ end
22
+ end
23
+
24
+ def a_get(path)
25
+ a_request(:get, HH::API::API_URL + path)
26
+ end
27
+
28
+ def stub_get(path)
29
+ stub_request(:get, HH::API::API_URL + path)
30
+ end
31
+
32
+ def fixture_path
33
+ File.expand_path("../fixtures", __FILE__)
34
+ end
35
+
36
+ def fixture(file)
37
+ File.new(fixture_path + '/' + file)
38
+ end
metadata ADDED
@@ -0,0 +1,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hh
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Igor Varavko
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-03-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '2.13'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '2.13'
55
+ - !ruby/object:Gem::Dependency
56
+ name: faraday
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '0.8'
62
+ - - <
63
+ - !ruby/object:Gem::Version
64
+ version: '0.10'
65
+ type: :runtime
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ~>
70
+ - !ruby/object:Gem::Version
71
+ version: '0.8'
72
+ - - <
73
+ - !ruby/object:Gem::Version
74
+ version: '0.10'
75
+ - !ruby/object:Gem::Dependency
76
+ name: faraday_middleware
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ~>
80
+ - !ruby/object:Gem::Version
81
+ version: '0.9'
82
+ - - <
83
+ - !ruby/object:Gem::Version
84
+ version: '0.11'
85
+ type: :runtime
86
+ prerelease: false
87
+ version_requirements: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ~>
90
+ - !ruby/object:Gem::Version
91
+ version: '0.9'
92
+ - - <
93
+ - !ruby/object:Gem::Version
94
+ version: '0.11'
95
+ description: A Ruby interface to the HeadHanter.
96
+ email:
97
+ - ivaravko@me.com
98
+ executables: []
99
+ extensions: []
100
+ extra_rdoc_files: []
101
+ files:
102
+ - .gitignore
103
+ - .rspec
104
+ - .travis.yml
105
+ - Gemfile
106
+ - LICENSE.txt
107
+ - README.md
108
+ - Rakefile
109
+ - hh.gemspec
110
+ - lib/hh.rb
111
+ - lib/hh/API/metro.rb
112
+ - lib/hh/API/specialization.rb
113
+ - lib/hh/api.rb
114
+ - lib/hh/client.rb
115
+ - lib/hh/version.rb
116
+ - spec/fixtures/metro.json
117
+ - spec/fixtures/metro_line.json
118
+ - spec/fixtures/metro_station.json
119
+ - spec/hh/api/metro_spec.rb
120
+ - spec/hh/client_spec.rb
121
+ - spec/hh_spec.rb
122
+ - spec/spec_helper.rb
123
+ homepage: http://ivaravko.github.com/hh/
124
+ licenses:
125
+ - MIT
126
+ metadata: {}
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ! '>='
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ! '>='
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ requirements: []
142
+ rubyforge_project:
143
+ rubygems_version: 2.0.3
144
+ signing_key:
145
+ specification_version: 4
146
+ summary: A Ruby interface to the HeadHanter.
147
+ test_files:
148
+ - spec/fixtures/metro.json
149
+ - spec/fixtures/metro_line.json
150
+ - spec/fixtures/metro_station.json
151
+ - spec/hh/api/metro_spec.rb
152
+ - spec/hh/client_spec.rb
153
+ - spec/hh_spec.rb
154
+ - spec/spec_helper.rb
155
+ has_rdoc: