aitch 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 74de1f797705e033d093d57165a479c6b98f4586
4
- data.tar.gz: ccad13b73ffdc1e648c666cbbb6d8fad162e08c8
3
+ metadata.gz: de38868979f48b300cc6c7bcf89867eb5a6c763f
4
+ data.tar.gz: 44071a93ca9d00f5adb3f8324ae12421818ae63d
5
5
  SHA512:
6
- metadata.gz: 1849671f3d88abcee256d31d6200d7ce7831eebdc750fe272fdc75023faf20bfd048cc7cb5e32edf9a8c064abc3037f50f49f1f95b4b971cf0f18c86c44b5730
7
- data.tar.gz: e4eac1e14d9a4a6a998c26cd3d33b32e2d349db37ef39cde837208407f834ca938af125ca6974d77e95c48043a1ac6a58458c5313e4a0268e4823f81b9b185e7
6
+ metadata.gz: 21f5737e0c0ace3b19f464c54020194d3a7ba5debef88853e6c93248f7ae4845447d830f4852c3fcdcdee351f7afde456df37107dcf2bd309053bf98a9d7d21f
7
+ data.tar.gz: 6adb9a4df4c44b6ff700ba5e2e9f49fa42d65eed09cfd3800a462b947c1389f414bff7efb9409b88f3aa1abe173fb38c9d75f8c94a9c66879f7ddda685669423
@@ -2,6 +2,7 @@ language: ruby
2
2
  script: "bundle exec rspec"
3
3
 
4
4
  rvm:
5
+ - 2.1.2
5
6
  - 2.0.0
6
7
  - 1.9.3
7
8
  - jruby-19mode
data/Gemfile CHANGED
@@ -1,2 +1,4 @@
1
1
  source "https://rubygems.org"
2
2
  gemspec
3
+
4
+ gem "pry-meta", platforms: :ruby
@@ -1,69 +1,64 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- aitch (0.3.0)
4
+ aitch (0.4.0)
5
5
  activesupport
6
6
  nokogiri (>= 1.6.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activesupport (4.0.4)
11
+ activesupport (4.1.8)
12
12
  i18n (~> 0.6, >= 0.6.9)
13
- minitest (~> 4.2)
14
- multi_json (~> 1.3)
13
+ json (~> 1.7, >= 1.7.7)
14
+ minitest (~> 5.1)
15
15
  thread_safe (~> 0.1)
16
- tzinfo (~> 0.3.37)
17
- atomic (1.1.16)
16
+ tzinfo (~> 1.1)
18
17
  awesome_print (1.2.0)
19
18
  coderay (1.1.0)
20
- columnize (0.3.6)
21
- debugger (1.6.6)
22
- columnize (>= 0.3.1)
23
- debugger-linecache (~> 1.2.0)
24
- debugger-ruby_core_source (~> 1.3.2)
25
- debugger-linecache (1.2.0)
26
- debugger-ruby_core_source (1.3.2)
27
19
  diff-lcs (1.2.5)
28
20
  fakeweb (1.3.0)
29
- i18n (0.6.9)
21
+ i18n (0.6.11)
22
+ json (1.8.1)
30
23
  method_source (0.8.2)
31
- mini_portile (0.5.3)
32
- minitest (4.7.5)
33
- multi_json (1.9.2)
34
- nokogiri (1.6.1)
35
- mini_portile (~> 0.5.0)
36
- notifier (0.4.1)
37
- pry (0.9.12.6)
38
- coderay (~> 1.0)
39
- method_source (~> 0.8)
24
+ mini_portile (0.6.1)
25
+ minitest (5.5.0)
26
+ nokogiri (1.6.5)
27
+ mini_portile (~> 0.6.0)
28
+ notifier (0.5.0)
29
+ pry (0.10.1)
30
+ coderay (~> 1.1.0)
31
+ method_source (~> 0.8.1)
40
32
  slop (~> 3.4)
41
- pry-debugger (0.2.2)
42
- debugger (~> 1.3)
43
- pry (~> 0.9.10)
44
- pry-meta (0.0.6)
33
+ pry-meta (0.0.9)
45
34
  awesome_print
46
35
  pry
47
- pry-debugger
36
+ pry-nav
48
37
  pry-remote
38
+ pry-nav (0.2.4)
39
+ pry (>= 0.9.10, < 0.11.0)
49
40
  pry-remote (0.1.8)
50
41
  pry (~> 0.9)
51
42
  slop (~> 3.0)
52
- rake (10.2.2)
53
- rspec (2.14.1)
54
- rspec-core (~> 2.14.0)
55
- rspec-expectations (~> 2.14.0)
56
- rspec-mocks (~> 2.14.0)
57
- rspec-core (2.14.8)
58
- rspec-expectations (2.14.5)
59
- diff-lcs (>= 1.1.3, < 2.0)
60
- rspec-mocks (2.14.6)
61
- slop (3.5.0)
62
- test_notifier (1.0.1)
43
+ rake (10.4.2)
44
+ rspec (3.1.0)
45
+ rspec-core (~> 3.1.0)
46
+ rspec-expectations (~> 3.1.0)
47
+ rspec-mocks (~> 3.1.0)
48
+ rspec-core (3.1.7)
49
+ rspec-support (~> 3.1.0)
50
+ rspec-expectations (3.1.2)
51
+ diff-lcs (>= 1.2.0, < 2.0)
52
+ rspec-support (~> 3.1.0)
53
+ rspec-mocks (3.1.3)
54
+ rspec-support (~> 3.1.0)
55
+ rspec-support (3.1.2)
56
+ slop (3.6.0)
57
+ test_notifier (2.0.3)
63
58
  notifier
64
- thread_safe (0.3.1)
65
- atomic (>= 1.1.7, < 2)
66
- tzinfo (0.3.39)
59
+ thread_safe (0.3.4)
60
+ tzinfo (1.2.2)
61
+ thread_safe (~> 0.1)
67
62
 
68
63
  PLATFORMS
69
64
  ruby
data/README.md CHANGED
@@ -169,7 +169,7 @@ Setting basic auth credentials:
169
169
  ```ruby
170
170
  response = Aitch.get do
171
171
  url "http://restrict.example.org/"
172
- options: user: "john", password: "test"
172
+ options: {user: "john", password: "test"}
173
173
  end
174
174
  ```
175
175
 
@@ -24,7 +24,6 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency "bundler"
25
25
  spec.add_development_dependency "rake"
26
26
  spec.add_development_dependency "rspec"
27
- spec.add_development_dependency "pry-meta"
28
27
  spec.add_development_dependency "test_notifier"
29
28
  spec.add_development_dependency "fakeweb"
30
29
  end
@@ -7,12 +7,12 @@ module Aitch
7
7
  attr_accessor :options
8
8
 
9
9
  def initialize(options)
10
+ self.headers ||= {}
11
+ self.options ||= {}
12
+
10
13
  options.each do |name, value|
11
14
  public_send("#{name}=", value)
12
15
  end
13
-
14
- self.headers ||= {}
15
- self.options ||= {}
16
16
  end
17
17
 
18
18
  def perform
@@ -35,6 +35,14 @@ module Aitch
35
35
  raise RequestTimeoutError
36
36
  end
37
37
 
38
+ def content_type=(content_type)
39
+ headers['Content-Type'] = content_type
40
+ end
41
+
42
+ def content_type
43
+ headers['Content-Type']
44
+ end
45
+
38
46
  def request
39
47
  @request ||= http_method_class.new(uri.request_uri).tap do |request|
40
48
  set_body(request) if request.request_body_permitted?
@@ -65,13 +73,14 @@ module Aitch
65
73
 
66
74
  private
67
75
  def set_body(request)
76
+ body_data = data
68
77
  body_data = data.to_h if data.respond_to?(:to_h)
69
- body_data ||= data
78
+ body_data = options[:json_parser].dump(body_data) if content_type.to_s =~ /\bjson\b/
70
79
 
71
80
  if body_data.kind_of?(Hash)
72
81
  request.body = Utils.build_query(body_data)
73
82
  else
74
- request.body = data.to_s
83
+ request.body = body_data.to_s
75
84
  end
76
85
  end
77
86
 
@@ -1,3 +1,3 @@
1
1
  module Aitch
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -38,17 +38,14 @@ describe Aitch do
38
38
  options: options.merge(Aitch.config.to_h)
39
39
  }
40
40
 
41
- Aitch::Request
42
- .should_receive(:new)
43
- .with(expected)
44
- .and_return(request)
41
+ expect(Aitch::Request).to receive(:new).with(expected).and_return(request)
45
42
 
46
43
  Aitch.get("URL", "DATA", "HEADERS", options)
47
44
  end
48
45
 
49
46
  it "performs request" do
50
- Aitch::Request.stub new: request
51
- request.should_receive(:perform)
47
+ allow(Aitch::Request).to receive(:new).and_return(request)
48
+ expect(request).to receive(:perform)
52
49
 
53
50
  Aitch.get("URL")
54
51
  end
@@ -57,14 +54,14 @@ describe Aitch do
57
54
  describe "#execute!" do
58
55
  it "returns response when successful" do
59
56
  response = double(error?: false)
60
- Aitch::Request.any_instance.stub perform: response
57
+ allow_any_instance_of(Aitch::Request).to receive(:perform).and_return(response)
61
58
 
62
59
  expect(Aitch.get!("URL")).to eql(response)
63
60
  end
64
61
 
65
62
  it "raises when has errors" do
66
63
  response = double(error?: true, error: "ERROR")
67
- Aitch::Request.any_instance.stub perform: response
64
+ allow_any_instance_of(Aitch::Request).to receive(:perform).and_return(response)
68
65
 
69
66
  expect {
70
67
  Aitch.get!("URL")
@@ -2,10 +2,7 @@ require "spec_helper"
2
2
 
3
3
  describe Aitch::HTMLParser do
4
4
  it "instantiates Nokogiri" do
5
- Nokogiri
6
- .should_receive(:HTML)
7
- .with("HTML")
8
-
5
+ expect(Nokogiri).to receive(:HTML).with("HTML")
9
6
  Aitch::HTMLParser.load("HTML")
10
7
  end
11
8
  end
@@ -9,6 +9,11 @@ describe Aitch::Request do
9
9
  }.merge(options))
10
10
  end
11
11
 
12
+ it "sets content type" do
13
+ request = build_request(content_type: 'application/json')
14
+ expect(request.content_type).to eq('application/json')
15
+ end
16
+
12
17
  it "raises with invalid uri" do
13
18
  expect {
14
19
  build_request(url: "\\").uri
@@ -17,7 +22,7 @@ describe Aitch::Request do
17
22
 
18
23
  it "raises on timeout", ruby: 2.0 do
19
24
  request = build_request(request_method: "post", url: "http://example.org")
20
- request.stub_chain(:client, :request).and_raise(Net::ReadTimeout)
25
+ allow(request).to receive_message_chain(:client, :request).and_raise(Net::ReadTimeout)
21
26
 
22
27
  expect {
23
28
  request.perform
@@ -26,7 +31,7 @@ describe Aitch::Request do
26
31
 
27
32
  it "raises on timeout", ruby: 1.9 do
28
33
  request = build_request(request_method: "post", url: "http://example.org")
29
- request.stub_chain(:client, :request).and_raise(Timeout::Error)
34
+ allow(request).to receive_message_chain(:client, :request).and_raise(Timeout::Error)
30
35
 
31
36
  expect {
32
37
  request.perform
@@ -59,6 +64,17 @@ describe Aitch::Request do
59
64
  expect(request.body).to eql("some body")
60
65
  end
61
66
 
67
+ it "sets json body from object" do
68
+ request = build_request(
69
+ request_method: "post",
70
+ data: {a: 1},
71
+ content_type: "application/json",
72
+ options: {json_parser: JSON}
73
+ ).request
74
+
75
+ expect(request.body).to eql({a: 1}.to_json)
76
+ end
77
+
62
78
  it "sets request body from to_h protocol" do
63
79
  data = double(to_h: {a: 1})
64
80
  request = build_request(request_method: "post", data: data).request
@@ -110,7 +126,7 @@ describe Aitch::Request do
110
126
  subject(:client) { request.client }
111
127
 
112
128
  it "sets https" do
113
- expect(client.use_ssl?).to be_true
129
+ expect(client.use_ssl?).to be_truthy
114
130
  end
115
131
 
116
132
  it "sets verification mode" do
@@ -208,7 +208,7 @@ describe Aitch::Response do
208
208
  config = double
209
209
  http_response = double(code: code)
210
210
  response = Aitch::Response.new(config, http_response)
211
- expect(response.public_send("#{name}?")).to be_true
211
+ expect(response.public_send("#{name}?")).to be_truthy
212
212
  end
213
213
  end
214
214
  end
@@ -3,10 +3,7 @@ require "spec_helper"
3
3
 
4
4
  describe Aitch::XMLParser do
5
5
  it "instantiates Nokogiri" do
6
- Nokogiri
7
- .should_receive(:XML)
8
- .with("XML", nil, "utf-8")
9
-
6
+ expect(Nokogiri).to receive(:XML).with("XML", nil, "utf-8")
10
7
  Aitch::XMLParser.load("XML")
11
8
  end
12
9
 
@@ -13,4 +13,8 @@ RSpec.configure do |config|
13
13
  config.filter_run_excluding :ruby => -> version {
14
14
  !(RUBY_VERSION.to_s =~ /^#{version.to_s}/)
15
15
  }
16
+
17
+ config.expect_with :rspec do |c|
18
+ c.syntax = :expect
19
+ end
16
20
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aitch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-28 00:00:00.000000000 Z
11
+ date: 2014-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -80,20 +80,6 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: pry-meta
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
83
  - !ruby/object:Gem::Dependency
98
84
  name: test_notifier
99
85
  requirement: !ruby/object:Gem::Requirement