hh 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MmI5ZDVjMGJjMGViNDhmM2E2Yjc0YThlZGFlMzdhNGZjYTZmY2EyYQ==
4
+ MTc1ZmIzMGU0M2NiNzdkNzJiYzBkNWQ4NTI1MTFmNjBjM2IzODAxYw==
5
5
  data.tar.gz: !binary |-
6
- Nzc4NDQ4MDllZWVhODg0MmJkNjRkMDQyMzIyN2NlMzIzNzY1OTI2NA==
6
+ MzgyOTBkMTJhY2QzODVkN2RiY2JlMzZhYzkzOTAwM2Q0NTE3YTE0OQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- MTZlYjI3N2Y0OGM1ZjYxZDBkMjcwZTAzNjA5MGUzMGU2OTg5N2MxMDNiNjY5
10
- ZDk0YTM3ZjgzYmI3ZDA1MzE4M2ZjZjk0YjY0NDQzYWZhMjAzY2M5YjM5NTA4
11
- NTMxOTMzZWVlMmQ4NDU4N2U3MDI5Y2Y2YjVhODg1ZWE1M2Q0NWQ=
9
+ MDE1ZThkNjYwZTg0Njg0MTE1YWZlOTE2MmQ2ZjVkMzQ2NWVhYmZjZDRiYjYy
10
+ Nzc3ZTg2NjZlMDA3OTczN2YxYmUwMGJhNDNkMGEyNTdjYWI0NzFjYzdlNWYw
11
+ MTgwMWRmYTU4ZTI3MGJmNGUyMzY4MTA2ZmViYzg1MDJkNDg4OGY=
12
12
  data.tar.gz: !binary |-
13
- YjRkODkzOWIxNGVjYzU5M2JkYWY0ZjM4ODVhN2JlYzcwYjc5Y2UwMDYxOTVi
14
- NTcwNmI3NGI0OTYwOGI1MTdkYjdmNzg5MTQyYTc5ZTQ4ODM3MzQ4ZGZkMzJh
15
- ZGQxNTkyOTE0MmMxNGJkMDYxNDUwMTBkMWY3M2ExNzExYzk4MWU=
13
+ ODM1MDkzNWYwYjgzMTJkZWMwNGY4ZjZhZjFlMjE3ODlkMTM2Y2ZjMGE1M2Ix
14
+ NWMzYzliYzNiM2JiN2Y2MmZmMzY1OWU3NjdmMzMxNmI1MGIwYmIzNjE2OTA3
15
+ ZDcxNTM3NzE5YWEwNGU3ZTE3MDBkMjk2YTYzMmI3YjZiNWQ4NTg=
@@ -1,4 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
+ - rbx-19mode
4
+ - 1.9.2
3
5
  - 1.9.3
4
6
  - 2.0.0
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/hh.png)](http://badge.fury.io/rb/hh)
4
4
  [![Build Status](https://travis-ci.org/ivaravko/hh.png?branch=master)](https://travis-ci.org/ivaravko/hh)
5
+ [![Dependency Status](https://gemnasium.com/ivaravko/hh.png)](https://gemnasium.com/ivaravko/hh)
6
+ [![Coverage Status](https://coveralls.io/repos/ivaravko/hh/badge.png?branch=master)](https://coveralls.io/r/ivaravko/hh)
5
7
 
6
8
  A Ruby interface to the HeadHanter
7
9
 
data/lib/hh.rb CHANGED
@@ -1,3 +1,5 @@
1
+ #encoding: utf-8
2
+
1
3
  require 'hh/version'
2
4
  require 'faraday'
3
5
  require 'faraday_middleware'
@@ -1,3 +1,5 @@
1
+ #encoding: utf-8
2
+
1
3
  module HH
2
4
  module API
3
5
  module Specialization
@@ -1,3 +1,5 @@
1
+ #encoding: utf-8
2
+
1
3
  module HH
2
4
  module API
3
5
 
@@ -1,24 +1,61 @@
1
+ #encoding: utf-8
2
+
1
3
  module HH
2
4
  class Client
3
5
  include API
4
6
 
5
- DEFAULT_MIDDLEWARE = Proc.new do |conn|
6
- conn.request :json
7
- conn.response :json
8
- conn.adapter Faraday.default_adapter
7
+ # @param options [Hash]
8
+ def default_middleware(options={})
9
+ Proc.new do |conn|
10
+ conn.request :multipart
11
+ conn.adapter :net_http
12
+
13
+ if ENV['DEBUG']
14
+ conn.response :logger
15
+ else
16
+ conn.response :json
17
+ end
18
+ end
19
+ end
20
+
21
+ @stack = nil
22
+
23
+ # Exposes middleware builder to facilitate custom stacks
24
+ # @param options [Hash]
25
+ # @return [Faraday::Builder]
26
+ def stack(options={}, &block)
27
+ @stack ||= begin
28
+ if block_given?
29
+ Faraday::Builder.new(&block)
30
+ else
31
+ Faraday::Builder.new(&default_middleware(options))
32
+ end
33
+ end
9
34
  end
10
35
 
11
- def connection
12
- @connection ||= Faraday::Connection.new(:url => API_URL, :headers => default_headers, &DEFAULT_MIDDLEWARE)
36
+ # @param options [Hash]
37
+ # @return [Faraday::Connection]
38
+ def connection(options={})
39
+ conn_options = default_options(options)
40
+ puts "OPTIONS:#{conn_options.inspect}" if ENV['DEBUG']
41
+
42
+ @connection ||= Faraday.new(conn_options.merge(builder: stack(options)))
13
43
  end
14
44
 
15
45
  private
16
46
 
17
- def default_headers
18
- headers = {
19
- :accept => 'application/json',
20
- :user_agent => "Ruby gem HH version #{HH::VERSION}"
21
- }
47
+ # @param options [Hash]
48
+ # @return [Hash]
49
+ def default_options(options={})
50
+ {
51
+ headers: {
52
+ accept: "application/json;q=0.1",
53
+ accept_charset: "utf-8",
54
+ user_agent: "Ruby gem HH version #{HH::VERSION}",
55
+ content_type: "application/json"
56
+ },
57
+ url: API_URL
58
+ }.merge(options)
22
59
  end
23
60
  end
24
61
  end
@@ -1,3 +1,3 @@
1
1
  module HH
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -1,11 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe HH::Client do
4
- let(:connection) { HH::Client.new.connection }
4
+ let(:connection) { described_class.new.connection }
5
5
 
6
- describe "DEFAULT_MIDDLEWARE" do
7
- it "connection use FaradayMiddleware::EncodeJson" do
8
- expect(connection.inspect).to include('FaradayMiddleware::EncodeJson')
6
+ describe "default middleware" do
7
+ it "connection use Faraday::Request::Multipart" do
8
+ expect(connection.inspect).to include('Faraday::Request::Multipart')
9
9
  end
10
10
  it "response parse by ParseJson" do
11
11
  expect(connection.inspect).to include('FaradayMiddleware::ParseJson')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Varavko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-30 00:00:00.000000000 Z
11
+ date: 2013-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler