aitch 0.1.3 → 0.1.4

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: 784b17de50a0aa8ff0b9232c153aa67a30f0c713
4
- data.tar.gz: 96c2f060bb52b68d26a6040f19315ef7578a8a50
3
+ metadata.gz: 3dafc61f37b289947518c8879951025874155bf7
4
+ data.tar.gz: f684b8320ddd805a08e623f896bf53e146d199b0
5
5
  SHA512:
6
- metadata.gz: 3e264c4a316fb85601f6cf112ee1aab7d8f17140ed019d1096bf0045f1b3d7052b66a282f5365f9e9b474bfd928a23b1ca99c35e13faa5ea1478282fe7a071b3
7
- data.tar.gz: 0b70c3a814cb20dab65aaa4293506f596441618d95b4dc3c76a3e2d9a28a6f5f825bac8829191dc60bbb4316d7ce86851747249c7cb25519cf1b9b7ab2df4e0a
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
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_dependency "nokogiri"
22
+ spec.add_dependency "activesupport"
22
23
 
23
24
  spec.add_development_dependency "bundler"
24
25
  spec.add_development_dependency "rake"
@@ -3,6 +3,9 @@ require "forwardable"
3
3
  require "json"
4
4
  require "zlib"
5
5
 
6
+ require "nokogiri"
7
+ require "active_support/core_ext/object/to_query"
8
+
6
9
  require "aitch/utils"
7
10
  require "aitch/uri"
8
11
  require "aitch/namespace"
@@ -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
- request.form_data = data.to_h
67
- elsif data.kind_of?(Hash)
68
- request.form_data = data
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
@@ -7,5 +7,9 @@ module Aitch
7
7
 
8
8
  string.downcase
9
9
  end
10
+
11
+ def build_query(data)
12
+ data.to_query
13
+ end
10
14
  end
11
15
  end
@@ -1,3 +1,3 @@
1
1
  module Aitch
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -1,7 +1,7 @@
1
1
  module Aitch
2
2
  module XMLParser
3
3
  def self.load(source)
4
- Nokogiri::XML(source.to_s)
4
+ Nokogiri::XML(source.to_s, nil, "utf-8")
5
5
  end
6
6
  end
7
7
  end
@@ -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
@@ -0,0 +1,2 @@
1
+ <?xml version="1.0" encoding="ISO-8859-1"?>
2
+ <text>����������</text>
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.3
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-05-12 00:00:00.000000000 Z
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