aitch 0.1.3 → 0.1.4
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.
- checksums.yaml +4 -4
- data/README.md +10 -0
- data/aitch.gemspec +1 -0
- data/lib/aitch.rb +3 -0
- data/lib/aitch/request.rb +6 -4
- data/lib/aitch/utils.rb +4 -0
- data/lib/aitch/version.rb +1 -1
- data/lib/aitch/xml_parser.rb +1 -1
- data/spec/aitch/request_spec.rb +5 -0
- data/spec/aitch/xml_parser_spec.rb +9 -1
- data/spec/fixtures/iso8859-1.xml +2 -0
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3dafc61f37b289947518c8879951025874155bf7
|
4
|
+
data.tar.gz: f684b8320ddd805a08e623f896bf53e146d199b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 620b2fb8f76ec9982ffd0609f3add953466404d93ed4a385f60cfcfa7a9121ec0d1ff4873a58740d3a20c30247ea365dc94bc6243524e566f4147259581f3a16
|
7
|
+
data.tar.gz: c645b75d8bb7be5273313883a18b2ab8068a283a925c0b8b47f8c05de917e925beee19f5c3154cf0298a253351bde5fe9887a1e87417917e57965d8ab9cf68c5
|
data/README.md
CHANGED
@@ -148,6 +148,16 @@ Aitch.get("http://restrict.example.org/", {}, {}, user: "john", password: "test"
|
|
148
148
|
Aitch.get("http://example.org", {}, {"User-Agent" => "MyBot/1.0.0"})
|
149
149
|
```
|
150
150
|
|
151
|
+
The header value can be a callable object.
|
152
|
+
|
153
|
+
```ruby
|
154
|
+
Aitch.configure do |config|
|
155
|
+
config.default_headers = {
|
156
|
+
"Authorization" => -> { "Token token=#{ENV.fetch("API_TOKEN")}" }
|
157
|
+
}
|
158
|
+
end
|
159
|
+
```
|
160
|
+
|
151
161
|
### Creating namespaced requests
|
152
162
|
|
153
163
|
Sometimes you don't want to use the global settings (maybe you're building a
|
data/aitch.gemspec
CHANGED
data/lib/aitch.rb
CHANGED
data/lib/aitch/request.rb
CHANGED
@@ -62,10 +62,10 @@ module Aitch
|
|
62
62
|
|
63
63
|
private
|
64
64
|
def set_body(request)
|
65
|
-
if data.respond_to?(:to_h)
|
66
|
-
|
67
|
-
|
68
|
-
request.
|
65
|
+
body_data = data.to_h if data.respond_to?(:to_h)
|
66
|
+
|
67
|
+
if body_data.kind_of?(Hash)
|
68
|
+
request.body = Utils.build_query(body_data)
|
69
69
|
else
|
70
70
|
request.body = data.to_s
|
71
71
|
end
|
@@ -73,7 +73,9 @@ module Aitch
|
|
73
73
|
|
74
74
|
def set_headers(request)
|
75
75
|
all_headers = config.default_headers.merge(headers)
|
76
|
+
|
76
77
|
all_headers.each do |name, value|
|
78
|
+
value = value.respond_to?(:call) ? value.call : value
|
77
79
|
request[name.to_s] = value.to_s
|
78
80
|
end
|
79
81
|
end
|
data/lib/aitch/utils.rb
CHANGED
data/lib/aitch/version.rb
CHANGED
data/lib/aitch/xml_parser.rb
CHANGED
data/spec/aitch/request_spec.rb
CHANGED
@@ -92,6 +92,11 @@ describe Aitch::Request do
|
|
92
92
|
expect(request["HEADER"]).to eql("VALUE")
|
93
93
|
end
|
94
94
|
|
95
|
+
it "executes headers with callable protocol" do
|
96
|
+
request = build_request(headers: {"HEADER" => -> { "VALUE" }}).request
|
97
|
+
expect(request["HEADER"]).to eql("VALUE")
|
98
|
+
end
|
99
|
+
|
95
100
|
it "sets basic auth credentials" do
|
96
101
|
request = build_request(options: {user: "USER", password: "PASS"}).request
|
97
102
|
credentials = Base64.decode64(request["Authorization"].gsub(/Basic /, ""))
|
@@ -1,11 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
1
2
|
require "spec_helper"
|
2
3
|
|
3
4
|
describe Aitch::XMLParser do
|
4
5
|
it "instantiates Nokogiri" do
|
5
6
|
Nokogiri
|
6
7
|
.should_receive(:XML)
|
7
|
-
.with("XML")
|
8
|
+
.with("XML", nil, "utf-8")
|
8
9
|
|
9
10
|
Aitch::XMLParser.load("XML")
|
10
11
|
end
|
12
|
+
|
13
|
+
it "converts ISO-8859-1 to UTF-8" do
|
14
|
+
xml = Aitch::XMLParser.load(File.read("./spec/fixtures/iso8859-1.xml"))
|
15
|
+
|
16
|
+
expect(xml.encoding).to eql("utf-8")
|
17
|
+
expect(xml.to_xml).to include(%[<?xml version="1.0" encoding="utf-8"?>])
|
18
|
+
end
|
11
19
|
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.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nando Vieira
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-06-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -161,6 +175,7 @@ files:
|
|
161
175
|
- spec/aitch/uri_spec.rb
|
162
176
|
- spec/aitch/utils_spec.rb
|
163
177
|
- spec/aitch/xml_parser_spec.rb
|
178
|
+
- spec/fixtures/iso8859-1.xml
|
164
179
|
- spec/spec_helper.rb
|
165
180
|
homepage: http://rubygems.org/gems/aitch
|
166
181
|
licenses:
|
@@ -196,4 +211,5 @@ test_files:
|
|
196
211
|
- spec/aitch/uri_spec.rb
|
197
212
|
- spec/aitch/utils_spec.rb
|
198
213
|
- spec/aitch/xml_parser_spec.rb
|
214
|
+
- spec/fixtures/iso8859-1.xml
|
199
215
|
- spec/spec_helper.rb
|